mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
fix(sshd_config): Bugfixes
This commit is contained in:
parent
942e2477e2
commit
06182ddda7
@ -1,5 +1,5 @@
|
||||
package common
|
||||
|
||||
func CursorToCharacterIndex(cursor uint32) uint32 {
|
||||
return max(0, cursor-1)
|
||||
return max(1, cursor) - 1
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -18,17 +18,32 @@ 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
|
||||
for key, option := range fields.Options {
|
||||
if _, found := d.Indexes.AllOptionsPerName[key]; !found {
|
||||
availableOptions[key] = option
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for option := range fields.MatchAllowedOptions {
|
||||
if opt, found := fields.Options[option]; found {
|
||||
availableOptions[option] = opt
|
||||
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(
|
||||
availableOptions,
|
||||
|
@ -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]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user