提交 51b0bf3c 编写于 作者: J Johannes Rieken

support `findFiles`

上级 0b03de63
......@@ -155,6 +155,9 @@ declare module 'vscode' {
// todo@remote
// create(resource: Uri): Thenable<FileStat>;
// find files by names
findFiles?(query: string, progress: Progress<Uri>, token: CancellationToken): Thenable<void>;
}
export namespace workspace {
......
......@@ -5,7 +5,7 @@
'use strict';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { TPromise, PPromise } from 'vs/base/common/winjs.base';
import { ExtHostContext, MainContext, IExtHostContext, MainThreadFileSystemShape, ExtHostFileSystemShape } from '../node/extHost.protocol';
import { IFileService, IFileSystemProvider, IStat, IFileChange } from 'vs/platform/files/common/files';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
......@@ -13,6 +13,7 @@ import Event, { Emitter } from 'vs/base/common/event';
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
import { IProgress } from 'vs/platform/progress/common/progress';
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
import { ISearchResultProvider, ISearchQuery, ISearchComplete, ISearchProgressItem, QueryType, IFileMatch, ISearchService } from 'vs/platform/search/common/search';
@extHostNamedCustomer(MainContext.MainThreadFileSystem)
export class MainThreadFileSystem implements MainThreadFileSystemShape {
......@@ -24,6 +25,7 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
constructor(
extHostContext: IExtHostContext,
@IFileService private readonly _fileService: IFileService,
@ISearchService private readonly _searchService: ISearchService,
@IWorkspaceEditingService private readonly _workspaceEditService: IWorkspaceEditingService
) {
this._proxy = extHostContext.get(ExtHostContext.ExtHostFileSystem);
......@@ -34,7 +36,7 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
}
$registerFileSystemProvider(handle: number, scheme: string): void {
this._provider.set(handle, new RemoteFileSystemProvider(this._fileService, scheme, handle, this._proxy));
this._provider.set(handle, new RemoteFileSystemProvider(this._fileService, this._searchService, scheme, handle, this._proxy));
}
$unregisterFileSystemProvider(handle: number): void {
......@@ -53,28 +55,38 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
$reportFileChunk(handle: number, resource: URI, chunk: number[]): void {
this._provider.get(handle).reportFileChunk(resource, chunk);
}
// --- search
$handleSearchProgress(handle: number, session: number, resource: URI): void {
this._provider.get(handle).handleSearchProgress(session, resource);
}
}
class RemoteFileSystemProvider implements IFileSystemProvider {
class RemoteFileSystemProvider implements IFileSystemProvider, ISearchResultProvider {
private readonly _onDidChange = new Emitter<IFileChange[]>();
private readonly _registration: IDisposable;
private readonly _reads = new Map<string, IProgress<Uint8Array>>();
private readonly _registrations: IDisposable[];
readonly onDidChange: Event<IFileChange[]> = this._onDidChange.event;
constructor(
service: IFileService,
fileService: IFileService,
searchService: ISearchService,
scheme: string,
private readonly _handle: number,
private readonly _proxy: ExtHostFileSystemShape
) {
this._registration = service.registerProvider(scheme, this);
this._registrations = [
fileService.registerProvider(scheme, this),
searchService.registerSearchResultProvider(this),
];
}
dispose(): void {
this._registration.dispose();
dispose(this._registrations);
this._onDidChange.dispose();
}
......@@ -115,4 +127,36 @@ class RemoteFileSystemProvider implements IFileSystemProvider {
rmdir(resource: URI): TPromise<void, any> {
return this._proxy.$rmdir(this._handle, resource);
}
// --- search
private _searches = new Map<number, (resource: URI) => void>();
private _searchesIdPool = 0;
search(query: ISearchQuery): PPromise<ISearchComplete, ISearchProgressItem> {
if (query.type === QueryType.Text) {
return PPromise.as<ISearchComplete>({ results: [], stats: undefined });
}
const id = ++this._searchesIdPool;
const matches: IFileMatch[] = [];
return new PPromise((resolve, reject, report) => {
this._proxy.$fileFiles(this._handle, id, query.filePattern).then(() => {
this._searches.delete(id);
resolve({
results: matches,
stats: undefined
});
}, reject);
this._searches.set(id, resource => {
const match: IFileMatch = { resource };
matches.push(match);
report(match);
});
});
}
handleSearchProgress(session: number, resource: URI): void {
this._searches.get(session)(resource);
}
}
......@@ -324,6 +324,8 @@ export interface MainThreadFileSystemShape extends IDisposable {
$onDidAddFileSystemRoot(root: URI): void;
$onFileSystemChange(handle: number, resource: IFileChange[]): void;
$reportFileChunk(handle: number, resource: URI, chunk: number[] | null): void;
$handleSearchProgress(handle: number, session: number, resource: URI): void;
}
export interface MainThreadTaskShape extends IDisposable {
......@@ -489,6 +491,7 @@ export interface ExtHostFileSystemShape {
$mkdir(handle: number, resource: URI): TPromise<IStat>;
$readdir(handle: number, resource: URI): TPromise<[URI, IStat][]>;
$rmdir(handle: number, resource: URI): TPromise<void>;
$fileFiles(handle: number, session: number, query: string): TPromise<void>;
}
export interface ExtHostExtensionServiceShape {
......
......@@ -74,4 +74,12 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
$rmdir(handle: number, resource: URI): TPromise<void, any> {
return asWinJsPromise(token => this._provider.get(handle).rmdir(resource));
}
$fileFiles(handle: number, session: number, query: string): TPromise<void> {
const provider = this._provider.get(handle);
if (!provider.findFiles) {
return TPromise.as(undefined);
}
const progress = { report: (uri) => this._proxy.$handleSearchProgress(handle, session, uri) };
return asWinJsPromise(token => provider.findFiles(query, progress, token));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册