Skip to content

Commit

Permalink
Anchor patterns (fixes #36438)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Oct 26, 2017
1 parent 9c62fff commit 77ba628
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/vs/workbench/services/search/node/ripgrepFileSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { rgPath } from 'vscode-ripgrep';

import { isMacintosh as isMac } from 'vs/base/common/platform';
import * as glob from 'vs/base/common/glob';
import { normalizeNFD } from 'vs/base/common/strings';
import { normalizeNFD, startsWith } from 'vs/base/common/strings';

import { IFolderSearch, IRawSearch } from './search';
import { foldersToIncludeGlobs, foldersToRgExcludeGlobs } from './ripgrepTextSearch';
Expand All @@ -26,14 +26,14 @@ function getRgArgs(config: IRawSearch, folderQuery: IFolderSearch, includePatter

// includePattern can't have siblingClauses
foldersToIncludeGlobs([folderQuery], includePattern, false).forEach(globArg => {
args.push('-g', isMac ? normalizeNFD(globArg) : globArg);
args.push('-g', anchor(isMac ? normalizeNFD(globArg) : globArg));
});

let siblingClauses: glob.IExpression;

const rgGlobs = foldersToRgExcludeGlobs([folderQuery], excludePattern, undefined, false);
rgGlobs.globArgs
.forEach(rgGlob => args.push('-g', `!${isMac ? normalizeNFD(rgGlob) : rgGlob}`));
.forEach(rgGlob => args.push('-g', `!${anchor(isMac ? normalizeNFD(rgGlob) : rgGlob)}`));
siblingClauses = rgGlobs.siblingClauses;

if (config.disregardIgnoreFiles) {
Expand All @@ -57,3 +57,7 @@ function getRgArgs(config: IRawSearch, folderQuery: IFolderSearch, includePatter

return { globArgs: args, siblingClauses };
}

function anchor(glob: string) {
return startsWith(glob, '**') || startsWith(glob, '/') ? glob : `/${glob}`;
}
Empty file.
Empty file.
42 changes: 42 additions & 0 deletions src/vs/workbench/services/search/test/node/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const ROOT_FOLDER_QUERY: IFolderSearch[] = [
TEST_ROOT_FOLDER
];

const ROOT_FOLDER_QUERY_36438: IFolderSearch[] = [
{ folder: path.normalize(require.toUrl('./fixtures2/36438')) }
];

const MULTIROOT_QUERIES: IFolderSearch[] = [
{ folder: EXAMPLES_FIXTURES },
{ folder: MORE_FIXTURES }
Expand Down Expand Up @@ -381,6 +385,44 @@ suite('FileSearchEngine', () => {
});
});

test('Files: exclude folder without wildcard #36438', function (done: () => void) {
this.timeout(testTimeout);
let engine = new FileSearchEngine({
folderQueries: ROOT_FOLDER_QUERY_36438,
excludePattern: { 'modules': true }
});

let count = 0;
engine.search((result) => {
if (result) {
count++;
}
}, () => { }, (error) => {
assert.ok(!error);
assert.equal(count, 1);
done();
});
});

test('Files: include folder without wildcard #36438', function (done: () => void) {
this.timeout(testTimeout);
let engine = new FileSearchEngine({
folderQueries: ROOT_FOLDER_QUERY_36438,
includePattern: { 'modules/**': true }
});

let count = 0;
engine.search((result) => {
if (result) {
count++;
}
}, () => { }, (error) => {
assert.ok(!error);
assert.equal(count, 1);
done();
});
});

test('Files: *.* exclude folder with leading wildcard', function (done: () => void) {
this.timeout(testTimeout);
let engine = new FileSearchEngine({
Expand Down

0 comments on commit 77ba628

Please sign in to comment.