Skip to content

Commit 63a9e97

Browse files
authored
Implementations, CodeLens, IncomingCalls across projects (#2235)
1 parent bc8c332 commit 63a9e97

22 files changed

+2959
-440
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/testutil"
8+
)
9+
10+
func TestCallHierarchyAcrossProject(t *testing.T) {
11+
t.Parallel()
12+
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `
15+
// @stateBaseline: true
16+
// @Filename: /projects/temp/temp.ts
17+
/*temp*/let x = 10
18+
// @Filename: /projects/temp/tsconfig.json
19+
{}
20+
// @Filename: /projects/container/lib/tsconfig.json
21+
{
22+
"compilerOptions": {
23+
"composite": true,
24+
},
25+
references: [],
26+
files: [
27+
"index.ts",
28+
"bar.ts",
29+
"baz.ts"
30+
],
31+
}
32+
// @Filename: /projects/container/lib/index.ts
33+
export function /*call*/createModelReference() {}
34+
// @Filename: /projects/container/lib/bar.ts
35+
import { createModelReference } from "./index";
36+
function openElementsAtEditor() {
37+
createModelReference();
38+
}
39+
// @Filename: /projects/container/lib/baz.ts
40+
import { createModelReference } from "./index";
41+
function registerDefaultLanguageCommand() {
42+
createModelReference();
43+
}
44+
// @Filename: /projects/container/exec/tsconfig.json
45+
{
46+
"files": ["./index.ts"],
47+
"references": [
48+
{ "path": "../lib" },
49+
],
50+
}
51+
// @Filename: /projects/container/exec/index.ts
52+
import { createModelReference } from "../lib";
53+
function openElementsAtEditor1() {
54+
createModelReference();
55+
}
56+
// @Filename: /projects/container/compositeExec/tsconfig.json
57+
{
58+
"compilerOptions": {
59+
"composite": true,
60+
},
61+
"files": ["./index.ts"],
62+
"references": [
63+
{ "path": "../lib" },
64+
],
65+
}
66+
// @Filename: /projects/container/compositeExec/index.ts
67+
import { createModelReference } from "../lib";
68+
function openElementsAtEditor2() {
69+
createModelReference();
70+
}
71+
// @Filename: /projects/container/tsconfig.json
72+
{
73+
"files": [],
74+
"include": [],
75+
"references": [
76+
{ "path": "./exec" },
77+
{ "path": "./compositeExec" },
78+
],
79+
}
80+
// @Filename: /projects/container/tsconfig.json
81+
{
82+
"files": [],
83+
"include": [],
84+
"references": [
85+
{ "path": "./exec" },
86+
{ "path": "./compositeExec" },
87+
],
88+
}
89+
// @Filename: /projects/container/tsconfig.json
90+
{
91+
"files": [],
92+
"include": [],
93+
"references": [
94+
{ "path": "./exec" },
95+
{ "path": "./compositeExec" },
96+
],
97+
}`
98+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
99+
defer done()
100+
f.GoToMarker(t, "call")
101+
// Open temp file and verify all projects alive
102+
f.GoToMarker(t, "temp")
103+
104+
// Ref projects are loaded after as part of this command
105+
f.GoToMarker(t, "call")
106+
f.VerifyBaselineCallHierarchy(t)
107+
108+
// Open temp file and verify all projects alive
109+
f.CloseFileOfMarker(t, "temp")
110+
f.GoToMarker(t, "temp")
111+
112+
// Close all files and open temp file, only inferred project should be alive
113+
f.CloseFileOfMarker(t, "call")
114+
f.CloseFileOfMarker(t, "temp")
115+
f.GoToMarker(t, "temp")
116+
}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/ls/lsutil"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestCodeLensAcrossProjects(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
content := `
15+
// @stateBaseline: true
16+
// @Filename: /projects/temp/temp.ts
17+
/*temp*/let x = 10
18+
// @Filename: /projects/temp/tsconfig.json
19+
{}
20+
// @Filename: /projects/container/lib/tsconfig.json
21+
{
22+
"compilerOptions": {
23+
"composite": true,
24+
},
25+
references: [],
26+
files: [
27+
"index.ts",
28+
"bar.ts"
29+
],
30+
}
31+
// @Filename: /projects/container/lib/index.ts
32+
/*impl*/
33+
export interface Pointable {
34+
getX(): number;
35+
getY(): number;
36+
}
37+
export const val = 42;
38+
// @Filename: /projects/container/lib/bar.ts
39+
import { Pointable } from "./index";
40+
class Point implements Pointable {
41+
getX(): number {
42+
return 0;
43+
}
44+
getY(): number {
45+
return 0;
46+
}
47+
}
48+
// @Filename: /projects/container/exec/tsconfig.json
49+
{
50+
"files": ["./index.ts"],
51+
"references": [
52+
{ "path": "../lib" },
53+
],
54+
}
55+
// @Filename: /projects/container/exec/index.ts
56+
import { Pointable } from "../lib";
57+
class Point1 implements Pointable {
58+
getX(): number {
59+
return 0;
60+
}
61+
getY(): number {
62+
return 0;
63+
}
64+
}
65+
// @Filename: /projects/container/compositeExec/tsconfig.json
66+
{
67+
"compilerOptions": {
68+
"composite": true,
69+
},
70+
"files": ["./index.ts"],
71+
"references": [
72+
{ "path": "../lib" },
73+
],
74+
}
75+
// @Filename: /projects/container/compositeExec/index.ts
76+
import { Pointable } from "../lib";
77+
class Point2 implements Pointable {
78+
getX(): number {
79+
return 0;
80+
}
81+
getY(): number {
82+
return 0;
83+
}
84+
}
85+
// @Filename: /projects/container/tsconfig.json
86+
{
87+
"files": [],
88+
"include": [],
89+
"references": [
90+
{ "path": "./exec" },
91+
{ "path": "./compositeExec" },
92+
],
93+
}
94+
// @Filename: /projects/container/tsconfig.json
95+
{
96+
"files": [],
97+
"include": [],
98+
"references": [
99+
{ "path": "./exec" },
100+
{ "path": "./compositeExec" },
101+
],
102+
}
103+
// @Filename: /projects/container/tsconfig.json
104+
{
105+
"files": [],
106+
"include": [],
107+
"references": [
108+
{ "path": "./exec" },
109+
{ "path": "./compositeExec" },
110+
],
111+
}
112+
`
113+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
114+
defer done()
115+
f.GoToMarker(t, "impl")
116+
// Open temp file and verify all projects alive
117+
f.GoToMarker(t, "temp")
118+
119+
// Ref projects are loaded after as part of this command
120+
f.VerifyBaselineCodeLens(t, &lsutil.UserPreferences{
121+
CodeLens: lsutil.CodeLensUserPreferences{
122+
ReferencesCodeLensEnabled: true,
123+
ReferencesCodeLensShowOnAllFunctions: true,
124+
125+
ImplementationsCodeLensEnabled: true,
126+
ImplementationsCodeLensShowOnInterfaceMethods: true,
127+
ImplementationsCodeLensShowOnAllClassMethods: true,
128+
},
129+
})
130+
131+
// Open temp file and verify all projects alive
132+
f.CloseFileOfMarker(t, "temp")
133+
f.GoToMarker(t, "temp")
134+
135+
// Close all files and open temp file, only inferred project should be alive
136+
f.CloseFileOfMarker(t, "impl")
137+
f.CloseFileOfMarker(t, "temp")
138+
f.GoToMarker(t, "temp")
139+
}
140+
141+
func TestCodeLensOnFunctionAcrossProjects1(t *testing.T) {
142+
t.Parallel()
143+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
144+
const content = `
145+
// @filename: ./a/tsconfig.json
146+
{
147+
"compilerOptions": {
148+
"composite": true,
149+
"declaration": true,
150+
"declarationMaps": true,
151+
"outDir": "./dist",
152+
"rootDir": "src"
153+
},
154+
"include": ["./src"]
155+
}
156+
157+
// @filename: ./a/src/foo.ts
158+
export function aaa() {}
159+
aaa();
160+
161+
// @filename: ./b/tsconfig.json
162+
{
163+
"compilerOptions": {
164+
"composite": true,
165+
"declaration": true,
166+
"declarationMaps": true,
167+
"outDir": "./dist",
168+
"rootDir": "src"
169+
},
170+
"references": [{ "path": "../a" }],
171+
"include": ["./src"]
172+
}
173+
174+
// @filename: ./b/src/bar.ts
175+
import * as foo from '../../a/dist/foo.js';
176+
foo.aaa();
177+
`
178+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
179+
defer done()
180+
181+
f.VerifyBaselineCodeLens(t, &lsutil.UserPreferences{
182+
CodeLens: lsutil.CodeLensUserPreferences{
183+
ReferencesCodeLensEnabled: true,
184+
},
185+
})
186+
}

0 commit comments

Comments
 (0)