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

@@ -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 {