mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-16 17:22:29 -05:00
Task contribution (#742)
* work in progress * set up necessary code. need to work on getting it working * formatting * work in progress * work in progress * formatting * work in progress * work in progress * work in progress * formatting * needs a lot of work regarding how we do actions vs how extensions do actions * formatting * use connection profile for actions * change action to be
This commit is contained in:
91
src/sql/workbench/api/node/extHostTasks.ts
Normal file
91
src/sql/workbench/api/node/extHostTasks.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { validateConstraint } from 'vs/base/common/types';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { IMainContext } from 'vs/workbench/api/node/extHost.protocol';
|
||||
import * as extHostTypes from 'vs/workbench/api/node/extHostTypes';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
|
||||
import * as sqlops from 'sqlops';
|
||||
|
||||
import { ITaskHandlerDescription } from 'sql/platform/tasks/common/tasks';
|
||||
import { SqlMainContext, MainThreadTasksShape, ExtHostTasksShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
|
||||
|
||||
interface TaskHandler {
|
||||
callback: Function;
|
||||
thisArg: any;
|
||||
description: ITaskHandlerDescription;
|
||||
}
|
||||
|
||||
export class ExtHostTasks implements ExtHostTasksShape {
|
||||
private _proxy: MainThreadTasksShape;
|
||||
private _tasks = new Map<string, TaskHandler>();
|
||||
|
||||
constructor(
|
||||
mainContext: IMainContext,
|
||||
private logService: ILogService
|
||||
) {
|
||||
this._proxy = mainContext.get(SqlMainContext.MainThreadTasks);
|
||||
}
|
||||
|
||||
registerTask(id: string, callback: sqlops.tasks.ITaskHandler, thisArg?: any, description?: ITaskHandlerDescription): extHostTypes.Disposable {
|
||||
this.logService.trace('ExtHostTasks#registerTask', id);
|
||||
|
||||
if (!id.trim().length) {
|
||||
throw new Error('invalid id');
|
||||
}
|
||||
|
||||
if (this._tasks.has(id)) {
|
||||
throw new Error(`task '${id}' already exists`);
|
||||
}
|
||||
|
||||
this._tasks.set(id, { callback, thisArg, description });
|
||||
this._proxy.$registerTask(id);
|
||||
|
||||
return new extHostTypes.Disposable(() => {
|
||||
if (this._tasks.delete(id)) {
|
||||
this._proxy.$unregisterTask(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$executeContributedTask<T>(id: string, ...args: any[]): Thenable<T> {
|
||||
let command = this._tasks.get(id);
|
||||
if (!command) {
|
||||
return TPromise.wrapError<T>(new Error(`Contributed task '${id}' does not exist.`));
|
||||
}
|
||||
|
||||
let { callback, thisArg, description } = command;
|
||||
|
||||
if (description) {
|
||||
for (let i = 0; i < description.args.length; i++) {
|
||||
try {
|
||||
validateConstraint(args[i], description.args[i].constraint);
|
||||
} catch (err) {
|
||||
return TPromise.wrapError<T>(new Error(`Running the contributed task:'${id}' failed. Illegal argument '${description.args[i].name}' - ${description.args[i].description}`));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
let result = callback.apply(thisArg, args);
|
||||
return TPromise.as(result);
|
||||
} catch (err) {
|
||||
// console.log(err);
|
||||
// try {
|
||||
// console.log(toErrorMessage(err));
|
||||
// } catch (err) {
|
||||
// //
|
||||
// }
|
||||
return TPromise.wrapError<T>(new Error(`Running the contributed task:'${id}' failed.`));
|
||||
}
|
||||
}
|
||||
|
||||
$getContributedTaskHandlerDescriptions(): TPromise<{ [id: string]: any; }> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import * as sqlExtHostTypes from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
|
||||
import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration';
|
||||
import { ExtHostModalDialogs } from 'sql/workbench/api/node/extHostModalDialog';
|
||||
import { ExtHostTasks } from 'sql/workbench/api/node/extHostTasks';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { IExtensionApiFactory } from 'vs/workbench/api/node/extHost.api.impl';
|
||||
import { ExtHostDashboardWebviews } from 'sql/workbench/api/node/extHostDashboardWebview';
|
||||
@@ -57,6 +58,7 @@ export function createApiFactory(
|
||||
const extHostSerializationProvider = threadService.set(SqlExtHostContext.ExtHostSerializationProvider, new ExtHostSerializationProvider(threadService));
|
||||
const extHostResourceProvider = threadService.set(SqlExtHostContext.ExtHostResourceProvider, new ExtHostResourceProvider(threadService));
|
||||
const extHostModalDialogs = threadService.set(SqlExtHostContext.ExtHostModalDialogs, new ExtHostModalDialogs(threadService));
|
||||
const extHostTasks = threadService.set(SqlExtHostContext.ExtHostTasks, new ExtHostTasks(threadService, logService));
|
||||
const extHostWebviewWidgets = threadService.set(SqlExtHostContext.ExtHostDashboardWebviews, new ExtHostDashboardWebviews(threadService));
|
||||
|
||||
return {
|
||||
@@ -255,12 +257,18 @@ export function createApiFactory(
|
||||
}
|
||||
};
|
||||
|
||||
const window = {
|
||||
const window: typeof sqlops.window = {
|
||||
createDialog(name: string) {
|
||||
return extHostModalDialogs.createDialog(name);
|
||||
}
|
||||
};
|
||||
|
||||
const tasks: typeof sqlops.tasks = {
|
||||
registerTask(id: string, task: (...args: any[]) => any, thisArgs?: any): vscode.Disposable {
|
||||
return extHostTasks.registerTask(id, task, thisArgs);
|
||||
}
|
||||
};
|
||||
|
||||
const dashboard = {
|
||||
registerWebviewProvider(widgetId: string, handler: (webview: sqlops.DashboardWebview) => void) {
|
||||
extHostWebviewWidgets.$registerProvider(widgetId, handler);
|
||||
@@ -282,6 +290,7 @@ export function createApiFactory(
|
||||
TaskExecutionMode: sqlExtHostTypes.TaskExecutionMode,
|
||||
ScriptOperation: sqlExtHostTypes.ScriptOperation,
|
||||
window,
|
||||
tasks,
|
||||
dashboard
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import 'sql/workbench/api/node/mainThreadCredentialManagement';
|
||||
import 'sql/workbench/api/node/mainThreadDataProtocol';
|
||||
import 'sql/workbench/api/node/mainThreadSerializationProvider';
|
||||
import 'sql/workbench/api/node/mainThreadResourceProvider';
|
||||
import 'sql/workbench/api/electron-browser/mainThreadTasks';
|
||||
import 'sql/workbench/api/node/mainThreadDashboardWebview';
|
||||
import './mainThreadAccountManagement';
|
||||
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
|
||||
|
||||
@@ -9,11 +9,12 @@ import {
|
||||
createExtHostContextProxyIdentifier as createExtId,
|
||||
ProxyIdentifier
|
||||
} from 'vs/workbench/services/thread/common/threadService';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
import * as sqlops from 'sqlops';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ITaskHandlerDescription } from 'sql/platform/tasks/common/tasks';
|
||||
|
||||
export abstract class ExtHostAccountManagementShape {
|
||||
$autoOAuthCancelled(handle: number): Thenable<void> { throw ni(); }
|
||||
@@ -421,6 +422,7 @@ export const SqlMainContext = {
|
||||
MainThreadSerializationProvider: createMainId<MainThreadSerializationProviderShape>('MainThreadSerializationProvider'),
|
||||
MainThreadResourceProvider: createMainId<MainThreadResourceProviderShape>('MainThreadResourceProvider'),
|
||||
MainThreadModalDialog: createMainId<MainThreadModalDialogShape>('MainThreadModalDialog'),
|
||||
MainThreadTasks: createMainId<MainThreadTasksShape>('MainThreadTasks'),
|
||||
MainThreadDashboardWebview: createMainId<MainThreadDashboardWebviewShape>('MainThreadDashboardWebview')
|
||||
};
|
||||
|
||||
@@ -432,6 +434,7 @@ export const SqlExtHostContext = {
|
||||
ExtHostSerializationProvider: createExtId<ExtHostSerializationProviderShape>('ExtHostSerializationProvider'),
|
||||
ExtHostResourceProvider: createExtId<ExtHostResourceProviderShape>('ExtHostResourceProvider'),
|
||||
ExtHostModalDialogs: createExtId<ExtHostModalDialogsShape>('ExtHostModalDialogs'),
|
||||
ExtHostTasks: createExtId<ExtHostTasksShape>('ExtHostTasks'),
|
||||
ExtHostDashboardWebviews: createExtId<ExtHostDashboardWebviewsShape>('ExtHostDashboardWebviews')
|
||||
};
|
||||
|
||||
@@ -449,6 +452,16 @@ export interface ExtHostModalDialogsShape {
|
||||
$onClosed(handle: number): void;
|
||||
}
|
||||
|
||||
export interface ExtHostTasksShape {
|
||||
$executeContributedTask<T>(id: string, ...args: any[]): Thenable<T>;
|
||||
$getContributedTaskHandlerDescriptions(): TPromise<{ [id: string]: string | ITaskHandlerDescription }>;
|
||||
}
|
||||
|
||||
export interface MainThreadTasksShape extends IDisposable {
|
||||
$registerTask(id: string): TPromise<any>;
|
||||
$unregisterTask(id: string): TPromise<any>;
|
||||
}
|
||||
|
||||
export interface ExtHostDashboardWebviewsShape {
|
||||
$registerProvider(widgetId: string, handler: (webview: sqlops.DashboardWebview) => void): void;
|
||||
$onMessage(handle: number, message: any): void;
|
||||
|
||||
Reference in New Issue
Block a user