Skip to content

Commit 6bd68a8

Browse files
authored
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 (microsoft#37596)
Fixes microsoft#37500
1 parent b58a29b commit 6bd68a8

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/services/services.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1405,8 +1405,10 @@ namespace ts {
14051405

14061406
function dispose(): void {
14071407
if (program) {
1408+
// Use paths to ensure we are using correct key and paths as document registry could bre created with different current directory than host
1409+
const key = documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions());
14081410
forEach(program.getSourceFiles(), f =>
1409-
documentRegistry.releaseDocument(f.fileName, program.getCompilerOptions()));
1411+
documentRegistry.releaseDocumentWithKey(f.resolvedPath, key));
14101412
program = undefined!; // TODO: GH#18217
14111413
}
14121414
host = undefined!;

src/testRunner/unittests/tsserver/dynamicFiles.ts

+24
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,30 @@ var x = 10;`
9797
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [untitled.path, libFile.path, config.path]);
9898
checkProjectActualFiles(service.inferredProjects[0], [untitledFile, libFile.path]);
9999
});
100+
101+
it("opening and closing untitled files when projectRootPath is different from currentDirectory", () => {
102+
const config: File = {
103+
path: `${tscWatch.projectRoot}/tsconfig.json`,
104+
content: "{}"
105+
};
106+
const file: File = {
107+
path: `${tscWatch.projectRoot}/file.ts`,
108+
content: "const y = 10"
109+
};
110+
const host = createServerHost([config, file, libFile], { useCaseSensitiveFileNames: true });
111+
const service = createProjectService(host, /*parameters*/ undefined, { useInferredProjectPerProjectRoot: true });
112+
service.openClientFile(untitledFile, "const x = 10;", /*scriptKind*/ undefined, tscWatch.projectRoot);
113+
checkNumberOfProjects(service, { inferredProjects: 1 });
114+
checkProjectActualFiles(service.inferredProjects[0], [untitledFile, libFile.path]);
115+
verifyDynamic(service, `${tscWatch.projectRoot}/${untitledFile}`);
116+
117+
// Close untitled file
118+
service.closeClientFile(untitledFile);
119+
120+
// Open file from configured project which should collect inferredProject
121+
service.openClientFile(file.path);
122+
checkNumberOfProjects(service, { configuredProjects: 1 });
123+
});
100124
});
101125

102126
describe("unittests:: tsserver:: dynamicFiles:: ", () => {

0 commit comments

Comments
 (0)