Skip to content

Commit

Permalink
improved documentation and logging related to file.watcherExclude
Browse files Browse the repository at this point in the history
  • Loading branch information
matepek committed Feb 7, 2024
1 parent bbc3993 commit 3d08dd9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions documents/support.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
23 changes: 21 additions & 2 deletions src/ConfigOfExecGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, boolean>>('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]);
}
Expand Down Expand Up @@ -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));
Expand Down
33 changes: 14 additions & 19 deletions src/util/FSWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -91,23 +97,16 @@ export class VSCFSWatcherWrapper implements FSWatcher {
return Promise.resolve();
}

watched(): Promise<string[]> {
const excludeObj = vscode.workspace.getConfiguration('files').get<Record<string, boolean>>('watcherExclude') ?? {};
const enabledExcludes = Object.entries(excludeObj)
.filter(i => i[1])
.map(i => i[0]);
async watched(): Promise<string[]> {
// 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 {
Expand All @@ -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[] = [];
}

0 comments on commit 3d08dd9

Please sign in to comment.