Merge pull request #19615 from dwelle/ripgrep-pcre2

Add ripgrep pcre2 search support
This commit is contained in:
Rafael Oleza 2019-07-01 18:18:36 +02:00 committed by GitHub
commit 9ae30a3545
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -2680,6 +2680,30 @@ describe('Workspace', () => {
});
});
});
describe('pcre2 enabled', async () => {
it('supports lookbehind searches', async () => {
const results = [];
await scan(/(?<!a)aa\b/, { PCRE2: true }, result =>
results.push(result)
);
expect(results.length).toBe(1);
const { filePath, matches } = results[0];
expect(filePath).toBe(
atom.project.getDirectories()[0].resolve('a')
);
expect(matches).toHaveLength(1);
expect(matches[0]).toEqual({
matchText: 'aa',
lineText: 'cc aa cc',
lineTextOffset: 0,
range: [[1, 3], [1, 5]],
leadingContextLines: [],
trailingContextLines: []
});
});
});
}
it('returns results on lines with unicode strings', async () => {

View File

@ -269,6 +269,10 @@ module.exports = class RipgrepDirectorySearcher {
args.push('--no-ignore-vcs');
}
if (options.PCRE2) {
args.push('--pcre2');
}
args.push('.');
const child = spawn(this.rgPath, args, {

View File

@ -2104,6 +2104,7 @@ module.exports = class Workspace extends Model {
follow: this.config.get('core.followSymlinks'),
leadingContextLineCount: options.leadingContextLineCount || 0,
trailingContextLineCount: options.trailingContextLineCount || 0,
PCRE2: options.PCRE2,
didMatch: result => {
if (!this.project.isPathModified(result.filePath)) {
return iterator(result);