Release the documents from language service using key instead of calculating it on the spot since we want to use correct paths for the files (#37596)

Fixes #37500
This commit is contained in:
Sheetal Nandi
2020-03-25 15:51:07 -07:00
committed by GitHub
parent b58a29b808
commit 6bd68a83b4
2 changed files with 27 additions and 1 deletions

View File

@@ -1405,8 +1405,10 @@ namespace ts {
function dispose(): void {
if (program) {
// Use paths to ensure we are using correct key and paths as document registry could bre created with different current directory than host
const key = documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions());
forEach(program.getSourceFiles(), f =>
documentRegistry.releaseDocument(f.fileName, program.getCompilerOptions()));
documentRegistry.releaseDocumentWithKey(f.resolvedPath, key));
program = undefined!; // TODO: GH#18217
}
host = undefined!;

View File

@@ -97,6 +97,30 @@ var x = 10;`
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [untitled.path, libFile.path, config.path]);
checkProjectActualFiles(service.inferredProjects[0], [untitledFile, libFile.path]);
});
it("opening and closing untitled files when projectRootPath is different from currentDirectory", () => {
const config: File = {
path: `${tscWatch.projectRoot}/tsconfig.json`,
content: "{}"
};
const file: File = {
path: `${tscWatch.projectRoot}/file.ts`,
content: "const y = 10"
};
const host = createServerHost([config, file, libFile], { useCaseSensitiveFileNames: true });
const service = createProjectService(host, /*parameters*/ undefined, { useInferredProjectPerProjectRoot: true });
service.openClientFile(untitledFile, "const x = 10;", /*scriptKind*/ undefined, tscWatch.projectRoot);
checkNumberOfProjects(service, { inferredProjects: 1 });
checkProjectActualFiles(service.inferredProjects[0], [untitledFile, libFile.path]);
verifyDynamic(service, `${tscWatch.projectRoot}/${untitledFile}`);
// Close untitled file
service.closeClientFile(untitledFile);
// Open file from configured project which should collect inferredProject
service.openClientFile(file.path);
checkNumberOfProjects(service, { configuredProjects: 1 });
});
});
describe("unittests:: tsserver:: dynamicFiles:: ", () => {