Skip to content

Commit

Permalink
Fix the open File watch triggered setting
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Jan 17, 2020
1 parent 590dc95 commit 532b28a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,11 @@ namespace ts.server {
// don't trigger callback on open, existing files
if (project.fileIsOpen(fileOrDirectoryPath)) {
if (project.pendingReload !== ConfigFileProgramReloadLevel.Full) {
project.openFileWatchTriggered.set(fileOrDirectoryPath, true);
const info = Debug.assertDefined(this.getScriptInfoForPath(fileOrDirectoryPath));
if (!info.isAttached(project)) {
if (info.isAttached(project)) {
project.openFileWatchTriggered.set(fileOrDirectoryPath, true);
}
else {
project.pendingReload = ConfigFileProgramReloadLevel.Partial;
this.delayUpdateProjectGraphAndEnsureProjectStructureForOpenFiles(project);
}
Expand Down
63 changes: 46 additions & 17 deletions src/testRunner/unittests/tsserver/configuredProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -940,13 +940,23 @@ declare var console: {
})
};
const fooBar: File = {
path: `${tscWatch.projectRoot}/src/fooBar.ts`,
path: `${tscWatch.projectRoot}/src/sub/fooBar.ts`,
content: "export function fooBar() { }"
};
function verifySessionWorker({ openFileBeforeCreating, checkProjectBeforeError, checkProjectAfterError, }: VerifySession, errorOnNewFileBeforeOldFile: boolean) {
const host = createServerHost([foo, bar, config, libFile]);
function verifySessionWorker({ withExclude, openFileBeforeCreating, checkProjectBeforeError, checkProjectAfterError, }: VerifySession, errorOnNewFileBeforeOldFile: boolean) {
const host = createServerHost([
foo, bar, libFile, { path: `${tscWatch.projectRoot}/src/sub` },
withExclude ?
{
path: config.path,
content: JSON.stringify({
include: ["./src"],
exclude: ["./src/sub"]
})
} :
config
]);
const session = createSession(host, {
//logger: createLoggerWritingToConsole(),
canUseEvents: true
});
session.executeCommandSeq<protocol.OpenRequest>({
Expand Down Expand Up @@ -990,6 +1000,7 @@ declare var console: {
checkProjectAfterError(service);
}
interface VerifySession {
withExclude?: boolean;
openFileBeforeCreating: boolean;
checkProjectBeforeError: (service: server.ProjectService) => void;
checkProjectAfterError: (service: server.ProjectService) => void;
Expand All @@ -1003,35 +1014,53 @@ declare var console: {
verifySessionWorker(input, /*errorOnNewFileBeforeOldFile*/ false);
});
}
function checkFooBarInInferredProject(service: server.ProjectService) {
checkNumberOfProjects(service, { configuredProjects: 1, inferredProjects: 1 });
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, libFile.path, config.path]);
checkProjectActualFiles(service.inferredProjects[0], [fooBar.path, libFile.path]);
}
function checkFooBarInConfiguredProject(service: server.ProjectService) {
checkNumberOfProjects(service, { configuredProjects: 1 });
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, fooBar.path, libFile.path, config.path]);
}
describe("when new file creation directory watcher is invoked before file is opened in editor", () => {
verifySession({
openFileBeforeCreating: false,
checkProjectBeforeError: service => {
checkNumberOfProjects(service, { configuredProjects: 1 });
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, fooBar.path, libFile.path, config.path]);
},
checkProjectAfterError: service => {
checkNumberOfProjects(service, { configuredProjects: 1 });
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, fooBar.path, libFile.path, config.path]);
}
checkProjectBeforeError: checkFooBarInConfiguredProject,
checkProjectAfterError: checkFooBarInConfiguredProject
});
describe("when new file is excluded from config", () => {
verifySession({
withExclude: true,
openFileBeforeCreating: false,
checkProjectBeforeError: checkFooBarInInferredProject,
checkProjectAfterError: checkFooBarInInferredProject
});
});
});

describe("when new file creation directory watcher is invoked after file is opened in editor", () => {
verifySession({
openFileBeforeCreating: true,
checkProjectBeforeError: service => {
checkNumberOfProjects(service, { configuredProjects: 1, inferredProjects: 1 });
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, libFile.path, config.path]);
checkProjectActualFiles(service.inferredProjects[0], [fooBar.path, libFile.path]);
},
checkProjectBeforeError: checkFooBarInInferredProject,
checkProjectAfterError: service => {
// Both projects exist but fooBar is in configured project after the update
// Inferred project is yet to be updated so still has fooBar
checkNumberOfProjects(service, { configuredProjects: 1, inferredProjects: 1 });
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, fooBar.path, libFile.path, config.path]);
checkProjectActualFiles(service.inferredProjects[0], [fooBar.path, libFile.path]);
assert.isTrue(service.inferredProjects[0].dirty);
assert.equal(service.inferredProjects[0].getRootFilesMap().size, 0);
}
});
describe("when new file is excluded from config", () => {
verifySession({
withExclude: true,
openFileBeforeCreating: true,
checkProjectBeforeError: checkFooBarInInferredProject,
checkProjectAfterError: checkFooBarInInferredProject
});
});
});
});
});
Expand Down

0 comments on commit 532b28a

Please sign in to comment.