Skip to content

Commit

Permalink
refactor(server): Remove external project tracking (#1682)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
atscott committed Jun 8, 2022
1 parent 2db9148 commit 16b045d
Showing 1 changed file with 0 additions and 47 deletions.
47 changes: 0 additions & 47 deletions server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export class Session {
private readonly logger: ts.server.Logger;
private readonly ivy: boolean;
private readonly disableAutomaticNgcc: boolean;
private readonly configuredProjToExternalProj = new Map<string, string>();
private readonly logToConsole: boolean;
private readonly openFiles = new MruTracker();
private readonly includeAutomaticOptionalChainCompletions: boolean;
Expand Down Expand Up @@ -624,7 +623,6 @@ export class Session {
scriptInfo.detachAllProjects();
scriptInfo.attachToProject(project);
}
this.createExternalProject(project);

return project;
}
Expand Down Expand Up @@ -719,24 +717,6 @@ export class Session {
}
throw error;
}
this.closeOrphanedExternalProjects();
}

/**
* Creates an external project with the same config path as `project` so that TypeScript keeps the
* project open when navigating away from `html` files.
*/
private createExternalProject(project: ts.server.Project): void {
if (isConfiguredProject(project) &&
!this.configuredProjToExternalProj.has(project.projectName)) {
const extProjectName = `${project.projectName}-external`;
project.projectService.openExternalProject({
projectFileName: extProjectName,
rootFiles: [{fileName: project.getConfigFilePath()}],
options: {}
});
this.configuredProjToExternalProj.set(project.projectName, extProjectName);
}
}

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

/**
* We open external projects for files so that we can prevent TypeScript from closing a project
* when there is open external HTML template that still references the project. This function
* checks if there are no longer any open files in any external project. If there
* aren't, we also close the external project that was created.
*/
private closeOrphanedExternalProjects(): void {
for (const [configuredProjName, externalProjName] of this.configuredProjToExternalProj) {
const configuredProj = this.projectService.findProject(configuredProjName);
if (!configuredProj || configuredProj.isClosed()) {
this.projectService.closeExternalProject(externalProjName);
this.configuredProjToExternalProj.delete(configuredProjName);
continue;
}
// See if any openFiles belong to the configured project.
// if not, close external project this.projectService.openFiles
const openFiles = toArray(this.projectService.openFiles.keys());
if (!openFiles.some(file => {
const scriptInfo = this.projectService.getScriptInfo(file);
return scriptInfo?.isAttached(configuredProj);
})) {
this.projectService.closeExternalProject(externalProjName);
this.configuredProjToExternalProj.delete(configuredProjName);
}
}
}

private onDidChangeTextDocument(params: lsp.DidChangeTextDocumentParams): void {
const {contentChanges, textDocument} = params;
const filePath = uriToFilePath(textDocument.uri);
Expand Down

0 comments on commit 16b045d

Please sign in to comment.