Have resource deployment providers return disposables (#13690)

* Add dependent field provider to resource deployment

* Change name to value provider service

* Add error handling

* providerId -> id

* Set dropdown value correctly

* missed id

* back to providerId

* fix updating missed id

* Make resource deployment providers disposable
This commit is contained in:
Charles Gagnon
2020-12-07 10:27:37 -08:00
committed by GitHub
parent a70dce7855
commit 97a4de4111
6 changed files with 25 additions and 8 deletions

View File

@@ -67,7 +67,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<arc.IE
// register option sources
const rdApi = <rd.IExtension>vscode.extensions.getExtension(rd.extension.name)?.exports;
rdApi.registerOptionsSourceProvider(new ArcControllersOptionsSourceProvider(treeDataProvider));
context.subscriptions.push(rdApi.registerOptionsSourceProvider(new ArcControllersOptionsSourceProvider(treeDataProvider)));
return arcApi(treeDataProvider);
}

View File

@@ -65,7 +65,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<azdata
// register option source(s)
const rdApi = <rd.IExtension>vscode.extensions.getExtension(rd.extension.name)?.exports;
rdApi.registerOptionsSourceProvider(new ArcControllerConfigProfilesOptionsSource(azdataApi));
context.subscriptions.push(rdApi.registerOptionsSourceProvider(new ArcControllerConfigProfilesOptionsSource(azdataApi)));
return azdataApi;
}

View File

@@ -109,7 +109,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
// Don't block on this since there's a bit of a circular dependency here with the extension activation since resource deployment
// depends on this extension too. It's fine to wait a bit for that to finish before registering the provider
vscode.extensions.getExtension(resourceDeployment.extension.name).activate().then((api: resourceDeployment.IExtension) => {
api.registerValueProvider({
context.subscriptions.push(api.registerValueProvider({
id: 'subscription-id-to-tenant-id',
getValue: async (triggerValue: string) => {
if (triggerValue === '') {
@@ -137,7 +137,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
console.error(`Unable to find subscription with ID ${triggerValue} when mapping subscription ID to tenant ID`);
return '';
}
});
}));
});
return {

View File

@@ -3,16 +3,24 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as rd from 'resource-deployment';
import * as loc from '../localizedConstants';
class OptionsSourcesService {
private _optionsSourceStore = new Map<string, rd.IOptionsSourceProvider>();
registerOptionsSourceProvider(provider: rd.IOptionsSourceProvider): void {
registerOptionsSourceProvider(provider: rd.IOptionsSourceProvider): vscode.Disposable {
if (this._optionsSourceStore.has(provider.id)) {
throw new Error(loc.optionsSourceAlreadyDefined(provider.id));
}
this._optionsSourceStore.set(provider.id, provider);
return {
dispose: () => this.unregisterOptionsSourceProvider(provider.id)
};
}
private unregisterOptionsSourceProvider(providerId: string): void {
this._optionsSourceStore.delete(providerId);
}
getOptionsSource(optionsSourceProviderId: string): rd.IOptionsSourceProvider {

View File

@@ -3,16 +3,24 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as rd from 'resource-deployment';
import * as loc from '../localizedConstants';
class ValueProviderService {
private _valueProviderStore = new Map<string, rd.IValueProvider>();
registerValueProvider(provider: rd.IValueProvider): void {
registerValueProvider(provider: rd.IValueProvider): vscode.Disposable {
if (this._valueProviderStore.has(provider.id)) {
throw new Error(loc.valueProviderAlreadyDefined(provider.id));
}
this._valueProviderStore.set(provider.id, provider);
return {
dispose: () => this.unregisterValueProvider(provider.id)
};
}
private unregisterValueProvider(providerId: string): void {
this._valueProviderStore.delete(providerId);
}
getValueProvider(providerId: string): rd.IValueProvider {

View File

@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
declare module 'resource-deployment' {
import * as azdata from 'azdata';
import * as vscode from 'vscode';
export const enum ErrorType {
userCancelled,
@@ -36,7 +37,7 @@ declare module 'resource-deployment' {
*/
export interface IExtension {
registerOptionsSourceProvider(provider: IOptionsSourceProvider): void,
registerValueProvider(provider: IValueProvider): void
registerOptionsSourceProvider(provider: IOptionsSourceProvider): vscode.Disposable,
registerValueProvider(provider: IValueProvider): vscode.Disposable
}
}