diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go index c1078d3f..73d614e3 100644 --- a/internal/lsp/lsp_test.go +++ b/internal/lsp/lsp_test.go @@ -423,7 +423,7 @@ func (d definitions) test(t *testing.T, s *server, typ bool) { locs, err = s.Definition(context.Background(), params) } if err != nil { - t.Fatal(err) + t.Fatalf("failed for %s: %v", src, err) } if len(locs) != 1 { t.Errorf("got %d locations for definition, expected 1", len(locs)) diff --git a/internal/lsp/source/definition.go b/internal/lsp/source/definition.go index 9d9ea173..27dc0d1a 100644 --- a/internal/lsp/source/definition.go +++ b/internal/lsp/source/definition.go @@ -42,7 +42,11 @@ func Identifier(ctx context.Context, v View, f File, pos token.Pos) (*Identifier // If the position is not an identifier but immediately follows // an identifier or selector period (as is common when // requesting a completion), use the path to the preceding node. - return identifier(ctx, v, f, pos-1) + result, err := identifier(ctx, v, f, pos-1) + if result == nil && err == nil { + err = fmt.Errorf("no identifier found") + } + return result, err } func (i *IdentifierInfo) Hover(q types.Qualifier) (string, error) {