api-ify search provider, needs query logic...

This commit is contained in:
Johannes Rieken
2017-08-17 10:43:23 +02:00
parent fe20718355
commit af195c9638
5 changed files with 101 additions and 11 deletions

View File

@@ -280,6 +280,11 @@ export interface MainThreadWorkspaceShape extends IDisposable {
$applyWorkspaceEdit(edits: IResourceEdit[]): TPromise<boolean>;
$registerFileSystemProvider(handle: number, authority: string): void;
$onFileSystemChange(handle: number, resource: URI): void;
$registerSearchProvider(handle: number, type: number): void;
$unregisterSearchProvider(handle: number): void;
$updateSearchSession(session: number, data): void;
$finishSearchSession(session: number, err?: any): void;
}
export interface MainThreadTaskShape extends IDisposable {
@@ -418,8 +423,11 @@ export interface ExtHostTreeViewsShape {
export interface ExtHostWorkspaceShape {
$acceptWorkspaceData(workspace: IWorkspaceData): void;
$resolveFile(handle: number, resource: URI): TPromise<string>;
$storeFile(handle: number, resource: URI, content: string): TPromise<any>;
$startSearch(handle: number, session: number, query): void;
$cancelSearch(handle: number, session: number): void;
}
export interface ExtHostExtensionServiceShape {

View File

@@ -19,6 +19,8 @@ import { compare } from "vs/base/common/strings";
import { asWinJsPromise } from 'vs/base/common/async';
import { Disposable } from 'vs/workbench/api/node/extHostTypes';
import { TrieMap } from 'vs/base/common/map';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { Progress } from 'vs/platform/progress/common/progress';
class Workspace2 extends Workspace {
@@ -207,27 +209,56 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape {
// --- EXPERIMENT: workspace resolver
private readonly _provider = new Map<number, vscode.FileSystemProvider>();
public registerFileSystemProvider(authority: string, provider: vscode.FileSystemProvider): vscode.Disposable {
private _handlePool = 0;
private readonly _fsProvider = new Map<number, vscode.FileSystemProvider>();
private readonly _searchProvider = new Map<number, vscode.SearchProvider>();
private readonly _searchSession = new Map<number, CancellationTokenSource>();
const handle = this._provider.size;
this._provider.set(handle, provider);
registerFileSystemProvider(authority: string, provider: vscode.FileSystemProvider): vscode.Disposable {
const handle = ++this._handlePool;
this._fsProvider.set(handle, provider);
const reg = provider.onDidChange(e => this._proxy.$onFileSystemChange(handle, <URI>e));
this._proxy.$registerFileSystemProvider(handle, authority);
return new Disposable(() => {
this._provider.delete(handle);
this._fsProvider.delete(handle);
reg.dispose();
});
}
$resolveFile(handle: number, resource: URI): TPromise<string> {
const provider = this._provider.get(handle);
const provider = this._fsProvider.get(handle);
return asWinJsPromise(token => provider.resolveContents(resource));
}
$storeFile(handle: number, resource: URI, content: string): TPromise<any> {
const provider = this._provider.get(handle);
const provider = this._fsProvider.get(handle);
return asWinJsPromise(token => provider.writeContents(resource, content));
}
registerSearchProvider(provider: vscode.SearchProvider): vscode.Disposable {
const handle = ++this._handlePool;
this._searchProvider.set(handle, provider);
return new Disposable(() => this._fsProvider.delete(handle));
}
$startSearch(handle: number, session: number, query): void {
const provider = this._searchProvider.get(handle);
const source = new CancellationTokenSource();
const progress = new Progress<any>(chunk => this._proxy.$updateSearchSession(session, chunk));
this._searchSession.set(session, source);
TPromise.wrap(provider.provideSearchResults(query, progress, source.token)).then(() => {
this._proxy.$finishSearchSession(session);
}, err => {
this._proxy.$finishSearchSession(session, err);
});
}
$cancelSearch(handle: number, session: number): void {
if (this._searchSession.has(session)) {
this._searchSession.get(session).cancel();
this._searchSession.delete(session);
}
}
}