More adoption of @extHostNamedCustomer

This commit is contained in:
Alex Dima
2017-08-16 12:55:53 +02:00
parent 4d5ded68d2
commit a99eeae966
30 changed files with 197 additions and 136 deletions

View File

@@ -7,16 +7,29 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { ITaskService } from 'vs/workbench/parts/tasks/common/taskService';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { ExtHostContext, MainThreadTaskShape, ExtHostTaskShape } from '../node/extHost.protocol';
import { ExtHostContext, MainThreadTaskShape, ExtHostTaskShape, MainContext, IExtHostContext } from '../node/extHost.protocol';
import { extHostNamedCustomer } from "vs/workbench/api/electron-browser/extHostCustomers";
@extHostNamedCustomer(MainContext.MainThreadTask)
export class MainThreadTask implements MainThreadTaskShape {
private _proxy: ExtHostTaskShape;
private _activeHandles: { [handle: number]: boolean; };
constructor( @IThreadService threadService: IThreadService, @ITaskService private _taskService: ITaskService) {
this._proxy = threadService.get(ExtHostContext.ExtHostTask);
constructor(
extHostContext: IExtHostContext,
@ITaskService private _taskService: ITaskService
) {
this._proxy = extHostContext.get(ExtHostContext.ExtHostTask);
this._activeHandles = Object.create(null);
}
public dispose(): void {
Object.keys(this._activeHandles).forEach((handle) => {
this._taskService.unregisterTaskProvider(parseInt(handle, 10));
});
this._activeHandles = Object.create(null);
}
public $registerTaskProvider(handle: number): TPromise<void> {
@@ -25,11 +38,13 @@ export class MainThreadTask implements MainThreadTaskShape {
return this._proxy.$provideTasks(handle);
}
});
this._activeHandles[handle] = true;
return TPromise.as<void>(undefined);
}
public $unregisterTaskProvider(handle: number): TPromise<any> {
this._taskService.unregisterTaskProvider(handle);
delete this._activeHandles[handle];
return TPromise.as<void>(undefined);
}
}