Add nupkg database reference option for sql projects in vscode (#22882)

* add nupkg db ref option in vscode

* add telemetry for nupkg db ref

* update comment
This commit is contained in:
Kim Santiago
2023-04-28 14:57:22 -07:00
committed by GitHub
parent 468b3e4f06
commit 934d8ff8fa
2 changed files with 79 additions and 1 deletions

View File

@@ -166,6 +166,7 @@ export const newText = localize('new', "New");
export const selectDatabase = localize('selectDatabase', "Select database");
export const done = localize('done', "Done");
export const nameMustNotBeEmpty = localize('nameMustNotBeEmpty', "Name must not be empty");
export const versionMustNotBeEmpty = localize('versionMustNotBeEmpty', "Version must not be empty");
//#endregion

View File

@@ -9,10 +9,11 @@ import * as constants from '../common/constants';
import { getSqlProjectsInWorkspace, getSystemDatabase, validateSqlCmdVariableName } from '../common/utils';
import { DbServerValues, populateResultWithVars } from './utils';
import { AddDatabaseReferenceSettings } from '../controllers/projectController';
import { IDacpacReferenceSettings, IProjectReferenceSettings, ISystemDatabaseReferenceSettings } from '../models/IDatabaseReferenceSettings';
import { IDacpacReferenceSettings, INugetPackageReferenceSettings, IProjectReferenceSettings, ISystemDatabaseReferenceSettings } from '../models/IDatabaseReferenceSettings';
import { Project } from '../models/project';
import { getSystemDbOptions, promptDacpacLocation } from './addDatabaseReferenceDialog';
import { TelemetryActions, TelemetryReporter, TelemetryViews } from '../common/telemetry';
import { ProjectType } from 'mssql';
@@ -29,6 +30,11 @@ export async function addDatabaseReferenceQuickpick(project: Project): Promise<A
[constants.projectLabel, constants.systemDatabase, constants.dacpacText] :
[constants.systemDatabase, constants.dacpacText];
// only add nupkg database reference option if project is SDK-style
if (project.sqlProjStyle === ProjectType.SdkStyle) {
referenceTypes.push(constants.nupkgText);
}
const referenceType = await vscode.window.showQuickPick(
referenceTypes,
{ title: constants.referenceType, ignoreFocusOut: true });
@@ -44,6 +50,8 @@ export async function addDatabaseReferenceQuickpick(project: Project): Promise<A
return addSystemDatabaseReference(project);
case constants.dacpacText:
return addDacpacReference(project);
case constants.nupkgText:
return addNupkgReference();
default:
console.log(`Unknown reference type ${referenceType}`);
return undefined;
@@ -200,6 +208,75 @@ async function addDacpacReference(project: Project): Promise<IDacpacReferenceSet
return referenceSettings;
}
async function addNupkgReference(): Promise<INugetPackageReferenceSettings | undefined> {
// (steps continued from addDatabaseReferenceQuickpick)
// 2. Prompt for location
const location = await promptLocation();
if (!location) {
// User cancelled
return undefined;
}
// 3. Prompt for NuGet package name
const nupkgName = await vscode.window.showInputBox(
{
title: constants.nupkgText,
placeHolder: constants.nupkgNamePlaceholder,
validateInput: (value) => {
return value ? undefined : constants.nameMustNotBeEmpty;
},
ignoreFocusOut: true
});
if (!nupkgName) {
// User cancelled
return undefined;
}
// 4. Prompt for NuGet package version
const nupkgVersion = await vscode.window.showInputBox(
{
title: constants.version,
placeHolder: constants.versionPlaceholder,
validateInput: (value) => {
return value ? undefined : constants.versionMustNotBeEmpty;
},
ignoreFocusOut: true
});
if (!nupkgVersion) {
// User cancelled
return undefined;
}
// 5. Prompt for db/server values
const dbServerValues = await promptDbServerValues(location, path.parse(nupkgName).name);
if (!dbServerValues) {
// User cancelled
return;
}
// 6. Prompt suppress unresolved ref errors
const suppressErrors = await promptSuppressUnresolvedRefErrors();
// 7. Construct result
const referenceSettings: INugetPackageReferenceSettings = {
packageName: nupkgName,
packageVersion: nupkgVersion,
suppressMissingDependenciesErrors: suppressErrors
};
populateResultWithVars(referenceSettings, dbServerValues);
TelemetryReporter.createActionEvent(TelemetryViews.ProjectTree, TelemetryActions.addDatabaseReference)
.withAdditionalProperties({ referenceType: constants.nupkgText })
.send();
return referenceSettings;
}
async function promptLocation(): Promise<string | undefined> {
return vscode.window.showQuickPick(
constants.locationDropdownValues,