diff --git a/extensions/azuremonitor/package.json b/extensions/azuremonitor/package.json index 83a59490dc..8f13663219 100644 --- a/extensions/azuremonitor/package.json +++ b/extensions/azuremonitor/package.json @@ -109,20 +109,6 @@ "categoryValues": null, "isRequired": true, "isArray": false - }, - { - "specialValueType": "databaseName", - "isIdentity": true, - "name": "database", - "displayName": "%azuremonitor.connectionOptions.databaseName.displayName%", - "description": "%azuremonitor.connectionOptions.databaseName.description%", - "groupName": "%azuremonitor.connectionProperties.groupName.source%", - "valueType": "string", - "defaultValue": null, - "objectType": null, - "categoryValues": null, - "isRequired": false, - "isArray": false } ] }, diff --git a/src/sql/platform/connection/common/providerConnectionInfo.ts b/src/sql/platform/connection/common/providerConnectionInfo.ts index c1fd07e52e..3d15c988b8 100644 --- a/src/sql/platform/connection/common/providerConnectionInfo.ts +++ b/src/sql/platform/connection/common/providerConnectionInfo.ts @@ -160,9 +160,13 @@ export class ProviderConnectionInfo extends Disposable implements azdata.Connect } private getServerInfo() { - let databaseName = this.databaseName ? this.databaseName : ''; - let userName = this.userName ? this.userName : 'Windows Authentication'; - return this.serverName + ', ' + databaseName + ' (' + userName + ')'; + let title = this.serverName; + // Only show database name if the provider supports it. + if (this.serverCapabilities?.connectionOptions?.find(option => option.specialValueType === ConnectionOptionSpecialType.databaseName)) { + title += `, ${this.databaseName || ''}`; + } + title += ` (${this.userName || this.authenticationType})`; + return title; } /** diff --git a/src/sql/workbench/common/editor/query/queryEditorInput.ts b/src/sql/workbench/common/editor/query/queryEditorInput.ts index edf75078de..496ef9d0fd 100644 --- a/src/sql/workbench/common/editor/query/queryEditorInput.ts +++ b/src/sql/workbench/common/editor/query/queryEditorInput.ts @@ -229,11 +229,11 @@ export abstract class QueryEditorInput extends EditorInput implements IConnectab title = this._description + ' '; } if (profile) { - if (profile.userName) { - title += `${profile.serverName}.${profile.databaseName} (${profile.userName})`; - } else { - title += `${profile.serverName}.${profile.databaseName} (${profile.authenticationType})`; + title += `${profile.serverName}`; + if (profile.databaseName) { + title += `.${profile.databaseName}`; } + title += ` (${profile.userName || profile.authenticationType})`; } else { title += localize('disconnected', "disconnected"); } diff --git a/src/sql/workbench/contrib/query/browser/queryActions.ts b/src/sql/workbench/contrib/query/browser/queryActions.ts index f429f06707..4e7304fa72 100644 --- a/src/sql/workbench/contrib/query/browser/queryActions.ts +++ b/src/sql/workbench/contrib/query/browser/queryActions.ts @@ -791,6 +791,11 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt } private updateConnection(databaseName: string): void { + // Ignore if the database name is not provided, this happens when the query editor connection is changed to + // a provider that does not support database. + if (!databaseName) { + return; + } this._isConnected = true; this._currentDatabaseName = databaseName; // Set the value immediately to the initial database so the user can see that, and then diff --git a/src/sql/workbench/contrib/query/browser/queryEditor.ts b/src/sql/workbench/contrib/query/browser/queryEditor.ts index 89322c8b10..2e24b67776 100644 --- a/src/sql/workbench/contrib/query/browser/queryEditor.ts +++ b/src/sql/workbench/contrib/query/browser/queryEditor.ts @@ -42,6 +42,8 @@ import { IRange } from 'vs/editor/common/core/range'; import { UntitledQueryEditorInput } from 'sql/base/query/browser/untitledQueryEditorInput'; import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar'; import { IEditorOptions } from 'vs/platform/editor/common/editor'; +import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService'; +import { ConnectionOptionSpecialType } from 'sql/platform/connection/common/interfaces'; const QUERY_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'queryEditorViewState'; @@ -107,6 +109,7 @@ export class QueryEditor extends EditorPane { @IInstantiationService private readonly instantiationService: IInstantiationService, @IConfigurationService private readonly configurationService: IConfigurationService, @IModeService private readonly modeService: IModeService, + @ICapabilitiesService private readonly capabilitiesService: ICapabilitiesService ) { super(QueryEditor.ID, telemetryService, themeService, storageService); @@ -266,73 +269,43 @@ export class QueryEditor extends EditorPane { } private setTaskbarContent(): void { - // Create HTML Elements for the taskbar - const separator = Taskbar.createTaskbarSeparator(); - let content: ITaskbarContent[]; const previewFeaturesEnabled = this.configurationService.getValue('workbench')['enablePreviewFeatures']; - let connectionProfile = this.connectionManagementService.getConnectionProfile(this.input?.uri); - let fileExtension = path.extname(this.input?.uri || ''); + const connectionProfile = this.connectionManagementService.getConnectionProfile(this.input?.uri); + const fileExtension = path.extname(this.input?.uri || ''); const providerId = connectionProfile?.providerName || this.connectionManagementService.getProviderIdFromUri(this.input?.uri) || this.connectionManagementService.getDefaultProviderId(); - // TODO: Make it more generic, some way for extensions to register the commands it supports - if ((providerId === 'KUSTO') || this.modeService.getExtensions('Kusto').indexOf(fileExtension) > -1) { - if (this.input instanceof UntitledQueryEditorInput) { // Sets proper language mode for untitled query editor based on the connection selected by user. + const content: ITaskbarContent[] = [ + { action: this._runQueryAction }, + { action: this._cancelQueryAction }, + { element: Taskbar.createTaskbarSeparator() }, + { action: this._toggleConnectDatabaseAction }, + { action: this._changeConnectionAction } + ]; + + // TODO: Allow query provider to provide the language mode. + if (this.input instanceof UntitledQueryEditorInput) { + if ((providerId === 'KUSTO') || this.modeService.getExtensions('Kusto').indexOf(fileExtension) > -1) { this.input.setMode('kusto'); } - - content = [ - { action: this._runQueryAction }, - { action: this._cancelQueryAction }, - { element: separator }, - { action: this._toggleConnectDatabaseAction }, - { action: this._changeConnectionAction }, - { action: this._listDatabasesAction } - ]; - } - else if (providerId === 'LOGANALYTICS' || this.modeService.getExtensions('LogAnalytics').indexOf(fileExtension) > -1) { - if (this.input instanceof UntitledQueryEditorInput) { + else if (providerId === 'LOGANALYTICS' || this.modeService.getExtensions('LogAnalytics').indexOf(fileExtension) > -1) { this.input.setMode('loganalytics'); } - - content = [ - { action: this._runQueryAction }, - { action: this._cancelQueryAction }, - { element: separator }, - { action: this._toggleConnectDatabaseAction }, - { action: this._changeConnectionAction }, - { action: this._listDatabasesAction } - ]; } - else { - if (previewFeaturesEnabled) { - content = [ - { action: this._runQueryAction }, - { action: this._cancelQueryAction }, - { element: separator }, - { action: this._toggleConnectDatabaseAction }, - { action: this._changeConnectionAction }, - { action: this._listDatabasesAction }, - ]; - if (providerId === 'MSSQL') { - content.push({ element: separator }, - { action: this._estimatedQueryPlanAction }, - { action: this._toggleSqlcmdMode } - ); + // Only show the databases dropdown if the connection provider supports it. + if (this.capabilitiesService.getCapabilities(providerId).connection?.connectionOptions?.find(option => option.specialValueType === ConnectionOptionSpecialType.databaseName)) { + content.push({ action: this._listDatabasesAction }); + } - content.push({ action: this._exportAsNotebookAction }); - } - } else { - content = [ - { action: this._runQueryAction }, - { action: this._cancelQueryAction }, - { element: separator }, - { action: this._toggleConnectDatabaseAction }, - { action: this._changeConnectionAction }, - { action: this._listDatabasesAction } - ]; - } + // TODO: Allow extensions to contribute toolbar actions. + if (previewFeaturesEnabled && providerId === 'MSSQL') { + content.push( + { element: Taskbar.createTaskbarSeparator() }, + { action: this._estimatedQueryPlanAction }, + { action: this._toggleSqlcmdMode }, + { action: this._exportAsNotebookAction } + ); } this.taskbar.setContent(content);