Skip to content

Commit 9f15b6b

Browse files
authored
Improve ext installation experience (#170)
Signed-off-by: Rome Li <[email protected]>
1 parent ace4a7a commit 9f15b6b

File tree

8 files changed

+77
-42
lines changed

8 files changed

+77
-42
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"publisher": "vscjava",
88
"preview": true,
99
"engines": {
10-
"vscode": "^1.28.0"
10+
"vscode": "^1.32.0"
1111
},
1212
"aiKey": "b4a8a622-6ac7-4cf8-83aa-f325e1890795",
1313
"icon": "logo.png",

src/commands/handler.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ export async function showExtensionCmdHandler(context: vscode.ExtensionContext,
3131
vscode.commands.executeCommand("extension.open", extensionName);
3232
}
3333

34+
export async function installExtensionCmdHandler(context: vscode.ExtensionContext, operationId: string, extensionName: string, displayName: string) {
35+
sendInfo(operationId, { extName: extensionName });
36+
return vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: `Installing ${displayName||extensionName}...`}, progress => {
37+
return vscode.commands.executeCommand("workbench.extensions.installExtension", extensionName);
38+
}).then(() => {
39+
vscode.window.showInformationMessage(`Successfully installed ${displayName||extensionName}.`);
40+
});
41+
}
42+
3443
export async function openUrlCmdHandler(context: vscode.ExtensionContext, operationId: string, url: string) {
3544
sendInfo(operationId, { url: url });
3645
vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(url));

src/commands/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import * as vscode from "vscode";
55

66
import { instrumentCommand } from "../utils";
7-
import { createMavenProjectCmdHanlder, createSpringBootProjectCmdHandler, showExtensionCmdHandler, openUrlCmdHandler, showReleaseNotesHandler } from "./handler";
7+
import { createMavenProjectCmdHanlder, createSpringBootProjectCmdHandler, showExtensionCmdHandler, openUrlCmdHandler, showReleaseNotesHandler, installExtensionCmdHandler } from "./handler";
88
import { overviewCmdHandler } from "../overview";
99
import { javaRuntimeCmdHandler } from "../java-runtime";
1010

@@ -16,4 +16,5 @@ export function initialize(context: vscode.ExtensionContext) {
1616
context.subscriptions.push(vscode.commands.registerCommand("java.helper.openUrl", instrumentCommand(context, "java.helper.openUrl", openUrlCmdHandler)));
1717
context.subscriptions.push(vscode.commands.registerCommand("java.showReleaseNotes", instrumentCommand(context, "java.showReleaseNotes", showReleaseNotesHandler)));
1818
context.subscriptions.push(vscode.commands.registerCommand("java.runtime", instrumentCommand(context, "java.runtime", javaRuntimeCmdHandler)));
19+
context.subscriptions.push(vscode.commands.registerCommand("java.helper.installExtension", instrumentCommand(context, "java.helper.installExtension", installExtensionCmdHandler)));
1920
}

