fix(sshd_config): Do not show all completions when inside a match block

This commit is contained in:
Myzel394 2024-10-03 17:18:02 +02:00
parent 9cf1403bbd
commit 683be36a03
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185

View File

@ -7,6 +7,7 @@ import (
"config-lsp/handlers/sshd_config/ast"
"config-lsp/handlers/sshd_config/fields"
"config-lsp/utils"
"fmt"
protocol "github.com/tliron/glsp/protocol_3_16"
)
@ -16,6 +17,8 @@ func GetRootCompletions(
parentMatchBlock *ast.SSHDMatchBlock,
suggestValue bool,
) ([]protocol.CompletionItem, error) {
println("getting root completions and the parnet Match block eta:")
println(fmt.Sprintf("%v", parentMatchBlock))
kind := protocol.CompletionItemKindField
availableOptions := make(map[string]docvalues.DocumentationValue, 0)
@ -23,24 +26,22 @@ func GetRootCompletions(
for key, option := range fields.Options {
var exists = false
// Don't allow duplicates
if optionsMap, found := d.Indexes.AllOptionsPerName[key]; found {
if _, found := optionsMap[parentMatchBlock]; found {
exists = true
}
}
if !exists || utils.KeyExists(fields.AllowedDuplicateOptions, key) {
availableOptions[key] = option
}
}
// Remove all fields that are already present and are not allowed to be duplicated
for _, option := range d.Config.GetAllOptions() {
if _, found := fields.AllowedDuplicateOptions[option.Key.Key]; found {
if exists && !utils.KeyExists(fields.AllowedDuplicateOptions, key) {
continue
}
delete(availableOptions, option.Key.Key)
if parentMatchBlock != nil && !utils.KeyExists(fields.MatchAllowedOptions, key) {
continue
}
availableOptions[key] = option
}
return utils.MapMapToSlice(