fix(sshd_config): Bugfixes

This commit is contained in:
Myzel394 2024-09-18 00:13:43 +02:00
parent 942e2477e2
commit 06182ddda7
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
4 changed files with 47 additions and 9 deletions

View File

@ -1,5 +1,5 @@
package common
func CursorToCharacterIndex(cursor uint32) uint32 {
return max(0, cursor-1)
return max(1, cursor) - 1
}

View File

@ -64,3 +64,27 @@ func (c SSHDConfig) FindOption(line uint32) (*SSHDOption, *SSHDMatchBlock) {
return nil, nil
}
func (c SSHDConfig) GetAllOptions() []*SSHDOption {
options := make(
[]*SSHDOption,
0,
// Approximation, this does not need to be exact
c.Options.Size()+10,
)
for _, rawEntry := range c.Options.Values() {
switch entry := rawEntry.(type) {
case *SSHDOption:
options = append(options, entry)
case *SSHDMatchBlock:
options = append(options, entry.MatchEntry)
for _, rawOption := range entry.Options.Values() {
options = append(options, rawOption.(*SSHDOption))
}
}
}
return options
}

View File

@ -18,16 +18,31 @@ func GetRootCompletions(
) ([]protocol.CompletionItem, error) {
kind := protocol.CompletionItemKindField
availableOptions := make(map[string]docvalues.DocumentationValue)
availableOptions := make(map[string]docvalues.DocumentationValue, 0)
if parentMatchBlock == nil {
availableOptions = fields.Options
} else {
for option := range fields.MatchAllowedOptions {
if opt, found := fields.Options[option]; found {
availableOptions[option] = opt
for key, option := range fields.Options {
if _, found := d.Indexes.AllOptionsPerName[key]; !found {
availableOptions[key] = option
}
}
} else {
for key := range fields.MatchAllowedOptions {
if option, found := fields.Options[key]; found {
if _, found := d.Indexes.AllOptionsPerName[key]; !found {
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 {
continue
}
delete(availableOptions, option.Key.Key)
}
return utils.MapMapToSlice(

View File

@ -1,7 +1,6 @@
package lsp
import (
"config-lsp/common"
sshdconfig "config-lsp/handlers/sshd_config"
"config-lsp/handlers/sshd_config/handlers"
"regexp"
@ -14,7 +13,7 @@ var isEmptyPattern = regexp.MustCompile(`^\s*$`)
func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) {
line := params.Position.Line
cursor := common.CursorToCharacterIndex(params.Position.Character)
cursor := params.Position.Character
d := sshdconfig.DocumentParserMap[params.TextDocument.URI]