Skip to content

Commit

Permalink
Task: Show override message when regenerating (microsoft#5493)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome authored Sep 30, 2024
1 parent c3a18ca commit 8b857a6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion vscode/microsoft-kiota/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
parseGenerationType, parsePluginType, updateTreeViewIcons
} from "./util";
import { IntegrationParams, isDeeplinkEnabled, transformToGenerationConfig, validateDeepLinkQueryParams } from './utilities/deep-linking';
import { confirmOverride } from './utilities/regeneration';
import { loadTreeView } from "./workspaceTreeProvider";

let kiotaStatusBarItem: vscode.StatusBarItem;
Expand Down Expand Up @@ -314,6 +315,11 @@ export async function activate(
await updateTreeViewIcons(treeViewId, false, true);
}),
registerCommandWithTelemetry(reporter, `${treeViewId}.regenerateButton`, async () => {
const regenerate = await confirmOverride();
if (!regenerate) {
return;
}

if (!clientOrPluginKey || clientOrPluginKey === '') {
clientOrPluginKey = config.clientClassName || config.pluginName || '';
}
Expand All @@ -339,6 +345,11 @@ export async function activate(
}
}),
registerCommandWithTelemetry(reporter, `${extensionId}.regenerate`, async (clientKey: string, clientObject: ClientOrPluginProperties, generationType: string) => {
const regenerate = await confirmOverride();
if (!regenerate) {
return;
}

const settings = getExtensionSettings(extensionId);
const workspaceJson = vscode.workspace.textDocuments.find(doc => doc.fileName.endsWith(KIOTA_WORKSPACE_FILE));
if (workspaceJson && workspaceJson.isDirty) {
Expand Down Expand Up @@ -449,7 +460,7 @@ export async function activate(
if (!isSuccess) {
await exportLogsAndShowErrors(result);
}
const isttkIntegration = deepLinkParams.source && deepLinkParams.source.toLowerCase() === 'ttk'? true : false;
const isttkIntegration = deepLinkParams.source && deepLinkParams.source.toLowerCase() === 'ttk';
if (!isttkIntegration) {
void vscode.window.showInformationMessage(vscode.l10n.t('Plugin generated successfully.'));
}
Expand Down
12 changes: 12 additions & 0 deletions vscode/microsoft-kiota/src/utilities/regeneration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as vscode from "vscode";

export async function confirmOverride(): Promise<boolean> {
const yesAnswer = vscode.l10n.t("Yes, override it");
const confirmation = await vscode.window
.showWarningMessage(
vscode.l10n.t("When regenerating, all changes made manually to the generated files will be overridden."),
yesAnswer,
vscode.l10n.t("Cancel")
);
return confirmation === yesAnswer;
}

0 comments on commit 8b857a6

Please sign in to comment.