Skip to content

Release the documents from language service using paths and keys #37596

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

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand Down
24 changes: 24 additions & 0 deletions src/testRunner/unittests/tsserver/dynamicFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:: ", () => {
Expand Down