Skip to content

Commit c969807

Browse files
authored
Merge pull request #17497 from Microsoft/disposeWatchedDirectoriesOnlyIfPresentMaster
[master] dispose the watched wild card directories only if present
2 parents 4f13bcf + 1317153 commit c969807

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,50 @@ namespace ts.projectSystem {
23322332
const navbar = projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/ false).getNavigationBarItems(f1.path);
23332333
assert.equal(navbar[0].spans[0].length, f1.content.length);
23342334
});
2335+
2336+
it("deleting config file opened from the external project works", () => {
2337+
const site = {
2338+
path: "/user/someuser/project/js/site.js",
2339+
content: ""
2340+
};
2341+
const configFile = {
2342+
path: "/user/someuser/project/tsconfig.json",
2343+
content: "{}"
2344+
};
2345+
const projectFileName = "/user/someuser/project/WebApplication6.csproj";
2346+
const host = createServerHost([libFile, site, configFile]);
2347+
const projectService = createProjectService(host);
2348+
2349+
const externalProject: protocol.ExternalProject = {
2350+
projectFileName,
2351+
rootFiles: [toExternalFile(site.path), toExternalFile(configFile.path)],
2352+
options: { allowJs: false },
2353+
typeAcquisition: { "include": [] }
2354+
};
2355+
2356+
projectService.openExternalProjects([externalProject]);
2357+
2358+
let knownProjects = projectService.synchronizeProjectList([]);
2359+
checkNumberOfProjects(projectService, { configuredProjects: 1, externalProjects: 0, inferredProjects: 0 });
2360+
2361+
const configProject = projectService.configuredProjects[0];
2362+
checkProjectActualFiles(configProject, [libFile.path]);
2363+
2364+
const diagnostics = configProject.getAllProjectErrors();
2365+
assert.equal(diagnostics[0].code, Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2.code);
2366+
2367+
host.reloadFS([libFile, site]);
2368+
host.triggerFileWatcherCallback(configFile.path, FileWatcherEventKind.Deleted);
2369+
2370+
knownProjects = projectService.synchronizeProjectList(map(knownProjects, proj => proj.info));
2371+
checkNumberOfProjects(projectService, { configuredProjects: 0, externalProjects: 0, inferredProjects: 0 });
2372+
2373+
externalProject.rootFiles.length = 1;
2374+
projectService.openExternalProjects([externalProject]);
2375+
2376+
checkNumberOfProjects(projectService, { configuredProjects: 0, externalProjects: 1, inferredProjects: 0 });
2377+
checkProjectActualFiles(projectService.externalProjects[0], [site.path, libFile.path]);
2378+
});
23352379
});
23362380

23372381
describe("Proper errors", () => {

src/server/project.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,9 @@ namespace ts.server {
936936
export class ConfiguredProject extends Project {
937937
private typeAcquisition: TypeAcquisition;
938938
private projectFileWatcher: FileWatcher;
939-
private directoryWatcher: FileWatcher;
940-
private directoriesWatchedForWildcards: Map<FileWatcher>;
941-
private typeRootsWatchers: FileWatcher[];
939+
private directoryWatcher: FileWatcher | undefined;
940+
private directoriesWatchedForWildcards: Map<FileWatcher> | undefined;
941+
private typeRootsWatchers: FileWatcher[] | undefined;
942942
readonly canonicalConfigFilePath: NormalizedPath;
943943

944944
private plugins: PluginModule[] = [];
@@ -1134,10 +1134,12 @@ namespace ts.server {
11341134
this.typeRootsWatchers = undefined;
11351135
}
11361136

1137-
this.directoriesWatchedForWildcards.forEach(watcher => {
1138-
watcher.close();
1139-
});
1140-
this.directoriesWatchedForWildcards = undefined;
1137+
if (this.directoriesWatchedForWildcards) {
1138+
this.directoriesWatchedForWildcards.forEach(watcher => {
1139+
watcher.close();
1140+
});
1141+
this.directoriesWatchedForWildcards = undefined;
1142+
}
11411143

11421144
this.stopWatchingDirectory();
11431145
}

0 commit comments

Comments
 (0)