Skip to content

Commit d070132

Browse files
authoredJul 30, 2024··
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 #879 Signed-off-by: Charlie Egan <charlie@styra.com>
1 parent af89fef commit d070132

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
 

‎internal/lsp/server.go

+9
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,15 @@ func (l *LanguageServer) handleTextDocumentCompletion(
863863
return nil, fmt.Errorf("failed to unmarshal params: %w", err)
864864
}
865865

866+
// when config ignores a file, then we return an empty completion list
867+
// as a no-op.
868+
if l.ignoreURI(params.TextDocument.URI) {
869+
return types.CompletionList{
870+
IsIncomplete: false,
871+
Items: []types.CompletionItem{},
872+
}, nil
873+
}
874+
866875
// items is allocated here so that the return value is always a non-nil CompletionList
867876
items, err := l.completionsManager.Run(params, &providers.Options{
868877
ClientIdentifier: l.clientIdentifier,

0 commit comments

Comments
 (0)
Please sign in to comment.