Skip to content

Commit 1171089

Browse files
committed
Declaration map tests
1 parent 28dd671 commit 1171089

23 files changed

+5100
-0
lines changed

internal/lsp/lspservertests/declarationmaps_test.go

Lines changed: 489 additions & 0 deletions
Large diffs are not rendered by default.

internal/lsp/lspservertests/findallrefs_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,29 @@ func TestFindAllReferences(t *testing.T) {
276276
server.baselineReferences(coreFile, lsptestutil.PositionToLineAndCharacter(coreFile, server.content(coreFile), "prop", 0))
277277
},
278278
},
279+
{
280+
subScenario: "references on file opened is in configured project that will be removed",
281+
files: func() map[string]any {
282+
return map[string]any{
283+
"/user/username/projects/myproject/playground/tsconfig.json": "{}",
284+
"/user/username/projects/myproject/playground/tests.ts": "export function foo() {}",
285+
"/user/username/projects/myproject/playground/tsconfig-json/tests/spec.ts": "export function bar() { }",
286+
"/user/username/projects/myproject/playground/tsconfig-json/tsconfig.json": stringtestutil.Dedent(`
287+
{
288+
"include": ["./src"],
289+
}`),
290+
"/user/username/projects/myproject/playground/tsconfig-json/src/src.ts": "export function foobar() { }",
291+
}
292+
},
293+
test: func(server *testServer) {
294+
testsFile := "/user/username/projects/myproject/playground/tests.ts"
295+
server.openFile(testsFile, lsproto.LanguageKindTypeScript)
296+
server.closeFile(testsFile)
297+
innerFile := "/user/username/projects/myproject/playground/tsconfig-json/tests/spec.ts"
298+
server.openFile(innerFile, lsproto.LanguageKindTypeScript)
299+
server.baselineReferences(innerFile, lsptestutil.PositionToLineAndCharacter(innerFile, server.content(innerFile), "bar", 0))
300+
},
301+
},
279302
getFindAllRefsTestCaseForSpecialLocalnessHandling(
280303
"when using arrow function assignment",
281304
`export const dog = () => { };`,

internal/lsp/lspservertests/testserver.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func newTestServer(t *testing.T, files map[string]any) *testServer {
5454
}
5555

5656
func (s *testServer) content(fileName string) string {
57+
if text, ok := s.openFiles[fileName]; ok {
58+
return text
59+
}
5760
return s.files[fileName].(string)
5861
}
5962

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
UseCaseSensitiveFileNames: false
2+
//// [/home/src/projects/project/a/a.ts] *new*
3+
export function f() {}
4+
//// [/home/src/projects/project/a/tsconfig.json] *new*
5+
{
6+
"compilerOptions": {
7+
"outDir": "bin",
8+
"declarationMap": true,
9+
"composite": true
10+
}
11+
}
12+
//// [/home/src/projects/project/b/b.ts] *new*
13+
import { f } from "../a/bin/a";
14+
f();
15+
//// [/home/src/projects/project/b/tsconfig.json] *new*
16+
{
17+
"references": [
18+
{ "path": "../a" }
19+
]
20+
}
21+
//// [/home/src/projects/project/bin/a.d.ts] *new*
22+
export declare function f(): void;
23+
//# sourceMappingURL=a.d.ts.map
24+
//// [/home/src/projects/project/bin/a.d.ts.map] *new*
25+
{
26+
"version":3,
27+
"file":"a.d.ts",
28+
"sourceRoot":"",
29+
"sources":["a.ts"],
30+
"names":[],
31+
"mappings":"AAAA,wBAAgB,CAAC,SAAK"
32+
}
33+
34+
{
35+
"method": "textDocument/didOpen",
36+
"params": {
37+
"textDocument": {
38+
"uri": "file:///home/src/projects/project/b/b.ts",
39+
"languageId": "typescript",
40+
"version": 0,
41+
"text": "import { f } from \"../a/bin/a\";\nf();"
42+
}
43+
}
44+
}
45+
Projects::
46+
[/home/src/projects/project/b/tsconfig.json] *new*
47+
/home/src/projects/project/a/a.ts
48+
/home/src/projects/project/b/b.ts
49+
Open Files::
50+
[/home/src/projects/project/b/b.ts] *new*
51+
/home/src/projects/project/b/tsconfig.json (default)
52+
Config::
53+
[/home/src/projects/project/a/tsconfig.json] *new*
54+
RetainingProjects:
55+
/home/src/projects/project/b/tsconfig.json
56+
[/home/src/projects/project/b/tsconfig.json] *new*
57+
RetainingProjects:
58+
/home/src/projects/project/b/tsconfig.json
59+
RetainingOpenFiles:
60+
/home/src/projects/project/b/b.ts
61+
Config File Names::
62+
[/home/src/projects/project/b/b.ts] *new*
63+
NearestConfigFileName: /home/src/projects/project/b/tsconfig.json
64+
{
65+
"method": "textDocument/references",
66+
"params": {
67+
"textDocument": {
68+
"uri": "file:///home/src/projects/project/b/b.ts"
69+
},
70+
"position": {
71+
"line": 1,
72+
"character": 0
73+
},
74+
"context": {
75+
"includeDeclaration": false
76+
}
77+
}
78+
}
79+
// === /home/src/projects/project/a/a.ts ===
80+
// export function [|f|]() {}
81+
82+
// === /home/src/projects/project/b/b.ts ===
83+
// import { [|f|] } from "../a/bin/a";
84+
// /*FIND ALL REFS*/[|f|]();
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
UseCaseSensitiveFileNames: false
2+
//// [/home/src/projects/project/a/a.ts] *new*
3+
export function fnA() {}
4+
export interface IfaceA {}
5+
export const instanceA: IfaceA = {};
6+
//// [/home/src/projects/project/a/bin/a.d.ts] *new*
7+
export declare function fnA(): void;
8+
export interface IfaceA {
9+
}
10+
export declare const instanceA: IfaceA;
11+
//# sourceMappingURL=a.d.ts.map
12+
//// [/home/src/projects/project/a/bin/a.d.ts.map] *new*
13+
{
14+
"version": 3,
15+
"file": "a.d.ts",
16+
"sourceRoot": "",
17+
"sources": ["../a.ts"],
18+
"names": [],
19+
"mappings": "AAAA,wBAAgB,GAAG,SAAK;AACxB,MAAM,WAAW,MAAM;CAAG;AAC1B,eAAO,MAAM,SAAS,EAAE,MAAW,CAAC"
20+
}
21+
//// [/home/src/projects/project/a/tsconfig.json] *new*
22+
{
23+
"compilerOptions": {
24+
"outDir": "bin",
25+
"declarationMap": true,
26+
"composite": true
27+
}
28+
}
29+
//// [/home/src/projects/project/b/bin/b.d.ts] *new*
30+
export declare function fnB(): void;
31+
//# sourceMappingURL=b.d.ts.map
32+
//// [/home/src/projects/project/b/bin/b.d.ts.map] *new*
33+
{
34+
"version": 3,
35+
"file": "b.d.ts",
36+
"sourceRoot": "",
37+
"sources": ["../b.ts"],
38+
"names": [],
39+
"mappings": "AAAA,wBAAgB,GAAG,SAAK"
40+
}
41+
//// [/home/src/projects/project/b/tsconfig.json] *new*
42+
{
43+
"compilerOptions": {
44+
"outDir": "bin",
45+
"declarationMap": true,
46+
"composite": true
47+
}
48+
}
49+
//// [/home/src/projects/project/dummy/dummy.ts] *new*
50+
export const a = 10;
51+
//// [/home/src/projects/project/dummy/tsconfig.json] *new*
52+
{}
53+
//// [/home/src/projects/project/user/user.ts] *new*
54+
import * as a from "../a/bin/a";
55+
import * as b from "../b/bin/b";
56+
export function fnUser() { a.fnA(); b.fnB(); a.instanceA; }
57+
58+
{
59+
"method": "textDocument/didOpen",
60+
"params": {
61+
"textDocument": {
62+
"uri": "file:///home/src/projects/project/user/user.ts",
63+
"languageId": "typescript",
64+
"version": 0,
65+
"text": "import * as a from \"../a/bin/a\";\nimport * as b from \"../b/bin/b\";\nexport function fnUser() { a.fnA(); b.fnB(); a.instanceA; }"
66+
}
67+
}
68+
}
69+
Projects::
70+
[/dev/null/inferred] *new*
71+
/home/src/projects/project/a/bin/a.d.ts
72+
/home/src/projects/project/b/bin/b.d.ts
73+
/home/src/projects/project/user/user.ts
74+
Open Files::
75+
[/home/src/projects/project/user/user.ts] *new*
76+
/dev/null/inferred (default)
77+
Config File Names::
78+
[/home/src/projects/project/user/user.ts] *new*
79+
NearestConfigFileName:
80+
{
81+
"method": "textDocument/didOpen",
82+
"params": {
83+
"textDocument": {
84+
"uri": "file:///home/src/projects/project/a/a.ts",
85+
"languageId": "typescript",
86+
"version": 0,
87+
"text": "export function fnA() {}\nexport interface IfaceA {}\nexport const instanceA: IfaceA = {};"
88+
}
89+
}
90+
}
91+
Projects::
92+
[/dev/null/inferred]
93+
/home/src/projects/project/a/bin/a.d.ts
94+
/home/src/projects/project/b/bin/b.d.ts
95+
/home/src/projects/project/user/user.ts
96+
[/home/src/projects/project/a/tsconfig.json] *new*
97+
/home/src/projects/project/a/a.ts
98+
Open Files::
99+
[/home/src/projects/project/a/a.ts] *new*
100+
/home/src/projects/project/a/tsconfig.json (default)
101+
[/home/src/projects/project/user/user.ts]
102+
/dev/null/inferred (default)
103+
Config::
104+
[/home/src/projects/project/a/tsconfig.json] *new*
105+
RetainingProjects:
106+
/home/src/projects/project/a/tsconfig.json
107+
RetainingOpenFiles:
108+
/home/src/projects/project/a/a.ts
109+
Config File Names::
110+
[/home/src/projects/project/a/a.ts] *new*
111+
NearestConfigFileName: /home/src/projects/project/a/tsconfig.json
112+
[/home/src/projects/project/user/user.ts]
113+
NearestConfigFileName:
114+
{
115+
"method": "textDocument/references",
116+
"params": {
117+
"textDocument": {
118+
"uri": "file:///home/src/projects/project/a/a.ts"
119+
},
120+
"position": {
121+
"line": 0,
122+
"character": 16
123+
},
124+
"context": {
125+
"includeDeclaration": false
126+
}
127+
}
128+
}
129+
// === /home/src/projects/project/a/a.ts ===
130+
// export function /*FIND ALL REFS*/[|fnA|]() {}
131+
// export interface IfaceA {}
132+
// export const instanceA: IfaceA = {};
133+
{
134+
"method": "textDocument/didClose",
135+
"params": {
136+
"textDocument": {
137+
"uri": "file:///home/src/projects/project/user/user.ts"
138+
}
139+
}
140+
}
141+
Open Files::
142+
[/home/src/projects/project/a/a.ts]
143+
/home/src/projects/project/a/tsconfig.json (default)
144+
[/home/src/projects/project/user/user.ts] *closed*
145+
{
146+
"method": "textDocument/didOpen",
147+
"params": {
148+
"textDocument": {
149+
"uri": "file:///home/src/projects/project/dummy/dummy.ts",
150+
"languageId": "typescript",
151+
"version": 0,
152+
"text": "export const a = 10;"
153+
}
154+
}
155+
}
156+
Projects::
157+
[/dev/null/inferred] *deleted*
158+
/home/src/projects/project/a/bin/a.d.ts
159+
/home/src/projects/project/b/bin/b.d.ts
160+
/home/src/projects/project/user/user.ts
161+
[/home/src/projects/project/a/tsconfig.json]
162+
/home/src/projects/project/a/a.ts
163+
[/home/src/projects/project/dummy/tsconfig.json] *new*
164+
/home/src/projects/project/dummy/dummy.ts
165+
Open Files::
166+
[/home/src/projects/project/a/a.ts]
167+
/home/src/projects/project/a/tsconfig.json (default)
168+
[/home/src/projects/project/dummy/dummy.ts] *new*
169+
/home/src/projects/project/dummy/tsconfig.json (default)
170+
Config::
171+
[/home/src/projects/project/a/tsconfig.json]
172+
RetainingProjects:
173+
/home/src/projects/project/a/tsconfig.json
174+
RetainingOpenFiles:
175+
/home/src/projects/project/a/a.ts
176+
[/home/src/projects/project/dummy/tsconfig.json] *new*
177+
RetainingProjects:
178+
/home/src/projects/project/dummy/tsconfig.json
179+
RetainingOpenFiles:
180+
/home/src/projects/project/dummy/dummy.ts
181+
Config File Names::
182+
[/home/src/projects/project/a/a.ts]
183+
NearestConfigFileName: /home/src/projects/project/a/tsconfig.json
184+
[/home/src/projects/project/dummy/dummy.ts] *new*
185+
NearestConfigFileName: /home/src/projects/project/dummy/tsconfig.json
186+
[/home/src/projects/project/user/user.ts] *deleted*

0 commit comments

Comments
 (0)