Add query execution plan extensibility APIs (#4072)

* WIP 1

* WIP 2

* Fix typos

* Iterate on API a bit

* Query Tab WIP

* More dynamic query tab impl

* Fix merge breaks

* Update interfaces

* Update to single event handler for query events

* Remove query plan extension

* Add generated JS file
This commit is contained in:
Karl Burtram
2019-03-28 10:59:02 -07:00
committed by GitHub
parent ee413f3b24
commit cc2951265e
18 changed files with 688 additions and 12 deletions

View File

@@ -7,11 +7,35 @@
import { IMainContext } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostQueryEditorShape, SqlMainContext, MainThreadQueryEditorShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import { IQueryEvent } from 'sql/platform/query/common/queryModel';
class ExtHostQueryDocument implements azdata.queryeditor.QueryDocument {
constructor(
public providerId: string,
public uri: string,
private _proxy: MainThreadQueryEditorShape) {
}
// get the document's execution options
getOptions(): Map<string, string> {
return undefined;
}
// set the document's execution optionsß
setOptions(options: Map<string, string>): void {
}
createQueryTab(tab: azdata.window.DialogTab): void {
this._proxy.$createQueryTab(this.uri, tab.title, tab.content);
}
}
export class ExtHostQueryEditor implements ExtHostQueryEditorShape {
private _proxy: MainThreadQueryEditorShape;
private _nextListenerHandle: number = 0;
private _queryListeners = new Map<number, azdata.queryeditor.QueryEventListener>();
constructor(
mainContext: IMainContext
@@ -26,4 +50,17 @@ export class ExtHostQueryEditor implements ExtHostQueryEditorShape {
public $runQuery(fileUri: string): void {
return this._proxy.$runQuery(fileUri);
}
public $registerQueryInfoListener(providerId: string, listener: azdata.queryeditor.QueryEventListener): void {
this._queryListeners[this._nextListenerHandle] = listener;
this._proxy.$registerQueryInfoListener(this._nextListenerHandle, providerId);
this._nextListenerHandle++;
}
public $onQueryEvent(handle: number, fileUri:string, event: IQueryEvent): void {
let listener: azdata.queryeditor.QueryEventListener = this._queryListeners[handle];
if (listener) {
listener.onQueryEvent(event.type, new ExtHostQueryDocument('MSSQL', fileUri, this._proxy), event.params.planXml);
}
}
}

View File

@@ -12,6 +12,7 @@ import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/q
import { QueryEditor } from 'sql/parts/query/editor/queryEditor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { IQueryModelService, IQueryEvent } from 'sql/platform/query/common/queryModel';
@extHostNamedCustomer(SqlMainContext.MainThreadQueryEditor)
export class MainThreadQueryEditor implements MainThreadQueryEditorShape {
@@ -23,6 +24,7 @@ export class MainThreadQueryEditor implements MainThreadQueryEditorShape {
extHostContext: IExtHostContext,
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IQueryEditorService private _queryEditorService: IQueryEditorService,
@IQueryModelService private _queryModelService: IQueryModelService,
@IEditorService private _editorService: IEditorService
) {
if (extHostContext) {
@@ -75,4 +77,24 @@ export class MainThreadQueryEditor implements MainThreadQueryEditorShape {
}
}
}
public $registerQueryInfoListener(handle: number, providerId: string): void {
this._toDispose.push(this._queryModelService.onQueryEvent(event => {
this._proxy.$onQueryEvent(handle, event.uri, event);
}));
}
public $createQueryTab(fileUri: string, title: string, componentId: string): void {
let editors = this._editorService.visibleControls.filter(resource => {
return !!resource && resource.input.getResource().toString() === fileUri;
});
let editor = editors && editors.length > 0 ? editors[0] : undefined;
if (editor) {
let queryEditor = editor as QueryEditor;
if (queryEditor) {
queryEditor.registerQueryModelViewTab(title, componentId);
}
}
}
}

View File

@@ -438,13 +438,20 @@ export function createApiFactory(
// namespace: queryeditor
const queryEditor: typeof azdata.queryeditor = {
connect(fileUri: string, connectionId: string): Thenable<void> {
return extHostQueryEditor.$connect(fileUri, connectionId);
},
runQuery(fileUri: string): void {
runQuery(fileUri: string, options?: Map<string, string>): void {
extHostQueryEditor.$runQuery(fileUri);
},
registerQueryEventListener(listener: azdata.queryeditor.QueryEventListener): void {
extHostQueryEditor.$registerQueryInfoListener('MSSQL', listener);
},
getQueryDocument(fileUri: string): azdata.queryeditor.QueryDocument {
return undefined;
}
};

View File

@@ -24,6 +24,7 @@ import {
import { EditorViewColumn } from 'vs/workbench/api/common/shared/editor';
import { IUndoStopOptions } from 'vs/workbench/api/common/extHost.protocol';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { IQueryEvent } from 'sql/platform/query/common/queryModel';
export abstract class ExtHostAccountManagementShape {
$autoOAuthCancelled(handle: number): Thenable<void> { throw ni(); }
@@ -757,11 +758,14 @@ export interface MainThreadModelViewDialogShape extends IDisposable {
$setDirty(handle: number, isDirty: boolean): void;
}
export interface ExtHostQueryEditorShape {
$onQueryEvent(handle: number, fileUri:string, event: IQueryEvent): void;
}
export interface MainThreadQueryEditorShape extends IDisposable {
$connect(fileUri: string, connectionId: string): Thenable<void>;
$runQuery(fileUri: string): void;
$createQueryTab(fileUri: string, title: string, content: string): void;
$registerQueryInfoListener(handle: number, providerId: string): void;
}
export interface ExtHostNotebookShape {
@@ -870,4 +874,4 @@ export interface ExtHostExtensionManagementShape {
export interface MainThreadExtensionManagementShape extends IDisposable {
$install(vsixPath: string): Thenable<string>;
}
}