提交 d0b06a63 编写于 作者: R Rob Lourens

Change EH search back to use URIs between EH and renderer process

上级 a521c01d
......@@ -104,17 +104,12 @@ export interface IPatternInfo {
isSmartCase?: boolean;
}
export interface IFileMatch<U = uri> {
export interface IFileMatch<U extends UriComponents = uri> {
resource?: U;
lineMatches?: ILineMatch[];
}
export interface IPathInFolder {
folderIdx: number;
relativePath: string;
}
export type IRawFileMatch2 = IFileMatch<IPathInFolder>;
export type IRawFileMatch2 = IFileMatch<UriComponents>;
export interface ILineMatch {
preview: string;
......
......@@ -4,13 +4,12 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as path from 'path';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
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, ISearchComplete, ISearchProgressItem, ISearchQuery, ISearchResultProvider, ISearchService, QueryType, IRawFileMatch2, ISearchCompleteStats, IFolderQuery } from 'vs/platform/search/common/search';
import { IFileMatch, ISearchComplete, ISearchProgressItem, ISearchQuery, ISearchResultProvider, ISearchService, QueryType, IRawFileMatch2, ISearchCompleteStats } 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';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
......@@ -58,7 +57,6 @@ class SearchOperation {
constructor(
readonly progress: (match: IFileMatch) => any,
readonly folders: IFolderQuery[],
readonly id: number = ++SearchOperation._idPool,
readonly matches = new Map<string, IFileMatch>()
) {
......@@ -112,7 +110,7 @@ class RemoteSearchProvider implements ISearchResultProvider {
return new PPromise((resolve, reject, report) => {
const search = new SearchOperation(report, query.folderQueries);
const search = new SearchOperation(report);
this._searches.set(search.id, search);
outer = query.type === QueryType.File
......@@ -142,14 +140,8 @@ class RemoteSearchProvider implements ISearchResultProvider {
const searchOp = this._searches.get(session);
if (Array.isArray(dataOrUri)) {
dataOrUri.forEach(m => {
const folderQuery = searchOp.folders[m.resource.folderIdx];
if (!folderQuery) {
return;
}
const fullUri = URI.file(path.join(folderQuery.folder.fsPath, m.resource.relativePath));
searchOp.addMatch({
resource: fullUri,
resource: URI.revive(m.resource),
lineMatches: m.lineMatches
});
});
......
......@@ -14,7 +14,7 @@ import * as strings from 'vs/base/common/strings';
import URI, { UriComponents } from 'vs/base/common/uri';
import { PPromise, TPromise } from 'vs/base/common/winjs.base';
import { IItemAccessor, ScorerCache, compareItemsByScore, prepareQuery } from 'vs/base/parts/quickopen/common/quickOpenScorer';
import { ICachedSearchStats, IRawFileMatch2, IFolderQuery, IPatternInfo, IRawSearchQuery, ISearchQuery, ISearchCompleteStats, IFileMatch } from 'vs/platform/search/common/search';
import { ICachedSearchStats, IFileMatch, IFolderQuery, IPatternInfo, IRawSearchQuery, ISearchQuery, ISearchCompleteStats, IRawFileMatch2 } from 'vs/platform/search/common/search';
import * as vscode from 'vscode';
import { ExtHostSearchShape, IMainContext, MainContext, MainThreadSearchShape } from './extHost.protocol';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
......@@ -133,9 +133,11 @@ function reviveFolderQuery(rawFolderQuery: IFolderQuery<UriComponents>): IFolder
class TextSearchResultsCollector {
private _batchedCollector: BatchedCollector<IRawFileMatch2>;
private _currentFolderIdx: number;
private _currentRelativePath: string;
private _currentFileMatch: IRawFileMatch2;
constructor(private _onResult: (result: IRawFileMatch2[]) => void) {
constructor(private folderQueries: IFolderQuery[], private _onResult: (result: IRawFileMatch2[]) => void) {
this._batchedCollector = new BatchedCollector<IRawFileMatch2>(512, items => this.sendItems(items));
}
......@@ -143,17 +145,15 @@ class TextSearchResultsCollector {
// Collects TextSearchResults into IInternalFileMatches and collates using BatchedCollector.
// This is efficient for ripgrep which sends results back one file at a time. It wouldn't be efficient for other search
// providers that send results in random order. We could do this step afterwards instead.
if (this._currentFileMatch && (this._currentFileMatch.resource.folderIdx !== folderIdx || this._currentFileMatch.resource.relativePath !== data.path)) {
if (this._currentFileMatch && (this._currentFolderIdx !== folderIdx || this._currentRelativePath !== data.path)) {
this.pushToCollector();
this._currentFileMatch = null;
}
if (!this._currentFileMatch) {
const resource = URI.file(path.join(this.folderQueries[folderIdx].folder.fsPath, data.path));
this._currentFileMatch = {
resource: {
folderIdx,
relativePath: data.path
},
resource,
lineMatches: []
};
}
......@@ -393,7 +393,7 @@ class TextSearchEngine {
const folderQueries = this.config.folderQueries;
return new PPromise<{ limitHit: boolean }, IRawFileMatch2[]>((resolve, reject, _onResult) => {
this.collector = new TextSearchResultsCollector(_onResult);
this.collector = new TextSearchResultsCollector(this.config.folderQueries, _onResult);
const onResult = (match: vscode.TextSearchResult, folderIdx: number) => {
if (this.isCanceled) {
......
......@@ -9,7 +9,7 @@ import * as path from 'path';
import * as extfs from 'vs/base/node/extfs';
import URI, { UriComponents } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { IRawFileMatch2, IRawSearchQuery, QueryType, ISearchQuery, IPatternInfo } from 'vs/platform/search/common/search';
import { IRawFileMatch2, IRawSearchQuery, QueryType, ISearchQuery, IPatternInfo, IFileMatch } from 'vs/platform/search/common/search';
import { MainContext, MainThreadSearchShape } from 'vs/workbench/api/node/extHost.protocol';
import { ExtHostSearch } from 'vs/workbench/api/node/extHostSearch';
import { TestRPCProtocol } from 'vs/workbench/test/electron-browser/api/testRPCProtocol';
......@@ -78,7 +78,7 @@ suite('ExtHostSearch', () => {
return (<UriComponents[]>mockMainThreadSearch.results).map(r => URI.revive(r));
}
async function runTextSearch(pattern: IPatternInfo, query: IRawSearchQuery, cancel = false): TPromise<IRawFileMatch2[]> {
async function runTextSearch(pattern: IPatternInfo, query: IRawSearchQuery, cancel = false): TPromise<IFileMatch[]> {
try {
const p = extHostSearch.$provideTextSearchResults(mockMainThreadSearch.lastHandle, 0, pattern, query);
if (cancel) {
......@@ -95,7 +95,12 @@ suite('ExtHostSearch', () => {
}
await rpcProtocol.sync();
return <IRawFileMatch2[]>mockMainThreadSearch.results;
return (<IRawFileMatch2[]>mockMainThreadSearch.results).map(r => ({
...r,
...{
resource: URI.revive(r.resource)
}
}));
}
setup(() => {
......@@ -114,7 +119,7 @@ suite('ExtHostSearch', () => {
return rpcProtocol.sync();
});
const rootFolderA = URI.file('/foo/bar');
const rootFolderA = URI.file('/foo/bar1');
const rootFolderB = URI.file('/foo/bar2');
// const rootFolderC = URI.file('/foo/bar3');
......@@ -647,15 +652,17 @@ suite('ExtHostSearch', () => {
};
}
function assertResults(actual: IRawFileMatch2[], expected: vscode.TextSearchResult[]) {
function assertResults(actual: IFileMatch[], expected: vscode.TextSearchResult[]) {
const actualTextSearchResults: vscode.TextSearchResult[] = [];
for (let fileMatch of actual) {
// Make relative
const relativePath = fileMatch.resource.fsPath.substr(rootFolderA.fsPath.length + 1);
for (let lineMatch of fileMatch.lineMatches) {
for (let [offset, length] of lineMatch.offsetAndLengths) {
actualTextSearchResults.push({
preview: { text: lineMatch.preview, match: null },
range: new Range(lineMatch.lineNumber, offset, lineMatch.lineNumber, length + offset),
path: fileMatch.resource.relativePath
path: relativePath
});
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册