Skip to content

Commit

Permalink
lsp: Missing built-in data is not a hard error (#619)
Browse files Browse the repository at this point in the history
Now when built-in state is not known for a file,
the hover response is empty. This is commonly the case
when the file that has just been opened has failed to
parse and never parsed in the time that the server has
been running.

Signed-off-by: Charlie Egan <charlie@styra.com>
  • Loading branch information
charlieegan3 authored Apr 3, 2024
1 parent b5de824 commit 155d8f5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,12 @@ func (l *LanguageServer) handleHover(
}

builtinsOnLine, ok := l.cache.GetBuiltinPositions(params.TextDocument.URI)
// when no builtins are found, we can't return a useful hover response.
// log the error, but return an empty struct to avoid an error being shown in the client.
if !ok {
return struct{}{}, fmt.Errorf("could not get builtins for uri %q", params.TextDocument.URI)
l.logError(fmt.Errorf("could not get builtins for uri %q", params.TextDocument.URI))

return struct{}{}, nil
}

for _, bp := range builtinsOnLine[params.Position.Line+1] {
Expand Down

0 comments on commit 155d8f5

Please sign in to comment.