feat(ssh_config): Add completions support

This commit is contained in:
Myzel394 2024-09-22 22:23:08 +02:00
parent 92b2f12e3f
commit a9e58a7f50
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
2 changed files with 47 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package handlers
import (
"config-lsp/common"
docvalues "config-lsp/doc-values"
sshconfig "config-lsp/handlers/ssh_config"
"config-lsp/handlers/ssh_config/ast"
@ -57,3 +58,41 @@ func GetRootCompletions(
},
), nil
}
func GetOptionCompletions(
d *sshconfig.SSHDocument,
entry *ast.SSHOption,
block ast.SSHBlock,
cursor common.CursorPosition,
) ([]protocol.CompletionItem, error) {
option, found := fields.Options[entry.Key.Key]
if !found {
return nil, nil
}
if entry.Key.Key == "Match" {
return nil, nil
// return getMatchCompletions(
// d,
// cursor,
// matchBlock.MatchValue,
// )
}
if entry.OptionValue == nil {
return option.FetchCompletions("", 0), nil
}
// Hello wo|rld
line := entry.OptionValue.Value.Raw
// NEW: docvalues index
return option.FetchCompletions(
line,
common.DeprecatedImprovedCursorToIndex(
cursor,
line,
entry.OptionValue.Start.Character,
),
), nil
}

View File

@ -37,14 +37,14 @@ func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionPa
)
}
// if option.Separator != nil && option.OptionValue.IsPositionAfterStart(cursor) {
// return handlers.GetOptionCompletions(
// d,
// entry,
// matchBlock,
// cursor,
// )
// }
if option.Separator != nil && option.OptionValue.IsPositionAfterStart(cursor) {
return handlers.GetOptionCompletions(
d,
option,
block,
cursor,
)
}
return nil, nil
}