Skip to content

Commit 8c4607d

Browse files
committed
Dont delay external project update from openExternalProject
Since external projects are needed to be uptodate when opening file, so in most likely scenarios these will be loaded anyways so there is no saving in postponing this work
1 parent a0190e3 commit 8c4607d

File tree

3 files changed

+8
-50
lines changed

3 files changed

+8
-50
lines changed

src/server/editorServices.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2564,7 +2564,9 @@ namespace ts.server {
25642564
externalProject.enableLanguageService();
25652565
}
25662566
// external project already exists and not config files were added - update the project and return;
2567+
// The graph update here isnt postponed since any file open operation needs all updated external projects
25672568
this.updateRootAndOptionsOfNonInferredProject(externalProject, proj.rootFiles, externalFilePropertyReader, compilerOptions, proj.typeAcquisition, proj.options.compileOnSave);
2569+
externalProject.updateGraph();
25682570
return;
25692571
}
25702572
// some config files were added to external project (that previously were not there)
@@ -2622,8 +2624,11 @@ namespace ts.server {
26222624
}
26232625
else {
26242626
// no config files - remove the item from the collection
2627+
// Create external project and update its graph, do not delay update since
2628+
// any file open operation needs all updated external projects
26252629
this.externalProjectToConfiguredProjectMap.delete(proj.projectFileName);
2626-
this.createExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typeAcquisition, excludedFiles);
2630+
const project = this.createExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typeAcquisition, excludedFiles);
2631+
project.updateGraph();
26272632
}
26282633
}
26292634

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,11 +1776,8 @@ namespace ts.projectSystem {
17761776
try {
17771777
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, office.path]) });
17781778
const proj = projectService.externalProjects[0];
1779-
// Since the file is not yet open, the project wont have program yet
1780-
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), emptyArray);
1781-
assert.deepEqual(proj.getTypeAcquisition().include, ["duck-types"]);
1782-
projectService.openClientFile(file1.path);
17831779
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), [file1.path]);
1780+
assert.deepEqual(proj.getTypeAcquisition().include, ["duck-types"]);
17841781
} finally {
17851782
projectService.resetSafeList();
17861783
}
@@ -1821,11 +1818,8 @@ namespace ts.projectSystem {
18211818
try {
18221819
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles(files.map(f => f.path)) });
18231820
const proj = projectService.externalProjects[0];
1824-
// Since the file is not yet open, the project wont have program yet
1825-
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), emptyArray);
1826-
assert.deepEqual(proj.getTypeAcquisition().include, ["kendo-ui", "office"]);
1827-
projectService.openClientFile(file1.path);
18281821
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), [file1.path]);
1822+
assert.deepEqual(proj.getTypeAcquisition().include, ["kendo-ui", "office"]);
18291823
} finally {
18301824
projectService.resetSafeList();
18311825
}
@@ -1865,9 +1859,6 @@ namespace ts.projectSystem {
18651859
try {
18661860
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, file2.path]), typeAcquisition: { enable: true } });
18671861
const proj = projectService.externalProjects[0];
1868-
// Since the file is not yet open, the project wont have program yet
1869-
assert.deepEqual(proj.getFileNames(), emptyArray);
1870-
projectService.openClientFile(file2.path);
18711862
assert.deepEqual(proj.getFileNames(), [file2.path]);
18721863
} finally {
18731864
projectService.resetSafeList();
@@ -2083,9 +2074,6 @@ namespace ts.projectSystem {
20832074

20842075
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path]) });
20852076
checkNumberOfProjects(projectService, { externalProjects: 1 });
2086-
// Since the file is not yet open, the project wont have program yet
2087-
assert.deepEqual(projectService.externalProjects[0].getFileNames(), emptyArray);
2088-
projectService.openClientFile(file1.path);
20892077
checkProjectActualFiles(projectService.externalProjects[0], [file1.path]);
20902078

