From 80c1c4c6c89e6428845d3074cc8d0f4958333a9f Mon Sep 17 00:00:00 2001 From: Yurong He <43652751+YurongHe@users.noreply.github.com> Date: Mon, 4 Feb 2019 19:55:32 -0800 Subject: [PATCH] Mssql extension exposes OE getNode API for Sql-2019vNext extension (#3901) * Mssql extension exposes OE getNode API for Sql-2019Vnext extension * Resolved PR comments --- extensions/mssql/src/api/mssqlapis.d.ts | 65 +++++++++++++++++++++++++ extensions/mssql/src/main.ts | 15 +++++- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 extensions/mssql/src/api/mssqlapis.d.ts diff --git a/extensions/mssql/src/api/mssqlapis.d.ts b/extensions/mssql/src/api/mssqlapis.d.ts new file mode 100644 index 0000000000..a7309454b3 --- /dev/null +++ b/extensions/mssql/src/api/mssqlapis.d.ts @@ -0,0 +1,65 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +// This is the place for extensions to expose APIs. + +import * as sqlops from 'sqlops'; +import * as vscode from 'vscode'; + +/** +* The APIs provided by Mssql extension +* +* @export +* @interface MssqlExtensionApi +*/ +export interface MssqlExtensionApi { + /** + * Gets the object explorer API that supports querying over the connections supported by this extension + * + * @returns {IMssqlObjectExplorerBrowser} + * @memberof IMssqlExtensionApi + */ + getMssqlObjectExplorerBrowser(): MssqlObjectExplorerBrowser; +} + +/** + * A browser supporting actions over the object explorer connections provided by this extension. + * Currently this is the + * + * @export + * @interface MssqlObjectExplorerBrowser + */ +export interface MssqlObjectExplorerBrowser { + /** + * Gets the matching node given a context object, e.g. one from a right-click on a node in Object Explorer + * + * @param {sqlops.ObjectExplorerContext} objectExplorerContext + * @returns {Promise} + */ + getNode(objectExplorerContext: sqlops.ObjectExplorerContext): Promise; +} + +/** + * A tree node in the object explorer tree + * + * @export + * @interface ITreeNode + */ +export interface ITreeNode { + getNodeInfo(): sqlops.NodeInfo; + getChildren(refreshChildren: boolean): ITreeNode[] | Promise; +} + +/** + * A HDFS file node. This is a leaf node in the object explorer tree, and its contents + * can be queried + * + * @export + * @interface IFileNode + * @extends {ITreeNode} + */ +export interface IFileNode extends ITreeNode { + getFileContentsAsString(maxBytes?: number): Promise; +} diff --git a/extensions/mssql/src/main.ts b/extensions/mssql/src/main.ts index 01c933f1ea..42674f6409 100644 --- a/extensions/mssql/src/main.ts +++ b/extensions/mssql/src/main.ts @@ -24,12 +24,13 @@ import { MssqlObjectExplorerNodeProvider } from './objectExplorerNodeProvider/ob import { UploadFilesCommand, MkDirCommand, SaveFileCommand, PreviewFileCommand, CopyPathCommand, DeleteFilesCommand } from './objectExplorerNodeProvider/hdfsCommands'; import { IPrompter } from './prompts/question'; import CodeAdapter from './prompts/adapter'; +import { MssqlExtensionApi, MssqlObjectExplorerBrowser } from './api/mssqlapis'; const baseConfig = require('./config.json'); const outputChannel = vscode.window.createOutputChannel(Constants.serviceName); const statusView = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); -export async function activate(context: vscode.ExtensionContext) { +export async function activate(context: vscode.ExtensionContext): Promise { // lets make sure we support this platform first let supported = await Utils.verifyPlatform(); @@ -113,6 +114,18 @@ export async function activate(context: vscode.ExtensionContext) { context.subscriptions.push(new CopyPathCommand(appContext)); context.subscriptions.push(new DeleteFilesCommand(prompter, appContext)); context.subscriptions.push({ dispose: () => languageClient.stop() }); + + let api: MssqlExtensionApi = { + getMssqlObjectExplorerBrowser(): MssqlObjectExplorerBrowser { + return { + getNode: (context: sqlops.ObjectExplorerContext) => { + let oeProvider = appContext.getService(Constants.ObjectExplorerService); + return oeProvider.findNodeForContext(context); + } + }; + } + }; + return api; } function generateServerOptions(executablePath: string): ServerOptions {