src/overview/assets/index.html

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,40 +140,40 @@ <h3 class="font-weight-light">Documentation</h3>
140140
<div class="row mb-3">
141141
<div class="col">
142142
<h3 class="font-weight-light">Key Bindings</h3>
143-
<div ext="k--kato.intellij-idea-keybindings">
144-
<a href="command:java.helper.showExtension?%22k--kato.intellij-idea-keybindings%22" title="Use IntelliJ IDEA hot keys in VS Code...">Use IntelliJ IDEA Key Bindings</a>
143+
<div ext="k--kato.intellij-idea-keybindings" displayName="IntelliJ IDEA Key Bindings">
144+
<a href="#" title="Use IntelliJ IDEA hot keys in VS Code...">Use IntelliJ IDEA Key Bindings</a>
145145
</div>
146-
<div ext="alphabotsec.vscode-eclipse-keybindings">
147-
<a href="command:java.helper.showExtension?%22alphabotsec.vscode-eclipse-keybindings%22" title="Use Eclipse hot keys in VS Code...">Use Eclipse Key Bindings</a>
146+
<div ext="alphabotsec.vscode-eclipse-keybindings" displayName="Eclipse Key Bindings">
147+
<a href="#" title="Use Eclipse hot keys in VS Code...">Use Eclipse Key Bindings</a>
148148
</div>
149149
</div>
150150
</div>
151151
<div class="row mb-3">
152152
<div class="col">
153153
<h3 class="font-weight-light">Extensions</h3>
154-
<div ext="redhat.java">
155-
<a href="command:java.helper.showExtension?%22redhat.java%22" title="Install Java Language Support extension...">Install Java Language Support by Red Hat</a>
154+
<div ext="redhat.java" displayName="Java Language Support by Red Hat">
155+
<a href="#" title="Install Java Language Support extension...">Install Java Language Support by Red Hat</a>
156156
</div>
157-
<div ext="redhat.java">
158-
<a href="command:java.helper.showExtension?%22vscjava.vscode-java-debug%22" title="Install Debugger for Java extension...">Install Debugger for Java</a>
157+
<div ext="vscjava.vscode-java-debug" displayName="Debugger for Java">
158+
<a href="#" title="Install Debugger for Java extension...">Install Debugger for Java</a>
159159
</div>
160-
<div ext="vscjava.vscode-java-test">
161-
<a href="command:java.helper.showExtension?%22vscjava.vscode-java-test%22" title="Install Java Test Runner extension...">Install Java Test Runner</a>
160+
<div ext="vscjava.vscode-java-test" displayName="Java Test Runner">
161+
<a href="#" title="Install Java Test Runner extension...">Install Java Test Runner</a>
162162
</div>
163-
<div ext="vscjava.vscode-maven">
164-
<a href="command:java.helper.showExtension?%22vscjava.vscode-maven%22" title="Install Maven for Java extension...">Install Maven for Java</a>
163+
<div ext="vscjava.vscode-maven" displayName="Maven for Java">
164+
<a href="#" title="Install Maven for Java extension...">Install Maven for Java</a>
165165
</div>
166-
<div ext="adashen.vscode-tomcat">
167-
<a href="command:java.helper.showExtension?%22adashen.vscode-tomcat%22" title="Install Tomcat for Java extension...">Install Tomcat for Java</a>
166+
<div ext="adashen.vscode-tomcat" displayName="Tomcat for Java">
167+
<a href="#" title="Install Tomcat for Java extension...">Install Tomcat for Java</a>
168168
</div>
169-
<div ext="shengchen.vscode-checkstyle">
170-
<a href="command:java.helper.showExtension?%22shengchen.vscode-checkstyle%22" title="Install Checkstyle for Java extension...">Install Checkstyle for Java</a>
169+
<div ext="shengchen.vscode-checkstyle" displayName="Checkstyle for Java">
170+
<a href="#" title="Install Checkstyle for Java extension...">Install Checkstyle for Java</a>
171171
</div>
172-
<div ext="redhat.vscode-xml">
173-
<a href="command:java.helper.showExtension?%22redhat.vscode-xml%22" title="Schema validation when editing pom.xml...">Install XML extension</a>
172+
<div ext="redhat.vscode-xml" displayName="XML">
173+
<a href="#" title="Schema validation when editing pom.xml...">Install XML extension</a>
174174
</div>
175-
<div ext="vscjava.vscode-java-dependency">
176-
<a href="command:java.helper.showExtension?%22vscjava.vscode-java-dependency%22" title="Install Java Dependency Viewer extension...">Install Java Dependency Viewer</a>
175+
<div ext="vscjava.vscode-java-dependency" displayName="Java Dependency Viewer">
176+
<a href="#" title="Install Java Dependency Viewer extension...">Install Java Dependency Viewer</a>
177177
</div>
178178
</div>
179179
</div>
@@ -188,8 +188,8 @@ <h3 class="font-weight-light">Spring</h3>
188188
<div>
189189
<a href="command:java.helper.openUrl?%22https%3A%2F%2Fgithub.com%2Fspring-projects%2Fspring-petclinic%22" title="Run PetClinic sample app in VS Code">Spring PetClinic Sample Application</a>
190190
</div>
191-
<div ext="pivotal.vscode-boot-dev-pack">
192-
<a href="command:java.helper.showExtension?%22pivotal.vscode-boot-dev-pack%22" title="Install Spring Boot Extension Pack...">Install Spring Boot Extension Pack</a>
191+
<div ext="pivotal.vscode-boot-dev-pack" displayName="Spring Boot Extension Pack">
192+
<a href="#" title="Install Spring Boot Extension Pack...">Install Spring Boot Extension Pack</a>
193193
</div>
194194
</div>
195195
</div>
@@ -202,11 +202,11 @@ <h3 class="font-weight-light">Microservices</h3>
202202
<div>
203203
<a href="command:java.helper.openUrl?%22https%3A%2F%2Fcode.visualstudio.com%2Fdocs%2Fazure%2Fdocker%22" title="Learn how to work with Docker in VS Code">Docker in VS Code</a>
204204
</div>
205-
<div ext="ms-kubernetes-tools.vscode-kubernetes-tools">
206-
<a href="command:java.helper.showExtension?%22ms-kubernetes-tools.vscode-kubernetes-tools%22" title="Install Kubernetes extension...">Install Kubernetes Extension</a>
205+
<div ext="ms-kubernetes-tools.vscode-kubernetes-tools" displayName="Kubernetes">
206+
<a href="#" title="Install Kubernetes extension...">Install Kubernetes Extension</a>
207207
</div>
208-
<div ext="peterjausovec.vscode-docker">
209-
<a href="command:java.helper.showExtension?%22peterjausovec.vscode-docker%22" title="Install Docker extension...">Install Docker Extension</a>
208+
<div ext="ms-azuretools.vscode-docker" displayName="Docker">
209+
<a href="#" title="Install Docker extension...">Install Docker Extension</a>
210210
</div>
211211
</div>
212212
</div>

