Skip to content
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

Fix the assert for orphan script info source change event #23841

Merged
merged 2 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
49 changes: 48 additions & 1 deletion src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3181,7 +3181,7 @@ namespace ts.projectSystem {
const projectLocation = "/user/username/projects/project";
const file1: FileOrFolder = {
path: `${projectLocation}/src/file1.ts`,
content: `import { y } from "./file1"; let x = 10;`
content: `import { y } from "./file2"; let x = 10;`
};
const file2: FileOrFolder = {
path: `${projectLocation}/src/file2.ts`,
Expand Down Expand Up @@ -3217,6 +3217,53 @@ namespace ts.projectSystem {
});

});

it("Orphan source files are handled correctly on watch trigger", () => {
const projectLocation = "/user/username/projects/project";
const file1: FileOrFolder = {
path: `${projectLocation}/src/file1.ts`,
content: `export let x = 10;`
};
const file2: FileOrFolder = {
path: `${projectLocation}/src/file2.ts`,
content: "export let y = 10;"
};
const configContent1 = JSON.stringify({
files: ["src/file1.ts", "src/file2.ts"]
});
const config: FileOrFolder = {
path: `${projectLocation}/tsconfig.json`,
content: configContent1
};
const files = [file1, file2, libFile, config];
const host = createServerHost(files);
const service = createProjectService(host);
service.openClientFile(file1.path);
checkProjectActualFiles(service.configuredProjects.get(config.path), [file1.path, file2.path, libFile.path, config.path]);

const configContent2 = JSON.stringify({
files: ["src/file1.ts"]
});
config.content = configContent2;
host.reloadFS(files);
host.runQueuedTimeoutCallbacks();

checkProjectActualFiles(service.configuredProjects.get(config.path), [file1.path, libFile.path, config.path]);
verifyFile2InfoIsOrphan();

file2.content += "export let z = 10;";
host.reloadFS(files);
host.runQueuedTimeoutCallbacks();

checkProjectActualFiles(service.configuredProjects.get(config.path), [file1.path, libFile.path, config.path]);
verifyFile2InfoIsOrphan();

function verifyFile2InfoIsOrphan() {
const info = service.getScriptInfoForPath(file2.path as Path);
assert.isDefined(info);
assert.equal(info.containingProjects.length, 0);
}
});
});

describe("tsserverProjectSystem Proper errors", () => {
Expand Down
9 changes: 5 additions & 4 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,12 @@ namespace ts.server {
}

private delayUpdateProjectGraphs(projects: ReadonlyArray<Project>) {
for (const project of projects) {
this.delayUpdateProjectGraph(project);
if (projects.length) {
for (const project of projects) {
this.delayUpdateProjectGraph(project);
}
this.delayEnsureProjectForOpenFiles();
}
this.delayEnsureProjectForOpenFiles();
}

setCompilerOptionsForInferredProjects(projectCompilerOptions: protocol.ExternalProjectCompilerOptions, projectRootPath?: string): void {
Expand Down Expand Up @@ -708,7 +710,6 @@ namespace ts.server {
this.handleDeletedFile(info);
}
else if (!info.isScriptOpen()) {
Debug.assert(info.containingProjects.length !== 0);
// file has been changed which might affect the set of referenced files in projects that include
// this file and set of inferred projects
info.delayReloadNonMixedContentFile();
Expand Down