Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tsc/internal/fourslash/tests/callHierarchyInterfaceMethod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ obj.foo();`
f.GoToMarker(t, "")
f.VerifyBaselineCallHierarchy(t)
}

func TestCallHierarchyOutgoingInterfaceMethod(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `interface G { m(): void; }
function /**/probe(g: G) { g.m(); }`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.GoToMarker(t, "")
f.VerifyBaselineCallHierarchy(t)
}
25 changes: 24 additions & 1 deletion tsc/internal/ls/callhierarchy.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ func (l *LanguageService) convertCallSiteGroupToIncomingCall(program *compiler.P
}

slices.SortFunc(fromRanges, lsproto.CompareRanges)
fromRanges = slices.Compact(fromRanges)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot for symmetry both sides should still have the Compact call.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored slices.Compact for outgoing ranges to match incoming handling. Focused tests and npx hereby validate pass. Commit: fe07e61.


return &lsproto.CallHierarchyIncomingCall{
From: from,
Expand Down Expand Up @@ -805,6 +806,25 @@ func (c *callSiteCollector) recordCallSite(node *ast.Node) {
}
}

func isCallSiteTarget(node *ast.Node) bool {
parent := node.Parent
if parent == nil {
return false
}

switch {
case ast.IsCallOrNewExpression(parent):
return parent.Expression() == node
case ast.IsTaggedTemplateExpression(parent):
return parent.AsTaggedTemplateExpression().Tag == node
case ast.IsDecorator(parent):
return parent.Expression() == node
case ast.IsJsxOpeningElement(parent), ast.IsJsxSelfClosingElement(parent):
return parent.TagName() == node
}
return false
}

func (c *callSiteCollector) collect(node *ast.Node) {
if node == nil {
return
Expand Down Expand Up @@ -882,7 +902,9 @@ func (c *callSiteCollector) collect(node *ast.Node) {
c.collect(node.Expression())
return
case ast.KindPropertyAccessExpression, ast.KindElementAccessExpression:
c.recordCallSite(node)
if !isCallSiteTarget(node) {
c.recordCallSite(node)
}
node.ForEachChild(func(child *ast.Node) bool {
c.collect(child)
return false
Expand Down Expand Up @@ -992,6 +1014,7 @@ func (l *LanguageService) convertCallSiteGroupToOutgoingCall(program *compiler.P
}

slices.SortFunc(fromRanges, lsproto.CompareRanges)
fromRanges = slices.Compact(fromRanges)

return &lsproto.CallHierarchyOutgoingCall{
To: to,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// === Call Hierarchy ===
╭ name: probe
├ kind: function
├ file: /callHierarchyOutgoingInterfaceMethod.ts
├ span:
│ ╭ /callHierarchyOutgoingInterfaceMethod.ts:2:1-2:32
│ │ 2: function probe(g: G) { g.m(); }
│ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ ╰
├ selectionSpan:
│ ╭ /callHierarchyOutgoingInterfaceMethod.ts:2:10-2:15
│ │ 2: function probe(g: G) { g.m(); }
│ │ ^^^^^
│ ╰
├ incoming: none
├ outgoing:
│ ╭ to:
│ │ ╭ name: m
│ │ ├ kind: method
│ │ ├ file: /callHierarchyOutgoingInterfaceMethod.ts
│ │ ├ span:
│ │ │ ╭ /callHierarchyOutgoingInterfaceMethod.ts:1:15-1:25
│ │ │ │ 1: interface G { m(): void; }
│ │ │ │ ^^^^^^^^^^
│ │ │ ╰
│ │ ├ selectionSpan:
│ │ │ ╭ /callHierarchyOutgoingInterfaceMethod.ts:1:15-1:16
│ │ │ │ 1: interface G { m(): void; }
│ │ │ │ ^
│ │ │ ╰
│ │ ╰ outgoing: none
│ ├ fromSpans:
│ │ ╭ /callHierarchyOutgoingInterfaceMethod.ts:2:24-2:27
│ │ │ 2: function probe(g: G) { g.m(); }
│ │ │ ^^^
╰ ╰ ╰