Skip to content

Commit fa754cd

Browse files
atscottthePunderWoman
authored andcommitted
fix(language-service): Prevent TSServer from removing templates from project (#45965)
As part of the `updateProjectIfDirty` process and inside `updateNonInferredProjectFiles` TS Server will remove the template files that we added as roots in `readResource`. https://sourcegraph.com/github.com/microsoft/TypeScript@c300fea3250abd7f75920d95a58d9e742ac730ee/-/blob/src/server/editorServices.ts?L2363 The external files are added to the list here so ensuring that the templates are included in the `getExternalFiles` will prevent this from happening https://sourcegraph.com/github.com/microsoft/TypeScript@c300fea3250abd7f75920d95a58d9e742ac730ee/-/blob/src/server/editorServices.ts?L2395:18 PR Close #45965
1 parent 5e404d3 commit fa754cd

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/language-service/src/ts_plugin.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,22 @@ export function getExternalFiles(project: ts.server.Project): string[] {
189189
return []; // project has not been initialized
190190
}
191191
const typecheckFiles: string[] = [];
192+
const resourceFiles: string[] = [];
192193
for (const scriptInfo of project.getScriptInfos()) {
193194
if (scriptInfo.scriptKind === ts.ScriptKind.External) {
194195
// script info for typecheck file is marked as external, see
195196
// getOrCreateTypeCheckScriptInfo() in
196197
// packages/language-service/src/language_service.ts
197198
typecheckFiles.push(scriptInfo.fileName);
198199
}
200+
if (scriptInfo.scriptKind === ts.ScriptKind.Unknown) {
201+
// script info for resource file is marked as unknown.
202+
// Including these as external files is necessary because otherwise they will get removed from
203+
// the project when `updateNonInferredProjectFiles` is called as part of the
204+
// `updateProjectIfDirty` cycle.
205+
// https://sourcegraph.com/github.com/microsoft/TypeScript@c300fea3250abd7f75920d95a58d9e742ac730ee/-/blob/src/server/editorServices.ts?L2363
206+
resourceFiles.push(scriptInfo.fileName);
207+
}
199208
}
200-
return typecheckFiles;
209+
return [...typecheckFiles, ...resourceFiles];
201210
}

packages/language-service/test/legacy/ts_plugin_spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ describe('getExternalFiles()', () => {
2323
ngLS.getSemanticDiagnostics(APP_COMPONENT);
2424
// Now that global analysis is run, we should have all the typecheck files
2525
externalFiles = getExternalFiles(project);
26-
expect(externalFiles.length).toBe(1);
26+
// Includes 1 typecheck file, 1 template, and 1 css files
27+
expect(externalFiles.length).toBe(3);
2728
expect(externalFiles[0].endsWith('app.component.ngtypecheck.ts')).toBeTrue();
2829
});
2930
});

0 commit comments

Comments
 (0)