Skip to content

Commit 4d68aa7

Browse files
committed
Fix the open File watch triggered setting
1 parent ab7b688 commit 4d68aa7

File tree

3 files changed

+51
-20
lines changed

3 files changed

+51
-20
lines changed

src/server/editorServices.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,11 @@ namespace ts.server {
11101110
// don't trigger callback on open, existing files
11111111
if (project.fileIsOpen(fileOrDirectoryPath)) {
11121112
if (project.pendingReload !== ConfigFileProgramReloadLevel.Full) {
1113-
project.openFileWatchTriggered.set(fileOrDirectoryPath, true);
11141113
const info = Debug.assertDefined(this.getScriptInfoForPath(fileOrDirectoryPath));
1115-
if (!info.isAttached(project)) {
1114+
if (info.isAttached(project)) {
1115+
project.openFileWatchTriggered.set(fileOrDirectoryPath, true);
1116+
}
1117+
else {
11161118
project.pendingReload = ConfigFileProgramReloadLevel.Partial;
11171119
this.delayUpdateProjectGraphAndEnsureProjectStructureForOpenFiles(project);
11181120
}

src/testRunner/unittests/tsserver/configuredProjects.ts

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -940,13 +940,23 @@ declare var console: {
940940
})
941941
};
942942
const fooBar: File = {
943-
path: `${tscWatch.projectRoot}/src/fooBar.ts`,
943+
path: `${tscWatch.projectRoot}/src/sub/fooBar.ts`,
944944
content: "export function fooBar() { }"
945945
};
946-
function verifySessionWorker({ openFileBeforeCreating, checkProjectBeforeError, checkProjectAfterError, }: VerifySession, errorOnNewFileBeforeOldFile: boolean) {
947-
const host = createServerHost([foo, bar, config, libFile]);
946+
function verifySessionWorker({ withExclude, openFileBeforeCreating, checkProjectBeforeError, checkProjectAfterError, }: VerifySession, errorOnNewFileBeforeOldFile: boolean) {
947+
const host = createServerHost([
948+
foo, bar, libFile, { path: `${tscWatch.projectRoot}/src/sub` },
949+
withExclude ?
950+
{
951+
path: config.path,
952+
content: JSON.stringify({
953+
include: ["./src"],
954+
exclude: ["./src/sub"]
955+
})
956+
} :
957+
config
958+
]);
948959
const session = createSession(host, {
949-
//logger: createLoggerWritingToConsole(),
950960
canUseEvents: true
951961
});
952962
session.executeCommandSeq<protocol.OpenRequest>({
@@ -990,6 +1000,7 @@ declare var console: {
9901000
checkProjectAfterError(service);
9911001
}
9921002
interface VerifySession {
1003+
withExclude?: boolean;
9931004
openFileBeforeCreating: boolean;
9941005
checkProjectBeforeError: (service: server.ProjectService) => void;
9951006
checkProjectAfterError: (service: server.ProjectService) => void;
@@ -1003,35 +1014,53 @@ declare var console: {
10031014
verifySessionWorker(input, /*errorOnNewFileBeforeOldFile*/ false);
10041015
});
10051016
}
1017+
function checkFooBarInInferredProject(service: server.ProjectService) {
1018+
checkNumberOfProjects(service, { configuredProjects: 1, inferredProjects: 1 });
1019+
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, libFile.path, config.path]);
1020+
checkProjectActualFiles(service.inferredProjects[0], [fooBar.path, libFile.path]);
1021+
}
1022+
function checkFooBarInConfiguredProject(service: server.ProjectService) {
1023+
checkNumberOfProjects(service, { configuredProjects: 1 });
1024+
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, fooBar.path, libFile.path, config.path]);
1025+
}
10061026
describe("when new file creation directory watcher is invoked before file is opened in editor", () => {
10071027
verifySession({
10081028
openFileBeforeCreating: false,
1009-
checkProjectBeforeError: service => {
1010-
checkNumberOfProjects(service, { configuredProjects: 1 });
1011-
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, fooBar.path, libFile.path, config.path]);
1012-
},
1013-
checkProjectAfterError: service => {
1014-
checkNumberOfProjects(service, { configuredProjects: 1 });
1015-
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, fooBar.path, libFile.path, config.path]);
1016-
}
1029+
checkProjectBeforeError: checkFooBarInConfiguredProject,
1030+
checkProjectAfterError: checkFooBarInConfiguredProject
1031+
});
1032+
describe("when new file is excluded from config", () => {
1033+
verifySession({
1034+
withExclude: true,
1035+
openFileBeforeCreating: false,
1036+
checkProjectBeforeError: checkFooBarInInferredProject,
1037+
checkProjectAfterError: checkFooBarInInferredProject
1038+
});
10171039
});
10181040
});
10191041

10201042
describe("when new file creation directory watcher is invoked after file is opened in editor", () => {
10211043
verifySession({
10221044
openFileBeforeCreating: true,
1023-
checkProjectBeforeError: service => {
1024-
checkNumberOfProjects(service, { configuredProjects: 1, inferredProjects: 1 });
1025-
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, libFile.path, config.path]);
1026-
checkProjectActualFiles(service.inferredProjects[0], [fooBar.path, libFile.path]);
1027-
},
1045+
checkProjectBeforeError: checkFooBarInInferredProject,
10281046
checkProjectAfterError: service => {
1047+
// Both projects exist but fooBar is in configured project after the update
1048+
// Inferred project is yet to be updated so still has fooBar
10291049
checkNumberOfProjects(service, { configuredProjects: 1, inferredProjects: 1 });
10301050
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, fooBar.path, libFile.path, config.path]);
10311051
checkProjectActualFiles(service.inferredProjects[0], [fooBar.path, libFile.path]);
10321052
assert.isTrue(service.inferredProjects[0].dirty);
1053+
assert.equal(service.inferredProjects[0].getRootFilesMap().size, 0);
10331054
}
10341055
});
1056+
describe("when new file is excluded from config", () => {
1057+
verifySession({
1058+
withExclude: true,
1059+
openFileBeforeCreating: true,
1060+
checkProjectBeforeError: checkFooBarInInferredProject,
1061+
checkProjectAfterError: checkFooBarInInferredProject
1062+
});
1063+
});
10351064
});
10361065
});
10371066
});

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9482,7 +9482,7 @@ declare namespace ts.server {
94829482
private getCompileOnSaveAffectedFileList;
94839483
private emitFile;
94849484
private getSignatureHelpItems;
9485-
private createCheckList;
9485+
private toPendingErrorCheck;
94869486
private getDiagnostics;
94879487
private change;
94889488
private reload;

0 commit comments

Comments
 (0)