Skip to content

Commit 700ee26

Browse files
committed
internal/lsp: propagate errors from find references
We were ignoring errors in a few cases and returning incorrect errors in the case of the command-line interface (no identifier found when there were just no references). I think it is better for references to return an error than incomplete results. Change-Id: Id90bca58ebdd9f6a910853cb4ac5b6ab6bec57f8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/213817 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
1 parent dfcf570 commit 700ee26

File tree

3 files changed

+4
-20
lines changed

3 files changed

+4
-20
lines changed

internal/lsp/cmd/references.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ func (r *references) Run(ctx context.Context, args ...string) error {
7171
if err != nil {
7272
return err
7373
}
74-
if len(locations) == 0 {
75-
return tool.CommandLineErrorf("%v: not an identifier", from)
76-
}
77-
7874
var spans []string
7975
for _, l := range locations {
8076
f := conn.AddFile(ctx, span.NewURI(l.URI))

internal/lsp/references.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import (
99

1010
"golang.org/x/tools/internal/lsp/protocol"
1111
"golang.org/x/tools/internal/lsp/source"
12-
"golang.org/x/tools/internal/lsp/telemetry"
1312
"golang.org/x/tools/internal/span"
14-
"golang.org/x/tools/internal/telemetry/log"
15-
"golang.org/x/tools/internal/telemetry/tag"
1613
)
1714

1815
func (s *Server) references(ctx context.Context, params *protocol.ReferenceParams) ([]protocol.Location, error) {
@@ -44,19 +41,14 @@ func (s *Server) references(ctx context.Context, params *protocol.ReferenceParam
4441
for _, ph := range phs {
4542
ident, err := source.Identifier(ctx, snapshot, fh, params.Position, source.SpecificPackageHandle(ph.ID()))
4643
if err != nil {
47-
if err == source.ErrNoIdentFound {
48-
return nil, err
49-
}
50-
log.Error(ctx, "no identifier", err, telemetry.URI.Of(uri))
51-
continue
44+
return nil, err
5245
}
5346

5447
lastIdent = ident
5548

5649
references, err := ident.References(ctx)
5750
if err != nil {
58-
log.Error(ctx, "no references", err, tag.Of("Identifier", ident.Name))
59-
continue
51+
return nil, err
6052
}
6153

6254
for _, ref := range references {

internal/lsp/source/references.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"go/types"
1111

1212
"golang.org/x/tools/go/types/objectpath"
13-
"golang.org/x/tools/internal/lsp/telemetry"
14-
"golang.org/x/tools/internal/telemetry/log"
1513
"golang.org/x/tools/internal/telemetry/trace"
1614
errors "golang.org/x/xerrors"
1715
)
@@ -50,13 +48,11 @@ func (i *IdentifierInfo) References(ctx context.Context) ([]*ReferenceInfo, erro
5048
for _, id := range reverseDeps {
5149
ph, err := i.Snapshot.PackageHandle(ctx, id)
5250
if err != nil {
53-
log.Error(ctx, "References: no CheckPackageHandle", err, telemetry.Package.Of(id))
54-
continue
51+
return nil, err
5552
}
5653
pkg, err := ph.Check(ctx)
5754
if err != nil {
58-
log.Error(ctx, "References: no Package", err, telemetry.Package.Of(id))
59-
continue
55+
return nil, err
6056
}
6157
searchpkgs = append(searchpkgs, pkg)
6258
}

0 commit comments

Comments
 (0)