Skip to content
Draft
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
3 changes: 2 additions & 1 deletion tsc/internal/fourslash/tests/callHierarchyFile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
func TestCallHierarchyFile(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `foo();
const content = `// @Filename: /src/callers.ts
foo();
function /**/foo() {
}`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
Expand Down
10 changes: 9 additions & 1 deletion tsc/internal/ls/callhierarchy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/microsoft/TypeScript/tsc/internal/printer"
"github.com/microsoft/TypeScript/tsc/internal/scanner"
"github.com/microsoft/TypeScript/tsc/internal/spanmap"
"github.com/microsoft/TypeScript/tsc/internal/tspath"
)

type CallHierarchyDeclaration = *ast.Node
Expand Down Expand Up @@ -161,7 +162,7 @@ func getSymbolOfCallHierarchyDeclaration(c *checker.Checker, node *ast.Node) *as
func getCallHierarchyItemName(program *compiler.Program, node *ast.Node) (text string, pos int, end int) {
if ast.IsSourceFile(node) {
sourceFile := node.AsSourceFile()
return sourceFile.FileName(), 0, 0
return tspath.GetBaseFileName(sourceFile.OriginalFileName()), 0, 0
}

if (ast.IsFunctionDeclaration(node) || ast.IsClassDeclaration(node)) && node.Name() == nil {
Expand Down Expand Up @@ -502,6 +503,13 @@ func (l *LanguageService) createCallHierarchyItem(program *compiler.Program, nod
sourceFile := ast.GetSourceFileOfNode(node)
nameText, namePos, nameEnd := getCallHierarchyItemName(program, node)
containerName := getCallHierarchyItemContainerName(program, node)
if ast.IsSourceFile(node) {
containerName = relativePathFromDirectory(
program.GetCurrentDirectory(),
tspath.GetDirectoryPath(sourceFile.OriginalFileName()),
l.UseCaseSensitiveFileNames(),
)
}

kind := getSymbolKindFromNode(node)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// === Call Hierarchy ===
╭ name: /main.ts
╭ name: main.ts
├ kind: file
├ file: /main.ts
├ span:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// === Call Hierarchy ===
╭ name: /main.ts
╭ name: main.ts
├ kind: file
├ file: /main.ts
├ span:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
│ │ │ ^^^
│ ╰ ╰
│ ╭ from:
│ │ ╭ name: /callHierarchyCallExpressionByConstNamedFunctionExpression.ts
│ │ ╭ name: callHierarchyCallExpressionByConstNamedFunctionExpression.ts
│ │ ├ kind: file
│ │ ├ file: /callHierarchyCallExpressionByConstNamedFunctionExpression.ts
│ │ ├ span:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// === Call Hierarchy ===
╭ name: /other.ts
╭ name: other.ts
├ kind: module
├ file: /other.ts
├ span:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
// === Call Hierarchy ===
╭ name: foo
├ kind: function
├ file: /callHierarchyFile.ts
├ file: /src/callers.ts
├ span:
│ ╭ /callHierarchyFile.ts:2:1-3:2
│ ╭ /src/callers.ts:2:1-3:2
│ │ 2: function foo() {
│ │ ^^^^^^^^^^^^^^^^
│ │ 3: }
│ │ ^
│ ╰
├ selectionSpan:
│ ╭ /callHierarchyFile.ts:2:10-2:13
│ ╭ /src/callers.ts:2:10-2:13
│ │ 2: function foo() {
│ │ ^^^
│ ╰
├ incoming:
│ ╭ from:
│ │ ╭ name: /callHierarchyFile.ts
│ │ ╭ name: callers.ts
│ │ ├ kind: file
│ │ ├ file: /callHierarchyFile.ts
│ │ ├ containerName: src
│ │ ├ file: /src/callers.ts
│ │ ├ span:
│ │ │ ╭ /callHierarchyFile.ts:1:1-3:2
│ │ │ ╭ /src/callers.ts:1:1-3:2
│ │ │ │ 1: foo();
│ │ │ │ ^^^^^^
│ │ │ │ 2: function foo() {
Expand All @@ -29,13 +30,13 @@
│ │ │ │ ^
│ │ │ ╰
│ │ ├ selectionSpan:
│ │ │ ╭ /callHierarchyFile.ts:1:1-1:1
│ │ │ ╭ /src/callers.ts:1:1-1:1
│ │ │ │ 1: foo();
│ │ │ │ <
│ │ │ ╰
│ │ ╰ incoming: none
│ ├ fromSpans:
│ │ ╭ /callHierarchyFile.ts:1:1-1:4
│ │ ╭ /src/callers.ts:1:1-1:4
│ │ │ 1: foo();
│ │ │ ^^^
│ ╰ ╰
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
│ ╰
├ incoming:
│ ╭ from:
│ │ ╭ name: /callHierarchyInterfaceMethod.ts
│ │ ╭ name: callHierarchyInterfaceMethod.ts
│ │ ├ kind: file
│ │ ├ file: /callHierarchyInterfaceMethod.ts
│ │ ├ span:
Expand Down