提交 81c11b82 编写于 作者: R Rob Lourens

EH search - file search sibling clauses and test

上级 32783ae2
...@@ -349,12 +349,12 @@ class FileSearchEngine { ...@@ -349,12 +349,12 @@ class FileSearchEngine {
config.folderQueries.forEach(folderQuery => { config.folderQueries.forEach(folderQuery => {
const folderExcludeExpression: glob.IExpression = { const folderExcludeExpression: glob.IExpression = {
...(folderQuery.excludePattern || {}), ...(this.config.excludePattern || {}),
...(this.config.excludePattern || {}) ...(folderQuery.excludePattern || {})
}; };
// Add excludes for other root folders // Add excludes for other root folders
const folderString = URI.from(folderQuery.folder).toString(); const folderString = URI.from(folderQuery.folder).fsPath;
config.folderQueries config.folderQueries
.map(rootFolderQuery => rootFolderQuery.folder) .map(rootFolderQuery => rootFolderQuery.folder)
.filter(rootFolder => rootFolder !== folderQuery.folder) .filter(rootFolder => rootFolder !== folderQuery.folder)
...@@ -469,8 +469,8 @@ class FileSearchEngine { ...@@ -469,8 +469,8 @@ class FileSearchEngine {
this.addDirectoryEntries(tree, folderStr, relativePath, onResult); this.addDirectoryEntries(tree, folderStr, relativePath, onResult);
}; };
// TODO@roblou const allFolderExcludes = this.folderExcludePatterns.get(fq.folder.fsPath);
const noSiblingsClauses = true; const noSiblingsClauses = !allFolderExcludes || !allFolderExcludes.hasSiblingClauses();
new TPromise(resolve => process.nextTick(resolve)) new TPromise(resolve => process.nextTick(resolve))
.then(() => { .then(() => {
this.activeCancellationTokens.add(cancellation); this.activeCancellationTokens.add(cancellation);
...@@ -691,6 +691,8 @@ class AbsoluteAndRelativeParsedExpression { ...@@ -691,6 +691,8 @@ class AbsoluteAndRelativeParsedExpression {
private absoluteParsedExpr: glob.ParsedExpression; private absoluteParsedExpr: glob.ParsedExpression;
private relativeParsedExpr: glob.ParsedExpression; private relativeParsedExpr: glob.ParsedExpression;
private _hasSiblingClauses = false;
constructor(public expression: glob.IExpression, private root: string) { constructor(public expression: glob.IExpression, private root: string) {
this.init(expression); this.init(expression);
} }
...@@ -711,12 +713,20 @@ class AbsoluteAndRelativeParsedExpression { ...@@ -711,12 +713,20 @@ class AbsoluteAndRelativeParsedExpression {
relativeGlobExpr = relativeGlobExpr || glob.getEmptyExpression(); relativeGlobExpr = relativeGlobExpr || glob.getEmptyExpression();
relativeGlobExpr[key] = expr[key]; relativeGlobExpr[key] = expr[key];
} }
if (typeof expr[key] !== 'boolean') {
this._hasSiblingClauses = true;
}
}); });
this.absoluteParsedExpr = absoluteGlobExpr && glob.parse(absoluteGlobExpr, { trimForExclusions: true }); this.absoluteParsedExpr = absoluteGlobExpr && glob.parse(absoluteGlobExpr, { trimForExclusions: true });
this.relativeParsedExpr = relativeGlobExpr && glob.parse(relativeGlobExpr, { trimForExclusions: true }); this.relativeParsedExpr = relativeGlobExpr && glob.parse(relativeGlobExpr, { trimForExclusions: true });
} }
public hasSiblingClauses(): boolean {
return this._hasSiblingClauses;
}
public test(_path: string, basename?: string, siblingsFn?: () => string[] | TPromise<string[]>): string | TPromise<string> { public test(_path: string, basename?: string, siblingsFn?: () => string[] | TPromise<string[]>): string | TPromise<string> {
return (this.relativeParsedExpr && this.relativeParsedExpr(_path, basename, siblingsFn)) || return (this.relativeParsedExpr && this.relativeParsedExpr(_path, basename, siblingsFn)) ||
(this.absoluteParsedExpr && this.absoluteParsedExpr(path.join(this.root, _path), basename, siblingsFn)); (this.absoluteParsedExpr && this.absoluteParsedExpr(path.join(this.root, _path), basename, siblingsFn));
......
...@@ -103,13 +103,15 @@ suite('ExtHostSearch', () => { ...@@ -103,13 +103,15 @@ suite('ExtHostSearch', () => {
function makeFileResult(root: URI, relativePath: string): URI { function makeFileResult(root: URI, relativePath: string): URI {
return URI.file( return URI.file(
path.join(root.toString(), relativePath)); path.join(root.fsPath, relativePath));
} }
function compareURIs(a: URI[], b: URI[]) { function compareURIs(actual: URI[], expected: URI[]) {
const sortAndStringify = (arr: URI[]) => arr.sort().map(u => u.toString());
assert.deepEqual( assert.deepEqual(
a.map(u => u.toString()), sortAndStringify(actual),
b.map(u => u.toString())); sortAndStringify(expected));
} }
test('no results', async () => { test('no results', async () => {
...@@ -315,6 +317,106 @@ suite('ExtHostSearch', () => { ...@@ -315,6 +317,106 @@ suite('ExtHostSearch', () => {
await runFileSearch(query); await runFileSearch(query);
}); });
test('basic sibling exclude clause', async () => {
const reportedResults = [
makeFileResult(rootFolderA, 'file1.ts'),
makeFileResult(rootFolderA, 'file1.js'),
];
await registerTestSearchProvider({
provideFileSearchResults(options: vscode.FileSearchOptions, progress: vscode.Progress<vscode.Uri>, token: vscode.CancellationToken): Thenable<void> {
reportedResults.forEach(r => progress.report(r));
return TPromise.wrap(null);
}
});
const query: ISearchQuery = {
type: QueryType.File,
filePattern: '',
excludePattern: {
'*.js': {
when: '$(basename).ts'
}
},
folderQueries: [
{ folder: rootFolderA }
]
};
const results = await runFileSearch(query);
compareURIs(
results,
[
makeFileResult(rootFolderA, 'file1.ts')
]);
});
test('multiroot sibling exclude clause', async () => {
await registerTestSearchProvider({
provideFileSearchResults(options: vscode.FileSearchOptions, progress: vscode.Progress<vscode.Uri>, token: vscode.CancellationToken): Thenable<void> {
let reportedResults;
if (options.folder.fsPath === rootFolderA.fsPath) {
reportedResults = [
makeFileResult(rootFolderA, 'folder/fileA.scss'),
makeFileResult(rootFolderA, 'folder/fileA.css'),
makeFileResult(rootFolderA, 'folder/file2.css')
];
} else {
reportedResults = [
makeFileResult(rootFolderB, 'fileB.ts'),
makeFileResult(rootFolderB, 'fileB.js'),
makeFileResult(rootFolderB, 'file3.js')
];
}
reportedResults.forEach(r => progress.report(r));
return TPromise.wrap(null);
}
});
const query: ISearchQuery = {
type: QueryType.File,
filePattern: '',
excludePattern: {
'*.js': {
when: '$(basename).ts'
},
'*.css': true
},
folderQueries: [
{
folder: rootFolderA,
excludePattern: {
'folder/*.css': {
when: '$(basename).scss'
}
}
},
{
folder: rootFolderB,
excludePattern: {
'*.js': false
}
}
]
};
const results = await runFileSearch(query);
compareURIs(
results,
[
makeFileResult(rootFolderA, 'folder/fileA.scss'),
makeFileResult(rootFolderA, 'folder/file2.css'),
makeFileResult(rootFolderB, 'fileB.ts'),
makeFileResult(rootFolderB, 'fileB.js'),
makeFileResult(rootFolderB, 'file3.js'),
]);
});
// Mock fs? // Mock fs?
// test('Returns result for absolute path', async () => { // test('Returns result for absolute path', async () => {
// const queriedFile = makeFileResult(rootFolderA, 'file2.ts'); // const queriedFile = makeFileResult(rootFolderA, 'file2.ts');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册