提交 36d5e046 编写于 作者: R Rob Lourens

Use combined search results for matches from editor, too

上级 7397ec97
......@@ -21,11 +21,12 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IProgressRunner } from 'vs/platform/progress/common/progress';
import { ReplacePattern } from 'vs/platform/search/common/replace';
import { IFileMatch, IPatternInfo, ISearchComplete, ISearchProgressItem, ISearchService, ITextQuery, ITextSearchPreviewOptions, ITextSearchResult, ITextSearchStats, TextSearchResult } from 'vs/platform/search/common/search';
import { IFileMatch, IPatternInfo, ISearchComplete, ISearchProgressItem, ISearchService, ITextQuery, ITextSearchPreviewOptions, ITextSearchResult, ITextSearchStats } from 'vs/platform/search/common/search';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { overviewRulerFindMatchForeground } from 'vs/platform/theme/common/colorRegistry';
import { themeColorFromId } from 'vs/platform/theme/common/themeService';
import { IReplaceService } from 'vs/workbench/parts/search/common/replace';
import { editorMatchesToTextSearchResults } from 'vs/workbench/services/search/common/searchHelpers';
export class Match {
......@@ -241,8 +242,8 @@ export class FileMatch extends Disposable {
}
private updateMatches(matches: FindMatch[], modelChange: boolean) {
matches.forEach(m => {
const textSearchResult = editorMatchToTextSearchResult(m, this._model, this._previewOptions);
const textSearchResults = editorMatchesToTextSearchResults(matches, this._model, this._previewOptions);
textSearchResults.forEach(textSearchResult => {
const match = new Match(this, textSearchResult);
if (!this._removedMatches.has(match.id())) {
......@@ -1009,13 +1010,6 @@ export class RangeHighlightDecorations implements IDisposable {
});
}
export function editorMatchToTextSearchResult(match: FindMatch, model: ITextModel, previewOptions: ITextSearchPreviewOptions): TextSearchResult {
return new TextSearchResult(
model.getLineContent(match.range.startLineNumber),
new Range(match.range.startLineNumber - 1, match.range.startColumn - 1, match.range.endLineNumber - 1, match.range.endColumn - 1),
previewOptions);
}
function textSearchResultToMatches(rawMatch: ITextSearchResult, fileMatch: FileMatch): Match[] {
if (Array.isArray(rawMatch.ranges)) {
return rawMatch.ranges.map((r, i) => {
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Range } from 'vs/editor/common/core/range';
import { FindMatch, ITextModel } from 'vs/editor/common/model';
import { ITextSearchPreviewOptions, TextSearchResult } from 'vs/platform/search/common/search';
function editorMatchToTextSearchResult(matches: FindMatch[], model: ITextModel, previewOptions?: ITextSearchPreviewOptions): TextSearchResult {
const firstLine = matches[0].range.startLineNumber;
const lastLine = matches[matches.length - 1].range.endLineNumber;
const lineTexts: string[] = [];
const numLines = previewOptions ? previewOptions.matchLines : Number.MAX_VALUE;
for (let i = firstLine; i <= lastLine && (i - firstLine) < numLines; i++) {
lineTexts.push(model.getLineContent(i));
}
return new TextSearchResult(
lineTexts.join('\n'),
matches.map(m => new Range(m.range.startLineNumber - 1, m.range.startColumn - 1, m.range.endLineNumber - 1, m.range.endColumn - 1)),
previewOptions);
}
/**
* Combine a set of FindMatches into a set of TextSearchResults. They should be grouped by matches that start on the same line that the previous match ends on.
*/
export function editorMatchesToTextSearchResults(matches: FindMatch[], model: ITextModel, previewOptions?: ITextSearchPreviewOptions): TextSearchResult[] {
let previousEndLine = -1;
const groupedMatches: FindMatch[][] = [];
let currentMatches: FindMatch[] = [];
matches.forEach((match) => {
if (match.range.startLineNumber !== previousEndLine) {
currentMatches = [];
groupedMatches.push(currentMatches);
}
currentMatches.push(match);
previousEndLine = match.range.endLineNumber;
});
return groupedMatches.map(sameLineMatches => {
return editorMatchToTextSearchResult(sameLineMatches, model, previewOptions);
});
}
\ No newline at end of file
......@@ -6,7 +6,7 @@
import { Event } from 'vs/base/common/event';
import * as glob from 'vs/base/common/glob';
import { TPromise } from 'vs/base/common/winjs.base';
import { IFileSearchStats, IFolderQuery, IProgress, IRawTextQuery, ISearchEngineStats, ISearchQuery, ITextSearchResult, ITextSearchStats, IRawFileQuery } from 'vs/platform/search/common/search';
import { IFileSearchStats, IFolderQuery, IProgress, IRawFileQuery, IRawTextQuery, ISearchEngineStats, ISearchQuery, ITextSearchResult, ITextSearchStats } from 'vs/platform/search/common/search';
import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
export interface ITelemetryEvent {
......
......@@ -18,19 +18,18 @@ import { TPromise } from 'vs/base/common/winjs.base';
import * as pfs from 'vs/base/node/pfs';
import { getNextTickChannel } from 'vs/base/parts/ipc/node/ipc';
import { Client, IIPCOptions } from 'vs/base/parts/ipc/node/ipc.cp';
import { Range } from 'vs/editor/common/core/range';
import { FindMatch, ITextModel } from 'vs/editor/common/model';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IDebugParams, IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
import { FileMatch, ICachedSearchStats, IFileMatch, IFileQuery, IFileSearchStats, IFolderQuery, IProgress, ISearchComplete, ISearchConfiguration, ISearchEngineStats, ISearchProgressItem, ISearchQuery, ISearchResultProvider, ISearchService, ITextQuery, ITextSearchPreviewOptions, pathIncludedInQuery, QueryType, SearchProviderType, TextSearchResult } from 'vs/platform/search/common/search';
import { FileMatch, ICachedSearchStats, IFileMatch, IFileQuery, IFileSearchStats, IFolderQuery, IProgress, ISearchComplete, ISearchConfiguration, ISearchEngineStats, ISearchProgressItem, ISearchQuery, ISearchResultProvider, ISearchService, ITextQuery, pathIncludedInQuery, QueryType, SearchProviderType } from 'vs/platform/search/common/search';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IRawSearchService, ISerializedFileMatch, ISerializedSearchComplete, ISerializedSearchProgressItem, isSerializedSearchComplete, isSerializedSearchSuccess } from './search';
import { ISearchChannel, SearchChannelClient } from './searchIpc';
import { editorMatchesToTextSearchResults } from 'vs/workbench/services/search/common/searchHelpers';
export class SearchService extends Disposable implements ISearchService {
public _serviceBrand: any;
......@@ -378,7 +377,7 @@ export class SearchService extends Disposable implements ISearchService {
scheme,
error: errorType,
useRipgrep: query.useRipgrep,
usePCRE2: query.usePCRE2
usePCRE2: !!query.usePCRE2
});
}
}
......@@ -423,9 +422,7 @@ export class SearchService extends Disposable implements ISearchService {
let fileMatch = new FileMatch(resource);
localResults.set(resource, fileMatch);
matches.forEach((match) => {
fileMatch.matches.push(editorMatchToTextSearchResult(match, model, query.previewOptions));
});
fileMatch.matches = editorMatchesToTextSearchResults(matches, model, query.previewOptions);
} else {
localResults.set(resource, null);
}
......@@ -584,7 +581,7 @@ export class DiskSearch implements ISearchResultProvider {
private static createFileMatch(data: ISerializedFileMatch): FileMatch {
let fileMatch = new FileMatch(uri.file(data.path));
if (data.matches) {
fileMatch.matches.push(...data.matches); // TODO why
fileMatch.matches.push(...data.matches);
}
return fileMatch;
}
......@@ -594,9 +591,3 @@ export class DiskSearch implements ISearchResultProvider {
}
}
function editorMatchToTextSearchResult(match: FindMatch, model: ITextModel, previewOptions: ITextSearchPreviewOptions): TextSearchResult {
return new TextSearchResult(
model.getLineContent(match.range.startLineNumber),
new Range(match.range.startLineNumber - 1, match.range.startColumn - 1, match.range.endLineNumber - 1, match.range.endColumn - 1),
previewOptions);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册