mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-15 01:25:36 -05:00
Object Explorer API (#783)
See https://github.com/Microsoft/sqlopsstudio/wiki/Extensibility-API#object-explorer for usage details
This commit is contained in:
70
src/sql/workbench/api/node/extHostObjectExplorer.ts
Normal file
70
src/sql/workbench/api/node/extHostObjectExplorer.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { ExtHostObjectExplorerShape, SqlMainContext, MainThreadObjectExplorerShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
|
||||
import * as sqlops from 'sqlops';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export class ExtHostObjectExplorer implements ExtHostObjectExplorerShape {
|
||||
|
||||
private _proxy: MainThreadObjectExplorerShape;
|
||||
|
||||
constructor(
|
||||
threadService: IThreadService
|
||||
) {
|
||||
this._proxy = threadService.get(SqlMainContext.MainThreadObjectExplorer);
|
||||
}
|
||||
|
||||
public $getNode(connectionId: string, nodePath?: string): Thenable<sqlops.objectexplorer.ObjectExplorerNode> {
|
||||
return this._proxy.$getNode(connectionId, nodePath).then(nodeInfo => nodeInfo === undefined ? undefined : new ExtHostObjectExplorerNode(nodeInfo, connectionId, this._proxy));
|
||||
}
|
||||
|
||||
public $getActiveConnectionNodes(): Thenable<sqlops.objectexplorer.ObjectExplorerNode[]> {
|
||||
return this._proxy.$getActiveConnectionNodes().then(results => results.map(result => new ExtHostObjectExplorerNode(result.nodeInfo, result.connectionId, this._proxy)));
|
||||
}
|
||||
}
|
||||
|
||||
class ExtHostObjectExplorerNode implements sqlops.objectexplorer.ObjectExplorerNode {
|
||||
public connectionId: string;
|
||||
public nodePath: string;
|
||||
public nodeType: string;
|
||||
public nodeSubType: string;
|
||||
public nodeStatus: string;
|
||||
public label: string;
|
||||
public isLeaf: boolean;
|
||||
public metadata: sqlops.ObjectMetadata;
|
||||
public errorMessage: string;
|
||||
|
||||
constructor(nodeInfo: sqlops.NodeInfo, connectionId: string, private _proxy: MainThreadObjectExplorerShape) {
|
||||
Object.entries(nodeInfo).forEach(([key, value]) => this[key] = value);
|
||||
this.connectionId = connectionId;
|
||||
}
|
||||
|
||||
isExpanded(): Thenable<boolean> {
|
||||
return this._proxy.$isExpanded(this.connectionId, this.nodePath);
|
||||
}
|
||||
|
||||
setExpandedState(expandedState: vscode.TreeItemCollapsibleState): Thenable<void> {
|
||||
return this._proxy.$setExpandedState(this.connectionId, this.nodePath, expandedState);
|
||||
}
|
||||
|
||||
setSelected(selected: boolean, clearOtherSelections: boolean = undefined): Thenable<void> {
|
||||
return this._proxy.$setSelected(this.connectionId, this.nodePath, selected, clearOtherSelections);
|
||||
}
|
||||
|
||||
getChildren(): Thenable<sqlops.objectexplorer.ObjectExplorerNode[]> {
|
||||
return this._proxy.$getChildren(this.connectionId, this.nodePath).then(children => children.map(nodeInfo => new ExtHostObjectExplorerNode(nodeInfo, this.connectionId, this._proxy)));
|
||||
}
|
||||
|
||||
getParent(): Thenable<sqlops.objectexplorer.ObjectExplorerNode> {
|
||||
let parentPathEndIndex = this.nodePath.lastIndexOf('/');
|
||||
if (parentPathEndIndex === -1) {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
return this._proxy.$getNode(this.connectionId, this.nodePath.slice(0, parentPathEndIndex)).then(nodeInfo => nodeInfo ? new ExtHostObjectExplorerNode(nodeInfo, this.connectionId, this._proxy) : undefined);
|
||||
}
|
||||
}
|
||||
72
src/sql/workbench/api/node/mainThreadObjectExplorer.ts
Normal file
72
src/sql/workbench/api/node/mainThreadObjectExplorer.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { SqlExtHostContext, SqlMainContext, ExtHostObjectExplorerShape, MainThreadObjectExplorerShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
|
||||
import * as sqlops from 'sqlops';
|
||||
import * as vscode from 'vscode';
|
||||
import { IExtHostContext } from 'vs/workbench/api/node/extHost.protocol';
|
||||
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
|
||||
import { IConnectionManagementService } from 'sql/parts/connection/common/connectionManagement';
|
||||
import { IObjectExplorerService, NodeInfoWithConnection } from 'sql/parts/registeredServer/common/objectExplorerService';
|
||||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import * as TaskUtilities from 'sql/workbench/common/taskUtilities';
|
||||
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
|
||||
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
@extHostNamedCustomer(SqlMainContext.MainThreadObjectExplorer)
|
||||
export class MainThreadObjectExplorer implements MainThreadObjectExplorerShape {
|
||||
|
||||
private _proxy: ExtHostObjectExplorerShape;
|
||||
private _toDispose: IDisposable[];
|
||||
|
||||
constructor(
|
||||
extHostContext: IExtHostContext,
|
||||
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
||||
@IObjectExplorerService private _objectExplorerService: IObjectExplorerService,
|
||||
@IWorkbenchEditorService private _workbenchEditorService: IWorkbenchEditorService
|
||||
) {
|
||||
if (extHostContext) {
|
||||
this._proxy = extHostContext.get(SqlExtHostContext.ExtHostObjectExplorer);
|
||||
}
|
||||
this._toDispose = [];
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this._toDispose = dispose(this._toDispose);
|
||||
}
|
||||
|
||||
public $getNode(connectionId: string, nodePath?: string): Thenable<sqlops.NodeInfo> {
|
||||
return this._objectExplorerService.getTreeNode(connectionId, nodePath).then(treeNode => {
|
||||
if (!treeNode) {
|
||||
return undefined;
|
||||
}
|
||||
return treeNode.toNodeInfo();
|
||||
});
|
||||
}
|
||||
|
||||
public $getActiveConnectionNodes(): Thenable<NodeInfoWithConnection[]> {
|
||||
let connectionNodes = this._objectExplorerService.getActiveConnectionNodes();
|
||||
return Promise.resolve(connectionNodes.map(node => {
|
||||
return {connectionId: node.connection.id, nodeInfo: node.toNodeInfo()};
|
||||
}));
|
||||
}
|
||||
|
||||
public $setExpandedState(connectionId: string, nodePath: string, expandedState: vscode.TreeItemCollapsibleState): Thenable<void> {
|
||||
return this._objectExplorerService.getTreeNode(connectionId, nodePath).then(treeNode => treeNode.setExpandedState(expandedState));
|
||||
}
|
||||
|
||||
public $setSelected(connectionId: string, nodePath: string, selected: boolean, clearOtherSelections: boolean = undefined): Thenable<void> {
|
||||
return this._objectExplorerService.getTreeNode(connectionId, nodePath).then(treeNode => treeNode.setSelected(selected, clearOtherSelections));
|
||||
}
|
||||
|
||||
public $getChildren(connectionId: string, nodePath: string): Thenable<sqlops.NodeInfo[]> {
|
||||
return this._objectExplorerService.getTreeNode(connectionId, nodePath).then(treeNode => treeNode.getChildren().then(children => children.map(node => node.toNodeInfo())));
|
||||
}
|
||||
|
||||
public $isExpanded(connectionId: string, nodePath: string): Thenable<boolean> {
|
||||
return this._objectExplorerService.getTreeNode(connectionId, nodePath).then(treeNode => treeNode.isExpanded());
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import { IExtensionApiFactory } from 'vs/workbench/api/node/extHost.api.impl';
|
||||
import { ExtHostDashboardWebviews } from 'sql/workbench/api/node/extHostDashboardWebview';
|
||||
import { ExtHostConnectionManagement } from 'sql/workbench/api/node/extHostConnectionManagement';
|
||||
import { ExtHostDashboard } from 'sql/workbench/api/node/extHostDashboard';
|
||||
import { ExtHostObjectExplorer } from 'sql/workbench/api/node/extHostObjectExplorer';
|
||||
|
||||
export interface ISqlExtensionApiFactory {
|
||||
vsCodeFactory(extension: IExtensionDescription): typeof vscode;
|
||||
@@ -56,6 +57,7 @@ export function createApiFactory(
|
||||
const extHostConnectionManagement = threadService.set(SqlExtHostContext.ExtHostConnectionManagement, new ExtHostConnectionManagement(threadService));
|
||||
const extHostCredentialManagement = threadService.set(SqlExtHostContext.ExtHostCredentialManagement, new ExtHostCredentialManagement(threadService));
|
||||
const extHostDataProvider = threadService.set(SqlExtHostContext.ExtHostDataProtocol, new ExtHostDataProtocol(threadService));
|
||||
const extHostObjectExplorer = threadService.set(SqlExtHostContext.ExtHostObjectExplorer, new ExtHostObjectExplorer(threadService));
|
||||
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));
|
||||
@@ -105,6 +107,16 @@ export function createApiFactory(
|
||||
}
|
||||
};
|
||||
|
||||
// namespace: objectexplorer
|
||||
const objectExplorer: typeof sqlops.objectexplorer = {
|
||||
getNode(connectionId: string, nodePath?: string): Thenable<sqlops.objectexplorer.ObjectExplorerNode> {
|
||||
return extHostObjectExplorer.$getNode(connectionId, nodePath);
|
||||
},
|
||||
getActiveConnectionNodes(): Thenable<sqlops.objectexplorer.ObjectExplorerNode[]> {
|
||||
return extHostObjectExplorer.$getActiveConnectionNodes();
|
||||
}
|
||||
};
|
||||
|
||||
// namespace: serialization
|
||||
const serialization: typeof sqlops.serialization = {
|
||||
registerProvider(provider: sqlops.SerializationProvider): vscode.Disposable {
|
||||
@@ -286,6 +298,7 @@ export function createApiFactory(
|
||||
accounts,
|
||||
connection,
|
||||
credentials,
|
||||
objectexplorer: objectExplorer,
|
||||
resources,
|
||||
serialization,
|
||||
dataprotocol,
|
||||
|
||||
@@ -13,6 +13,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
|
||||
import 'sql/workbench/api/node/mainThreadConnectionManagement';
|
||||
import 'sql/workbench/api/node/mainThreadCredentialManagement';
|
||||
import 'sql/workbench/api/node/mainThreadDataProtocol';
|
||||
import 'sql/workbench/api/node/mainThreadObjectExplorer';
|
||||
import 'sql/workbench/api/node/mainThreadSerializationProvider';
|
||||
import 'sql/workbench/api/node/mainThreadResourceProvider';
|
||||
import 'sql/workbench/api/electron-browser/mainThreadTasks';
|
||||
|
||||
@@ -13,6 +13,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
import * as sqlops from 'sqlops';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import { ITaskHandlerDescription } from 'sql/platform/tasks/common/tasks';
|
||||
|
||||
@@ -305,7 +306,6 @@ export abstract class ExtHostDataProtocolShape {
|
||||
$stopSession(handle: number, sessionId: string): Thenable<boolean> { throw ni(); }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ResourceProvider extension host class.
|
||||
*/
|
||||
@@ -419,6 +419,7 @@ export const SqlMainContext = {
|
||||
MainThreadConnectionManagement: createMainId<MainThreadConnectionManagementShape>('MainThreadConnectionManagement'),
|
||||
MainThreadCredentialManagement: createMainId<MainThreadCredentialManagementShape>('MainThreadCredentialManagement'),
|
||||
MainThreadDataProtocol: createMainId<MainThreadDataProtocolShape>('MainThreadDataProtocol'),
|
||||
MainThreadObjectExplorer: createMainId<MainThreadObjectExplorerShape>('MainThreadObjectExplorer'),
|
||||
MainThreadSerializationProvider: createMainId<MainThreadSerializationProviderShape>('MainThreadSerializationProvider'),
|
||||
MainThreadResourceProvider: createMainId<MainThreadResourceProviderShape>('MainThreadResourceProvider'),
|
||||
MainThreadModalDialog: createMainId<MainThreadModalDialogShape>('MainThreadModalDialog'),
|
||||
@@ -432,6 +433,7 @@ export const SqlExtHostContext = {
|
||||
ExtHostConnectionManagement: createExtId<ExtHostConnectionManagementShape>('ExtHostConnectionManagement'),
|
||||
ExtHostCredentialManagement: createExtId<ExtHostCredentialManagementShape>('ExtHostCredentialManagement'),
|
||||
ExtHostDataProtocol: createExtId<ExtHostDataProtocolShape>('ExtHostDataProtocol'),
|
||||
ExtHostObjectExplorer: createExtId<ExtHostObjectExplorerShape>('ExtHostObjectExplorer'),
|
||||
ExtHostSerializationProvider: createExtId<ExtHostSerializationProviderShape>('ExtHostSerializationProvider'),
|
||||
ExtHostResourceProvider: createExtId<ExtHostResourceProviderShape>('ExtHostResourceProvider'),
|
||||
ExtHostModalDialogs: createExtId<ExtHostModalDialogsShape>('ExtHostModalDialogs'),
|
||||
@@ -485,3 +487,15 @@ export interface MainThreadDashboardWebviewShape extends IDisposable {
|
||||
$registerProvider(widgetId: string);
|
||||
$setHtml(handle: number, value: string);
|
||||
}
|
||||
|
||||
export interface ExtHostObjectExplorerShape {
|
||||
}
|
||||
|
||||
export interface MainThreadObjectExplorerShape extends IDisposable {
|
||||
$getNode(connectionId: string, nodePath?: string): Thenable<sqlops.NodeInfo>;
|
||||
$getActiveConnectionNodes(): Thenable<{ nodeInfo: sqlops.NodeInfo, connectionId: string}[]>;
|
||||
$setExpandedState(connectionId: string, nodePath: string, expandedState: vscode.TreeItemCollapsibleState): Thenable<void>;
|
||||
$setSelected(connectionId: string, nodePath: string, selected: boolean, clearOtherSelections?: boolean): Thenable<void>;
|
||||
$getChildren(connectionId: string, nodePath: string): Thenable<sqlops.NodeInfo[]>;
|
||||
$isExpanded(connectionId: string, nodePath: string): Thenable<boolean>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user