1
- import * as VSCode from 'vscode' ;
2
1
import { LanguageClient } from "vscode-languageclient/node" ;
3
2
import { ActivatorOptions } from '@pivotal-tools/commons-vscode' ;
4
- import { commands , window } from 'vscode' ;
3
+ import { ExtensionContext , QuickPickItem , commands , window } from 'vscode' ;
5
4
6
5
interface ProcessCommandInfo {
7
6
processKey : string ;
@@ -22,17 +21,26 @@ export interface RemoteBootApp {
22
21
projectName ?: string ;
23
22
}
24
23
24
+ interface BootAppQuickPick extends QuickPickItem {
25
+ commandInfo : ProcessCommandInfo ;
26
+ }
27
+
25
28
type BootAppState = "none" | "connecting" | "connected" | "disconnecting" | "disconnected" ;
26
29
27
30
let activeBootApp : RemoteBootApp | undefined ;
28
31
let state : BootAppState
29
32
30
33
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 => {
36
44
let actionLabel = "" ;
37
45
switch ( p . action ) {
38
46
case "sts/livedata/connect" :
@@ -46,28 +54,55 @@ async function liveHoverConnectHandler() {
46
54
break ;
47
55
}
48
56
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
+
51
62
} ) ;
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 ) ;
69
87
}
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 ) ;
71
106
}
72
107
}
73
108
@@ -82,7 +117,7 @@ async function updateBootAppState(newState: BootAppState) {
82
117
export function activate (
83
118
client : LanguageClient ,
84
119
options : ActivatorOptions ,
85
- context : VSCode . ExtensionContext
120
+ context : ExtensionContext
86
121
) {
87
122
context . subscriptions . push (
88
123
0 commit comments