提交 98b1318a 编写于 作者: C Christof Marti

Kill rg when maxResults hit (fixes #34823)

上级 1429c4ec
......@@ -239,6 +239,9 @@ export class FileWalker {
done(err);
return;
}
if (this.isLimitHit) {
return;
}
// Mac: uses NFD unicode form on disk, but we want NFC
const normalized = leftover + (isMac ? strings.normalizeNFC(stdout) : stdout);
......@@ -272,8 +275,12 @@ export class FileWalker {
}
const basename = path.basename(relativePath);
this.matchFile(onResult, { base: rootFolder, relativePath, basename });
if (this.isLimitHit) {
killCmd();
break;
}
}
if (last) {
if (last || this.isLimitHit) {
if (!filePatternSeen) {
this.checkFilePatternRelativeMatch(folderQuery.folder, (match, size) => {
if (match) {
......@@ -482,6 +489,10 @@ export class FileWalker {
self.matchFile(onResult, entry);
}
if (self.isLimitHit) {
break;
}
};
}
matchDirectory(rootEntries);
......
......@@ -47,6 +47,43 @@ suite('FileSearchEngine', () => {
});
});
test('Files: maxResults', function (done: () => void) {
let engine = new FileSearchEngine({
folderQueries: ROOT_FOLDER_QUERY,
maxResults: 1
});
let count = 0;
engine.search((result) => {
if (result) {
count++;
}
}, () => { }, (error) => {
assert.ok(!error);
assert.equal(count, 1);
done();
});
});
test('Files: maxResults without Ripgrep', function (done: () => void) {
let engine = new FileSearchEngine({
folderQueries: ROOT_FOLDER_QUERY,
maxResults: 1,
useRipgrep: false
});
let count = 0;
engine.search((result) => {
if (result) {
count++;
}
}, () => { }, (error) => {
assert.ok(!error);
assert.equal(count, 1);
done();
});
});
test('Files: examples/com*', function (done: () => void) {
let engine = new FileSearchEngine({
folderQueries: ROOT_FOLDER_QUERY,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册