1
0
mirror of https://github.com/golang/go synced 2024-11-19 08:54:47 -07:00
go/internal/lsp/references.go
Rebecca Stambler eca45d481d internal/lsp: refactor references/rename/implementations
As part of investigating golang/go#38100, I noticed a few things that I
wanted to clean up. Mostly, for renames, we were calling
qualifiedObjAtProtocolPos twice, so I factored out a shared helper
function. I also added an error return for builtins so that callers
don't have to check.

Change-Id: I28c75c801cbec1611736af931cfa72befd219201
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225777
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-03-27 17:09:18 +00:00

36 lines
947 B
Go

// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package lsp
import (
"context"
"golang.org/x/tools/internal/lsp/protocol"
"golang.org/x/tools/internal/lsp/source"
)
func (s *Server) references(ctx context.Context, params *protocol.ReferenceParams) ([]protocol.Location, error) {
snapshot, fh, ok, err := s.beginFileRequest(params.TextDocument.URI, source.Go)
if !ok {
return nil, err
}
references, err := source.References(ctx, snapshot, fh, params.Position, params.Context.IncludeDeclaration)
if err != nil {
return nil, err
}
var locations []protocol.Location
for _, ref := range references {
refRange, err := ref.Range()
if err != nil {
return nil, err
}
locations = append(locations, protocol.Location{
URI: protocol.URIFromSpanURI(ref.URI()),
Range: refRange,
})
}
return locations, nil
}