Fix #61041
This commit is contained in:
parent
9b739ad670
commit
d47f6b4f99
3 changed files with 46 additions and 26 deletions
|
@ -7,7 +7,6 @@ import * as path from 'path';
|
|||
import * as arrays from 'vs/base/common/arrays';
|
||||
import { CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
|
||||
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import { toErrorMessage } from 'vs/base/common/errorMessage';
|
||||
import { canceled } from 'vs/base/common/errors';
|
||||
import * as glob from 'vs/base/common/glob';
|
||||
import * as resources from 'vs/base/common/resources';
|
||||
|
@ -17,9 +16,9 @@ import { URI } from 'vs/base/common/uri';
|
|||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { compareItemsByScore, IItemAccessor, prepareQuery, ScorerCache } from 'vs/base/parts/quickopen/common/quickOpenScorer';
|
||||
import { ICachedSearchStats, IFileIndexProviderStats, IFileMatch, IFileSearchStats, IFolderQuery, IRawSearchQuery, ISearchCompleteStats, ISearchQuery } from 'vs/platform/search/common/search';
|
||||
import { IDirectoryEntry, IDirectoryTree, IInternalFileMatch } from 'vs/workbench/services/search/node/fileSearchManager';
|
||||
import { QueryGlobTester, resolvePatternsForProvider } from 'vs/workbench/services/search/node/search';
|
||||
import * as vscode from 'vscode';
|
||||
import { resolvePatternsForProvider, QueryGlobTester } from 'vs/workbench/services/search/node/search';
|
||||
import { IInternalFileMatch, IDirectoryTree, IDirectoryEntry } from 'vs/workbench/services/search/node/fileSearchManager';
|
||||
|
||||
interface IInternalSearchComplete<T = IFileSearchStats> {
|
||||
limitHit: boolean;
|
||||
|
@ -67,10 +66,6 @@ export class FileIndexSearchEngine {
|
|||
}
|
||||
|
||||
public search(_onResult: (match: IInternalFileMatch) => void): TPromise<{ isLimitHit: boolean, stats: IFileIndexProviderStats }> {
|
||||
if (this.config.folderQueries.length !== 1) {
|
||||
throw new Error('Searches just one folder');
|
||||
}
|
||||
|
||||
// Searches a single folder
|
||||
const folderQuery = this.config.folderQueries[0];
|
||||
|
||||
|
@ -99,14 +94,24 @@ export class FileIndexSearchEngine {
|
|||
});
|
||||
}
|
||||
|
||||
return this.searchInFolder(folderQuery, _onResult)
|
||||
.then(stats => {
|
||||
return Promise.all(this.config.folderQueries.map(fq => this.searchInFolder(folderQuery, onResult))).then(stats => {
|
||||
resolve({
|
||||
isLimitHit: this.isLimitHit,
|
||||
stats
|
||||
stats: {
|
||||
directoriesWalked: this.dirsWalked,
|
||||
filesWalked: this.filesWalked,
|
||||
fileWalkTime: stats.map(s => s.fileWalkTime).reduce((s, c) => s + c, 0),
|
||||
providerTime: stats.map(s => s.providerTime).reduce((s, c) => s + c, 0),
|
||||
providerResultCount: stats.map(s => s.providerResultCount).reduce((s, c) => s + c, 0)
|
||||
}
|
||||
});
|
||||
}, (err: Error) => {
|
||||
reject(new Error(toErrorMessage(err)));
|
||||
}, (errs: Error[]) => {
|
||||
if (!Array.isArray(errs)) {
|
||||
errs = [errs];
|
||||
}
|
||||
|
||||
errs = errs.filter(e => !!e);
|
||||
return TPromise.wrapError(errs[0]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ export class QueryBuilder {
|
|||
|
||||
const query: ISearchQuery = {
|
||||
type,
|
||||
folderQueries,
|
||||
folderQueries: folderQueries || [],
|
||||
usingSearchPaths: !!(searchPaths && searchPaths.length),
|
||||
extraFileResources: options.extraFileResources,
|
||||
filePattern: options.filePattern
|
||||
|
|
|
@ -9,7 +9,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
|
|||
import { canceled } from 'vs/base/common/errors';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ResourceMap, values } from 'vs/base/common/map';
|
||||
import { ResourceMap, values, keys } from 'vs/base/common/map';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import * as objects from 'vs/base/common/objects';
|
||||
import { StopWatch } from 'vs/base/common/stopwatch';
|
||||
|
@ -215,24 +215,26 @@ export class SearchService extends Disposable implements ISearchService {
|
|||
const diskSearchQueries: IFolderQuery[] = [];
|
||||
const searchPs: TPromise<ISearchComplete>[] = [];
|
||||
|
||||
query.folderQueries.forEach(fq => {
|
||||
const fqs = this.groupFolderQueriesByScheme(query);
|
||||
keys(fqs).forEach(scheme => {
|
||||
const schemeFQs = fqs.get(scheme);
|
||||
let provider = query.type === QueryType.File ?
|
||||
this.fileSearchProviders.get(fq.folder.scheme) || this.fileIndexProviders.get(fq.folder.scheme) :
|
||||
this.textSearchProviders.get(fq.folder.scheme);
|
||||
this.fileSearchProviders.get(scheme) || this.fileIndexProviders.get(scheme) :
|
||||
this.textSearchProviders.get(scheme);
|
||||
|
||||
if (!provider && fq.folder.scheme === 'file') {
|
||||
diskSearchQueries.push(fq);
|
||||
if (!provider && scheme === 'file') {
|
||||
diskSearchQueries.push(...schemeFQs);
|
||||
} else if (!provider) {
|
||||
throw new Error('No search provider registered for scheme: ' + fq.folder.scheme);
|
||||
throw new Error('No search provider registered for scheme: ' + scheme);
|
||||
} else {
|
||||
const oneFolderQuery = {
|
||||
const oneSchemeQuery = {
|
||||
...query,
|
||||
...{
|
||||
folderQueries: [fq]
|
||||
folderQueries: schemeFQs
|
||||
}
|
||||
};
|
||||
|
||||
searchPs.push(provider.search(oneFolderQuery, onProviderProgress, token));
|
||||
searchPs.push(provider.search(oneSchemeQuery, onProviderProgress, token));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -260,6 +262,19 @@ export class SearchService extends Disposable implements ISearchService {
|
|||
});
|
||||
}
|
||||
|
||||
private groupFolderQueriesByScheme(query: ISearchQuery): Map<string, IFolderQuery[]> {
|
||||
const queries = new Map<string, IFolderQuery[]>();
|
||||
|
||||
query.folderQueries.forEach(fq => {
|
||||
const schemeFQs = queries.get(fq.folder.scheme) || [];
|
||||
schemeFQs.push(fq);
|
||||
|
||||
queries.set(fq.folder.scheme, schemeFQs);
|
||||
});
|
||||
|
||||
return queries;
|
||||
}
|
||||
|
||||
private sendTelemetry(query: ISearchQuery, endToEndTime: number, complete: ISearchComplete): void {
|
||||
const fileSchemeOnly = query.folderQueries.every(fq => fq.folder.scheme === 'file');
|
||||
const otherSchemeOnly = query.folderQueries.every(fq => fq.folder.scheme !== 'file');
|
||||
|
|
Loading…
Reference in a new issue