mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-15 09:35:37 -05:00
Add support for adding new setting in local.settings.json in add SQL binding quickpick (#17093)
* be able to add new setting in local.settings.json * cleanup * addressing comments * remove todo comment * addressing comments * update some strings to uris
This commit is contained in:
@@ -78,9 +78,9 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined,
|
||||
}
|
||||
|
||||
// 4. ask for connection string setting name
|
||||
let project: string | undefined;
|
||||
let projectUri: vscode.Uri | undefined;
|
||||
try {
|
||||
project = await azureFunctionsUtils.getAFProjectContainingFile(uri.fsPath);
|
||||
projectUri = await azureFunctionsUtils.getAFProjectContainingFile(uri);
|
||||
} 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
|
||||
}
|
||||
@@ -88,16 +88,80 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined,
|
||||
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) : [];
|
||||
if (projectUri) {
|
||||
let settings;
|
||||
try {
|
||||
settings = await azureFunctionsUtils.getLocalSettingsJson(path.join(path.dirname(projectUri.fsPath!), constants.azureFunctionLocalSettingsFileName));
|
||||
} catch (e) {
|
||||
void vscode.window.showErrorMessage(e);
|
||||
return;
|
||||
}
|
||||
|
||||
let existingSettings: (vscode.QuickPickItem & { isCreateNew?: boolean })[] = [];
|
||||
if (settings?.Values) {
|
||||
existingSettings = Object.keys(settings.Values).map(setting => {
|
||||
return {
|
||||
label: setting
|
||||
} as vscode.QuickPickItem & { isCreateNew?: boolean };
|
||||
});
|
||||
}
|
||||
|
||||
existingSettings.unshift({ label: constants.createNewLocalAppSettingWithIcon, isCreateNew: true });
|
||||
|
||||
while (!connectionStringSettingName) {
|
||||
const selectedSetting = await vscode.window.showQuickPick(existingSettings, {
|
||||
canPickMany: false,
|
||||
title: constants.selectSetting,
|
||||
ignoreFocusOut: true
|
||||
});
|
||||
if (!selectedSetting) {
|
||||
// User cancelled
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedSetting.isCreateNew) {
|
||||
const newConnectionStringSettingName = await vscode.window.showInputBox(
|
||||
{
|
||||
title: constants.enterConnectionStringSettingName,
|
||||
ignoreFocusOut: true,
|
||||
validateInput: input => input ? undefined : constants.nameMustNotBeEmpty
|
||||
}
|
||||
) ?? '';
|
||||
|
||||
if (!newConnectionStringSettingName) {
|
||||
// go back to select setting quickpick if user escapes from inputting the setting name in case they changed their mind
|
||||
continue;
|
||||
}
|
||||
|
||||
const newConnectionStringValue = await vscode.window.showInputBox(
|
||||
{
|
||||
title: constants.enterConnectionString,
|
||||
ignoreFocusOut: true,
|
||||
validateInput: input => input ? undefined : constants.valueMustNotBeEmpty
|
||||
}
|
||||
) ?? '';
|
||||
|
||||
if (!newConnectionStringValue) {
|
||||
// go back to select setting quickpick if user escapes from inputting the value in case they changed their mind
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const success = await azureFunctionsUtils.setLocalAppSetting(path.dirname(projectUri.fsPath), newConnectionStringSettingName, newConnectionStringValue);
|
||||
if (success) {
|
||||
connectionStringSettingName = newConnectionStringSettingName;
|
||||
}
|
||||
} catch (e) {
|
||||
// display error message and show select setting quickpick again
|
||||
void vscode.window.showErrorMessage(e);
|
||||
}
|
||||
// If user cancels out of this or doesn't want to overwrite an existing setting
|
||||
// just return them to the select setting quickpick in case they changed their mind
|
||||
} else {
|
||||
connectionStringSettingName = selectedSetting.label;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
@@ -132,6 +196,6 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined,
|
||||
}
|
||||
|
||||
// 6. Add sql extension package reference to project. If the reference is already there, it doesn't get added again
|
||||
await packageHelper.addPackageToAFProjectContainingFile(uri.fsPath, constants.sqlExtensionPackageName);
|
||||
await packageHelper.addPackageToAFProjectContainingFile(uri, constants.sqlExtensionPackageName);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user