Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit e01bf53

Browse files
abhikeegancsmith
authored andcommitted
Adding an error check in handleHoverGodef (#340)
This commit adds an error check to avoid crash while accessing the result of typecheck when there is an error generated. Signed-off-by: Abhinandan Prativadi <aprativadi@fb.com>
1 parent 4a51fa2 commit e01bf53

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

langserver/hover.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,22 @@ func (h *LangHandler) handleHoverGodef(ctx context.Context, conn jsonrpc2.JSONRP
435435

436436
// Handle builtin objects with invalid locations.
437437
if loc.URI == "file://" {
438-
_, node, _, _, _, _, _ := h.typecheck(ctx, conn, params.TextDocument.URI, params.Position)
439-
438+
_, node, _, _, _, _, err := h.typecheck(ctx, conn, params.TextDocument.URI, params.Position)
439+
if err != nil {
440+
// Invalid nodes means we tried to click on something which is
441+
// not an ident (eg comment/string/etc). Return no information.
442+
if _, ok := err.(*invalidNodeError); ok {
443+
return nil, nil
444+
}
445+
// This is a common error we get in production when a user is
446+
// browsing a go pkg which only contains files we can't
447+
// analyse (usually due to build tags). To reduce signal of
448+
// actual bad errors, we return no error in this case.
449+
if _, ok := err.(*build.NoGoError); ok {
450+
return nil, nil
451+
}
452+
return nil, err
453+
}
440454
contents := builtinDoc(node.Name)
441455
return &lsp.Hover{
442456
Contents: contents,

0 commit comments

Comments
 (0)