20912079
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, file2.path]) });
@@ -2113,17 +2101,11 @@ namespace ts.projectSystem {
21132101
projectService.openExternalProject({ projectFileName: "project", options: { moduleResolution: ModuleResolutionKind.NodeJs }, rootFiles: toExternalFiles([file1.path, file2.path]) });
21142102
checkNumberOfProjects(projectService, { externalProjects: 1 });
21152103
checkProjectRootFiles(projectService.externalProjects[0], [file1.path, file2.path]);
2116-
// Since the file is not yet open, the project wont have program yet
2117-
checkProjectActualFiles(projectService.externalProjects[0], emptyArray);
2118-
projectService.openClientFile(file1.path);
21192104
checkProjectActualFiles(projectService.externalProjects[0], [file1.path, file2.path]);
21202105

21212106
projectService.openExternalProject({ projectFileName: "project", options: { moduleResolution: ModuleResolutionKind.Classic }, rootFiles: toExternalFiles([file1.path, file2.path]) });
21222107
checkNumberOfProjects(projectService, { externalProjects: 1 });
21232108
checkProjectRootFiles(projectService.externalProjects[0], [file1.path, file2.path]);
2124-
// The update doesnt happen right away until needed, so either open a file or ensure projects uptodate
2125-
checkProjectActualFiles(projectService.externalProjects[0], [file1.path, file2.path]);
2126-
projectService.ensureInferredProjectsUpToDate_TestOnly();
21272109
checkProjectActualFiles(projectService.externalProjects[0], [file1.path, file2.path, file3.path]);
21282110
});
21292111

@@ -2425,10 +2407,6 @@ namespace ts.projectSystem {
24252407
projectService.openExternalProject({ projectFileName, options: {}, rootFiles: [{ fileName: file1.path, scriptKind: ScriptKind.JS, hasMixedContent: true }] });
24262408

24272409
checkNumberOfProjects(projectService, { externalProjects: 1 });
2428-
// Since the external project is not updated till needed (eg opening client file/ensuringProjectStructureUptodate)
2429-
// watched files will be empty at first
2430-
checkWatchedFiles(host, emptyArray);
2431-
projectService.ensureInferredProjectsUpToDate_TestOnly();
24322410
checkWatchedFiles(host, [libFile.path]); // watching the "missing" lib file
24332411

24342412
const project = projectService.externalProjects[0];
@@ -3013,9 +2991,6 @@ namespace ts.projectSystem {
30132991
projectService.openExternalProjects([externalProject]);
30142992

30152993
checkNumberOfProjects(projectService, { configuredProjects: 0, externalProjects: 1, inferredProjects: 0 });
3016-
// Since the external project is not updated till needed (eg opening client file/ensuringProjectStructureUptodate)
3017-
checkProjectActualFiles(projectService.externalProjects[0], emptyArray);
3018-
projectService.ensureInferredProjectsUpToDate_TestOnly();
30192994
checkProjectActualFiles(projectService.externalProjects[0], [site.path, libFile.path]);
30202995
});
30212996

@@ -4019,8 +3994,6 @@ namespace ts.projectSystem {
40193994
});
40203995

40213996
projectService.checkNumberOfProjects({ externalProjects: 1 });
4022-
checkProjectActualFiles(projectService.externalProjects[0], emptyArray); // external project created but not updated till actually needed
4023-
projectService.ensureInferredProjectsUpToDate_TestOnly();
40243997
checkProjectActualFiles(projectService.externalProjects[0], [f1.path, f2.path]);
40253998
});
40263999

@@ -4058,8 +4031,6 @@ namespace ts.projectSystem {
40584031
});
40594032

40604033
projectService.checkNumberOfProjects({ externalProjects: 1 });
4061-
checkProjectActualFiles(projectService.externalProjects[0], emptyArray); // external project created but program is not created till its needed
4062-
projectService.ensureInferredProjectsUpToDate_TestOnly();
40634034
checkProjectActualFiles(projectService.externalProjects[0], [f1.path]);
40644035

40654036
// add two config file as root files
@@ -4093,8 +4064,6 @@ namespace ts.projectSystem {
40934064
});
40944065

40954066
projectService.checkNumberOfProjects({ externalProjects: 1 });
4096-
checkProjectActualFiles(projectService.externalProjects[0], emptyArray); // external project created but program is not created till its needed
4097-
projectService.ensureInferredProjectsUpToDate_TestOnly();
40984067
checkProjectActualFiles(projectService.externalProjects[0], [f1.path]);
40994068

41004069
// open two config files

