Skip to content

Commit

Permalink
refine text search api, #41536
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jan 12, 2018
1 parent c75ebac commit 0b9b336
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ declare module 'vscode' {
type: FileType;
}

export interface FindMatch {
export interface TextSearchQuery {
pattern: string;
isRegex?: boolean;
isCaseSensitive?: boolean;
isWordMatch?: boolean;
}

export interface TextSearchResult {
uri: Uri;
range: Range;
preview: { leading: string, matching: string, trailing: string };
Expand Down Expand Up @@ -137,7 +144,8 @@ declare module 'vscode' {

// find files by names
findFiles?(query: string, progress: Progress<Uri>, token: CancellationToken): Thenable<void>;
findInFiles?(query: string, isRegex: boolean, progress: Progress<FindMatch>, token: CancellationToken): Thenable<void>;

provideTextSearchResults?(query: TextSearchQuery, include: GlobPattern, exclude: GlobPattern, progress: Progress<TextSearchResult>, token: CancellationToken): Thenable<void>;
}

export namespace workspace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class RemoteFileSystemProvider implements IFileSystemProvider, ISearchResultProv

const promise = query.type === QueryType.File
? this._proxy.$findFiles(this._handle, search.id, query.filePattern)
: this._proxy.$findInFiles(this._handle, search.id, query.contentPattern);
: this._proxy.$provideTextSearchResults(this._handle, search.id, query.contentPattern, undefined, undefined);

promise.then(() => {
this._searches.delete(search.id);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ export interface ExtHostFileSystemShape {
$readdir(handle: number, resource: UriComponents): TPromise<[UriComponents, IStat][]>;
$rmdir(handle: number, resource: UriComponents): TPromise<void>;
$findFiles(handle: number, session: number, query: string): TPromise<void>;
$findInFiles(handle: number, session: number, pattern: IPatternInfo): TPromise<void>;
$provideTextSearchResults(handle: number, session: number, pattern: IPatternInfo, include: string, exclude: string): TPromise<void>;
}

export interface ExtHostExtensionServiceShape {
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/api/node/extHostFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
};
return asWinJsPromise(token => provider.findFiles(query, progress, token));
}
$findInFiles(handle: number, session: number, pattern: IPatternInfo): TPromise<void> {
$provideTextSearchResults(handle: number, session: number, pattern: IPatternInfo, include: string, exclude: string): TPromise<void> {
const provider = this._provider.get(handle);
if (!provider.findInFiles) {
if (!provider.provideTextSearchResults) {
return TPromise.as(undefined);
}
const progress = {
report: (data: vscode.FindMatch) => {
report: (data: vscode.TextSearchResult) => {
this._proxy.$handleFindMatch(handle, session, [data.uri, {
lineNumber: 1 + data.range.start.line,
preview: data.preview.leading + data.preview.matching + data.preview.trailing,
offsetAndLengths: [[data.preview.leading.length, data.preview.matching.length]]
}]);
}
};
return asWinJsPromise(token => provider.findInFiles(pattern.pattern, pattern.isRegExp, progress, token));
return asWinJsPromise(token => provider.provideTextSearchResults(pattern, include, exclude, progress, token));
}
}

0 comments on commit 0b9b336

Please sign in to comment.