github.com/v2fly/tools@v0.100.0/internal/lsp/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 lsp
     6  
     7  import (
     8  	"context"
     9  
    10  	"github.com/v2fly/tools/internal/lsp/protocol"
    11  	"github.com/v2fly/tools/internal/lsp/source"
    12  )
    13  
    14  func (s *Server) prepareCallHierarchy(ctx context.Context, params *protocol.CallHierarchyPrepareParams) ([]protocol.CallHierarchyItem, error) {
    15  	snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.Go)
    16  	defer release()
    17  	if !ok {
    18  		return nil, err
    19  	}
    20  
    21  	return source.PrepareCallHierarchy(ctx, snapshot, fh, params.Position)
    22  }
    23  
    24  func (s *Server) incomingCalls(ctx context.Context, params *protocol.CallHierarchyIncomingCallsParams) ([]protocol.CallHierarchyIncomingCall, error) {
    25  	snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.Item.URI, source.Go)
    26  	defer release()
    27  	if !ok {
    28  		return nil, err
    29  	}
    30  
    31  	return source.IncomingCalls(ctx, snapshot, fh, params.Item.Range.Start)
    32  }
    33  
    34  func (s *Server) outgoingCalls(ctx context.Context, params *protocol.CallHierarchyOutgoingCallsParams) ([]protocol.CallHierarchyOutgoingCall, error) {
    35  	snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.Item.URI, source.Go)
    36  	defer release()
    37  	if !ok {
    38  		return nil, err
    39  	}
    40  
    41  	return source.OutgoingCalls(ctx, snapshot, fh, params.Item.Range.Start)
    42  }