diff --git a/internal/lsp/source/identifier.go b/internal/lsp/source/identifier.go index 918ec81665..2c5447bb19 100644 --- a/internal/lsp/source/identifier.go +++ b/internal/lsp/source/identifier.go @@ -282,7 +282,7 @@ func objToNode(ctx context.Context, view View, originPkg *types.Package, obj typ func importSpec(ctx context.Context, f GoFile, fAST *ast.File, pkg Package, pos token.Pos) (*IdentifierInfo, error) { var imp *ast.ImportSpec for _, spec := range fAST.Imports { - if spec.Pos() <= pos && pos < spec.End() { + if spec.Path.Pos() <= pos && pos < spec.Path.End() { imp = spec } } diff --git a/internal/lsp/testdata/godef/a/a.go.golden b/internal/lsp/testdata/godef/a/a.go.golden index 41ae66529b..0d2a49ca20 100644 --- a/internal/lsp/testdata/godef/a/a.go.golden +++ b/internal/lsp/testdata/godef/a/a.go.golden @@ -67,8 +67,8 @@ godef/a/a.go:14:6-9: defined here as var err error -- err-hover -- var err error --- string-hover -- -string -- make-hover -- The make built-in function allocates and initializes an object of type slice, map, or chan (only). func(t Type, size ...IntegerType) Type +-- string-hover -- +string diff --git a/internal/lsp/testdata/godef/a/f.go.golden b/internal/lsp/testdata/godef/a/f.go.golden index 45ba99575d..c7cb59afca 100644 --- a/internal/lsp/testdata/godef/a/f.go.golden +++ b/internal/lsp/testdata/godef/a/f.go.golden @@ -1,3 +1,27 @@ +-- switchStringY-definition -- +godef/a/f.go:8:9-10: defined here as var y string + +-- switchStringY-definition-json -- +{ + "span": { + "uri": "file://godef/a/f.go", + "start": { + "line": 8, + "column": 9, + "offset": 76 + }, + "end": { + "line": 8, + "column": 10, + "offset": 77 + } + }, + "description": "var y string" +} + + +-- switchStringY-hover -- +var y string -- switchY-definition -- godef/a/f.go:8:9-10: defined here as var y int @@ -22,27 +46,3 @@ godef/a/f.go:8:9-10: defined here as var y int -- switchY-hover -- var y int --- switchStringY-definition -- -godef/a/f.go:8:9-10: defined here as var y string - --- switchStringY-definition-json -- -{ - "span": { - "uri": "file://godef/a/f.go", - "start": { - "line": 8, - "column": 9, - "offset": 76 - }, - "end": { - "line": 8, - "column": 10, - "offset": 77 - } - }, - "description": "var y string" -} - - --- switchStringY-hover -- -var y string \ No newline at end of file diff --git a/internal/lsp/testdata/godef/b/b.go b/internal/lsp/testdata/godef/b/b.go index a881d1a6c6..0d756112a3 100644 --- a/internal/lsp/testdata/godef/b/b.go +++ b/internal/lsp/testdata/godef/b/b.go @@ -1,7 +1,7 @@ package b import ( - myFoo "golang.org/x/tools/internal/lsp/foo" //@godef("foo", PackageFoo),godef("myFoo", PackageFoo) + myFoo "golang.org/x/tools/internal/lsp/foo" //@mark(myFoo, "myFoo"),godef("foo", PackageFoo),godef("myFoo", myFoo) "golang.org/x/tools/internal/lsp/godef/a" //@mark(AImport, "\"") ) @@ -31,5 +31,5 @@ func Bar() { _ = x.F2 //@godef("F2", S2F2) _ = x.S2.F1 //@godef("F1", S2F1) - var _ *myFoo.StructFoo + var _ *myFoo.StructFoo //@godef("myFoo", myFoo) } diff --git a/internal/lsp/testdata/godef/b/b.go.golden b/internal/lsp/testdata/godef/b/b.go.golden index fb534d22c6..e3b0d1941d 100644 --- a/internal/lsp/testdata/godef/b/b.go.golden +++ b/internal/lsp/testdata/godef/b/b.go.golden @@ -66,7 +66,7 @@ foo/foo.go:1:9-12: defined here as } -- PackageFoo-hover -- -myFoo "golang.org/x/tools/internal/lsp/foo" //@godef("foo", PackageFoo),godef("myFoo", PackageFoo) +myFoo "golang.org/x/tools/internal/lsp/foo" //@mark(myFoo, "myFoo"),godef("foo", PackageFoo),godef("myFoo", myFoo) -- S1-definition -- godef/b/b.go:8:6-8: defined here as S1 struct { @@ -249,3 +249,5 @@ godef/a/a.go:9:6-11: defined here as func a.Stuff() -- Stuff-hover -- func a.Stuff() +-- myFoo-hover -- +package myFoo ("golang.org/x/tools/internal/lsp/foo") diff --git a/internal/lsp/tests/tests.go b/internal/lsp/tests/tests.go index 01b7d1169f..a79c1e3726 100644 --- a/internal/lsp/tests/tests.go +++ b/internal/lsp/tests/tests.go @@ -34,7 +34,7 @@ const ( ExpectedDiagnosticsCount = 21 ExpectedFormatCount = 6 ExpectedImportCount = 2 - ExpectedDefinitionsCount = 38 + ExpectedDefinitionsCount = 39 ExpectedTypeDefinitionsCount = 2 ExpectedHighlightsCount = 2 ExpectedReferencesCount = 5