@@ -20,36 +20,46 @@ export interface OutputNotificationBody {
20
20
output : string ;
21
21
}
22
22
23
- export namespace ShowChoicePromptNotification {
24
- export const type : NotificationType < ShowChoicePromptNotificationBody > =
23
+ export namespace ShowChoicePromptRequest {
24
+ export const type : RequestType < ShowChoicePromptRequestArgs , ShowChoicePromptResponseBody , string > =
25
25
{ get method ( ) { return 'powerShell/showChoicePrompt' ; } } ;
26
26
}
27
27
28
+ export namespace ShowInputPromptRequest {
29
+ export const type : RequestType < ShowInputPromptRequestArgs , ShowInputPromptResponseBody , string > =
30
+ { get method ( ) { return 'powerShell/showInputPrompt' ; } } ;
31
+ }
32
+
28
33
interface ChoiceDetails {
29
34
label : string ;
30
35
helpMessage : string ;
31
36
}
32
37
33
- interface ShowChoicePromptNotificationBody {
38
+ interface ShowInputPromptRequestArgs {
39
+ name : string ;
40
+ label : string ;
41
+ }
42
+
43
+ interface ShowChoicePromptRequestArgs {
34
44
caption : string ;
35
45
message : string ;
36
46
choices : ChoiceDetails [ ] ;
37
47
defaultChoice : number ;
38
48
}
39
49
40
- export namespace CompleteChoicePromptNotification {
41
- export const type : NotificationType < CompleteChoicePromptNotificationBody > =
42
- { get method ( ) { return 'powerShell/completeChoicePrompt' ; } } ;
50
+ interface ShowChoicePromptResponseBody {
51
+ chosenItem : string ;
52
+ promptCancelled : boolean ;
43
53
}
44
54
45
- interface CompleteChoicePromptNotificationBody {
46
- chosenItem : string ;
55
+ interface ShowInputPromptResponseBody {
56
+ responseText : string ;
47
57
promptCancelled : boolean ;
48
58
}
49
59
50
60
function showChoicePrompt (
51
- promptDetails : ShowChoicePromptNotificationBody ,
52
- client : LanguageClient ) {
61
+ promptDetails : ShowChoicePromptRequestArgs ,
62
+ client : LanguageClient ) : Thenable < ShowChoicePromptResponseBody > {
53
63
54
64
var quickPickItems =
55
65
promptDetails . choices . map < vscode . QuickPickItem > ( choice => {
@@ -71,24 +81,60 @@ function showChoicePrompt(
71
81
quickPickItems = [ defaultChoiceItem ] . concat ( quickPickItems ) ;
72
82
}
73
83
74
- vscode . window
75
- . showQuickPick (
76
- quickPickItems ,
77
- { placeHolder : promptDetails . caption + " - " + promptDetails . message } )
78
- . then ( chosenItem => onItemSelected ( chosenItem , client ) ) ;
84
+ // For some bizarre reason, the quick pick dialog does not
85
+ // work if I return the Thenable immediately at this point.
86
+ // It only works if I save the thenable to a variable and
87
+ // return the variable instead...
88
+ var resultThenable =
89
+ vscode . window
90
+ . showQuickPick (
91
+ quickPickItems ,
92
+ { placeHolder : promptDetails . caption + " - " + promptDetails . message } )
93
+ . then ( onItemSelected ) ;
94
+
95
+ return resultThenable ;
79
96
}
80
97
81
- function onItemSelected ( chosenItem : vscode . QuickPickItem , client : LanguageClient ) {
98
+ function showInputPrompt (
99
+ promptDetails : ShowInputPromptRequestArgs ,
100
+ client : LanguageClient ) : Thenable < ShowInputPromptResponseBody > {
101
+
102
+ var resultThenable =
103
+ vscode . window . showInputBox ( {
104
+ placeHolder : promptDetails . name + ": "
105
+ } ) . then ( onInputEntered )
106
+
107
+ return resultThenable ;
108
+ }
109
+
110
+ function onItemSelected ( chosenItem : vscode . QuickPickItem ) : ShowChoicePromptResponseBody {
82
111
if ( chosenItem !== undefined ) {
83
- client . sendNotification (
84
- CompleteChoicePromptNotification . type ,
85
- { chosenItem : chosenItem . label } ) ;
112
+ return {
113
+ promptCancelled : false ,
114
+ chosenItem : chosenItem . label
115
+ } ;
86
116
}
87
117
else {
88
118
// User cancelled the prompt, send the cancellation
89
- client . sendNotification (
90
- CompleteChoicePromptNotification . type ,
91
- { promptCancelled : true } ) ;
119
+ return {
120
+ promptCancelled : true ,
121
+ chosenItem : undefined
122
+ } ;
123
+ }
124
+ }
125
+
126
+ function onInputEntered ( responseText : string ) : ShowInputPromptResponseBody {
127
+ if ( responseText !== undefined ) {
128
+ return {
129
+ promptCancelled : false ,
130
+ responseText : responseText
131
+ }
132
+ }
133
+ else {
134
+ return {
135
+ promptCancelled : true ,
136
+ responseText : undefined
137
+ }
92
138
}
93
139
}
94
140
@@ -118,7 +164,13 @@ export function registerConsoleCommands(client: LanguageClient): void {
118
164
consoleChannel . append ( output . output ) ;
119
165
} ) ;
120
166
121
- client . onNotification (
122
- ShowChoicePromptNotification . type ,
167
+ var t : Thenable < ShowChoicePromptResponseBody > ;
168
+
169
+ client . onRequest (
170
+ ShowChoicePromptRequest . type ,
123
171
promptDetails => showChoicePrompt ( promptDetails , client ) ) ;
172
+
173
+ client . onRequest (
174
+ ShowInputPromptRequest . type ,
175
+ promptDetails => showInputPrompt ( promptDetails , client ) ) ;
124
176
}
0 commit comments