mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-05 17:23:51 -05:00
Add sample value provider (#17548)
This commit is contained in:
18
samples/sample-resource-deployment/src/extension.ts
Normal file
18
samples/sample-resource-deployment/src/extension.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as rd from 'resource-deployment';
|
||||
import * as vscode from 'vscode';
|
||||
import { SampleValueProvider } from './sampleValueProvider';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
// Get the extension API for the resource deployment extension so we can register the value provider. Because the extension itself has a dependency
|
||||
// on the resource deployment extension we don't need to activate it here - we're guaranteed that it's already activated by the time activate is called here.
|
||||
const resourceDeploymentApi = vscode.extensions.getExtension(rd.extension.name)!.exports as rd.IExtension;
|
||||
// Always register value provider disposables so they're deregistered properly if the extension is deactivated
|
||||
context.subscriptions.push(resourceDeploymentApi.registerValueProvider(new SampleValueProvider()));
|
||||
}
|
||||
|
||||
export function deactivate() { }
|
||||
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as rd from 'resource-deployment';
|
||||
|
||||
/**
|
||||
* This is a sample value provider used to demonstrate how values are received and can be used to generate the return value.
|
||||
*/
|
||||
export class SampleValueProvider implements rd.IValueProvider {
|
||||
/**
|
||||
* This ID corresponds to the `providerId` property in the `valueProvider` properties of the package.json definitions.
|
||||
*/
|
||||
readonly id = 'sample-resource-deployment.sample-value-provider';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param triggerValues This is an object whose keys correspond to the `variableName` (or `label` if no `variableName` is given) property of the trigger fields.
|
||||
* This will contain an entry for every trigger field defined in the `valueProvider` property on the target field - even if those values are empty/undefined.
|
||||
* @returns The calculated input type to return. This is expected to match the type of the target field (so string for text, boolean for checkbox, etc)
|
||||
*/
|
||||
public async getValue(triggerValues: { [key: string]: rd.InputValueType; }): Promise<rd.InputValueType> {
|
||||
Object.values(triggerValues)
|
||||
// Because this example is used by two different fields we have logic here to handle determining which one it came from.
|
||||
// If you are making a generic provider that you don't want to have know about each field that uses it you can use
|
||||
// Object.values(triggerValues) to get the array of values and operate on those directly.
|
||||
if (triggerValues['AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_MULTIPLE_PLACE'] !== undefined) {
|
||||
return `Hello ${triggerValues['AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_MULTIPLE_NAME']} from ${triggerValues['AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_MULTIPLE_PLACE']}!`;
|
||||
} else {
|
||||
return `Hello ${triggerValues['AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_SINGLE_NAME']}!`;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
samples/sample-resource-deployment/src/typings/refs.d.ts
vendored
Normal file
9
samples/sample-resource-deployment/src/typings/refs.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// This is used to get typing support for the resource-deployment extension API. For external extensions you will need to copy
|
||||
// https://github.com/microsoft/azuredatastudio/blob/main/extensions/resource-deployment/src/typings/resource-deployment.d.ts
|
||||
// to your extension repo and reference it there.
|
||||
/// <reference path='../../../../extensions/resource-deployment/src/typings/resource-deployment.d.ts'/>
|
||||
Reference in New Issue
Block a user