Skip to content

Commit 3307e76

Browse files
committed
Relative file match (microsoft#24074)
1 parent 783df42 commit 3307e76

3 files changed

Lines changed: 41 additions & 22 deletions

File tree

scripts/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ test -d node_modules || ./scripts/npm.sh install
2828
(test -f "$CODE" && [ $INTENDED_VERSION == $INSTALLED_VERSION ]) || ./node_modules/.bin/gulp electron
2929

3030
# Unit Tests
31+
export ELECTRON_ENABLE_LOGGING=1
3132
if [[ "$OSTYPE" == "darwin"* ]]; then
3233
cd $ROOT ; ulimit -n 4096 ; \
3334
"$CODE" \

src/vs/workbench/services/search/node/fileSearch.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export class FileWalker {
221221
const useRipgrep = this.useRipgrep;
222222
let cmd: childProcess.ChildProcess;
223223
let noSiblingsClauses: boolean;
224+
let filePatternSeen = false;
224225
if (useRipgrep) {
225226
const ripgrep = spawnRipgrepCmd(folderQuery, this.config.includePattern, this.folderExcludePatterns.get(folderQuery.folder).expression);
226227
cmd = ripgrep.cmd;
@@ -262,11 +263,28 @@ export class FileWalker {
262263

263264
if (useRipgrep && noSiblingsClauses) {
264265
for (const relativePath of relativeFiles) {
266+
if (relativePath === this.filePattern) {
267+
filePatternSeen = true;
268+
}
265269
const basename = path.basename(relativePath);
266270
this.matchFile(onResult, { base: rootFolder, relativePath, basename });
267271
}
268272
if (last) {
269-
done();
273+
if (!filePatternSeen) {
274+
this.checkFilePatternRelativeMatch(folderQuery.folder, (match, size) => {
275+
if (match) {
276+
this.resultCount++;
277+
onResult({
278+
base: folderQuery.folder,
279+
relativePath: this.filePattern,
280+
basename: path.basename(this.filePattern),
281+
});
282+
}
283+
done();
284+
});
285+
} else {
286+
done();
287+
}
270288
}
271289
return;
272290
}

src/vs/workbench/services/search/test/node/search.test.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -368,27 +368,27 @@ suite('FileSearchEngine', () => {
368368
});
369369
});
370370

371-
// test('Files: relative path to file ignores excludes', function (done: () => void) {
372-
// let engine = new FileSearchEngine({
373-
// folderQueries: ROOT_FOLDER_QUERY,
374-
// filePattern: path.normalize(path.join('examples', 'company.js')),
375-
// excludePattern: { '**/*.js': true }
376-
// });
377-
378-
// let count = 0;
379-
// let res: IRawFileMatch;
380-
// engine.search((result) => {
381-
// if (result) {
382-
// count++;
383-
// }
384-
// res = result;
385-
// }, () => { }, (error) => {
386-
// assert.ok(!error);
387-
// assert.equal(count, 1);
388-
// assert.equal(path.basename(res.relativePath), 'company.js');
389-
// done();
390-
// });
391-
// });
371+
test('Files: relative path to file ignores excludes', function (done: () => void) {
372+
let engine = new FileSearchEngine({
373+
folderQueries: ROOT_FOLDER_QUERY,
374+
filePattern: path.normalize(path.join('examples', 'company.js')),
375+
excludePattern: { '**/*.js': true }
376+
});
377+
378+
let count = 0;
379+
let res: IRawFileMatch;
380+
engine.search((result) => {
381+
if (result) {
382+
count++;
383+
}
384+
res = result;
385+
}, () => { }, (error) => {
386+
assert.ok(!error);
387+
assert.equal(count, 1);
388+
assert.equal(path.basename(res.relativePath), 'company.js');
389+
done();
390+
});
391+
});
392392

393393
test('Files: Include pattern, single files', function (done: () => void) {
394394
let engine = new FileSearchEngine({

0 commit comments

Comments
 (0)