4
4
5
5
import vscode = require( 'vscode' ) ;
6
6
import { IFeature } from '../feature' ;
7
+ import { showCheckboxQuickPick , CheckboxQuickPickItem } from '../checkboxQuickPick'
7
8
import { LanguageClient , RequestType , NotificationType } from 'vscode-languageclient' ;
8
9
9
10
export namespace EvaluateRequest {
@@ -46,14 +47,15 @@ interface ShowInputPromptRequestArgs {
46
47
}
47
48
48
49
interface ShowChoicePromptRequestArgs {
50
+ isMultiChoice : boolean ;
49
51
caption : string ;
50
52
message : string ;
51
53
choices : ChoiceDetails [ ] ;
52
- defaultChoice : number ;
54
+ defaultChoices : number [ ] ;
53
55
}
54
56
55
57
interface ShowChoicePromptResponseBody {
56
- chosenItem : string ;
58
+ responseText : string ;
57
59
promptCancelled : boolean ;
58
60
}
59
61
@@ -66,36 +68,62 @@ function showChoicePrompt(
66
68
promptDetails : ShowChoicePromptRequestArgs ,
67
69
client : LanguageClient ) : Thenable < ShowChoicePromptResponseBody > {
68
70
69
- var quickPickItems =
70
- promptDetails . choices . map < vscode . QuickPickItem > ( choice => {
71
- return {
72
- label : choice . label ,
73
- description : choice . helpMessage
74
- }
75
- } ) ;
71
+ var resultThenable : Thenable < ShowChoicePromptResponseBody > = undefined ;
72
+
73
+ if ( ! promptDetails . isMultiChoice ) {
74
+ var quickPickItems =
75
+ promptDetails . choices . map < vscode . QuickPickItem > ( choice => {
76
+ return {
77
+ label : choice . label ,
78
+ description : choice . helpMessage
79
+ }
80
+ } ) ;
81
+
82
+ if ( promptDetails . defaultChoices &&
83
+ promptDetails . defaultChoices . length > 0 ) {
76
84
77
- // Shift the default item to the front of the
78
- // array so that the user can select it easily
79
- if ( promptDetails . defaultChoice > - 1 &&
80
- promptDetails . defaultChoice < promptDetails . choices . length ) {
85
+ // Shift the default items to the front of the
86
+ // array so that the user can select it easily
87
+ var defaultChoice = promptDetails . defaultChoices [ 0 ] ;
88
+ if ( defaultChoice > - 1 &&
89
+ defaultChoice < promptDetails . choices . length ) {
81
90
82
- var defaultChoiceItem = quickPickItems [ promptDetails . defaultChoice ] ;
83
- quickPickItems . splice ( promptDetails . defaultChoice , 1 ) ;
91
+ var defaultChoiceItem = quickPickItems [ defaultChoice ] ;
92
+ quickPickItems . splice ( defaultChoice , 1 ) ;
84
93
85
- // Add the default choice to the head of the array
86
- quickPickItems = [ defaultChoiceItem ] . concat ( quickPickItems ) ;
94
+ // Add the default choice to the head of the array
95
+ quickPickItems = [ defaultChoiceItem ] . concat ( quickPickItems ) ;
96
+ }
97
+ }
98
+
99
+ resultThenable =
100
+ vscode . window
101
+ . showQuickPick (
102
+ quickPickItems ,
103
+ { placeHolder : promptDetails . caption + " - " + promptDetails . message } )
104
+ . then ( onItemSelected ) ;
87
105
}
106
+ else {
107
+ var checkboxQuickPickItems =
108
+ promptDetails . choices . map < CheckboxQuickPickItem > ( choice => {
109
+ return {
110
+ label : choice . label ,
111
+ description : choice . helpMessage ,
112
+ isSelected : false
113
+ }
114
+ } ) ;
88
115
89
- // For some bizarre reason, the quick pick dialog does not
90
- // work if I return the Thenable immediately at this point.
91
- // It only works if I save the thenable to a variable and
92
- // return the variable instead...
93
- var resultThenable =
94
- vscode . window
95
- . showQuickPick (
96
- quickPickItems ,
97
- { placeHolder : promptDetails . caption + " - " + promptDetails . message } )
98
- . then ( onItemSelected ) ;
116
+ // Select the defaults
117
+ promptDetails . defaultChoices . forEach ( choiceIndex => {
118
+ checkboxQuickPickItems [ choiceIndex ] . isSelected = true
119
+ } ) ;
120
+
121
+ resultThenable =
122
+ showCheckboxQuickPick (
123
+ checkboxQuickPickItems ,
124
+ { confirmPlaceHolder : `${ promptDetails . caption } - ${ promptDetails . message } ` } )
125
+ . then ( onItemsSelected ) ;
126
+ }
99
127
100
128
return resultThenable ;
101
129
}
@@ -112,18 +140,34 @@ function showInputPrompt(
112
140
return resultThenable ;
113
141
}
114
142
143
+ function onItemsSelected ( chosenItems : CheckboxQuickPickItem [ ] ) : ShowChoicePromptResponseBody {
144
+ if ( chosenItems !== undefined ) {
145
+ return {
146
+ promptCancelled : false ,
147
+ responseText : chosenItems . filter ( item => item . isSelected ) . map ( item => item . label ) . join ( ", " )
148
+ } ;
149
+ }
150
+ else {
151
+ // User cancelled the prompt, send the cancellation
152
+ return {
153
+ promptCancelled : true ,
154
+ responseText : undefined
155
+ } ;
156
+ }
157
+ }
158
+
115
159
function onItemSelected ( chosenItem : vscode . QuickPickItem ) : ShowChoicePromptResponseBody {
116
160
if ( chosenItem !== undefined ) {
117
161
return {
118
162
promptCancelled : false ,
119
- chosenItem : chosenItem . label
163
+ responseText : chosenItem . label
120
164
} ;
121
165
}
122
166
else {
123
167
// User cancelled the prompt, send the cancellation
124
168
return {
125
169
promptCancelled : true ,
126
- chosenItem : undefined
170
+ responseText : undefined
127
171
} ;
128
172
}
129
173
}
0 commit comments