From 0508ad4c83ab9b4ebb5d3e3b500dd135e399fd7e Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Thu, 16 Jan 2020 08:45:02 -0800 Subject: [PATCH] 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 Reviewed-by: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/source/references.go | 35 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/internal/lsp/source/references.go b/internal/lsp/source/references.go index 8db48ddda9a..ec2b31d2abe 100644 --- a/internal/lsp/source/references.go +++ b/internal/lsp/source/references.go @@ -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 }