Skip to content

Commit

Permalink
Merge pull request #23841 from Microsoft/sourceFileChangeAssert
Browse files Browse the repository at this point in the history
Fix the assert for orphan script info source change event
  • Loading branch information
sheetalkamat authored May 3, 2018
2 parents 724e656 + a196f16 commit 24e58c3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
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 @@ -3259,6 +3259,53 @@ namespace ts.projectSystem {
// Allow allowNonTsExtensions will be set to true for deferred extensions.
assert.isTrue(configuredProject.getCompilerOptions().allowNonTsExtensions);
});

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

0 comments on commit 24e58c3

Please sign in to comment.