From 3d08dd9460a6bfdffccb9cea0c1ebcea697f0d64 Mon Sep 17 00:00:00 2001 From: Mate Pek Date: Wed, 7 Feb 2024 13:09:49 +0700 Subject: [PATCH] improved documentation and logging related to file.watcherExclude --- CHANGELOG.md | 4 ++++ documents/support.md | 6 ++++++ src/ConfigOfExecGroup.ts | 23 +++++++++++++++++++++-- src/util/FSWatcher.ts | 33 ++++++++++++++------------------- 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c76165e..10453e66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +## [4.8.1] + +Improved logging + ## [4.8.0] - 2023-12-29 ### Changed diff --git a/documents/support.md b/documents/support.md index fdee290e..45e3e272 100644 --- a/documents/support.md +++ b/documents/support.md @@ -13,6 +13,12 @@ BUT before that read ALL this document. ## F.A.Q +### The extension cannot find my test executables. + +> In version `4.8.0` a new filtering was introduced. +> Searching for executables respects `files.watcherExclude` vscode config. +> One can try removing their executable files' pattern from this config. + ### Link / Build process fails because the executable is locked by this extension. > Check `testMate.cpp.test.advancedExecutables` -> `executableCloning`. diff --git a/src/ConfigOfExecGroup.ts b/src/ConfigOfExecGroup.ts index 19573386..38e143c2 100644 --- a/src/ConfigOfExecGroup.ts +++ b/src/ConfigOfExecGroup.ts @@ -70,12 +70,31 @@ export class ConfigOfExecGroup implements vscode.Disposable { if (this._pattern.indexOf('\\') != -1) this._shared.log.info('Pattern contains backslash character. Try to avoid that.'); + let enabledExcludes: string[] = []; + try { + const fileWatcherExclude = + vscode.workspace.getConfiguration('files').get>('watcherExclude') ?? {}; + enabledExcludes = Object.entries(fileWatcherExclude) + .filter(i => i[1]) + .map(i => i[0]); + } catch (err) { + this._shared.log.error('Something wrong with exclusion', err); + } + + if (enabledExcludes.length > 0) { + this._shared.log.info( + 'Test executables might be ignored! Excluding some patterns because they are set in vscode under `files.watcherExclude`.', + enabledExcludes, + ); + enabledExcludes = []; //TODO:mapek + } + let filePaths: string[] = []; let execWatcher: FSWatcher | undefined = undefined; try { if (pattern.isPartOfWs) { - execWatcher = new VSCFSWatcherWrapper(this._shared.workspaceFolder, pattern.relativeToWsPosix); + execWatcher = new VSCFSWatcherWrapper(this._shared.workspaceFolder, pattern.relativeToWsPosix, enabledExcludes); } else { execWatcher = new GazeWrapper([pattern.absPath]); } @@ -166,7 +185,7 @@ export class ConfigOfExecGroup implements vscode.Disposable { for (const pattern of this._dependsOn) { const p = await this._pathProcessor(pattern); if (p.isPartOfWs) { - const w = new VSCFSWatcherWrapper(this._shared.workspaceFolder, p.relativeToWsPosix); + const w = new VSCFSWatcherWrapper(this._shared.workspaceFolder, p.relativeToWsPosix, []); this._disposables.push(w); w.onError((e: Error): void => this._shared.log.error('dependsOn watcher:', e, p)); diff --git a/src/util/FSWatcher.ts b/src/util/FSWatcher.ts index 06f953ab..b0117e7f 100644 --- a/src/util/FSWatcher.ts +++ b/src/util/FSWatcher.ts @@ -74,15 +74,21 @@ export class GazeWrapper implements FSWatcher { } export class VSCFSWatcherWrapper implements FSWatcher { - constructor(workspaceFolder: vscode.WorkspaceFolder, relativePattern: string) { + constructor(workspaceFolder: vscode.WorkspaceFolder, relativePattern: string, excludePatterns: string[]) { if (path.isAbsolute(relativePattern)) throw new Error('Relative path is expected:' + relativePattern); this._relativePattern = new vscode.RelativePattern(workspaceFolder, relativePattern); this._vscWatcher = vscode.workspace.createFileSystemWatcher(this._relativePattern, false, false, false); this._disposables.push(this._vscWatcher); + this._excludePattern = excludePatterns; } + private readonly _relativePattern: vscode.RelativePattern; + private readonly _vscWatcher: vscode.FileSystemWatcher; + private readonly _disposables: vscode.Disposable[] = []; + private readonly _excludePattern: readonly string[] = []; + dispose(): void { this._disposables.forEach(c => c.dispose()); } @@ -91,23 +97,16 @@ export class VSCFSWatcherWrapper implements FSWatcher { return Promise.resolve(); } - watched(): Promise { - const excludeObj = vscode.workspace.getConfiguration('files').get>('watcherExclude') ?? {}; - const enabledExcludes = Object.entries(excludeObj) - .filter(i => i[1]) - .map(i => i[0]); + async watched(): Promise { // this trick seems working but would need more understanding const exclude = - enabledExcludes.length === 0 + this._excludePattern.length === 0 ? null - : enabledExcludes.length === 1 - ? enabledExcludes[0] - : '{' + enabledExcludes.join(',') + '}'; - return new Promise(resolve => { - vscode.workspace - .findFiles(this._relativePattern, exclude, 10000) - .then((uris: vscode.Uri[]) => resolve(uris.map(v => v.fsPath))); - }); + : this._excludePattern.length === 1 + ? this._excludePattern[0] + : '{' + this._excludePattern.join(',') + '}'; + const uris = await vscode.workspace.findFiles(this._relativePattern, exclude, 10000); + return uris.map(v => v.fsPath); } onAll(handler: (fsPath: string) => void): void { @@ -120,8 +119,4 @@ export class VSCFSWatcherWrapper implements FSWatcher { onError(_handler: (err: Error) => void): void { return undefined; } - - private readonly _relativePattern: vscode.RelativePattern; - private readonly _vscWatcher: vscode.FileSystemWatcher; - private readonly _disposables: vscode.Disposable[] = []; }