Skip to content

Commit 0efe4ee

Browse files
committed
Fix issue with js file having to be already present in project service
1 parent 43720b9 commit 0efe4ee

File tree

3 files changed

+64
-14
lines changed

3 files changed

+64
-14
lines changed

src/server/session.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,8 +1565,16 @@ export class Session<TMessage = string> implements EventSender {
15651565
const ambientCandidates = definitions.filter(d => toNormalizedPath(d.fileName) !== file && d.isAmbient);
15661566
for (const candidate of some(ambientCandidates) ? ambientCandidates : getAmbientCandidatesByClimbingAccessChain()) {
15671567
const fileNameToSearch = findImplementationFileFromDtsFileName(candidate.fileName, file, noDtsProject);
1568-
if (!fileNameToSearch || !ensureRoot(noDtsProject, fileNameToSearch)) {
1569-
continue;
1568+
if (!fileNameToSearch) continue;
1569+
const info = this.projectService.getOrCreateScriptInfoNotOpenedByClient(
1570+
fileNameToSearch,
1571+
noDtsProject.currentDirectory,
1572+
noDtsProject.directoryStructureHost,
1573+
);
1574+
if (!info) continue;
1575+
if (!noDtsProject.containsScriptInfo(info)) {
1576+
noDtsProject.addRoot(info);
1577+
noDtsProject.updateGraph();
15701578
}
15711579
const noDtsProgram = ls.getProgram()!;
15721580
const fileToSearch = Debug.checkDefined(noDtsProgram.getSourceFile(fileNameToSearch));
@@ -1672,16 +1680,6 @@ export class Session<TMessage = string> implements EventSender {
16721680
}
16731681
});
16741682
}
1675-
1676-
function ensureRoot(project: AuxiliaryProject, fileName: string) {
1677-
const info = project.getScriptInfo(fileName);
1678-
if (!info) return false;
1679-
if (!project.containsScriptInfo(info)) {
1680-
project.addRoot(info);
1681-
project.updateGraph();
1682-
}
1683-
return true;
1684-
}
16851683
}
16861684

16871685
private getEmitOutput(args: protocol.EmitOutputRequestArgs): EmitOutput | protocol.EmitOutput {
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
// === goToSourceDefinition ===
2+
// === /node_modules/yargs/callback.js ===
3+
// export class Yargs { [|positional|]() { } }
4+
25
// === /index.ts ===
36
// import { command } from "yargs";
47
// command("foo", yargs => {
58
// yargs./*GOTO SOURCE DEF*/positional();
6-
// });
9+
// });
10+
11+
// === Details ===
12+
[
13+
{
14+
"containerKind": "",
15+
"containerName": "",
16+
"kind": "",
17+
"name": "",
18+
"unverified": true
19+
}
20+
]

tests/baselines/reference/tsserver/auxiliaryProject/file-is-added-later-through-finding-definition.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,48 @@ Info seq [hh:mm:ss:mss] Files (2)
166166
index.ts
167167
Root file specified for compilation
168168

169+
Info seq [hh:mm:ss:mss] -----------------------------------------------
170+
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/auxiliaryProject1*
171+
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/auxiliaryProject1* Version: 2 structureChanged: true structureIsReused:: Not Elapsed:: *ms
172+
Info seq [hh:mm:ss:mss] Project '/dev/null/auxiliaryProject1*' (Auxiliary)
173+
Info seq [hh:mm:ss:mss] Files (3)
174+
/user/users/projects/myproject/node_modules/yargs/index.js Text-1 "// Specifically didnt have ./callback import to ensure that resolving module sepcifier adds the file to project at later stage\nexport function command(cmd, cb) { cb(Yargs) }\n"
175+
/user/users/projects/myproject/index.ts SVC-1-0 "import { command } from \"yargs\";\ncommand(\"foo\", yargs => {\n yargs.positional();\n});\n"
176+
/user/users/projects/myproject/node_modules/yargs/callback.js Text-1 "export class Yargs { positional() { } }\n"
177+
178+
179+
node_modules/yargs/index.js
180+
Imported via "yargs" from file 'index.ts' with packageId 'yargs/index.js@1.0.0'
181+
index.ts
182+
Root file specified for compilation
183+
node_modules/yargs/callback.js
184+
Root file specified for compilation
185+
169186
Info seq [hh:mm:ss:mss] -----------------------------------------------
170187
Info seq [hh:mm:ss:mss] response:
171188
{
172-
"response": [],
189+
"response": [
190+
{
191+
"file": "/user/users/projects/myproject/node_modules/yargs/callback.js",
192+
"start": {
193+
"line": 1,
194+
"offset": 22
195+
},
196+
"end": {
197+
"line": 1,
198+
"offset": 32
199+
},
200+
"contextStart": {
201+
"line": 1,
202+
"offset": 22
203+
},
204+
"contextEnd": {
205+
"line": 1,
206+
"offset": 38
207+
},
208+
"unverified": true
209+
}
210+
],
173211
"responseRequired": true
174212
}
175213
After request

0 commit comments

Comments
 (0)