Skip to content

Commit 2d40a69

Browse files
committed
Fix issue with unnecessary project update even with same source info file origination query
1 parent 5ef80a9 commit 2d40a69

File tree

4 files changed

+52
-37
lines changed

4 files changed

+52
-37
lines changed

src/server/project.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -2185,14 +2185,15 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
21852185
}
21862186

21872187
/** @internal */
2188-
getNoDtsResolutionProject(rootFileNames: readonly string[]): AuxiliaryProject {
2188+
getNoDtsResolutionProject(rootFile: NormalizedPath): AuxiliaryProject {
21892189
Debug.assert(this.projectService.serverMode === LanguageServiceMode.Semantic);
21902190
if (!this.noDtsResolutionProject) {
21912191
this.noDtsResolutionProject = new AuxiliaryProject(this.projectService, this.documentRegistry, this.getCompilerOptionsForNoDtsResolutionProject(), this.currentDirectory);
21922192
}
2193-
2194-
this.projectService.setFileNamesOfAutpImportProviderOrAuxillaryProject(this.noDtsResolutionProject, rootFileNames);
2195-
2193+
if (this.noDtsResolutionProject.rootFile !== rootFile) {
2194+
this.projectService.setFileNamesOfAutpImportProviderOrAuxillaryProject(this.noDtsResolutionProject, [rootFile]);
2195+
this.noDtsResolutionProject.rootFile = rootFile;
2196+
}
21962197
return this.noDtsResolutionProject;
21972198
}
21982199

@@ -2373,6 +2374,7 @@ export class InferredProject extends Project {
23732374

23742375
/** @internal */
23752376
export class AuxiliaryProject extends Project {
2377+
/** @internal */ rootFile: NormalizedPath | undefined;
23762378
constructor(projectService: ProjectService, documentRegistry: DocumentRegistry, compilerOptions: CompilerOptions, currentDirectory: string) {
23772379
super(projectService.newAuxiliaryProjectName(), ProjectKind.Auxiliary, projectService, documentRegistry, /*hasExplicitListOfFiles*/ false, /*lastFileExceededProgramSize*/ undefined, compilerOptions, /*compileOnSaveEnabled*/ false, /*watchOptions*/ undefined, projectService.host, currentDirectory);
23782380
}

src/server/session.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ export class Session<TMessage = string> implements EventSender {
15431543
if (needsJsResolution) {
15441544
const definitionSet = createSet<DefinitionInfo>(d => d.textSpan.start, documentSpansEqual);
15451545
definitions?.forEach(d => definitionSet.add(d));
1546-
const noDtsProject = project.getNoDtsResolutionProject([file]);
1546+
const noDtsProject = project.getNoDtsResolutionProject(file);
15471547
const ls = noDtsProject.getLanguageService();
15481548
const jsDefinitions = ls.getDefinitionAtPosition(file, position, /*searchOtherFilesOnly*/ true, /*stopAtAlias*/ false)
15491549
?.filter(d => toNormalizedPath(d.fileName) !== file);

src/testRunner/unittests/tsserver/auxiliaryProject.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe("unittests:: tsserver:: auxiliaryProject::", () => {
4242
command: ts.server.protocol.CommandTypes.FindSourceDefinition,
4343
arguments: protocolFileLocationFromSubstring(aTs, "B"),
4444
});
45-
const auxProject = inferredProject.getNoDtsResolutionProject([aTs.path]);
45+
const auxProject = inferredProject.getNoDtsResolutionProject(aTs.path as ts.server.NormalizedPath);
4646

4747
// b.js ScriptInfo is now available because it's contained by the AuxiliaryProject.
4848
// The AuxiliaryProject should never be the default project for anything, so
@@ -119,6 +119,10 @@ describe("unittests:: tsserver:: auxiliaryProject::", () => {
119119
command: ts.server.protocol.CommandTypes.FindSourceDefinition,
120120
arguments: protocolFileLocationFromSubstring(indexFile, "positional"),
121121
});
122+
session.executeCommandSeq<ts.server.protocol.FindSourceDefinitionRequest>({
123+
command: ts.server.protocol.CommandTypes.FindSourceDefinition,
124+
arguments: protocolFileLocationFromSubstring(indexFile, "command", { index: 1 }),
125+
});
122126
baselineTsserverLogs("auxiliaryProject", "file is added later through finding definition", session);
123127
});
124128
});

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

+40-31
Original file line numberDiff line numberDiff line change
@@ -249,37 +249,6 @@ Info seq [hh:mm:ss:mss] request:
249249
"seq": 3,
250250
"type": "request"
251251
}
252-
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/auxiliaryProject1*
253-
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/auxiliaryProject1* Version: 3 structureChanged: true structureIsReused:: Not Elapsed:: *ms
254-
Info seq [hh:mm:ss:mss] Project '/dev/null/auxiliaryProject1*' (Auxiliary)
255-
Info seq [hh:mm:ss:mss] Files (2)
256-
/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"
257-
/user/users/projects/myproject/index.ts SVC-1-0 "import { command } from \"yargs\";\ncommand(\"foo\", yargs => {\n yargs.positional();\n});\n"
258-
259-
260-
node_modules/yargs/index.js
261-
Imported via "yargs" from file 'index.ts' with packageId 'yargs/index.js@1.0.0'
262-
index.ts
263-
Root file specified for compilation
264-
265-
Info seq [hh:mm:ss:mss] -----------------------------------------------
266-
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/auxiliaryProject1*
267-
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/auxiliaryProject1* Version: 4 structureChanged: true structureIsReused:: Not Elapsed:: *ms
268-
Info seq [hh:mm:ss:mss] Project '/dev/null/auxiliaryProject1*' (Auxiliary)
269-
Info seq [hh:mm:ss:mss] Files (3)
270-
/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"
271-
/user/users/projects/myproject/index.ts SVC-1-0 "import { command } from \"yargs\";\ncommand(\"foo\", yargs => {\n yargs.positional();\n});\n"
272-
/user/users/projects/myproject/node_modules/yargs/callback.js Text-1 "export class Yargs { positional() { } }\n"
273-
274-
275-
node_modules/yargs/index.js
276-
Imported via "yargs" from file 'index.ts' with packageId 'yargs/index.js@1.0.0'
277-
index.ts
278-
Root file specified for compilation
279-
node_modules/yargs/callback.js
280-
Root file specified for compilation
281-
282-
Info seq [hh:mm:ss:mss] -----------------------------------------------
283252
Info seq [hh:mm:ss:mss] response:
284253
{
285254
"response": [
@@ -307,3 +276,43 @@ Info seq [hh:mm:ss:mss] response:
307276
"responseRequired": true
308277
}
309278
After request
279+
280+
Before request
281+
282+
Info seq [hh:mm:ss:mss] request:
283+
{
284+
"command": "findSourceDefinition",
285+
"arguments": {
286+
"file": "/user/users/projects/myproject/index.ts",
287+
"line": 2,
288+
"offset": 1
289+
},
290+
"seq": 4,
291+
"type": "request"
292+
}
293+
Info seq [hh:mm:ss:mss] response:
294+
{
295+
"response": [
296+
{
297+
"file": "/user/users/projects/myproject/node_modules/yargs/index.js",
298+
"start": {
299+
"line": 2,
300+
"offset": 17
301+
},
302+
"end": {
303+
"line": 2,
304+
"offset": 24
305+
},
306+
"contextStart": {
307+
"line": 2,
308+
"offset": 1
309+
},
310+
"contextEnd": {
311+
"line": 2,
312+
"offset": 47
313+
}
314+
}
315+
],
316+
"responseRequired": true
317+
}
318+
After request

0 commit comments

Comments
 (0)