Skip to content

Commit 3dc483b

Browse files
committed
skip findFiles if exact path is given
1 parent 65ef8ce commit 3dc483b

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
## [4.12.2]
10+
11+
### Added
12+
13+
- Workaround to make search faster with exact path specified instead of glob pattern. [related](https://github.com/matepek/vscode-catch2-test-adapter/issues/444)
14+
915
## [4.12.1] - 2024-10-19
1016

1117
### Fixed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"icon": "resources/icon.png",
66
"author": "Mate Pek",
77
"publisher": "matepek",
8-
"version": "4.12.1",
8+
"version": "4.12.2-beta",
99
"license": "MIT",
1010
"homepage": "https://github.com/matepek/vscode-catch2-test-adapter",
1111
"repository": {

Diff for: src/util/FSWatcher.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export class VSCFSWatcherWrapper implements FSWatcher {
7878
if (path.isAbsolute(relativePattern)) throw new Error('Relative path is expected:' + relativePattern);
7979

8080
this._relativePattern = new vscode.RelativePattern(workspaceFolder, relativePattern);
81-
8281
this._vscWatcher = vscode.workspace.createFileSystemWatcher(this._relativePattern, false, false, false);
8382
this._disposables.push(this._vscWatcher);
8483
this._excludePattern = excludePatterns;
@@ -98,6 +97,9 @@ export class VSCFSWatcherWrapper implements FSWatcher {
9897
}
9998

10099
async watched(): Promise<string[]> {
100+
if (!this._isGlobPattern()) {
101+
return [path.join(this._relativePattern.baseUri.fsPath, this._relativePattern.pattern)];
102+
}
101103
// this trick seems working but would need more understanding
102104
const exclude =
103105
this._excludePattern.length === 0
@@ -119,4 +121,20 @@ export class VSCFSWatcherWrapper implements FSWatcher {
119121
onError(_handler: (err: Error) => void): void {
120122
return undefined;
121123
}
124+
125+
_isGlobPattern(): boolean {
126+
/* According to findFiles documentation:
127+
* Glob patterns can have the following syntax:
128+
* * `*` to match zero or more characters in a path segment
129+
* * `?` to match on one character in a path segment
130+
* * `**` to match any number of path segments, including none
131+
* * `{}` to group conditions (e.g. `**​/*.{ts,js}` matches all TypeScript and JavaScript files)
132+
* * `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …)
133+
* * `[!...]` 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`)
134+
*
135+
*/
136+
return this._relativePattern.pattern.match(this._globRe) !== null;
137+
}
138+
139+
private readonly _globRe = /(?<!\\)(\[|\*|\?|\{)/;
122140
}

0 commit comments

Comments
 (0)