From 22cbfb711c370bbbe027833551146a6cf9fa415f Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Thu, 12 Sep 2024 23:25:56 +0200 Subject: [PATCH] fix(sshd_config): Improve completions --- handlers/sshd_config/analyzer/analyzer.go | 10 ---------- handlers/sshd_config/lsp/text-document-completion.go | 7 ++++--- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/handlers/sshd_config/analyzer/analyzer.go b/handlers/sshd_config/analyzer/analyzer.go index 7f93902..3bee59b 100644 --- a/handlers/sshd_config/analyzer/analyzer.go +++ b/handlers/sshd_config/analyzer/analyzer.go @@ -13,16 +13,6 @@ func Analyze( d *sshdconfig.SSHDocument, ) []protocol.Diagnostic { 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 diff --git a/handlers/sshd_config/lsp/text-document-completion.go b/handlers/sshd_config/lsp/text-document-completion.go index f207837..db7fc30 100644 --- a/handlers/sshd_config/lsp/text-document-completion.go +++ b/handlers/sshd_config/lsp/text-document-completion.go @@ -10,7 +10,7 @@ import ( 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) { line := params.Position.Line @@ -28,11 +28,12 @@ func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionPa entry.Separator == nil || entry.Key == nil || (common.CursorToCharacterIndex(cursor)) <= entry.Key.End.Character { - // Empty line + return handlers.GetRootCompletions( d, matchBlock, - entry == nil || containsSeparatorPattern.Match([]byte(entry.Value)), + // Empty line, or currently typing a new key + entry == nil || isEmptyPattern.Match([]byte(entry.Value[cursor:])), ) }