src/overview/assets/index.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import "bootstrap/js/src/tab";
77
import bytes = require("bytes");
88

99
window.addEventListener("message", event => {
10-
if (event.data.command === "hideInstalledExtensions") {
11-
hideInstalledExtensions(event.data.installedExtensions);
12-
hideEmptySections();
10+
if (event.data.command === "syncExtensionVisibility") {
11+
syncExtensionVisibility(event.data.installedExtensions);
12+
syncSectionVisibility();
1313
} else if (event.data.command === "setOverviewVisibility") {
1414
$("#showWhenUsingJava").prop("checked", event.data.visibility);
1515
} else if (event.data.command === "showJavaRuntimePanel") {
@@ -34,20 +34,24 @@ function applyJdkInfo(jdkInfo: any) {
3434
$("#jdkDownloadLink").removeClass("d-none");
3535
}
3636

37-
function hideInstalledExtensions(extensions: any) {
37+
function syncExtensionVisibility(extensions: any) {
3838
$("div[ext]").each((index, elem) => {
3939
const anchor = $(elem);
4040
const ext = (anchor.attr("ext") || "").toLowerCase();
4141
if (extensions.indexOf(ext) !== -1) {
4242
anchor.hide();
43+
} else {
44+
anchor.show();
4345
}
4446
});
4547
}
4648

47-
function hideEmptySections() {
49+
function syncSectionVisibility() {
4850
$("div h3").parent().each((i, div) => {
4951
if (!$(div).children("h3 ~ div").is(":visible")) {
5052
$(div).hide();
53+
} else {
54+
$(div).show();
5155
}
5256
});
5357
}
@@ -70,6 +74,18 @@ function requestJdkInfo(jdkVersion: string, jvmImpl: string) {
7074
});
7175
}
7276

77+
function installExtension(extName: string, displayName: string) {
78+
vscode.postMessage({
79+
command: "installExtension",
80+
extName: extName,
81+
displayName: displayName
82+
});
83+
}
84+
85+
$("div[ext]").click(function () {
86+
installExtension($(this).attr("ext"), $(this).attr("displayName"));
87+
});
88+
7389
$("input[type=radio]").change(() => {
7490
$("#jdkSpinner").removeClass("d-none");
7591
$("#jdkDownloadLink").addClass("d-none");

src/overview/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,18 @@ async function initializeOverviewView(context: vscode.ExtensionContext, webviewP
5858

5959
context.subscriptions.push(webviewPanel.onDidDispose(onDisposeCallback));
6060

61-
const installedExtensions = vscode.extensions.all.map(ext => ext.id.toLowerCase());
62-
webviewPanel.webview.postMessage({
63-
command: "hideInstalledExtensions",
64-
installedExtensions: installedExtensions
61+
function syncExtensionVisibility() {
62+
const installedExtensions = vscode.extensions.all.map(ext => ext.id.toLowerCase());
63+
webviewPanel.webview.postMessage({
64+
command: "syncExtensionVisibility",
65+
installedExtensions: installedExtensions
66+
});
67+
}
68+
69+
syncExtensionVisibility();
70+
71+
vscode.extensions.onDidChange(e => {
72+
syncExtensionVisibility();
6573
});
6674

6775
webviewPanel.webview.postMessage({
@@ -75,6 +83,8 @@ async function initializeOverviewView(context: vscode.ExtensionContext, webviewP
7583
} else if (e.command === "requestJdkInfo") {
7684
let jdkInfo = await suggestOpenJdk(e.jdkVersion, e.jvmImpl);
7785
applyJdkInfo(jdkInfo);
86+
} else if (e.command === "installExtension") {
87+
await vscode.commands.executeCommand("java.helper.installExtension", e.extName, e.displayName);
7888
}
7989
}));
8090

@@ -87,7 +97,6 @@ async function initializeOverviewView(context: vscode.ExtensionContext, webviewP
8797
applyJdkInfo(jdkInfo);
8898
}
8999

90-
91100
function applyJdkInfo(jdkInfo: any) {
92101
webviewPanel.webview.postMessage({
93102
command: "applyJdkInfo",

src/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ export function isExtensionInstalled( extName: string) {
2222
}
2323

2424
export async function recommendExtension(extName: string, message: string): Promise<void> {
25-
const action = "Details";
25+
const action = "Install";
2626
const answer = await vscode.window.showInformationMessage(message, action);
2727
if (answer === action) {
28-
await vscode.commands.executeCommand("java.helper.showExtension", extName);
28+
await vscode.commands.executeCommand("java.helper.installExtension", extName, extName);
2929
}
3030
}
3131

0 commit comments

Comments
 (0)