mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
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:
@@ -14,6 +14,7 @@ import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
|||||||
|
|
||||||
export class TestCapabilitiesService implements ICapabilitiesService {
|
export class TestCapabilitiesService implements ICapabilitiesService {
|
||||||
|
|
||||||
|
private pgsqlProviderName = 'PGSQL';
|
||||||
public _serviceBrand: undefined;
|
public _serviceBrand: undefined;
|
||||||
|
|
||||||
public capabilities: { [id: string]: ProviderFeatures } = {};
|
public capabilities: { [id: string]: ProviderFeatures } = {};
|
||||||
@@ -99,7 +100,13 @@ export class TestCapabilitiesService implements ICapabilitiesService {
|
|||||||
displayName: 'MSSQL',
|
displayName: 'MSSQL',
|
||||||
connectionOptions: connectionProvider,
|
connectionOptions: connectionProvider,
|
||||||
};
|
};
|
||||||
|
let pgSQLCapabilities = {
|
||||||
|
providerId: this.pgsqlProviderName,
|
||||||
|
displayName: this.pgsqlProviderName,
|
||||||
|
connectionOptions: connectionProvider,
|
||||||
|
};
|
||||||
this.capabilities[mssqlProviderName] = { connection: msSQLCapabilities };
|
this.capabilities[mssqlProviderName] = { connection: msSQLCapabilities };
|
||||||
|
this.capabilities[this.pgsqlProviderName] = { connection: pgSQLCapabilities };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ export interface IConnectionManagementService {
|
|||||||
onConnectionChanged: Event<IConnectionParams>;
|
onConnectionChanged: Event<IConnectionParams>;
|
||||||
onLanguageFlavorChanged: Event<azdata.DidChangeLanguageFlavorParams>;
|
onLanguageFlavorChanged: Event<azdata.DidChangeLanguageFlavorParams>;
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
providerNameToDisplayNameMap: { [providerDisplayName: string]: string };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the connection dialog to create new connection
|
* Opens the connection dialog to create new connection
|
||||||
*/
|
*/
|
||||||
@@ -180,6 +183,8 @@ export interface IConnectionManagementService {
|
|||||||
|
|
||||||
getDefaultProviderId(): string;
|
getDefaultProviderId(): string;
|
||||||
|
|
||||||
|
getUniqueConnectionProvidersByNameMap(providerNameToDisplayNameMap: { [providerDisplayName: string]: string }): { [providerDisplayName: string]: string };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels the connection
|
* Cancels the connection
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ export class TestConnectionManagementService implements IConnectionManagementSer
|
|||||||
return conEvent.event;
|
return conEvent.event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get providerNameToDisplayNameMap(): { [providerDisplayName: string]: string } {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
registerProvider(providerId: string, provider: azdata.ConnectionProvider): void {
|
registerProvider(providerId: string, provider: azdata.ConnectionProvider): void {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -213,9 +217,14 @@ export class TestConnectionManagementService implements IConnectionManagementSer
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getUniqueConnectionProvidersByNameMap(providerNameToDisplayNameMap: { [providerDisplayName: string]: string }): { [providerDisplayName: string]: string } {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
getProviderIdFromUri(ownerUri: string): string {
|
getProviderIdFromUri(ownerUri: string): string {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
hasRegisteredServers(): boolean {
|
hasRegisteredServers(): boolean {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -235,10 +244,6 @@ export class TestConnectionManagementService implements IConnectionManagementSer
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getProviderNames(): string[] {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
connectIfNotConnected(connection: IConnectionProfile, purpose?: 'dashboard' | 'insights' | 'connection', saveConnection: boolean = false): Promise<string> {
|
connectIfNotConnected(connection: IConnectionProfile, purpose?: 'dashboard' | 'insights' | 'connection', saveConnection: boolean = false): Promise<string> {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ configurationRegistry.registerConfiguration({
|
|||||||
},
|
},
|
||||||
'sql.defaultEngine': {
|
'sql.defaultEngine': {
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
'description': localize('sql.defaultEngineDescription', "Default SQL Engine to use. This drives default language provider in .sql files and the default to use when creating a new connection. Valid option is currently MSSQL"),
|
'description': localize('sql.defaultEngineDescription', "Default SQL Engine to use. This drives default language provider in .sql files and the default to use when creating a new connection."),
|
||||||
'default': 'MSSQL'
|
'default': 'MSSQL'
|
||||||
},
|
},
|
||||||
'connection.parseClipboardForConnectionString': {
|
'connection.parseClipboardForConnectionString': {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import * as nls from 'vs/nls';
|
|||||||
|
|
||||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||||
import * as WorkbenchUtils from 'sql/workbench/common/sqlWorkbenchUtils';
|
import * as WorkbenchUtils from 'sql/workbench/common/sqlWorkbenchUtils';
|
||||||
|
|
||||||
import { DidChangeLanguageFlavorParams } from 'azdata';
|
import { DidChangeLanguageFlavorParams } from 'azdata';
|
||||||
import Severity from 'vs/base/common/severity';
|
import Severity from 'vs/base/common/severity';
|
||||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
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 { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
|
||||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||||
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
|
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 {
|
export interface ISqlProviderEntry extends IQuickPickItem {
|
||||||
providerId: string;
|
providerId: string;
|
||||||
@@ -76,6 +75,7 @@ export class SqlFlavorStatusbarItem extends Disposable implements IWorkbenchCont
|
|||||||
this.statusItem = this._register(
|
this.statusItem = this._register(
|
||||||
this.statusbarService.addEntry({
|
this.statusbarService.addEntry({
|
||||||
text: nls.localize('changeProvider', "Change SQL language provider"),
|
text: nls.localize('changeProvider', "Change SQL language provider"),
|
||||||
|
command: 'sql.action.editor.changeProvider'
|
||||||
|
|
||||||
},
|
},
|
||||||
SqlFlavorStatusbarItem.ID,
|
SqlFlavorStatusbarItem.ID,
|
||||||
@@ -150,14 +150,23 @@ export class SqlFlavorStatusbarItem extends Disposable implements IWorkbenchCont
|
|||||||
if (uri === currentUri) {
|
if (uri === currentUri) {
|
||||||
let flavor: SqlProviderEntry = this._sqlStatusEditors[uri];
|
let flavor: SqlProviderEntry = this._sqlStatusEditors[uri];
|
||||||
if (flavor) {
|
if (flavor) {
|
||||||
this.statusItem.update({ text: flavor.label });
|
this.updateFlavorElement(flavor.label);
|
||||||
} else {
|
} else {
|
||||||
this.statusItem.update({ text: SqlProviderEntry.getDefaultLabel() });
|
this.updateFlavorElement(SqlProviderEntry.getDefaultLabel());
|
||||||
}
|
}
|
||||||
this.show();
|
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 {
|
export class ChangeFlavorAction extends Action {
|
||||||
@@ -184,21 +193,21 @@ export class ChangeFlavorAction extends Action {
|
|||||||
return this._showMessage(Severity.Info, nls.localize('alreadyConnected',
|
return this._showMessage(Severity.Info, nls.localize('alreadyConnected',
|
||||||
"A connection using engine {0} exists. To change please disconnect or change connection", currentProvider));
|
"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) {
|
if (!editorWidget) {
|
||||||
return this._showMessage(Severity.Info, nls.localize('noEditor', "No text editor active at this time"));
|
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
|
// 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
|
// 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
|
let providerNameToDisplayNameMap = this._connectionManagementService.providerNameToDisplayNameMap;
|
||||||
return this._quickInputService.pick(ProviderOptions, { placeHolder: nls.localize('pickSqlProvider', "Select SQL Language Provider") }).then(provider => {
|
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) {
|
if (provider) {
|
||||||
activeEditor = this._editorService.activeControl;
|
let activeEditor = this._editorService.activeControl.getControl();
|
||||||
const editorWidget = getCodeEditor(activeEditor);
|
const editorWidget = getCodeEditor(activeEditor);
|
||||||
if (editorWidget) {
|
if (editorWidget) {
|
||||||
if (currentUri) {
|
if (currentUri) {
|
||||||
@@ -218,3 +227,4 @@ export class ChangeFlavorAction extends Action {
|
|||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import 'vs/css!sql/media/overwriteVsIcons';
|
|||||||
import { Registry } from 'vs/platform/registry/common/platform';
|
import { Registry } from 'vs/platform/registry/common/platform';
|
||||||
import { EditorDescriptor, IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
|
import { EditorDescriptor, IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
|
||||||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
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 { IConfigurationRegistry, Extensions as ConfigExtensions, IConfigurationPropertySchema } from 'vs/platform/configuration/common/configurationRegistry';
|
||||||
import { SyncActionDescriptor, MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
|
import { SyncActionDescriptor, MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
|
||||||
import { KeyMod, KeyCode, KeyChord } from 'vs/base/common/keyCodes';
|
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 { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
|
||||||
import { TimeElapsedStatusBarContributions, RowCountStatusBarContributions, QueryStatusStatusBarContributions } from 'sql/workbench/contrib/query/browser/statusBarItems';
|
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 { IEditorInputFactoryRegistry, Extensions as EditorInputFactoryExtensions } from 'vs/workbench/common/editor';
|
||||||
import { FileQueryEditorInput } from 'sql/workbench/contrib/query/common/fileQueryEditorInput';
|
import { FileQueryEditorInput } from 'sql/workbench/contrib/query/common/fileQueryEditorInput';
|
||||||
import { FileQueryEditorInputFactory, UntitledQueryEditorInputFactory } from 'sql/workbench/contrib/query/common/queryInputFactory';
|
import { FileQueryEditorInputFactory, UntitledQueryEditorInputFactory } from 'sql/workbench/contrib/query/common/queryInputFactory';
|
||||||
@@ -76,7 +76,7 @@ Registry.as<IEditorRegistry>(EditorExtensions.Editors)
|
|||||||
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)]);
|
.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();
|
new NewQueryTask().registerTask();
|
||||||
|
|
||||||
@@ -205,6 +205,16 @@ actionRegistry.registerWorkbenchAction(
|
|||||||
ToggleQueryResultsKeyboardAction.LABEL
|
ToggleQueryResultsKeyboardAction.LABEL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Register Flavor Action
|
||||||
|
actionRegistry.registerWorkbenchAction(
|
||||||
|
SyncActionDescriptor.create(
|
||||||
|
ChangeFlavorAction,
|
||||||
|
ChangeFlavorAction.ID,
|
||||||
|
ChangeFlavorAction.LABEL
|
||||||
|
),
|
||||||
|
'Change Language Flavor'
|
||||||
|
);
|
||||||
|
|
||||||
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||||
id: gridActions.GRID_COPY_ID,
|
id: gridActions.GRID_COPY_ID,
|
||||||
weight: KeybindingWeight.EditorContrib,
|
weight: KeybindingWeight.EditorContrib,
|
||||||
|
|||||||
@@ -308,10 +308,8 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!isProviderInParams) {
|
if (!isProviderInParams) {
|
||||||
this._currentProviderType = find(Object.keys(this._providerNameToDisplayNameMap), (key) =>
|
let uniqueProvidersMap = this._connectionManagementService.getUniqueConnectionProvidersByNameMap(this._providerNameToDisplayNameMap);
|
||||||
this._providerNameToDisplayNameMap[key] === input.selectedProviderDisplayName &&
|
this._currentProviderType = find(Object.keys(uniqueProvidersMap), (key) => uniqueProvidersMap[key] === input.selectedProviderDisplayName);
|
||||||
key !== Constants.cmsProviderName
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._model.providerName = this._currentProviderType;
|
this._model.providerName = this._currentProviderType;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import { ILogService } from 'vs/platform/log/common/log';
|
|||||||
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
|
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
|
||||||
import { ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
|
import { ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
|
||||||
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
|
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
|
||||||
|
import { entries } from 'sql/base/common/collections';
|
||||||
|
|
||||||
export interface OnShowUIResponse {
|
export interface OnShowUIResponse {
|
||||||
selectedProviderDisplayName: string;
|
selectedProviderDisplayName: string;
|
||||||
@@ -116,21 +117,21 @@ export class ConnectionDialogWidget extends Modal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public refresh(): void {
|
public refresh(): void {
|
||||||
let filteredProviderDisplayNames = this.providerDisplayNameOptions;
|
let filteredProviderMap = this.providerNameToDisplayNameMap;
|
||||||
|
|
||||||
if (this._newConnectionParams && this._newConnectionParams.providers) {
|
if (this._newConnectionParams && this._newConnectionParams.providers) {
|
||||||
const validProviderNames = Object.keys(this.providerNameToDisplayNameMap).filter(x => this.includeProvider(x, this._newConnectionParams));
|
const validProviderMap = entries(this.providerNameToDisplayNameMap).filter(x => this.includeProvider(x[0], this._newConnectionParams));
|
||||||
if (validProviderNames && validProviderNames.length > 0) {
|
if (validProviderMap && validProviderMap.length > 0) {
|
||||||
filteredProviderDisplayNames = filteredProviderDisplayNames.filter(x => validProviderNames.some(
|
let map: { [providerDisplayName: string]: string } = {};
|
||||||
v => this.providerNameToDisplayNameMap[v] === x) !== undefined
|
validProviderMap.forEach(v => {
|
||||||
);
|
map[v[0]] = v[1];
|
||||||
|
});
|
||||||
|
filteredProviderMap = map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._providerTypeSelectBox.setOptions(filteredProviderDisplayNames.filter((providerDisplayName, index) =>
|
|
||||||
// Remove duplicate listings (CMS uses the same display name)
|
// Remove duplicate listings (CMS uses the same display name)
|
||||||
filteredProviderDisplayNames.indexOf(providerDisplayName) === index)
|
let uniqueProvidersMap = this._connectionManagementService.getUniqueConnectionProvidersByNameMap(filteredProviderMap);
|
||||||
);
|
this._providerTypeSelectBox.setOptions(Object.keys(uniqueProvidersMap).map(k => uniqueProvidersMap[k]));
|
||||||
}
|
}
|
||||||
|
|
||||||
private includeProvider(providerName: string, params?: INewConnectionParams): Boolean {
|
private includeProvider(providerName: string, params?: INewConnectionParams): Boolean {
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
_serviceBrand: undefined;
|
_serviceBrand: undefined;
|
||||||
|
|
||||||
private _providers = new Map<string, { onReady: Promise<azdata.ConnectionProvider>, properties: ConnectionProviderProperties }>();
|
private _providers = new Map<string, { onReady: Promise<azdata.ConnectionProvider>, properties: ConnectionProviderProperties }>();
|
||||||
|
private _providerNameToDisplayNameMap: { [providerDisplayName: string]: string } = {};
|
||||||
private _iconProviders = new Map<string, azdata.IconProvider>();
|
private _iconProviders = new Map<string, azdata.IconProvider>();
|
||||||
private _uriToProvider: { [uri: string]: string; } = Object.create(null);
|
private _uriToProvider: { [uri: string]: string; } = Object.create(null);
|
||||||
private _onAddConnectionProfile = new Emitter<interfaces.IConnectionProfile>();
|
private _onAddConnectionProfile = new Emitter<interfaces.IConnectionProfile>();
|
||||||
@@ -107,6 +108,8 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
this._mementoObj = this._mementoContext.getMemento(StorageScope.GLOBAL);
|
this._mementoObj = this._mementoContext.getMemento(StorageScope.GLOBAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.initializeConnectionProvidersMap();
|
||||||
|
|
||||||
const registry = platform.Registry.as<IConnectionProviderRegistry>(ConnectionProviderExtensions.ConnectionProviderContributions);
|
const registry = platform.Registry.as<IConnectionProviderRegistry>(ConnectionProviderExtensions.ConnectionProviderContributions);
|
||||||
|
|
||||||
let providerRegistration = (p: { id: string, properties: ConnectionProviderProperties }) => {
|
let providerRegistration = (p: { id: string, properties: ConnectionProviderProperties }) => {
|
||||||
@@ -126,6 +129,30 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
this._register(this._onDeleteConnectionProfile);
|
this._register(this._onDeleteConnectionProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the initial value for the connection provider map and listen to the provider change event
|
||||||
|
*/
|
||||||
|
private initializeConnectionProvidersMap() {
|
||||||
|
this.updateConnectionProvidersMap();
|
||||||
|
if (this._capabilitiesService) {
|
||||||
|
this._capabilitiesService.onCapabilitiesRegistered(() => {
|
||||||
|
this.updateConnectionProvidersMap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the map using the values from capabilities service
|
||||||
|
*/
|
||||||
|
private updateConnectionProvidersMap() {
|
||||||
|
if (this._capabilitiesService) {
|
||||||
|
this._providerNameToDisplayNameMap = {};
|
||||||
|
entries(this._capabilitiesService.providers).forEach(p => {
|
||||||
|
this._providerNameToDisplayNameMap[p[0]] = p[1].connection.displayName;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public providerRegistered(providerId: string): boolean {
|
public providerRegistered(providerId: string): boolean {
|
||||||
return !!this._providers.get(providerId);
|
return !!this._providers.get(providerId);
|
||||||
}
|
}
|
||||||
@@ -159,6 +186,10 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
return this._onLanguageFlavorChanged.event;
|
return this._onLanguageFlavorChanged.event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get providerNameToDisplayNameMap(): { readonly [providerDisplayName: string]: string } {
|
||||||
|
return this._providerNameToDisplayNameMap;
|
||||||
|
}
|
||||||
|
|
||||||
// Connection Provider Registration
|
// Connection Provider Registration
|
||||||
public registerProvider(providerId: string, provider: azdata.ConnectionProvider): void {
|
public registerProvider(providerId: string, provider: azdata.ConnectionProvider): void {
|
||||||
if (!this._providers.has(providerId)) {
|
if (!this._providers.has(providerId)) {
|
||||||
@@ -217,6 +248,20 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
return providerId;
|
return providerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the connection providers map and filter out CMS.
|
||||||
|
*/
|
||||||
|
public getUniqueConnectionProvidersByNameMap(providerNameToDisplayNameMap: { [providerDisplayName: string]: string }): { [providerDisplayName: string]: string } {
|
||||||
|
let uniqueProvidersMap = {};
|
||||||
|
entries(providerNameToDisplayNameMap).forEach(p => {
|
||||||
|
if (p[0] !== Constants.cmsProviderName) {
|
||||||
|
uniqueProvidersMap[p[0]] = p[1];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return uniqueProvidersMap;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the password and try to connect. If fails, shows the dialog so user can change the connection
|
* Loads the password and try to connect. If fails, shows the dialog so user can change the connection
|
||||||
* @param Connection Profile
|
* @param Connection Profile
|
||||||
@@ -672,6 +717,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
*/
|
*/
|
||||||
public doChangeLanguageFlavor(uri: string, language: string, provider: string): void {
|
public doChangeLanguageFlavor(uri: string, language: string, provider: string): void {
|
||||||
if (this._providers.has(provider)) {
|
if (this._providers.has(provider)) {
|
||||||
|
this._uriToProvider[uri] = provider;
|
||||||
this._onLanguageFlavorChanged.fire({
|
this._onLanguageFlavorChanged.fire({
|
||||||
uri: uri,
|
uri: uri,
|
||||||
language: language,
|
language: language,
|
||||||
@@ -689,9 +735,8 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
public ensureDefaultLanguageFlavor(uri: string): void {
|
public ensureDefaultLanguageFlavor(uri: string): void {
|
||||||
if (!this.getProviderIdFromUri(uri)) {
|
if (!this.getProviderIdFromUri(uri)) {
|
||||||
// Lookup the default settings and use this
|
// Lookup the default settings and use this
|
||||||
let defaultProvider = WorkbenchUtils.getSqlConfigValue<string>(this._configurationService, Constants.defaultEngine);
|
let defaultProvider = this.getDefaultProviderId();
|
||||||
if (defaultProvider && this._providers.has(defaultProvider)) {
|
if (defaultProvider) {
|
||||||
// Only set a default if it's in the list of registered providers
|
|
||||||
this.doChangeLanguageFlavor(uri, 'sql', defaultProvider);
|
this.doChangeLanguageFlavor(uri, 'sql', defaultProvider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -771,9 +816,6 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
options: connection.options
|
options: connection.options
|
||||||
});
|
});
|
||||||
|
|
||||||
// setup URI to provider ID map for connection
|
|
||||||
this._uriToProvider[uri] = connection.providerName;
|
|
||||||
|
|
||||||
return this._providers.get(connection.providerName).onReady.then((provider) => {
|
return this._providers.get(connection.providerName).onReady.then((provider) => {
|
||||||
provider.connect(uri, connectionInfo);
|
provider.connect(uri, connectionInfo);
|
||||||
this._onConnectRequestSent.fire();
|
this._onConnectRequestSent.fire();
|
||||||
|
|||||||
@@ -729,6 +729,21 @@ suite('SQL ConnectionManagementService tests', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getUniqueConnectionProvidersByNameMap should return non CMS providers', () => {
|
||||||
|
let nameToDisplayNameMap: { [providerDisplayName: string]: string } = { 'MSSQL': 'SQL Server', 'MSSQL-CMS': 'SQL Server' };
|
||||||
|
let providerNames = Object.keys(connectionManagementService.getUniqueConnectionProvidersByNameMap(nameToDisplayNameMap));
|
||||||
|
assert.equal(providerNames.length, 1);
|
||||||
|
assert.equal(providerNames[0], 'MSSQL');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('providerNameToDisplayNameMap should return all providers', () => {
|
||||||
|
let expectedNames = ['MSSQL', 'PGSQL'];
|
||||||
|
let providerNames = Object.keys(connectionManagementService.providerNameToDisplayNameMap);
|
||||||
|
assert.equal(providerNames.length, 2);
|
||||||
|
assert.equal(providerNames[0], expectedNames[0]);
|
||||||
|
assert.equal(providerNames[1], expectedNames[1]);
|
||||||
|
});
|
||||||
|
|
||||||
test('ensureDefaultLanguageFlavor should not send event if uri is connected', done => {
|
test('ensureDefaultLanguageFlavor should not send event if uri is connected', done => {
|
||||||
let uri: string = 'Editor Uri';
|
let uri: string = 'Editor Uri';
|
||||||
let options: IConnectionCompletionOptions = {
|
let options: IConnectionCompletionOptions = {
|
||||||
|
|||||||
Reference in New Issue
Block a user