Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-service): Prevent TSServer from removing templates from … #45965

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/language-service/src/ts_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,22 @@ export function getExternalFiles(project: ts.server.Project): string[] {
return []; // project has not been initialized
}
const typecheckFiles: string[] = [];
const resourceFiles: string[] = [];
for (const scriptInfo of project.getScriptInfos()) {
if (scriptInfo.scriptKind === ts.ScriptKind.External) {
// script info for typecheck file is marked as external, see
// getOrCreateTypeCheckScriptInfo() in
// packages/language-service/src/language_service.ts
typecheckFiles.push(scriptInfo.fileName);
}
if (scriptInfo.scriptKind === ts.ScriptKind.Unknown) {
// script info for resource file is marked as unknown.
// Including these as external files is necessary because otherwise they will get removed from
// the project when `updateNonInferredProjectFiles` is called as part of the
// `updateProjectIfDirty` cycle.
// https://sourcegraph.com/github.com/microsoft/TypeScript@c300fea3250abd7f75920d95a58d9e742ac730ee/-/blob/src/server/editorServices.ts?L2363
resourceFiles.push(scriptInfo.fileName);
}
}
return typecheckFiles;
return [...typecheckFiles, ...resourceFiles];
}
3 changes: 2 additions & 1 deletion packages/language-service/test/legacy/ts_plugin_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe('getExternalFiles()', () => {
ngLS.getSemanticDiagnostics(APP_COMPONENT);
// Now that global analysis is run, we should have all the typecheck files
externalFiles = getExternalFiles(project);
expect(externalFiles.length).toBe(1);
// Includes 1 typecheck file, 1 template, and 1 css files
expect(externalFiles.length).toBe(3);
expect(externalFiles[0].endsWith('app.component.ngtypecheck.ts')).toBeTrue();
});
});