golang.org/x/tools/gopls@v0.15.3/internal/server/call_hierarchy.go (about) 1 // Copyright 2020 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/internal/event" 14 ) 15 16 func (s *server) PrepareCallHierarchy(ctx context.Context, params *protocol.CallHierarchyPrepareParams) ([]protocol.CallHierarchyItem, error) { 17 ctx, done := event.Start(ctx, "lsp.Server.prepareCallHierarchy") 18 defer done() 19 20 fh, snapshot, release, err := s.fileOf(ctx, params.TextDocument.URI) 21 if err != nil { 22 return nil, err 23 } 24 defer release() 25 if snapshot.FileKind(fh) != file.Go { 26 return nil, nil // empty result 27 } 28 return golang.PrepareCallHierarchy(ctx, snapshot, fh, params.Position) 29 } 30 31 func (s *server) IncomingCalls(ctx context.Context, params *protocol.CallHierarchyIncomingCallsParams) ([]protocol.CallHierarchyIncomingCall, error) { 32 ctx, done := event.Start(ctx, "lsp.Server.incomingCalls") 33 defer done() 34 35 fh, snapshot, release, err := s.fileOf(ctx, params.Item.URI) 36 if err != nil { 37 return nil, err 38 } 39 defer release() 40 if snapshot.FileKind(fh) != file.Go { 41 return nil, nil // empty result 42 } 43 return golang.IncomingCalls(ctx, snapshot, fh, params.Item.Range.Start) 44 } 45 46 func (s *server) OutgoingCalls(ctx context.Context, params *protocol.CallHierarchyOutgoingCallsParams) ([]protocol.CallHierarchyOutgoingCall, error) { 47 ctx, done := event.Start(ctx, "lsp.Server.outgoingCalls") 48 defer done() 49 50 fh, snapshot, release, err := s.fileOf(ctx, params.Item.URI) 51 if err != nil { 52 return nil, err 53 } 54 defer release() 55 if snapshot.FileKind(fh) != file.Go { 56 return nil, nil // empty result 57 } 58 return golang.OutgoingCalls(ctx, snapshot, fh, params.Item.Range.Start) 59 }