Skip to content

Commit 94635af

Browse files
atscottKeen Yee Liau
authored andcommitted
perf: delay closing of orphaned projects until next open
Currently, when a document is closed, we check to see if there are any other open files in the associated project for that file. If not, we close the project (more specifically, we close the _external_ project for the HTML files which releases the inferred project and results in it being closed as well). If vscode, when navigating between files, even of the same project, this can result in the project being closed and then opened immediately because vscode closes the currently open file before opening the next. Instead, we wait to close "orphaned" external projects until after the next file has finished opening. This way, we avoid closing and opening a project when the two files are part of the same project. Fixes #1092
1 parent 922a96b commit 94635af

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

server/src/session.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ export class Session {
380380
}
381381
throw error;
382382
}
383+
this.closeOrphanedExternalProjects();
383384
}
384385

385386
/**
@@ -406,20 +407,15 @@ export class Session {
406407
return;
407408
}
408409
this.projectService.closeClientFile(filePath);
409-
this.maybeCloseExternalProject(filePath);
410410
}
411411

412412
/**
413413
* We open external projects for files so that we can prevent TypeScript from closing a project
414414
* when there is open external HTML template that still references the project. This function
415-
* checks if there are no longer any open files in the project for the given `filePath`. If there
415+
* checks if there are no longer any open files in any external project. If there
416416
* aren't, we also close the external project that was created.
417417
*/
418-
private maybeCloseExternalProject(filePath: string) {
419-
const scriptInfo = this.projectService.getScriptInfo(filePath);
420-
if (!scriptInfo) {
421-
return;
422-
}
418+
private closeOrphanedExternalProjects() {
423419
for (const [configuredProjName, externalProjName] of this.configuredProjToExternalProj) {
424420
const configuredProj = this.projectService.findProject(configuredProjName);
425421
if (!configuredProj || configuredProj.isClosed()) {

0 commit comments

Comments
 (0)