Skip to content

Commit

Permalink
search: fix handle empty results from ripgrep
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Dec 4, 2020
1 parent 63137db commit c2f68ba
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,18 @@ export class RipgrepParser extends EventEmitter {
let prevMatchEnd = 0;
let prevMatchEndCol = 0;
let prevMatchEndLine = lineNumber;

// it looks like certain regexes can match a line, but cause rg to not
// emit any specific submatches for that line.
// https://github.com/microsoft/vscode/issues/100569#issuecomment-738496991
if (data.submatches.length === 0) {
data.submatches.push(
fullText.length
? { start: 0, end: 1, match: { text: fullText[0] } }
: { start: 0, end: 0, match: { text: '' } }
);
}

const ranges = coalesce(data.submatches.map((match, i) => {
if (this.hitLimit) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,32 @@ suite('RipgrepTextSearchEngine', () => {
}
]);
});


test('empty result (#100569)', () => {
testParser(
[
makeRgMatch('file1.js', 'foobar', 4, []),
makeRgMatch('file1.js', '', 5, []),
],
[
{
preview: {
text: 'foobar',
matches: [new Range(0, 0, 0, 1)]
},
uri: joinPath(TEST_FOLDER, 'file1.js'),
ranges: [new Range(3, 0, 3, 1)]
},
{
preview: {
text: '',
matches: [new Range(0, 0, 0, 0)]
},
uri: joinPath(TEST_FOLDER, 'file1.js'),
ranges: [new Range(4, 0, 4, 0)]
}
]);
});
});
});

0 comments on commit c2f68ba

Please sign in to comment.