mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-30 09:35:39 -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:
@@ -58,6 +58,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private _providers = new Map<string, { onReady: Promise<azdata.ConnectionProvider>, properties: ConnectionProviderProperties }>();
|
||||
private _providerNameToDisplayNameMap: { [providerDisplayName: string]: string } = {};
|
||||
private _iconProviders = new Map<string, azdata.IconProvider>();
|
||||
private _uriToProvider: { [uri: string]: string; } = Object.create(null);
|
||||
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.initializeConnectionProvidersMap();
|
||||
|
||||
const registry = platform.Registry.as<IConnectionProviderRegistry>(ConnectionProviderExtensions.ConnectionProviderContributions);
|
||||
|
||||
let providerRegistration = (p: { id: string, properties: ConnectionProviderProperties }) => {
|
||||
@@ -126,6 +129,30 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
||||
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 {
|
||||
return !!this._providers.get(providerId);
|
||||
}
|
||||
@@ -159,6 +186,10 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
||||
return this._onLanguageFlavorChanged.event;
|
||||
}
|
||||
|
||||
public get providerNameToDisplayNameMap(): { readonly [providerDisplayName: string]: string } {
|
||||
return this._providerNameToDisplayNameMap;
|
||||
}
|
||||
|
||||
// Connection Provider Registration
|
||||
public registerProvider(providerId: string, provider: azdata.ConnectionProvider): void {
|
||||
if (!this._providers.has(providerId)) {
|
||||
@@ -217,6 +248,20 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
||||
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
|
||||
* @param Connection Profile
|
||||
@@ -672,6 +717,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
||||
*/
|
||||
public doChangeLanguageFlavor(uri: string, language: string, provider: string): void {
|
||||
if (this._providers.has(provider)) {
|
||||
this._uriToProvider[uri] = provider;
|
||||
this._onLanguageFlavorChanged.fire({
|
||||
uri: uri,
|
||||
language: language,
|
||||
@@ -689,9 +735,8 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
||||
public ensureDefaultLanguageFlavor(uri: string): void {
|
||||
if (!this.getProviderIdFromUri(uri)) {
|
||||
// Lookup the default settings and use this
|
||||
let defaultProvider = WorkbenchUtils.getSqlConfigValue<string>(this._configurationService, Constants.defaultEngine);
|
||||
if (defaultProvider && this._providers.has(defaultProvider)) {
|
||||
// Only set a default if it's in the list of registered providers
|
||||
let defaultProvider = this.getDefaultProviderId();
|
||||
if (defaultProvider) {
|
||||
this.doChangeLanguageFlavor(uri, 'sql', defaultProvider);
|
||||
}
|
||||
}
|
||||
@@ -771,9 +816,6 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
||||
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) => {
|
||||
provider.connect(uri, connectionInfo);
|
||||
this._onConnectRequestSent.fire();
|
||||
|
||||
Reference in New Issue
Block a user