mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-15 01:25:36 -05:00
Add Query Editor API to sqlops.proposed (#1196)
* add support query editor API * remove sqlops.proposed.d.ts in sp_whoIsActive * address comments * add catch error when connect
This commit is contained in:
29
src/sql/workbench/api/node/extHostQueryEditor.ts
Normal file
29
src/sql/workbench/api/node/extHostQueryEditor.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { IMainContext } from 'vs/workbench/api/node/extHost.protocol';
|
||||
import { ExtHostQueryEditorShape, SqlMainContext, MainThreadQueryEditorShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
|
||||
import * as sqlops from 'sqlops';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export class ExtHostQueryEditor implements ExtHostQueryEditorShape {
|
||||
|
||||
private _proxy: MainThreadQueryEditorShape;
|
||||
|
||||
constructor(
|
||||
mainContext: IMainContext
|
||||
) {
|
||||
this._proxy = mainContext.getProxy(SqlMainContext.MainThreadQueryEditor);
|
||||
}
|
||||
|
||||
public $connect(fileUri: string, connectionId: string): Thenable<void> {
|
||||
return this._proxy.$connect(fileUri, connectionId);
|
||||
}
|
||||
|
||||
public $runQuery(fileUri: string): void {
|
||||
return this._proxy.$runQuery(fileUri);
|
||||
}
|
||||
}
|
||||
78
src/sql/workbench/api/node/mainThreadQueryEditor.ts
Normal file
78
src/sql/workbench/api/node/mainThreadQueryEditor.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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, ExtHostQueryEditorShape, MainThreadQueryEditorShape } 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 { IConnectableInput, IConnectionManagementService, IConnectionCompletionOptions,
|
||||
ConnectionType , RunQueryOnConnectionMode
|
||||
} from 'sql/parts/connection/common/connectionManagement';
|
||||
import { IQueryEditorService } from 'sql/parts/query/common/queryEditorService';
|
||||
import { QueryEditor } from 'sql/parts/query/editor/queryEditor';
|
||||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
@extHostNamedCustomer(SqlMainContext.MainThreadQueryEditor)
|
||||
export class MainThreadQueryEditor implements MainThreadQueryEditorShape {
|
||||
|
||||
private _proxy: ExtHostQueryEditorShape;
|
||||
private _toDispose: IDisposable[];
|
||||
|
||||
constructor(
|
||||
extHostContext: IExtHostContext,
|
||||
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
||||
@IQueryEditorService private _queryEditorService: IQueryEditorService,
|
||||
@IWorkbenchEditorService private _editorService: IWorkbenchEditorService
|
||||
) {
|
||||
if (extHostContext) {
|
||||
this._proxy = extHostContext.getProxy(SqlExtHostContext.ExtHostQueryEditor);
|
||||
}
|
||||
this._toDispose = [];
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this._toDispose = dispose(this._toDispose);
|
||||
}
|
||||
|
||||
public $connect(fileUri: string, connectionId: string): Thenable<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
if (connectionId) {
|
||||
let connection = this._connectionManagementService.getActiveConnections().filter(c => c.id === connectionId);
|
||||
if (connection && connection.length > 0) {
|
||||
this._connectionManagementService.connect(connection[0], fileUri, options).then(() => {
|
||||
resolve();
|
||||
}).catch(error => {
|
||||
reject();
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public $runQuery(fileUri: string): void {
|
||||
let filteredEditors = this._editorService.getVisibleEditors().filter(editor => editor.input.getResource().toString() === fileUri);
|
||||
if (filteredEditors && filteredEditors.length > 0) {
|
||||
let editor = filteredEditors[0];
|
||||
if (editor instanceof QueryEditor) {
|
||||
let queryEditor: QueryEditor = editor;
|
||||
queryEditor.runCurrentQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import { ExtHostConnectionManagement } from 'sql/workbench/api/node/extHostConne
|
||||
import { ExtHostDashboard } from 'sql/workbench/api/node/extHostDashboard';
|
||||
import { ExtHostObjectExplorer } from 'sql/workbench/api/node/extHostObjectExplorer';
|
||||
import { ExtHostLogService } from 'vs/workbench/api/node/extHostLogService';
|
||||
import { ExtHostQueryEditor } from 'sql/workbench/api/node/extHostQueryEditor';
|
||||
|
||||
export interface ISqlExtensionApiFactory {
|
||||
vsCodeFactory(extension: IExtensionDescription): typeof vscode;
|
||||
@@ -64,6 +65,7 @@ export function createApiFactory(
|
||||
const extHostWebviewWidgets = rpcProtocol.set(SqlExtHostContext.ExtHostDashboardWebviews, new ExtHostDashboardWebviews(rpcProtocol));
|
||||
const extHostModelView = rpcProtocol.set(SqlExtHostContext.ExtHostModelView, new ExtHostModelView(rpcProtocol));
|
||||
const extHostDashboard = rpcProtocol.set(SqlExtHostContext.ExtHostDashboard, new ExtHostDashboard(rpcProtocol));
|
||||
const extHostQueryEditor = rpcProtocol.set(SqlExtHostContext.ExtHostQueryEditor, new ExtHostQueryEditor(rpcProtocol));
|
||||
|
||||
|
||||
return {
|
||||
@@ -315,6 +317,18 @@ export function createApiFactory(
|
||||
}
|
||||
};
|
||||
|
||||
// namespace: queryeditor
|
||||
const queryEditor: typeof sqlops.queryeditor = {
|
||||
|
||||
connect(fileUri: string, connectionId: string): Thenable<void> {
|
||||
return extHostQueryEditor.$connect(fileUri, connectionId);
|
||||
},
|
||||
|
||||
runQuery(fileUri: string): void {
|
||||
extHostQueryEditor.$runQuery(fileUri);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
accounts,
|
||||
connection,
|
||||
@@ -333,7 +347,8 @@ export function createApiFactory(
|
||||
window,
|
||||
tasks,
|
||||
dashboard,
|
||||
workspace
|
||||
workspace,
|
||||
queryeditor: queryEditor
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -19,6 +19,7 @@ import 'sql/workbench/api/node/mainThreadResourceProvider';
|
||||
import 'sql/workbench/api/electron-browser/mainThreadTasks';
|
||||
import 'sql/workbench/api/electron-browser/mainThreadDashboard';
|
||||
import 'sql/workbench/api/node/mainThreadDashboardWebview';
|
||||
import 'sql/workbench/api/node/mainThreadQueryEditor';
|
||||
import 'sql/workbench/api/node/mainThreadModelView';
|
||||
import './mainThreadAccountManagement';
|
||||
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
|
||||
|
||||
@@ -447,7 +447,8 @@ export const SqlMainContext = {
|
||||
MainThreadTasks: createMainId<MainThreadTasksShape>('MainThreadTasks'),
|
||||
MainThreadDashboardWebview: createMainId<MainThreadDashboardWebviewShape>('MainThreadDashboardWebview'),
|
||||
MainThreadModelView: createMainId<MainThreadModelViewShape>('MainThreadModelView'),
|
||||
MainThreadDashboard: createMainId<MainThreadDashboardShape>('MainThreadDashboard')
|
||||
MainThreadDashboard: createMainId<MainThreadDashboardShape>('MainThreadDashboard'),
|
||||
MainThreadQueryEditor: createMainId<MainThreadQueryEditorShape>('MainThreadQueryEditor'),
|
||||
};
|
||||
|
||||
export const SqlExtHostContext = {
|
||||
@@ -462,7 +463,8 @@ export const SqlExtHostContext = {
|
||||
ExtHostTasks: createExtId<ExtHostTasksShape>('ExtHostTasks'),
|
||||
ExtHostDashboardWebviews: createExtId<ExtHostDashboardWebviewsShape>('ExtHostDashboardWebviews'),
|
||||
ExtHostModelView: createExtId<ExtHostModelViewShape>('ExtHostModelView'),
|
||||
ExtHostDashboard: createExtId<ExtHostDashboardShape>('ExtHostDashboard')
|
||||
ExtHostDashboard: createExtId<ExtHostDashboardShape>('ExtHostDashboard'),
|
||||
ExtHostQueryEditor: createExtId<ExtHostQueryEditorShape>('ExtHostQueryEditor')
|
||||
};
|
||||
|
||||
export interface MainThreadDashboardShape extends IDisposable {
|
||||
@@ -540,3 +542,11 @@ export interface MainThreadObjectExplorerShape extends IDisposable {
|
||||
$isExpanded(connectionId: string, nodePath: string): Thenable<boolean>;
|
||||
$findNodes(connectionId: string, type: string, schema: string, name: string, database: string, parentObjectNames: string[]): Thenable<sqlops.NodeInfo[]>;
|
||||
}
|
||||
|
||||
export interface ExtHostQueryEditorShape {
|
||||
}
|
||||
|
||||
export interface MainThreadQueryEditorShape extends IDisposable {
|
||||
$connect(fileUri: string, connectionId: string): Thenable<void>;
|
||||
$runQuery(fileUri: string): void;
|
||||
}
|
||||
Reference in New Issue
Block a user