From d07013215903c6846361fcb29a77278f7582c3e8 Mon Sep 17 00:00:00 2001 From: Charlie Egan Date: Tue, 30 Jul 2024 14:17:32 +0100 Subject: [PATCH] lsp: Skip textDocument/completion for ignored files (#953) When files are ignored, they will have no file contents in the cache, and so completions are impossible. This leads to an error message which is now avoided by just returning an empty list. Fixes https://github.com/StyraInc/regal/issues/879 Signed-off-by: Charlie Egan --- internal/lsp/server.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/lsp/server.go b/internal/lsp/server.go index 31b637ce..feb27e6d 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -863,6 +863,15 @@ func (l *LanguageServer) handleTextDocumentCompletion( return nil, fmt.Errorf("failed to unmarshal params: %w", err) } + // when config ignores a file, then we return an empty completion list + // as a no-op. + if l.ignoreURI(params.TextDocument.URI) { + return types.CompletionList{ + IsIncomplete: false, + Items: []types.CompletionItem{}, + }, nil + } + // items is allocated here so that the return value is always a non-nil CompletionList items, err := l.completionsManager.Run(params, &providers.Options{ ClientIdentifier: l.clientIdentifier,