fix(sshd_config): Improve completions

This commit is contained in:
Myzel394 2024-09-12 23:25:56 +02:00
parent 998c0740d1
commit 22cbfb711c
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
2 changed files with 4 additions and 13 deletions

View File

@ -13,16 +13,6 @@ func Analyze(
d *sshdconfig.SSHDocument, d *sshdconfig.SSHDocument,
) []protocol.Diagnostic { ) []protocol.Diagnostic {
errors := analyzeOptionsAreValid(d) errors := analyzeOptionsAreValid(d)
if len(errors) > 0 {
return utils.Map(
errors,
func(err common.LSPError) protocol.Diagnostic {
return err.ToDiagnostic()
},
)
}
indexes, indexErrors := indexes.CreateIndexes(*d.Config) indexes, indexErrors := indexes.CreateIndexes(*d.Config)
_ = indexes _ = indexes

View File

@ -10,7 +10,7 @@ import (
protocol "github.com/tliron/glsp/protocol_3_16" protocol "github.com/tliron/glsp/protocol_3_16"
) )
var containsSeparatorPattern = regexp.MustCompile(`\s+$`) var isEmptyPattern = regexp.MustCompile(`^\s*$`)
func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) { func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) {
line := params.Position.Line line := params.Position.Line
@ -28,11 +28,12 @@ func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionPa
entry.Separator == nil || entry.Separator == nil ||
entry.Key == nil || entry.Key == nil ||
(common.CursorToCharacterIndex(cursor)) <= entry.Key.End.Character { (common.CursorToCharacterIndex(cursor)) <= entry.Key.End.Character {
// Empty line
return handlers.GetRootCompletions( return handlers.GetRootCompletions(
d, d,
matchBlock, matchBlock,
entry == nil || containsSeparatorPattern.Match([]byte(entry.Value)), // Empty line, or currently typing a new key
entry == nil || isEmptyPattern.Match([]byte(entry.Value[cursor:])),
) )
} }