@@ -543,7 +543,7 @@ namespace ts.server {
543543 }
544544
545545 /**
546- * This is the callback function when a watched directory has added or removed files.
546+ * This is the callback function when a watched directory has added or removed source code files.
547547 * @param project the project that associates with this directory watcher
548548 * @param fileName the absolute file name that changed in watched directory
549549 */
@@ -567,12 +567,15 @@ namespace ts.server {
567567 // just update the current project.
568568 this.updateConfiguredProject(project);
569569
570- // Call updateProjectStructure to clean up inferred projects we may have created for the
571- // new files
570+ // Call updateProjectStructure to clean up inferred projects we may have
571+ // created for the new files
572572 this.updateProjectStructure();
573573 }
574574 }
575575
576+ /**
577+ * This is the callback function when a watched directory has an added tsconfig file.
578+ */
576579 directoryWatchedForTsconfigChanged(fileName: string) {
577580 if (ts.getBaseFileName(fileName) != "tsconfig.json") {
578581 this.log(fileName + " is not tsconfig.json");
@@ -585,6 +588,8 @@ namespace ts.server {
585588 let rootFilesInTsconfig = projectOptions.files.map(f => this.getCanonicalFileName(f));
586589 let openFileRoots = this.openFileRoots.map(s => this.getCanonicalFileName(s.fileName));
587590
591+ // We should only care about the new tsconfig file if it contains any
592+ // opened root files of existing inferred projects
588593 for (let openFileRoot of openFileRoots) {
589594 if (rootFilesInTsconfig.indexOf(openFileRoot) >= 0) {
590595 this.reloadProjects();
@@ -708,6 +713,7 @@ namespace ts.server {
708713 }
709714 else {
710715 for (let directory of project.directoriesWatchedForTsconfig) {
716+ // if the ref count for this directory watcher drops to 0, it's time to close it
711717 if (!(--project.projectService.directoryWatchersRefCount[directory])) {
712718 this.log("Close directory watcher for: " + directory);
713719 project.projectService.directoryWatchersForTsconfig[directory].close();
@@ -956,9 +962,6 @@ namespace ts.server {
956962 this.addOpenFile(unattachedOpenFiles[i]);
957963 }
958964 this.printProjects();
959-
960- this.log("Current openFileRoots: " + this.openFileRoots.map(s => s.fileName).toString());
961- this.log("Current openFileRootsConfigured: " + this.openFileRootsConfigured.map(s => s.fileName).toString());
962965 }
963966
964967 getScriptInfo(filename: string) {
0 commit comments