Add changes for flavor selection (#8419)

* Add changes for flavor selection

* Use getDefaultProviderId method

* Update default engine user setting description

* Add back check for codeEditor

* Add test for multiple providers

* Removing extra merge line

* Add an attribute to ConnectionProviderProperties for language flavor

Adding a boolean property to ConnectionProviderProperties for providers that are language flavors. When it is set to true, the provider will be part of drop down for changing SQL language flavor.

* Update variable name

* Put logic for removing CMS at one place and remove flag for flavor provider

* Using keys instead of entries

Using Object.keys instead of entries as doing [0] can be error prone if no provider matches.

* Adding logic to check from params

* Updating variable names

* Rename dedup map

* Fix action
This commit is contained in:
swjain23
2019-12-05 15:28:35 -08:00
committed by GitHub
parent 0d9353d99e
commit 0bf4790a64
10 changed files with 133 additions and 40 deletions

View File

@@ -13,7 +13,6 @@ import * as nls from 'vs/nls';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import * as WorkbenchUtils from 'sql/workbench/common/sqlWorkbenchUtils';
import { DidChangeLanguageFlavorParams } from 'azdata';
import Severity from 'vs/base/common/severity';
import { INotificationService } from 'vs/platform/notification/common/notification';
@@ -21,7 +20,7 @@ import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IStatusbarService, StatusbarAlignment, IStatusbarEntryAccessor } from 'vs/workbench/services/statusbar/common/statusbar';
import { IStatusbarService, StatusbarAlignment, IStatusbarEntryAccessor, IStatusbarEntry } from 'vs/workbench/services/statusbar/common/statusbar';
export interface ISqlProviderEntry extends IQuickPickItem {
providerId: string;
@@ -76,6 +75,7 @@ export class SqlFlavorStatusbarItem extends Disposable implements IWorkbenchCont
this.statusItem = this._register(
this.statusbarService.addEntry({
text: nls.localize('changeProvider', "Change SQL language provider"),
command: 'sql.action.editor.changeProvider'
},
SqlFlavorStatusbarItem.ID,
@@ -150,14 +150,23 @@ export class SqlFlavorStatusbarItem extends Disposable implements IWorkbenchCont
if (uri === currentUri) {
let flavor: SqlProviderEntry = this._sqlStatusEditors[uri];
if (flavor) {
this.statusItem.update({ text: flavor.label });
this.updateFlavorElement(flavor.label);
} else {
this.statusItem.update({ text: SqlProviderEntry.getDefaultLabel() });
this.updateFlavorElement(SqlProviderEntry.getDefaultLabel());
}
this.show();
}
}
}
private updateFlavorElement(text: string): void {
const props: IStatusbarEntry = {
text,
command: 'sql.action.editor.changeProvider'
};
this.statusItem.update(props);
}
}
export class ChangeFlavorAction extends Action {
@@ -184,21 +193,21 @@ export class ChangeFlavorAction extends Action {
return this._showMessage(Severity.Info, nls.localize('alreadyConnected',
"A connection using engine {0} exists. To change please disconnect or change connection", currentProvider));
}
const editorWidget = getCodeEditor(activeEditor);
const editorWidget = getCodeEditor(activeEditor.getControl());
if (!editorWidget) {
return this._showMessage(Severity.Info, nls.localize('noEditor', "No text editor active at this time"));
}
// TODO #1334 use connectionManagementService.GetProviderNames here. The challenge is that the credentials provider is returned
// so we need a way to filter this using a capabilities check, with isn't yet implemented
const ProviderOptions: ISqlProviderEntry[] = [
new SqlProviderEntry(mssqlProviderName)
];
// TODO: select the current language flavor
return this._quickInputService.pick(ProviderOptions, { placeHolder: nls.localize('pickSqlProvider', "Select SQL Language Provider") }).then(provider => {
let providerNameToDisplayNameMap = this._connectionManagementService.providerNameToDisplayNameMap;
let providerOptions = Object.keys(this._connectionManagementService.getUniqueConnectionProvidersByNameMap(providerNameToDisplayNameMap)).map(p => new SqlProviderEntry(p));
return this._quickInputService.pick(providerOptions, { placeHolder: nls.localize('pickSqlProvider', "Select SQL Language Provider") }).then(provider => {
if (provider) {
activeEditor = this._editorService.activeControl;
let activeEditor = this._editorService.activeControl.getControl();
const editorWidget = getCodeEditor(activeEditor);
if (editorWidget) {
if (currentUri) {
@@ -218,3 +227,4 @@ export class ChangeFlavorAction extends Action {
return Promise.resolve(undefined);
}
}

View File

@@ -7,7 +7,7 @@ import 'vs/css!sql/media/overwriteVsIcons';
import { Registry } from 'vs/platform/registry/common/platform';
import { EditorDescriptor, IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { IConfigurationRegistry, Extensions as ConfigExtensions, IConfigurationPropertySchema } from 'vs/platform/configuration/common/configurationRegistry';
import { SyncActionDescriptor, MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
import { KeyMod, KeyCode, KeyChord } from 'vs/base/common/keyCodes';
@@ -31,7 +31,7 @@ import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } fr
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { TimeElapsedStatusBarContributions, RowCountStatusBarContributions, QueryStatusStatusBarContributions } from 'sql/workbench/contrib/query/browser/statusBarItems';
import { SqlFlavorStatusbarItem } from 'sql/workbench/contrib/query/browser/flavorStatus';
import { SqlFlavorStatusbarItem, ChangeFlavorAction } from 'sql/workbench/contrib/query/browser/flavorStatus';
import { IEditorInputFactoryRegistry, Extensions as EditorInputFactoryExtensions } from 'vs/workbench/common/editor';
import { FileQueryEditorInput } from 'sql/workbench/contrib/query/common/fileQueryEditorInput';
import { FileQueryEditorInputFactory, UntitledQueryEditorInputFactory } from 'sql/workbench/contrib/query/common/queryInputFactory';
@@ -76,7 +76,7 @@ Registry.as<IEditorRegistry>(EditorExtensions.Editors)
Registry.as<IEditorRegistry>(EditorExtensions.Editors)
.registerEditor(new EditorDescriptor(QueryEditor, QueryEditor.ID, localize('queryEditor.name', "Query Editor")), [new SyncDescriptor(FileQueryEditorInput), new SyncDescriptor(UntitledQueryEditorInput)]);
const actionRegistry = <IWorkbenchActionRegistry>Registry.as(Extensions.WorkbenchActions);
const actionRegistry = <IWorkbenchActionRegistry>Registry.as(ActionExtensions.WorkbenchActions);
new NewQueryTask().registerTask();
@@ -205,6 +205,16 @@ actionRegistry.registerWorkbenchAction(
ToggleQueryResultsKeyboardAction.LABEL
);
// Register Flavor Action
actionRegistry.registerWorkbenchAction(
SyncActionDescriptor.create(
ChangeFlavorAction,
ChangeFlavorAction.ID,
ChangeFlavorAction.LABEL
),
'Change Language Flavor'
);
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: gridActions.GRID_COPY_ID,
weight: KeybindingWeight.EditorContrib,