src/testRunner/unittests/typingsInstaller.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,6 @@ namespace ts.projectSystem {
330330
typeAcquisition: { enable: true, include: ["jquery"] }
331331
});
332332

333-
assert.isFalse(enqueueIsCalled, "expected enqueueIsCalled to be false since external project isnt updated right away");
334-
projectService.ensureInferredProjectsUpToDate_TestOnly();
335333
assert.isTrue(enqueueIsCalled, "expected enqueueIsCalled to be true");
336334
installer.installAll(/*expectedCount*/ 1);
337335

@@ -388,8 +386,6 @@ namespace ts.projectSystem {
388386

389387
const p = projectService.externalProjects[0];
390388
projectService.checkNumberOfProjects({ externalProjects: 1 });
391-
checkProjectActualFiles(p, emptyArray); // external project created but not updated
392-
projectService.ensureInferredProjectsUpToDate_TestOnly();
393389
checkProjectActualFiles(p, [file2Jsx.path, file3dts.path]);
394390

395391
installer.installAll(/*expectedCount*/ 1);
@@ -434,8 +430,6 @@ namespace ts.projectSystem {
434430

435431
const p = projectService.externalProjects[0];
436432
projectService.checkNumberOfProjects({ externalProjects: 1 });
437-
checkProjectActualFiles(p, emptyArray); // external project created but not updated
438-
projectService.ensureInferredProjectsUpToDate_TestOnly();
439433
checkProjectActualFiles(p, [jqueryJs.path]);
440434

441435
installer.checkPendingCommands(/*expectedCount*/ 0);
@@ -479,8 +473,6 @@ namespace ts.projectSystem {
479473
const p = projectService.externalProjects[0];
480474
projectService.checkNumberOfProjects({ externalProjects: 1 });
481475

482-
checkProjectActualFiles(p, emptyArray); // external project created but not updated
483-
projectService.ensureInferredProjectsUpToDate_TestOnly();
484476
checkProjectActualFiles(p, [jqueryJs.path, file2Ts.path]);
485477

486478
installer.checkPendingCommands(/*expectedCount*/ 0);
@@ -556,8 +548,6 @@ namespace ts.projectSystem {
556548

557549
const p = projectService.externalProjects[0];
558550
projectService.checkNumberOfProjects({ externalProjects: 1 });
559-
checkProjectActualFiles(p, emptyArray); // external project created but not updated
560-
projectService.ensureInferredProjectsUpToDate_TestOnly();
561551
checkProjectActualFiles(p, [file3dts.path]);
562552

563553
installer.installAll(/*expectedCount*/ 1);
@@ -640,8 +630,6 @@ namespace ts.projectSystem {
640630

641631
const p = projectService.externalProjects[0];
642632
projectService.checkNumberOfProjects({ externalProjects: 1 });
643-
checkProjectActualFiles(p, emptyArray); // external project created but not updated
644-
projectService.ensureInferredProjectsUpToDate_TestOnly();
645633
checkProjectActualFiles(p, [file3.path]);
646634
installer.checkPendingCommands(/*expectedCount*/ 1);
647635
installer.executePendingCommands();
@@ -726,8 +714,6 @@ namespace ts.projectSystem {
726714
typeAcquisition: { include: ["jquery", "cordova"] }
727715
});
728716

729-
checkProjectActualFiles(projectService.externalProjects[0], emptyArray); // external project created but not updated
730-
projectService.ensureInferredProjectsUpToDate_TestOnly();
731717
installer.checkPendingCommands(/*expectedCount*/ 1);
732718
assert.equal(installer.pendingRunRequests.length, 0, "expect no throttled requests");
733719

@@ -739,8 +725,6 @@ namespace ts.projectSystem {
739725
rootFiles: [toExternalFile(file3.path)],
740726
typeAcquisition: { include: ["grunt", "gulp"] }
741727
});
742-
checkProjectActualFiles(projectService.externalProjects[1], emptyArray); // external project created but not updated
743-
projectService.ensureInferredProjectsUpToDate_TestOnly();
744728
assert.equal(installer.pendingRunRequests.length, 1, "expect one throttled request");
745729

746730
const p1 = projectService.externalProjects[0];

0 commit comments

Comments
 (0)