mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-27 17:23:21 -05:00
Fix queryDocument.connect (#20682)
* Fix queryEditor.connect * Remove decorator * undo * fix test * Use connectionProfile for comparison * remove unused * Remove helper method
This commit is contained in:
@@ -18,6 +18,7 @@ import { ConnectionProfile } from 'sql/platform/connection/common/connectionProf
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
|
||||
@extHostNamedCustomer(SqlMainContext.MainThreadQueryEditor)
|
||||
export class MainThreadQueryEditor extends Disposable implements MainThreadQueryEditorShape {
|
||||
@@ -32,7 +33,8 @@ export class MainThreadQueryEditor extends Disposable implements MainThreadQuery
|
||||
@IEditorService private _editorService: IEditorService,
|
||||
@IQueryManagementService private _queryManagementService: IQueryManagementService,
|
||||
@ILogService private _logService: ILogService,
|
||||
@IQueryEditorService private _queryEditorService: IQueryEditorService
|
||||
@IQueryEditorService private _queryEditorService: IQueryEditorService,
|
||||
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService
|
||||
) {
|
||||
super();
|
||||
if (extHostContext) {
|
||||
@@ -70,34 +72,25 @@ export class MainThreadQueryEditor extends Disposable implements MainThreadQuery
|
||||
});
|
||||
}
|
||||
|
||||
private static connectionProfileToIConnectionProfile(connection: azdata.connection.ConnectionProfile): IConnectionProfile {
|
||||
let profile: ConnectionProfile = new ConnectionProfile(undefined, undefined);
|
||||
profile.options = connection.options;
|
||||
profile.providerName = connection.options['providerName'];
|
||||
return profile.toIConnectionProfile();
|
||||
}
|
||||
|
||||
public $connectWithProfile(fileUri: string, connection: azdata.connection.ConnectionProfile): Thenable<void> {
|
||||
return new Promise<void>(async (resolve, reject) => {
|
||||
let editors = this._editorService.visibleEditorPanes.filter(resource => {
|
||||
return !!resource && resource.input.resource.toString() === fileUri;
|
||||
});
|
||||
let editor = editors && editors.length > 0 ? editors[0] : undefined;
|
||||
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: editor ? editor.input as any : undefined },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: false,
|
||||
showFirewallRuleOnError: false,
|
||||
};
|
||||
|
||||
let profile: IConnectionProfile = MainThreadQueryEditor.connectionProfileToIConnectionProfile(connection);
|
||||
let connectionResult = await this._connectionManagementService.connect(profile, fileUri, options);
|
||||
if (connectionResult && connectionResult.connected) {
|
||||
this._logService.info(`editor ${fileUri} connected`);
|
||||
}
|
||||
public async $connectWithProfile(fileUri: string, connection: azdata.connection.ConnectionProfile): Promise<void> {
|
||||
let editors = this._editorService.visibleEditorPanes.filter(resource => {
|
||||
return !!resource && resource.input.resource.toString() === fileUri;
|
||||
});
|
||||
let editor = editors && editors.length > 0 ? editors[0] : undefined;
|
||||
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: editor ? editor.input as any : undefined },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: false,
|
||||
showFirewallRuleOnError: false,
|
||||
};
|
||||
|
||||
let profile: IConnectionProfile = new ConnectionProfile(this._capabilitiesService, connection).toIConnectionProfile();
|
||||
let connectionResult = await this._connectionManagementService.connect(profile, fileUri, options);
|
||||
if (connectionResult && connectionResult.connected) {
|
||||
this._logService.info(`editor ${fileUri} connected`);
|
||||
}
|
||||
}
|
||||
|
||||
public $runQuery(fileUri: string, runCurrentQuery: boolean = true): void {
|
||||
|
||||
@@ -10,7 +10,8 @@ import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/br
|
||||
import { TestConnectionManagementService } from 'sql/platform/connection/test/common/testConnectionManagementService';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { TestEditorService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { TestEditorInput, TestEditorService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
suite('TaskUtilities', function () {
|
||||
test('getCurrentGlobalConnection returns the selected OE server if a server or one of its children is selected', () => {
|
||||
@@ -71,16 +72,17 @@ suite('TaskUtilities', function () {
|
||||
mockConnectionManagementService.setup(x => x.isProfileConnected(TypeMoq.It.is(profile => profile === oeProfile || profile === tabProfile))).returns(() => true);
|
||||
|
||||
// Mock the workbench service to return the active tab connection
|
||||
let tabConnectionUri = 'file://test_uri';
|
||||
mockConnectionManagementService.setup(x => x.getConnectionProfile(tabConnectionUri)).returns(() => tabProfile);
|
||||
const tabConnectionUri = URI.file('file://test_uri');
|
||||
mockWorkbenchEditorService.setup(x => x.activeEditor).returns(() => new TestEditorInput(tabConnectionUri, 'my_type'));
|
||||
mockConnectionManagementService.setup(x => x.getConnectionProfile(tabConnectionUri.toString(true))).returns(() => tabProfile);
|
||||
|
||||
// If I call getCurrentGlobalConnection, it should return the expected profile from the active tab
|
||||
let actualProfile = TaskUtilities.getCurrentGlobalConnection(mockObjectExplorerService.object, mockConnectionManagementService.object, mockWorkbenchEditorService.object);
|
||||
assert.strictEqual(actualProfile.databaseName, tabProfile.databaseName);
|
||||
assert.strictEqual(actualProfile.authenticationType, tabProfile.authenticationType);
|
||||
assert.strictEqual(actualProfile.password, tabProfile.password);
|
||||
assert.strictEqual(actualProfile.serverName, tabProfile.serverName);
|
||||
assert.strictEqual(actualProfile.userName, tabProfile.userName);
|
||||
assert.strictEqual(actualProfile.databaseName, connectionProfile2.databaseName);
|
||||
assert.strictEqual(actualProfile.authenticationType, connectionProfile2.authenticationType);
|
||||
assert.strictEqual(actualProfile.password, connectionProfile2.password);
|
||||
assert.strictEqual(actualProfile.serverName, connectionProfile2.serverName);
|
||||
assert.strictEqual(actualProfile.userName, connectionProfile2.userName);
|
||||
});
|
||||
|
||||
test('getCurrentGlobalConnection returns the connection from OE if there is no active tab, even if OE is not focused', () => {
|
||||
|
||||
Reference in New Issue
Block a user