Skip to content

Commit cb9c438

Browse files
committed
Live connect command UI shown info message if no running apps found
1 parent 2543bdf commit cb9c438

File tree

1 file changed

+63
-28
lines changed

1 file changed

+63
-28
lines changed

vscode-extensions/vscode-spring-boot/lib/live-hover-connect-ui.ts

+63-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import * as VSCode from 'vscode';
21
import { LanguageClient } from "vscode-languageclient/node";
32
import { ActivatorOptions } from '@pivotal-tools/commons-vscode';
4-
import { commands, window } from 'vscode';
3+
import { ExtensionContext, QuickPickItem, commands, window } from 'vscode';
54

65
interface ProcessCommandInfo {
76
processKey : string;
@@ -22,17 +21,26 @@ export interface RemoteBootApp {
2221
projectName?: string;
2322
}
2423

24+
interface BootAppQuickPick extends QuickPickItem {
25+
commandInfo: ProcessCommandInfo;
26+
}
27+
2528
type BootAppState = "none" | "connecting" | "connected" | "disconnecting" | "disconnected";
2629

2730
let activeBootApp: RemoteBootApp | undefined;
2831
let state: BootAppState
2932

3033
async function liveHoverConnectHandler() {
31-
//sts.vscode-spring-boot.codeAction
32-
const processData : ProcessCommandInfo[] = await VSCode.commands.executeCommand('sts/livedata/listProcesses');
33-
const choiceMap = new Map<string, ProcessCommandInfo>();
34-
const choices : string[] = [];
35-
processData.forEach(p => {
34+
const quickPick = window.createQuickPick<BootAppQuickPick>();
35+
quickPick.title = 'Searching for running Spring Boot Apps...';
36+
quickPick.canSelectMany = true;
37+
quickPick.canSelectMany = false;
38+
quickPick.busy = true;
39+
quickPick.show();
40+
41+
const processData : ProcessCommandInfo[] = await commands.executeCommand('sts/livedata/listProcesses');
42+
43+
const items = processData.map(p => {
3644
let actionLabel = "";
3745
switch (p.action) {
3846
case "sts/livedata/connect":
@@ -46,28 +54,55 @@ async function liveHoverConnectHandler() {
4654
break;
4755
}
4856
const choiceLabel = actionLabel + " Live Data from: " + p.label;
49-
choiceMap.set(choiceLabel, p);
50-
choices.push(choiceLabel);
57+
return {
58+
commandInfo: p,
59+
label: choiceLabel
60+
} as BootAppQuickPick;
61+
5162
});
52-
if (choices) {
53-
const picked = await VSCode.window.showQuickPick(choices);
54-
if (picked) {
55-
const chosen = choiceMap.get(picked);
56-
if (activeBootApp?.jmxurl === chosen.processKey) {
57-
switch (chosen.action) {
58-
case "sts/livedata/connect":
59-
await commands.executeCommand('vscode-spring-boot.live.show.active');
60-
break;
61-
case "sts/livedata/disconnect":
62-
await commands.executeCommand('vscode-spring-boot.live.hide.active');
63-
break;
64-
default:
65-
await VSCode.commands.executeCommand(chosen.action, chosen);
66-
}
67-
} else {
68-
await VSCode.commands.executeCommand(chosen.action, chosen);
63+
64+
quickPick.busy = false;
65+
66+
quickPick.title = items.length ? "Select action for running Spring Boot App" : "No running Spring Boot Apps found";
67+
68+
quickPick.items = items;
69+
70+
if (!items.length) {
71+
quickPick.hide();
72+
window.showInformationMessage("No running Spring Boot Apps found");
73+
return;
74+
}
75+
76+
return await new Promise((resolve, reject) => {
77+
quickPick.onDidChangeSelection(() => quickPick.hide());
78+
quickPick.onDidHide(async () => {
79+
try {
80+
const chosen = quickPick.selectedItems ? quickPick.selectedItems[0] : undefined;
81+
if (chosen) {
82+
executeLiveProcessAction(chosen.commandInfo);
83+
}
84+
resolve(undefined);
85+
} catch (error) {
86+
reject(error);
6987
}
70-
}
88+
})
89+
});
90+
}
91+
92+
async function executeLiveProcessAction(commandInfo: ProcessCommandInfo) {
93+
if (activeBootApp?.jmxurl === commandInfo.processKey) {
94+
switch (commandInfo.action) {
95+
case "sts/livedata/connect":
96+
await commands.executeCommand('vscode-spring-boot.live.show.active');
97+
break;
98+
case "sts/livedata/disconnect":
99+
await commands.executeCommand('vscode-spring-boot.live.hide.active');
100+
break;
101+
default:
102+
await commands.executeCommand(commandInfo.action, commandInfo);
103+
}
104+
} else {
105+
await commands.executeCommand(commandInfo.action, commandInfo);
71106
}
72107
}
73108

@@ -82,7 +117,7 @@ async function updateBootAppState(newState: BootAppState) {
82117
export function activate(
83118
client: LanguageClient,
84119
options: ActivatorOptions,
85-
context: VSCode.ExtensionContext
120+
context: ExtensionContext
86121
) {
87122
context.subscriptions.push(
88123

0 commit comments

Comments
 (0)