API improvement: make registerConnectionEventProvider return disposable (#11880)

* promote api to official

* add comments

* disposable

* move getConnection out

* comment for connection namespace

* remove extra line

* also fix registerQueryInfoHandler
This commit is contained in:
Alan Ren
2020-10-12 14:29:48 -07:00
committed by GitHub
parent 108891ba2e
commit bc3527d310
8 changed files with 81 additions and 28 deletions

View File

@@ -12,7 +12,7 @@ import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/br
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import * as TaskUtilities from 'sql/workbench/browser/taskUtilities';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { Disposable } from 'vs/base/common/lifecycle';
import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
import { isUndefinedOrNull } from 'vs/base/common/types';
import { generateUuid } from 'vs/base/common/uuid';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
@@ -24,6 +24,7 @@ import { deepClone } from 'vs/base/common/objects';
export class MainThreadConnectionManagement extends Disposable implements MainThreadConnectionManagementShape {
private _proxy: ExtHostConnectionManagementShape;
private _connectionEventListenerDisposables = new Map<number, IDisposable>();
constructor(
extHostContext: IExtHostContext,
@@ -39,7 +40,7 @@ export class MainThreadConnectionManagement extends Disposable implements MainTh
}
}
public $registerConnectionEventListener(handle: number, providerId: string): void {
public $registerConnectionEventListener(handle: number): void {
let stripProfile = (inputProfile: azdata.IConnectionProfile) => {
if (!inputProfile) {
@@ -66,17 +67,28 @@ export class MainThreadConnectionManagement extends Disposable implements MainTh
return outputProfile;
};
this._connectionManagementService.onConnect((params: IConnectionParams) => {
const disposable = new DisposableStore();
disposable.add(this._connectionManagementService.onConnect((params: IConnectionParams) => {
this._proxy.$onConnectionEvent(handle, 'onConnect', params.connectionUri, stripProfile(params.connectionProfile));
});
}));
this._connectionManagementService.onConnectionChanged((params: IConnectionParams) => {
disposable.add(this._connectionManagementService.onConnectionChanged((params: IConnectionParams) => {
this._proxy.$onConnectionEvent(handle, 'onConnectionChanged', params.connectionUri, stripProfile(params.connectionProfile));
});
}));
this._connectionManagementService.onDisconnect((params: IConnectionParams) => {
disposable.add(this._connectionManagementService.onDisconnect((params: IConnectionParams) => {
this._proxy.$onConnectionEvent(handle, 'onDisconnect', params.connectionUri, stripProfile(params.connectionProfile));
});
}));
this._connectionEventListenerDisposables.set(handle, disposable);
}
public $unregisterConnectionEventListener(handle: number): void {
const disposable = this._connectionEventListenerDisposables.get(handle);
if (disposable) {
disposable.dispose();
this._connectionEventListenerDisposables.delete(handle);
}
}
public $getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]> {

View File

@@ -9,7 +9,7 @@ import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { IConnectionManagementService, IConnectionCompletionOptions, ConnectionType, RunQueryOnConnectionMode } from 'sql/platform/connection/common/connectionManagement';
import { QueryEditor } from 'sql/workbench/contrib/query/browser/queryEditor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { Disposable } from 'vs/base/common/lifecycle';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { IQueryModelService } from 'sql/workbench/services/query/common/queryModel';
import * as azdata from 'azdata';
import { IQueryManagementService } from 'sql/workbench/services/query/common/queryManagement';
@@ -21,6 +21,7 @@ import { ILogService } from 'vs/platform/log/common/log';
export class MainThreadQueryEditor extends Disposable implements MainThreadQueryEditorShape {
private _proxy: ExtHostQueryEditorShape;
private _queryEventListenerDisposables = new Map<number, IDisposable>();
constructor(
extHostContext: IExtHostContext,
@@ -112,10 +113,19 @@ export class MainThreadQueryEditor extends Disposable implements MainThreadQuery
}
public $registerQueryInfoListener(handle: number): void {
this._register(this._queryModelService.onQueryEvent(event => {
const disposable = this._queryModelService.onQueryEvent(event => {
let connectionProfile = this._connectionManagementService.getConnectionProfile(event.uri);
this._proxy.$onQueryEvent(connectionProfile?.providerName, handle, event.uri, event);
}));
});
this._queryEventListenerDisposables.set(handle, disposable);
}
public $unregisterQueryInfoListener(handle: number): void {
const disposable = this._queryEventListenerDisposables.get(handle);
if (disposable) {
disposable.dispose();
this._queryEventListenerDisposables.delete(handle);
}
}
public $createQueryTab(fileUri: string, title: string, componentId: string): void {