Skip to content

Commit 16b045d

Browse files
authored
refactor(server): Remove external project tracking (#1682)
The external project management was implemented to prevent TSServer from closing projects when navigating around. However, this didn't work for solution style projects. With angular/angular#45965, the external project management is no longer necessary because that change in the @angular/language-service package is a more complete fix.
1 parent 2db9148 commit 16b045d

File tree

1 file changed

+0
-47
lines changed

1 file changed

+0
-47
lines changed

server/src/session.ts

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export class Session {
5757
private readonly logger: ts.server.Logger;
5858
private readonly ivy: boolean;
5959
private readonly disableAutomaticNgcc: boolean;
60-
private readonly configuredProjToExternalProj = new Map<string, string>();
6160
private readonly logToConsole: boolean;
6261
private readonly openFiles = new MruTracker();
6362
private readonly includeAutomaticOptionalChainCompletions: boolean;
@@ -624,7 +623,6 @@ export class Session {
624623
scriptInfo.detachAllProjects();
625624
scriptInfo.attachToProject(project);
626625
}
627-
this.createExternalProject(project);
628626

629627
return project;
630628
}
@@ -719,24 +717,6 @@ export class Session {
719717
}
720718
throw error;
721719
}
722-
this.closeOrphanedExternalProjects();
723-
}
724-
725-
/**
726-
* Creates an external project with the same config path as `project` so that TypeScript keeps the
727-
* project open when navigating away from `html` files.
728-
*/
729-
private createExternalProject(project: ts.server.Project): void {
730-
if (isConfiguredProject(project) &&
731-
!this.configuredProjToExternalProj.has(project.projectName)) {
732-
const extProjectName = `${project.projectName}-external`;
733-
project.projectService.openExternalProject({
734-
projectFileName: extProjectName,
735-
rootFiles: [{fileName: project.getConfigFilePath()}],
736-
options: {}
737-
});
738-
this.configuredProjToExternalProj.set(project.projectName, extProjectName);
739-
}
740720
}
741721

742722
private onDidCloseTextDocument(params: lsp.DidCloseTextDocumentParams) {
@@ -749,33 +729,6 @@ export class Session {
749729
this.projectService.closeClientFile(filePath);
750730
}
751731

752-
/**
753-
* We open external projects for files so that we can prevent TypeScript from closing a project
754-
* when there is open external HTML template that still references the project. This function
755-
* checks if there are no longer any open files in any external project. If there
756-
* aren't, we also close the external project that was created.
757-
*/
758-
private closeOrphanedExternalProjects(): void {
759-
for (const [configuredProjName, externalProjName] of this.configuredProjToExternalProj) {
760-
const configuredProj = this.projectService.findProject(configuredProjName);
761-
if (!configuredProj || configuredProj.isClosed()) {
762-
this.projectService.closeExternalProject(externalProjName);
763-
this.configuredProjToExternalProj.delete(configuredProjName);
764-
continue;
765-
}
766-
// See if any openFiles belong to the configured project.
767-
// if not, close external project this.projectService.openFiles
768-
const openFiles = toArray(this.projectService.openFiles.keys());
769-
if (!openFiles.some(file => {
770-
const scriptInfo = this.projectService.getScriptInfo(file);
771-
return scriptInfo?.isAttached(configuredProj);
772-
})) {
773-
this.projectService.closeExternalProject(externalProjName);
774-
this.configuredProjToExternalProj.delete(configuredProjName);
775-
}
776-
}
777-
}
778-
779732
private onDidChangeTextDocument(params: lsp.DidChangeTextDocumentParams): void {
780733
const {contentChanges, textDocument} = params;
781734
const filePath = uriToFilePath(textDocument.uri);

0 commit comments

Comments
 (0)