44 "context"
55 "slices"
66 "strings"
7+ "sync"
78
89 "github.com/microsoft/typescript-go/internal/ast"
910 "github.com/microsoft/typescript-go/internal/astnav"
@@ -567,24 +568,78 @@ func (l *LanguageService) convertCallSiteGroupToIncomingCall(program *compiler.P
567568 }
568569}
569570
571+ type incomingEntry struct {
572+ ls * LanguageService
573+ node * ast.Node
574+
575+ sourceFileOnce sync.Once
576+ sourceFile * ast.SourceFile
577+
578+ documentUriOnce sync.Once
579+ documentUri lsproto.DocumentUri
580+
581+ positionOnce sync.Once
582+ position lsproto.Position
583+ }
584+
585+ var _ lsproto.HasTextDocumentPosition = (* incomingEntry )(nil )
586+
587+ func (d * incomingEntry ) getSourceFile () * ast.SourceFile {
588+ d .sourceFileOnce .Do (func () {
589+ d .sourceFile = ast .GetSourceFileOfNode (d .node )
590+ })
591+ return d .sourceFile
592+ }
593+
594+ func (d * incomingEntry ) TextDocumentURI () lsproto.DocumentUri {
595+ d .documentUriOnce .Do (func () {
596+ d .documentUri = lsconv .FileNameToDocumentURI (d .getSourceFile ().FileName ())
597+ })
598+ return d .documentUri
599+ }
600+
601+ func (d * incomingEntry ) TextDocumentPosition () lsproto.Position {
602+ d .positionOnce .Do (func () {
603+ start := scanner .GetTokenPosOfNode (d .node , d .getSourceFile (), false /*includeJsDoc*/ )
604+ d .position = d .ls .createLspPosition (start , d .getSourceFile ())
605+ })
606+ return d .position
607+ }
608+
570609// Gets the call sites that call into the provided call hierarchy declaration.
571- func (l * LanguageService ) getIncomingCalls (ctx context.Context , program * compiler.Program , declaration * ast.Node ) [] * lsproto.CallHierarchyIncomingCall {
610+ func (l * LanguageService ) getIncomingCalls (ctx context.Context , program * compiler.Program , declaration * ast.Node , orchestrator CrossProjectOrchestrator ) ( lsproto.CallHierarchyIncomingCallsResponse , error ) {
572611 // Source files and modules have no incoming calls.
573612 if ast .IsSourceFile (declaration ) || ast .IsModuleDeclaration (declaration ) || ast .IsClassStaticBlockDeclaration (declaration ) {
574- return nil
613+ return lsproto. CallHierarchyIncomingCallsOrNull {}, nil
575614 }
576615
577616 location := getCallHierarchyDeclarationReferenceNode (declaration )
578617 if location == nil {
579- return nil
618+ return lsproto. CallHierarchyIncomingCallsOrNull {}, nil
580619 }
581620
582- sourceFiles := program .GetSourceFiles ()
583- options := refOptions {use : referenceUseReferences }
584- symbolsAndEntries := l .getReferencedSymbolsForNode (ctx , 0 , location , program , sourceFiles , options , nil )
621+ incomingEntry := & incomingEntry {
622+ ls : l ,
623+ node : location ,
624+ }
625+
626+ return handleCrossProject (
627+ l ,
628+ ctx ,
629+ incomingEntry ,
630+ orchestrator ,
631+ (* LanguageService ).symbolAndEntriesToIncomingCalls ,
632+ combineIncomingCalls ,
633+ false ,
634+ false ,
635+ symbolEntryTransformOptions {},
636+ )
637+ }
585638
639+ func (l * LanguageService ) symbolAndEntriesToIncomingCalls (ctx context.Context , params * incomingEntry , data SymbolAndEntriesData , options symbolEntryTransformOptions ) (lsproto.CallHierarchyIncomingCallsResponse , error ) {
640+ program := l .GetProgram ()
586641 var refEntries []* ReferenceEntry
587- for _ , symbolAndEntry := range symbolsAndEntries {
642+ for _ , symbolAndEntry := range data . SymbolsAndEntries {
588643 refEntries = append (refEntries , symbolAndEntry .references ... )
589644 }
590645
@@ -596,7 +651,7 @@ func (l *LanguageService) getIncomingCalls(ctx context.Context, program *compile
596651 }
597652
598653 if len (callSites ) == 0 {
599- return nil
654+ return lsproto. CallHierarchyIncomingCallsOrNull {}, nil
600655 }
601656
602657 grouped := make (map [ast.NodeId ][]* callSite )
@@ -620,7 +675,7 @@ func (l *LanguageService) getIncomingCalls(ctx context.Context, program *compile
620675 return lsproto .CompareRanges (& a .FromRanges [0 ], & b .FromRanges [0 ])
621676 })
622677
623- return result
678+ return lsproto. CallHierarchyIncomingCallsOrNull { CallHierarchyIncomingCalls : & result }, nil
624679}
625680
626681type callSiteCollector struct {
@@ -947,6 +1002,7 @@ func (l *LanguageService) ProvidePrepareCallHierarchy(
9471002func (l * LanguageService ) ProvideCallHierarchyIncomingCalls (
9481003 ctx context.Context ,
9491004 item * lsproto.CallHierarchyItem ,
1005+ orchestrator CrossProjectOrchestrator ,
9501006) (lsproto.CallHierarchyIncomingCallsResponse , error ) {
9511007 program := l .GetProgram ()
9521008 fileName := item .Uri .FileName ()
@@ -986,11 +1042,7 @@ func (l *LanguageService) ProvideCallHierarchyIncomingCalls(
9861042 return lsproto.CallHierarchyIncomingCallsOrNull {}, nil
9871043 }
9881044
989- calls := l .getIncomingCalls (ctx , program , decl )
990- if calls == nil {
991- return lsproto.CallHierarchyIncomingCallsOrNull {}, nil
992- }
993- return lsproto.CallHierarchyIncomingCallsOrNull {CallHierarchyIncomingCalls : & calls }, nil
1045+ return l .getIncomingCalls (ctx , program , decl , orchestrator )
9941046}
9951047
9961048func (l * LanguageService ) ProvideCallHierarchyOutgoingCalls (
0 commit comments