Skip to content

Commit

Permalink
lsp: Skip textDocument/completion for ignored files (#953)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
charlieegan3 authored Jul 30, 2024
1 parent af89fef commit d070132
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d070132

Please sign in to comment.