#47058 - Search provider running in EH with switch to enable

This commit is contained in:
Rob Lourens
2018-05-09 12:56:57 -07:00
parent 33a00fd4a1
commit 2d08462e17
18 changed files with 2406 additions and 58 deletions

View File

@@ -9,7 +9,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { values } from 'vs/base/common/map';
import URI, { UriComponents } from 'vs/base/common/uri';
import { PPromise, TPromise } from 'vs/base/common/winjs.base';
import { IFileMatch, ILineMatch, ISearchComplete, ISearchProgressItem, ISearchQuery, ISearchResultProvider, ISearchService, QueryType } from 'vs/platform/search/common/search';
import { IFileMatch, ISearchComplete, ISearchProgressItem, ISearchQuery, ISearchResultProvider, ISearchService, QueryType, IRawFileMatch } from 'vs/platform/search/common/search';
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
import { ExtHostContext, ExtHostSearchShape, IExtHostContext, MainContext, MainThreadSearchShape } from '../node/extHost.protocol';
@@ -40,7 +40,7 @@ export class MainThreadSearch implements MainThreadSearchShape {
this._searchProvider.delete(handle);
}
$handleFindMatch(handle: number, session, data: UriComponents | [UriComponents, ILineMatch]): void {
$handleFindMatch(handle: number, session, data: UriComponents | IRawFileMatch[]): void {
this._searchProvider.get(handle).handleFindMatch(session, data);
}
}
@@ -57,14 +57,15 @@ class SearchOperation {
//
}
addMatch(resource: URI, match: ILineMatch): void {
if (!this.matches.has(resource.toString())) {
this.matches.set(resource.toString(), { resource, lineMatches: [] });
addMatch(match: IFileMatch): void {
if (this.matches.has(match.resource.toString())) {
// Merge with previous IFileMatches
this.matches.get(match.resource.toString()).lineMatches.push(...match.lineMatches);
} else {
this.matches.set(match.resource.toString(), match);
}
if (match) {
this.matches.get(resource.toString()).lineMatches.push(match);
}
this.progress(this.matches.get(resource.toString()));
this.progress(this.matches.get(match.resource.toString()));
}
}
@@ -73,7 +74,6 @@ class RemoteSearchProvider implements ISearchResultProvider {
private readonly _registrations: IDisposable[];
private readonly _searches = new Map<number, SearchOperation>();
constructor(
searchService: ISearchService,
private readonly _scheme: string,
@@ -93,15 +93,12 @@ class RemoteSearchProvider implements ISearchResultProvider {
return PPromise.as(undefined);
}
let includes = { ...query.includePattern };
let excludes = { ...query.excludePattern };
const folderQueriesForScheme = query.folderQueries.filter(fq => fq.folder.scheme === this._scheme);
for (const folderQuery of query.folderQueries) {
if (folderQuery.folder.scheme === this._scheme) {
includes = { ...includes, ...folderQuery.includePattern };
excludes = { ...excludes, ...folderQuery.excludePattern };
}
}
query = {
...query,
folderQueries: folderQueriesForScheme
};
let outer: TPromise;
@@ -112,7 +109,7 @@ class RemoteSearchProvider implements ISearchResultProvider {
outer = query.type === QueryType.File
? this._proxy.$provideFileSearchResults(this._handle, search.id, query.filePattern)
: this._proxy.$provideTextSearchResults(this._handle, search.id, query.contentPattern, { excludes: Object.keys(excludes), includes: Object.keys(includes) });
: this._proxy.$provideTextSearchResults(this._handle, search.id, query.contentPattern, query);
outer.then(() => {
this._searches.delete(search.id);
@@ -128,21 +125,22 @@ class RemoteSearchProvider implements ISearchResultProvider {
});
}
handleFindMatch(session: number, dataOrUri: UriComponents | [UriComponents, ILineMatch]): void {
handleFindMatch(session: number, dataOrUri: UriComponents | IRawFileMatch[]): void {
if (!this._searches.has(session)) {
// ignore...
return;
}
let resource: URI;
let match: ILineMatch;
const searchOp = this._searches.get(session);
if (Array.isArray(dataOrUri)) {
resource = URI.revive(dataOrUri[0]);
match = dataOrUri[1];
dataOrUri.forEach(m => {
searchOp.addMatch({
resource: URI.revive(m.resource),
lineMatches: m.lineMatches
});
});
} else {
resource = URI.revive(dataOrUri);
searchOp.addMatch({ resource: URI.revive(dataOrUri) });
}
this._searches.get(session).addMatch(resource, match);
}
}