From 6a80c2337ad45cd73238448092a2a218711ab8ec Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 11 Oct 2023 14:20:10 -0700 Subject: [PATCH] Close watchers for TI that are no longer needed --- src/server/project.ts | 4 +- src/typingsInstallerCore/typingsInstaller.ts | 2 +- ...n-when-typing-installer-installs-typing.js | 46 +++++++++++++++++++ ...eAquisition-with-already-aquired-typing.js | 46 +++++++++++++++++++ ...n-when-typing-installer-installs-typing.js | 44 ++++++++++++++++++ ...update-of-typings-after-project-changes.js | 44 ++++++++++++++++++ 6 files changed, 184 insertions(+), 2 deletions(-) diff --git a/src/server/project.ts b/src/server/project.ts index 797ce3dd5d4..46b1416095f 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -2023,9 +2023,11 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo else { this.typeAcquisition = undefined; } - // If the typeAcquition is disabled, dont use typing files as root + // If the typeAcquition is disabled, dont use typing files as root and close existing watchers from TI if (!this.getTypeAcquisition().enable) { + const typingsCache = this.typingsCache; this.updateTypingFiles(/*setTypings*/ undefined, /*newTypings*/ undefined, /*scheduleUpdate*/ false); + if (typingsCache) this.projectService.typingsInstaller.onProjectClosed(this); } } diff --git a/src/typingsInstallerCore/typingsInstaller.ts b/src/typingsInstallerCore/typingsInstaller.ts index ce9c607b83c..f6fc608fd71 100644 --- a/src/typingsInstallerCore/typingsInstaller.ts +++ b/src/typingsInstallerCore/typingsInstaller.ts @@ -487,7 +487,7 @@ export abstract class TypingsInstaller { const existing = this.projectWatchers.get(projectName); const newSet = new Set(files); - if (!existing || forEachKey(newSet, s => !existing.has(s)) || forEachKey(existing, s => !newSet.has(s))) { + if (!existing || newSet.size !== existing.size || forEachKey(newSet, s => !existing.has(s)) || forEachKey(existing, s => !newSet.has(s))) { this.projectWatchers.set(projectName, newSet); this.sendResponse({ kind: ActionWatchTypingLocations, projectName, files }); } diff --git a/tests/baselines/reference/tsserver/typeAquisition/changes-to-typeAquisition-when-typing-installer-installs-typing.js b/tests/baselines/reference/tsserver/typeAquisition/changes-to-typeAquisition-when-typing-installer-installs-typing.js index d3a92631e36..2d2f5725c33 100644 --- a/tests/baselines/reference/tsserver/typeAquisition/changes-to-typeAquisition-when-typing-installer-installs-typing.js +++ b/tests/baselines/reference/tsserver/typeAquisition/changes-to-typeAquisition-when-typing-installer-installs-typing.js @@ -890,6 +890,18 @@ Info seq [hh:mm:ss:mss] Config: /users/user/projects/project1/jsconfig.json : { "configFilePath": "/users/user/projects/project1/jsconfig.json" } } +TI:: [hh:mm:ss:mss] Closing file watchers for project '/users/user/projects/project1/jsconfig.json' +TI:: [hh:mm:ss:mss] Sending response: + { + "kind": "action::watchTypingLocations", + "projectName": "/users/user/projects/project1/jsconfig.json", + "files": [] + } +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/bower_components 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/bower_components 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/node_modules 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/node_modules 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +TI:: [hh:mm:ss:mss] Closing file watchers for project '/users/user/projects/project1/jsconfig.json' - done. Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /users/user/projects/project1/jsconfig.json Info seq [hh:mm:ss:mss] File '/home/src/Library/Caches/typescript/node_modules/@types/bar/package.json' does not exist according to earlier cached lookups. Info seq [hh:mm:ss:mss] File '/home/src/Library/Caches/typescript/node_modules/@types/package.json' does not exist according to earlier cached lookups. @@ -954,6 +966,40 @@ Info seq [hh:mm:ss:mss] event: } After running Timeout callback:: count: 0 +PolledWatches:: +/home/src/Library/Caches/typescript/node_modules/@types/bar/package.json: + {"pollingInterval":2000} +/home/src/Library/Caches/typescript/node_modules/@types/package.json: + {"pollingInterval":2000} +/home/src/Library/Caches/typescript/node_modules/package.json: + {"pollingInterval":2000} +/users/user/projects/node_modules: + {"pollingInterval":500} +/users/user/projects/node_modules/@types: + {"pollingInterval":500} +/users/user/projects/project1/node_modules/@types: + {"pollingInterval":500} + +PolledWatches *deleted*:: +/users/user/projects/project1/bower_components: + {"pollingInterval":500} + +FsWatches:: +/home/src/Library/Caches/typescript/package.json: + {} +/home/src/tslibs/TS/Lib/lib.d.ts: + {} +/users/user/projects/project1/jsconfig.json: + {} + +FsWatchesRecursive:: +/home/src/Library/Caches/typescript/node_modules: + {} +/users/user/projects/project1: + {} +/users/user/projects/project1/node_modules: + {} + Projects:: /users/user/projects/project1/jsconfig.json (Configured) *changed* projectStateVersion: 4 diff --git a/tests/baselines/reference/tsserver/typeAquisition/changes-to-typeAquisition-with-already-aquired-typing.js b/tests/baselines/reference/tsserver/typeAquisition/changes-to-typeAquisition-with-already-aquired-typing.js index 3473767c153..19cb16a189d 100644 --- a/tests/baselines/reference/tsserver/typeAquisition/changes-to-typeAquisition-with-already-aquired-typing.js +++ b/tests/baselines/reference/tsserver/typeAquisition/changes-to-typeAquisition-with-already-aquired-typing.js @@ -586,6 +586,18 @@ Info seq [hh:mm:ss:mss] Config: /users/user/projects/project1/jsconfig.json : { "configFilePath": "/users/user/projects/project1/jsconfig.json" } } +TI:: [hh:mm:ss:mss] Closing file watchers for project '/users/user/projects/project1/jsconfig.json' +TI:: [hh:mm:ss:mss] Sending response: + { + "kind": "action::watchTypingLocations", + "projectName": "/users/user/projects/project1/jsconfig.json", + "files": [] + } +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/bower_components 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/bower_components 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/node_modules 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/node_modules 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +TI:: [hh:mm:ss:mss] Closing file watchers for project '/users/user/projects/project1/jsconfig.json' - done. Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /users/user/projects/project1/jsconfig.json Info seq [hh:mm:ss:mss] File '/home/src/Library/Caches/typescript/node_modules/@types/bar/package.json' does not exist according to earlier cached lookups. Info seq [hh:mm:ss:mss] File '/home/src/Library/Caches/typescript/node_modules/@types/package.json' does not exist according to earlier cached lookups. @@ -650,6 +662,40 @@ Info seq [hh:mm:ss:mss] event: } After running Timeout callback:: count: 0 +PolledWatches:: +/home/src/Library/Caches/typescript/node_modules/@types/bar/package.json: + {"pollingInterval":2000} +/home/src/Library/Caches/typescript/node_modules/@types/package.json: + {"pollingInterval":2000} +/home/src/Library/Caches/typescript/node_modules/package.json: + {"pollingInterval":2000} +/users/user/projects/node_modules: + {"pollingInterval":500} +/users/user/projects/node_modules/@types: + {"pollingInterval":500} +/users/user/projects/project1/node_modules/@types: + {"pollingInterval":500} + +PolledWatches *deleted*:: +/users/user/projects/project1/bower_components: + {"pollingInterval":500} + +FsWatches:: +/home/src/Library/Caches/typescript/package.json: + {} +/home/src/tslibs/TS/Lib/lib.d.ts: + {} +/users/user/projects/project1/jsconfig.json: + {} + +FsWatchesRecursive:: +/home/src/Library/Caches/typescript/node_modules: + {} +/users/user/projects/project1: + {} +/users/user/projects/project1/node_modules: + {} + Projects:: /users/user/projects/project1/jsconfig.json (Configured) *changed* projectStateVersion: 3 diff --git a/tests/baselines/reference/tsserver/typeAquisition/midway-changes-to-typeAquisition-when-typing-installer-installs-typing.js b/tests/baselines/reference/tsserver/typeAquisition/midway-changes-to-typeAquisition-when-typing-installer-installs-typing.js index de5e5afc58d..8e313dae746 100644 --- a/tests/baselines/reference/tsserver/typeAquisition/midway-changes-to-typeAquisition-when-typing-installer-installs-typing.js +++ b/tests/baselines/reference/tsserver/typeAquisition/midway-changes-to-typeAquisition-when-typing-installer-installs-typing.js @@ -596,6 +596,18 @@ Info seq [hh:mm:ss:mss] Config: /users/user/projects/project1/jsconfig.json : { "configFilePath": "/users/user/projects/project1/jsconfig.json" } } +TI:: [hh:mm:ss:mss] Closing file watchers for project '/users/user/projects/project1/jsconfig.json' +TI:: [hh:mm:ss:mss] Sending response: + { + "kind": "action::watchTypingLocations", + "projectName": "/users/user/projects/project1/jsconfig.json", + "files": [] + } +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/bower_components 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/bower_components 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/node_modules 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/node_modules 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +TI:: [hh:mm:ss:mss] Closing file watchers for project '/users/user/projects/project1/jsconfig.json' - done. Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /users/user/projects/project1/jsconfig.json Info seq [hh:mm:ss:mss] File '/users/user/projects/project1/node_modules/bar/package.json' does not exist according to earlier cached lookups. Info seq [hh:mm:ss:mss] File '/users/user/projects/project1/node_modules/package.json' does not exist according to earlier cached lookups. @@ -696,6 +708,38 @@ Info seq [hh:mm:ss:mss] event: } After running Timeout callback:: count: 0 +PolledWatches:: +/users/user/projects/node_modules: + {"pollingInterval":500} +/users/user/projects/node_modules/@types: + {"pollingInterval":500} +/users/user/projects/package.json: + {"pollingInterval":2000} +/users/user/projects/project1/node_modules/@types: + {"pollingInterval":500} +/users/user/projects/project1/node_modules/bar/package.json: + {"pollingInterval":2000} +/users/user/projects/project1/node_modules/package.json: + {"pollingInterval":2000} +/users/user/projects/project1/package.json: + {"pollingInterval":2000} + +PolledWatches *deleted*:: +/users/user/projects/project1/bower_components: + {"pollingInterval":500} + +FsWatches:: +/home/src/tslibs/TS/Lib/lib.d.ts: + {} +/users/user/projects/project1/jsconfig.json: + {} + +FsWatchesRecursive:: +/users/user/projects/project1: + {} +/users/user/projects/project1/node_modules: + {} + Projects:: /users/user/projects/project1/jsconfig.json (Configured) *changed* projectStateVersion: 2 diff --git a/tests/baselines/reference/tsserver/typeAquisition/receives-update-of-typings-after-project-changes.js b/tests/baselines/reference/tsserver/typeAquisition/receives-update-of-typings-after-project-changes.js index 6bf899af0fe..d7c0a31c739 100644 --- a/tests/baselines/reference/tsserver/typeAquisition/receives-update-of-typings-after-project-changes.js +++ b/tests/baselines/reference/tsserver/typeAquisition/receives-update-of-typings-after-project-changes.js @@ -484,6 +484,18 @@ Info seq [hh:mm:ss:mss] Config: /users/user/projects/project1/jsconfig.json : { "configFilePath": "/users/user/projects/project1/jsconfig.json" } } +TI:: [hh:mm:ss:mss] Closing file watchers for project '/users/user/projects/project1/jsconfig.json' +TI:: [hh:mm:ss:mss] Sending response: + { + "kind": "action::watchTypingLocations", + "projectName": "/users/user/projects/project1/jsconfig.json", + "files": [] + } +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/bower_components 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/bower_components 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/node_modules 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Close:: WatchInfo: /users/user/projects/project1/node_modules 1 undefined Project: /users/user/projects/project1/jsconfig.json WatchType: Directory location for typing installer +TI:: [hh:mm:ss:mss] Closing file watchers for project '/users/user/projects/project1/jsconfig.json' - done. Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /users/user/projects/project1/jsconfig.json Info seq [hh:mm:ss:mss] File '/users/user/projects/project1/node_modules/bar/package.json' does not exist according to earlier cached lookups. Info seq [hh:mm:ss:mss] File '/users/user/projects/project1/node_modules/package.json' does not exist according to earlier cached lookups. @@ -551,6 +563,38 @@ Info seq [hh:mm:ss:mss] event: } After running Timeout callback:: count: 0 +PolledWatches:: +/users/user/projects/node_modules: + {"pollingInterval":500} +/users/user/projects/node_modules/@types: + {"pollingInterval":500} +/users/user/projects/package.json: + {"pollingInterval":2000} +/users/user/projects/project1/node_modules/@types: + {"pollingInterval":500} +/users/user/projects/project1/node_modules/bar/package.json: + {"pollingInterval":2000} +/users/user/projects/project1/node_modules/package.json: + {"pollingInterval":2000} +/users/user/projects/project1/package.json: + {"pollingInterval":2000} + +PolledWatches *deleted*:: +/users/user/projects/project1/bower_components: + {"pollingInterval":500} + +FsWatches:: +/home/src/tslibs/TS/Lib/lib.d.ts: + {} +/users/user/projects/project1/jsconfig.json: + {} + +FsWatchesRecursive:: +/users/user/projects/project1: + {} +/users/user/projects/project1/node_modules: + {} + Projects:: /users/user/projects/project1/jsconfig.json (Configured) *changed* projectStateVersion: 2