1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 "golang.org/x/tools/internal/lsp/protocol"
11 "golang.org/x/tools/internal/lsp/source"
14 func (s *Server) definition(ctx context.Context, params *protocol.DefinitionParams) ([]protocol.Location, error) {
15 snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.Go)
20 ident, err := source.Identifier(ctx, snapshot, fh, params.Position)
25 var locations []protocol.Location
26 for _, ref := range ident.Declaration.MappedRange {
27 decRange, err := ref.Range()
32 locations = append(locations, protocol.Location{
33 URI: protocol.URIFromSpanURI(ref.URI()),
41 func (s *Server) typeDefinition(ctx context.Context, params *protocol.TypeDefinitionParams) ([]protocol.Location, error) {
42 snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.Go)
47 ident, err := source.Identifier(ctx, snapshot, fh, params.Position)
51 identRange, err := ident.Type.Range()
55 return []protocol.Location{
57 URI: protocol.URIFromSpanURI(ident.Type.URI()),