Fix for user using command palette (#18948)

* fix for user using command palette command

* rework if a user uses the create azure function via the command

* for now only show in vs code

* move logic to azureFunctionService + address comments

* fix command location

* address comments

* fix validateFunction
This commit is contained in:
Vasu Bhog
2022-04-08 10:28:45 -07:00
committed by GitHub
parent dc14201088
commit ed8d2f9927
5 changed files with 142 additions and 42 deletions

View File

@@ -5,33 +5,18 @@
import * as vscode from 'vscode';
import { ITreeNodeInfo } from 'vscode-mssql';
import { IExtension, BindingType } from 'sql-bindings';
import { getAzdataApi, getVscodeMssqlApi } from './common/utils';
import { getAzdataApi } from './common/utils';
import { addSqlBinding, createAzureFunction, getAzureFunctions } from './services/azureFunctionsService';
import { launchAddSqlBindingQuickpick } from './dialogs/addSqlBindingQuickpick';
import { promptForBindingType, promptAndUpdateConnectionStringSetting, promptForObjectName } from './common/azureFunctionsUtils';
export async function activate(context: vscode.ExtensionContext): Promise<IExtension> {
const vscodeMssqlApi = await getVscodeMssqlApi();
void vscode.commands.executeCommand('setContext', 'azdataAvailable', !!getAzdataApi());
// register the add sql binding command
context.subscriptions.push(vscode.commands.registerCommand('sqlBindings.addSqlBinding', async (uri: vscode.Uri | undefined) => { return launchAddSqlBindingQuickpick(uri); }));
// Generate Azure Function command
context.subscriptions.push(vscode.commands.registerCommand('sqlBindings.createAzureFunction', async (node: ITreeNodeInfo) => {
let connectionInfo = node.connectionInfo;
// set the database containing the selected table so it can be used
// for the initial catalog property of the connection string
let newNode: ITreeNodeInfo = node;
while (newNode) {
if (newNode.nodeType === 'Database') {
connectionInfo.database = newNode.metadata.name;
break;
} else {
newNode = newNode.parentNode;
}
}
const connectionDetails = vscodeMssqlApi.createConnectionDetails(connectionInfo);
const connectionString = await vscodeMssqlApi.getConnectionString(connectionDetails, false, false);
await createAzureFunction(connectionString, node.metadata.schema, node.metadata.name, connectionInfo);
context.subscriptions.push(vscode.commands.registerCommand('sqlBindings.createAzureFunction', async (node?: ITreeNodeInfo) => {
return await createAzureFunction(node);
}));
return {
addSqlBinding: async (bindingType: BindingType, filePath: string, functionName: string, objectName: string, connectionStringSetting: string) => {