Skip to content

Commit cab8f49

Browse files
chore: revise extension install UX
1 parent cfa476b commit cab8f49

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

src/upgrade/upgradeManager.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Commands } from "../commands";
1111
import notificationManager from "./display/notificationManager";
1212
import { Settings } from "../settings";
1313
import assessmentManager from "./assessmentManager";
14-
import { checkOrInstallExtension } from "./utility";
14+
import { checkOrPromptToInstallAppModExtension } from "./utility";
1515

1616
const DEFAULT_UPGRADE_PROMPT = "Upgrade Java project dependency to latest version.";
1717

@@ -24,14 +24,22 @@ class UpgradeManager {
2424
public static initialize(context: ExtensionContext) {
2525
notificationManager.initialize(context);
2626

27-
// Commands to be used
27+
// Upgrade project
2828
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.JAVA_UPGRADE_WITH_COPILOT, async (promptText?: string) => {
29-
await checkOrInstallExtension(ExtensionName.APP_MODERNIZATION_UPGRADE_FOR_JAVA, ExtensionName.APP_MODERNIZATION_FOR_JAVA);
29+
await checkOrPromptToInstallAppModExtension(
30+
ExtensionName.APP_MODERNIZATION_UPGRADE_FOR_JAVA,
31+
"To upgrade the Java project, we need to use the App Modernization extension.",
32+
"Install extension and upgrade");
3033
const promptToUse = promptText ?? DEFAULT_UPGRADE_PROMPT;
3134
await commands.executeCommand(Commands.GOTO_AGENT_MODE, { prompt: promptToUse });
3235
}));
36+
37+
// Show modernization view
3338
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_MODERNIZE_JAVA_PROJECT, async () => {
34-
await checkOrInstallExtension(ExtensionName.APP_MODERNIZATION_FOR_JAVA);
39+
await checkOrPromptToInstallAppModExtension(
40+
ExtensionName.APP_MODERNIZATION_FOR_JAVA,
41+
"To modernize the Java project, we need to use the App Modernization extension.",
42+
"Install extension and modernize");
3543
await commands.executeCommand("workbench.view.extension.azureJavaMigrationExplorer");
3644
}));
3745

src/upgrade/utility.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { commands, extensions, Uri, window } from "vscode";
55
import * as semver from "semver";
66
import { UpgradeReason, type UpgradeIssue } from "./type";
7-
import { Upgrade } from "../constants";
7+
import { ExtensionName, Upgrade } from "../constants";
88

99

1010
function findEolDate(currentVersion: string, eolDate: Record<string, string>): string | null {
@@ -73,38 +73,33 @@ export function normalizePath(path: string): string {
7373
return Uri.parse(path).toString();
7474
}
7575

76-
export async function checkOrInstallExtension(extensionIdToCheck: string, extensionIdToInstall?: string): Promise<void> {
76+
export async function checkOrPromptToInstallAppModExtension(
77+
extensionIdToCheck: string,
78+
notificationText: string,
79+
buttonText: string): Promise<void> {
7780
if (extensions.getExtension(extensionIdToCheck)) {
7881
return;
7982
}
8083

81-
const actualExtensionIdToInstall = extensionIdToInstall ?? extensionIdToCheck;
82-
83-
{
84-
const BTN_TEXT = "Install extension";
85-
const choice = await window.showInformationMessage(
86-
"An extension is needed for the feature to work. Please install it and try again.",
87-
BTN_TEXT
88-
);
89-
if (choice === BTN_TEXT) {
90-
await commands.executeCommand("workbench.extensions.installExtension", actualExtensionIdToInstall);
91-
}
84+
const choice = await window.showInformationMessage(notificationText, buttonText);
85+
if (choice === buttonText) {
86+
await commands.executeCommand("workbench.extensions.installExtension", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
87+
} else {
88+
return;
9289
}
9390

94-
if (extensions.getExtension(actualExtensionIdToInstall)) {
91+
if (extensions.getExtension(ExtensionName.APP_MODERNIZATION_FOR_JAVA)) {
9592
return;
9693
}
9794

9895
// In this case the extension is disabled.
99-
await commands.executeCommand("workbench.extensions.search", actualExtensionIdToInstall);
100-
{
101-
const BTN_TEXT = "Show extension in sidebar";
102-
const choice = await window.showInformationMessage(
103-
"An extension is needed for the feature to work but it seems disabled. Please enable it manually and try again.",
104-
BTN_TEXT
105-
);
106-
if (choice === BTN_TEXT) {
107-
await commands.executeCommand("workbench.extensions.search", actualExtensionIdToInstall);
108-
}
96+
await commands.executeCommand("workbench.extensions.search", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
97+
const BTN_TEXT = "Show extension in sidebar";
98+
const choice2 = await window.showInformationMessage(
99+
"App Modernization extension is needed for the feature to work but it seems disabled. Please enable it manually and try again.",
100+
BTN_TEXT
101+
);
102+
if (choice2 === BTN_TEXT) {
103+
await commands.executeCommand("workbench.extensions.search", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
109104
}
110105
}

0 commit comments

Comments
 (0)