From 218be87e88e087003aec3340a89363fb82ff2d43 Mon Sep 17 00:00:00 2001 From: Koen Vlaswinkel Date: Wed, 20 Dec 2023 13:29:40 +0100 Subject: [PATCH] Do not reregister watchers on every file change for qltests During the qltest discovery, we were recreating the watchers for qltests on every file change. This was causing the watchers to be recreated on each change, while there were no functional changes to the watchers themselves. This commit moves the creation of the watchers to the constructor of the QLTestDiscovery class, and removes the creation of the watchers from the discover() method. The behavior should be the same. --- .../src/query-testing/qltest-discovery.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/extensions/ql-vscode/src/query-testing/qltest-discovery.ts b/extensions/ql-vscode/src/query-testing/qltest-discovery.ts index 73c2d5a2559..0174836305e 100644 --- a/extensions/ql-vscode/src/query-testing/qltest-discovery.ts +++ b/extensions/ql-vscode/src/query-testing/qltest-discovery.ts @@ -31,6 +31,15 @@ export class QLTestDiscovery extends Discovery { super("QL Test Discovery", extLogger); this.push(this.watcher.onDidChange(this.handleDidChange, this)); + + // Watch for changes to any `.ql` or `.qlref` file in any of the QL packs that contain tests. + this.watcher.addWatch( + new RelativePattern(this.workspaceFolder.uri.fsPath, "**/*.{ql,qlref}"), + ); + // need to explicitly watch for changes to directories themselves. + this.watcher.addWatch( + new RelativePattern(this.workspaceFolder.uri.fsPath, "**/"), + ); } /** @@ -56,15 +65,6 @@ export class QLTestDiscovery extends Discovery { protected async discover() { this._testDirectory = await this.discoverTests(); - this.watcher.clear(); - // Watch for changes to any `.ql` or `.qlref` file in any of the QL packs that contain tests. - this.watcher.addWatch( - new RelativePattern(this.workspaceFolder.uri.fsPath, "**/*.{ql,qlref}"), - ); - // need to explicitly watch for changes to directories themselves. - this.watcher.addWatch( - new RelativePattern(this.workspaceFolder.uri.fsPath, "**/"), - ); this._onDidChangeTests.fire(undefined); }