Skip to content

Commit

Permalink
fix(language-service): Prevent TSServer from removing templates from …
Browse files Browse the repository at this point in the history
…project

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
  • Loading branch information
atscott committed May 12, 2022
1 parent 6375fa7 commit 95bd2d2
Showing 1 changed file with 10 additions and 1 deletion.
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];
}

0 comments on commit 95bd2d2

Please sign in to comment.