Skip to content

Commit

Permalink
skip findFiles if exact path is given
Browse files Browse the repository at this point in the history
  • Loading branch information
matepek committed Oct 22, 2024
1 parent 65ef8ce commit 3dc483b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

## [4.12.2]

### Added

- Workaround to make search faster with exact path specified instead of glob pattern. [related](https://github.com/matepek/vscode-catch2-test-adapter/issues/444)

## [4.12.1] - 2024-10-19

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon": "resources/icon.png",
"author": "Mate Pek",
"publisher": "matepek",
"version": "4.12.1",
"version": "4.12.2-beta",
"license": "MIT",
"homepage": "https://github.com/matepek/vscode-catch2-test-adapter",
"repository": {
Expand Down
20 changes: 19 additions & 1 deletion src/util/FSWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export class VSCFSWatcherWrapper implements FSWatcher {
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;
Expand All @@ -98,6 +97,9 @@ export class VSCFSWatcherWrapper implements FSWatcher {
}

async watched(): Promise<string[]> {
if (!this._isGlobPattern()) {
return [path.join(this._relativePattern.baseUri.fsPath, this._relativePattern.pattern)];
}
// this trick seems working but would need more understanding
const exclude =
this._excludePattern.length === 0
Expand All @@ -119,4 +121,20 @@ export class VSCFSWatcherWrapper implements FSWatcher {
onError(_handler: (err: Error) => void): void {
return undefined;
}

_isGlobPattern(): boolean {
/* According to findFiles documentation:
* Glob patterns can have the following syntax:
* * `*` to match zero or more characters in a path segment
* * `?` to match on one character in a path segment
* * `**` to match any number of path segments, including none
* * `{}` to group conditions (e.g. `**​/*.{ts,js}` matches all TypeScript and JavaScript files)
* * `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …)
* * `[!...]` to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`)
*
*/
return this._relativePattern.pattern.match(this._globRe) !== null;
}

private readonly _globRe = /(?<!\\)(\[|\*|\?|\{)/;
}

0 comments on commit 3dc483b

Please sign in to comment.