1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:44:43 -07:00

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 golang/go#36598.

Change-Id: Ibdeaf9971aa5cb1f3244f6a888fe77bdf386e563
Reviewed-on: https://go-review.googlesource.com/c/tools/+/215057
Run-TryBot: Muir Manders <muir@mnd.rs>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Muir Manders 2020-01-16 08:45:02 -08:00 committed by Rebecca Stambler
parent 473961ec04
commit 0508ad4c83

View File

@ -41,6 +41,24 @@ func References(ctx context.Context, s Snapshot, f FileHandle, pp protocol.Posit
fset = s.View().Session().Cache().FileSet()
)
// Make sure declaration is the first item in the response.
if includeDeclaration {
rng, err := objToMappedRange(s.View(), qualifiedObjs[0].pkg, qualifiedObjs[0].obj)
if err != nil {
return nil, err
}
ident, _ := qualifiedObjs[0].node.(*ast.Ident)
references = append(references, &ReferenceInfo{
mappedRange: rng,
Name: qualifiedObjs[0].obj.Name(),
ident: ident,
obj: qualifiedObjs[0].obj,
pkg: qualifiedObjs[0].pkg,
isDeclaration: true,
})
}
for _, qo := range qualifiedObjs {
var searchPkgs []Package
@ -90,22 +108,5 @@ func References(ctx context.Context, s Snapshot, f FileHandle, pp protocol.Posit
}
}
if includeDeclaration {
rng, err := objToMappedRange(s.View(), qualifiedObjs[0].pkg, qualifiedObjs[0].obj)
if err != nil {
return nil, err
}
ident, _ := qualifiedObjs[0].node.(*ast.Ident)
references = append(references, &ReferenceInfo{
mappedRange: rng,
Name: qualifiedObjs[0].obj.Name(),
ident: ident,
obj: qualifiedObjs[0].obj,
pkg: qualifiedObjs[0].pkg,
isDeclaration: true,
})
}
return references, nil
}