Skip to content

Commit 0508ad4

Browse files
muirdmstamblerre
authored andcommitted
internal/lsp/source: return obj decl first in find-references
Restore previous behavior where the object's declaration is returned as the first reference in find-reference calls. Fixes #36598. Change-Id: Ibdeaf9971aa5cb1f3244f6a888fe77bdf386e563 Reviewed-on: https://go-review.googlesource.com/c/tools/+/215057 Run-TryBot: Muir Manders <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 473961e commit 0508ad4

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

internal/lsp/source/references.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ func References(ctx context.Context, s Snapshot, f FileHandle, pp protocol.Posit
4141
fset = s.View().Session().Cache().FileSet()
4242
)
4343

44+
// Make sure declaration is the first item in the response.
45+
if includeDeclaration {
46+
rng, err := objToMappedRange(s.View(), qualifiedObjs[0].pkg, qualifiedObjs[0].obj)
47+
if err != nil {
48+
return nil, err
49+
}
50+
51+
ident, _ := qualifiedObjs[0].node.(*ast.Ident)
52+
references = append(references, &ReferenceInfo{
53+
mappedRange: rng,
54+
Name: qualifiedObjs[0].obj.Name(),
55+
ident: ident,
56+
obj: qualifiedObjs[0].obj,
57+
pkg: qualifiedObjs[0].pkg,
58+
isDeclaration: true,
59+
})
60+
}
61+
4462
for _, qo := range qualifiedObjs {
4563
var searchPkgs []Package
4664

@@ -90,22 +108,5 @@ func References(ctx context.Context, s Snapshot, f FileHandle, pp protocol.Posit
90108
}
91109
}
92110

93-
if includeDeclaration {
94-
rng, err := objToMappedRange(s.View(), qualifiedObjs[0].pkg, qualifiedObjs[0].obj)
95-
if err != nil {
96-
return nil, err
97-
}
98-
99-
ident, _ := qualifiedObjs[0].node.(*ast.Ident)
100-
references = append(references, &ReferenceInfo{
101-
mappedRange: rng,
102-
Name: qualifiedObjs[0].obj.Name(),
103-
ident: ident,
104-
obj: qualifiedObjs[0].obj,
105-
pkg: qualifiedObjs[0].pkg,
106-
isDeclaration: true,
107-
})
108-
}
109-
110111
return references, nil
111112
}

0 commit comments

Comments
 (0)