Skip to content

Commit d618f0d

Browse files
committed
Fix exclude settings to be resolved against their root folder, not the searchPath, mainly for './' search scenarios
1 parent 413f588 commit d618f0d

6 files changed

Lines changed: 58 additions & 11 deletions

File tree

‎src/vs/base/common/glob.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export interface IExpression {
1515
[pattern: string]: boolean | SiblingClause | any;
1616
}
1717

18+
export function getEmptyExpression(): IExpression {
19+
return Object.create(null);
20+
}
21+
1822
export interface SiblingClause {
1923
when: string;
2024
}

‎src/vs/workbench/api/electron-browser/mainThreadWorkspace.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { isPromiseCanceledError } from 'vs/base/common/errors';
88
import URI from 'vs/base/common/uri';
9-
import { ISearchService, QueryType } from 'vs/platform/search/common/search';
9+
import { ISearchService, QueryType, ISearchQuery } from 'vs/platform/search/common/search';
1010
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
1111
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
1212
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
@@ -56,13 +56,16 @@ export class MainThreadWorkspace extends MainThreadWorkspaceShape {
5656
return undefined;
5757
}
5858

59-
const search = this._searchService.search({
59+
const query: ISearchQuery = {
6060
folderQueries: workspace.roots.map(root => ({ folder: root })),
6161
type: QueryType.File,
6262
maxResults,
6363
includePattern: { [include]: true },
6464
excludePattern: { [exclude]: true },
65-
}).then(result => {
65+
};
66+
this._searchService.extendQuery(query);
67+
68+
const search = this._searchService.search(query).then(result => {
6669
return result.results.map(m => m.resource);
6770
}, err => {
6871
if (!isPromiseCanceledError(err)) {

‎src/vs/workbench/parts/search/common/queryBuilder.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ export class QueryBuilder {
4545
let { searchPaths, includePattern } = this.parseSearchPaths(options.includePattern);
4646
let excludePattern = patternListToIExpression(splitGlobPattern(options.excludePattern));
4747

48-
// if we have searchPaths, then turn them into folderQueries, and get all the excludes for the workspaces, and add them to excludePattern.
49-
// If we don't, then turn the folderResources into folderQueries, with their excludes on each one
50-
5148
// Build folderQueries from searchPaths, if given, otherwise folderResources
5249
let folderQueries = folderResources && folderResources.map(uri => this.getFolderQueryForRoot(uri, options));
5350
if (searchPaths && searchPaths.length) {

‎src/vs/workbench/parts/search/test/common/queryBuilder.test.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ suite('QueryBuilder', () => {
9292
});
9393

9494
test('simple include', () => {
95-
mockConfigService.setUserConfiguration('search', { useRipgrep: true });
96-
9795
assertEqualQueries(
9896
queryBuilder.text(
9997
PATTERN_INFO,
@@ -142,7 +140,6 @@ suite('QueryBuilder', () => {
142140
const ROOT_3_URI = getUri(ROOT_3);
143141
mockWorkspace.roots = [ROOT_1_URI, ROOT_2_URI, ROOT_3_URI];
144142

145-
mockConfigService.setUserConfiguration('search', { useRipgrep: true });
146143
mockConfigService.setUserConfiguration('search', {
147144
useRipgrep: true,
148145
exclude: { 'foo/**/*.js': true }

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import fs = require('fs');
1212
import path = require('path');
1313
import { isEqualOrParent } from 'vs/base/common/paths';
1414
import { Readable } from 'stream';
15+
import { TPromise } from 'vs/base/common/winjs.base';
1516

1617
import scorer = require('vs/base/common/scorer');
1718
import objects = require('vs/base/common/objects');
@@ -103,10 +104,34 @@ export class FileWalker {
103104
}
104105
});
105106

106-
this.folderExcludePatterns.set(folderQuery.folder, glob.parse(folderExcludeExpression, { trimForExclusions: true }));
107+
this.folderExcludePatterns.set(folderQuery.folder, this.parseAbsoluteAndRelativeGlobs(folderExcludeExpression, folderQuery.folder));
107108
});
108109
}
109110

111+
private parseAbsoluteAndRelativeGlobs(expr: glob.IExpression, root: string): glob.ParsedExpression {
112+
let absoluteGlobExpr: glob.IExpression;
113+
let relativeGlobExpr: glob.IExpression;
114+
Object.keys(expr).forEach(key => {
115+
if (path.isAbsolute(key)) {
116+
absoluteGlobExpr = absoluteGlobExpr || glob.getEmptyExpression();
117+
absoluteGlobExpr[key] = true;
118+
} else {
119+
relativeGlobExpr = relativeGlobExpr || glob.getEmptyExpression();
120+
relativeGlobExpr[key] = true;
121+
}
122+
});
123+
124+
const absoluteParsedExpr = absoluteGlobExpr && glob.parse(absoluteGlobExpr, { trimForExclusions: true });
125+
const relativeParsedExpr = relativeGlobExpr && glob.parse(relativeGlobExpr, { trimForExclusions: true });
126+
127+
// The absolute and relative expressions don't "have" to be kept separate, but this keeps us from having to path.join every single
128+
// file searched, it's only used for a text search with a searchPath
129+
return (_path: string, basename?: string, siblingsFn?: () => string[] | TPromise<string[]>): string | TPromise<string> => {
130+
return (relativeParsedExpr && relativeParsedExpr(_path, basename, siblingsFn)) ||
131+
(absoluteParsedExpr && absoluteParsedExpr(path.join(root, _path), basename, siblingsFn));
132+
};
133+
}
134+
110135
public cancel(): void {
111136
this.isCanceled = true;
112137
}

‎src/vs/workbench/services/search/test/node/textSearch.integrationTest.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ function doRipgrepSearchTest(config: IRawSearch, expectedResultCount: number): T
8888
}
8989

9090
function doSearchTest(config: IRawSearch, expectedResultCount: number, done) {
91-
return doRipgrepSearchTest(config, expectedResultCount)
91+
return doLegacySearchTest(config, expectedResultCount)
92+
.then(() => doRipgrepSearchTest(config, expectedResultCount))
9293
.then(done, done);
9394
}
9495

@@ -187,6 +188,26 @@ suite('Search-integration', function () {
187188
doSearchTest(config, 382, done);
188189
});
189190

191+
test('Text: e (with absolute path excludes)', function (done: () => void) {
192+
const config: any = {
193+
folderQueries: ROOT_FOLDER_QUERY,
194+
contentPattern: { pattern: 'e' },
195+
excludePattern: makeExpression(path.join(TEST_FIXTURES, '**/examples'))
196+
};
197+
198+
doSearchTest(config, 394, done);
199+
});
200+
201+
test('Text: e (with mixed absolute/relative path excludes)', function (done: () => void) {
202+
const config: any = {
203+
folderQueries: ROOT_FOLDER_QUERY,
204+
contentPattern: { pattern: 'e' },
205+
excludePattern: makeExpression(path.join(TEST_FIXTURES, '**/examples'), '*.css')
206+
};
207+
208+
doSearchTest(config, 310, done);
209+
});
210+
190211
test('Text: sibling exclude', function (done: () => void) {
191212
const config: any = {
192213
folderQueries: ROOT_FOLDER_QUERY,

0 commit comments

Comments
 (0)