mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-15 09:35:37 -05:00
Load settings from local.settings.json for add sql bindings quickpick (#16957)
* load settings from local.settings.json for add sql bindings quickpick * cleanup * addressing comments
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import { BindingType } from 'vscode-mssql';
|
||||
import * as constants from '../common/constants';
|
||||
import * as utils from '../common/utils';
|
||||
import * as azureFunctionsUtils from '../common/azureFunctionsUtils';
|
||||
import { PackageHelper } from '../tools/packageHelper';
|
||||
|
||||
export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined, packageHelper: PackageHelper): Promise<void> {
|
||||
@@ -73,20 +75,43 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined,
|
||||
}
|
||||
|
||||
// 4. ask for connection string setting name
|
||||
// TODO: load local settings from local.settings.json like in LocalAppSettingListStep in vscode-azurefunctions repo
|
||||
const connectionStringSetting = await vscode.window.showInputBox({
|
||||
prompt: constants.connectionStringSetting,
|
||||
placeHolder: constants.connectionStringSettingPlaceholder,
|
||||
ignoreFocusOut: true
|
||||
});
|
||||
let project: string | undefined;
|
||||
try {
|
||||
project = await azureFunctionsUtils.getAFProjectContainingFile(uri.fsPath);
|
||||
} catch (e) {
|
||||
// continue even if there's no AF project found. The binding should still be able to be added as long as there was an azure function found in the file earlier
|
||||
}
|
||||
|
||||
if (!connectionStringSetting) {
|
||||
let connectionStringSettingName;
|
||||
|
||||
// show the settings from project's local.settings.json if there's an AF functions project
|
||||
// TODO: allow new setting name to get added here and added to local.settings.json
|
||||
if (project) {
|
||||
const settings = await azureFunctionsUtils.getLocalSettingsJson(path.join(path.dirname(project!), constants.azureFunctionLocalSettingsFileName));
|
||||
const existingSettings: string[] = settings.Values ? Object.keys(settings.Values) : [];
|
||||
|
||||
connectionStringSettingName = await vscode.window.showQuickPick(existingSettings, {
|
||||
canPickMany: false,
|
||||
title: constants.selectSetting,
|
||||
ignoreFocusOut: true
|
||||
});
|
||||
} else {
|
||||
// if no AF project was found or there's more than one AF functions project in the workspace,
|
||||
// ask for the user to input the setting name
|
||||
connectionStringSettingName = await vscode.window.showInputBox({
|
||||
prompt: constants.connectionStringSetting,
|
||||
placeHolder: constants.connectionStringSettingPlaceholder,
|
||||
ignoreFocusOut: true
|
||||
});
|
||||
}
|
||||
|
||||
if (!connectionStringSettingName) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 5. insert binding
|
||||
try {
|
||||
const result = await azureFunctionsService.addSqlBinding(selectedBinding.type, uri.fsPath, azureFunctionName, objectName, connectionStringSetting);
|
||||
const result = await azureFunctionsService.addSqlBinding(selectedBinding.type, uri.fsPath, azureFunctionName, objectName, connectionStringSettingName);
|
||||
|
||||
if (!result.success) {
|
||||
void vscode.window.showErrorMessage(result.errorMessage);
|
||||
|
||||
Reference in New Issue
Block a user