golang.org/x/tools/gopls@v0.15.3/internal/server/references.go (about) 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. 4 5 package server 6 7 import ( 8 "context" 9 10 "golang.org/x/tools/gopls/internal/file" 11 "golang.org/x/tools/gopls/internal/golang" 12 "golang.org/x/tools/gopls/internal/protocol" 13 "golang.org/x/tools/gopls/internal/telemetry" 14 "golang.org/x/tools/gopls/internal/template" 15 "golang.org/x/tools/internal/event" 16 "golang.org/x/tools/internal/event/tag" 17 ) 18 19 func (s *server) References(ctx context.Context, params *protocol.ReferenceParams) (_ []protocol.Location, rerr error) { 20 recordLatency := telemetry.StartLatencyTimer("references") 21 defer func() { 22 recordLatency(ctx, rerr) 23 }() 24 25 ctx, done := event.Start(ctx, "lsp.Server.references", tag.URI.Of(params.TextDocument.URI)) 26 defer done() 27 28 fh, snapshot, release, err := s.fileOf(ctx, params.TextDocument.URI) 29 if err != nil { 30 return nil, err 31 } 32 defer release() 33 switch snapshot.FileKind(fh) { 34 case file.Tmpl: 35 return template.References(ctx, snapshot, fh, params) 36 case file.Go: 37 return golang.References(ctx, snapshot, fh, params.Position, params.Context.IncludeDeclaration) 38 } 39 return nil, nil // empty result 40 }