@@ -9,6 +9,8 @@ import { IFeature } from "../feature";
9
9
10
10
export const EvaluateRequestType = new RequestType < IEvaluateRequestArguments , void , void , void > ( "evaluate" ) ;
11
11
export const OutputNotificationType = new NotificationType < IOutputNotificationBody , void > ( "output" ) ;
12
+ export const ExecutionStatusChangedNotificationType =
13
+ new NotificationType < IExecutionStatusDetails , void > ( "powerShell/executionStatusChanged" ) ;
12
14
13
15
export const ShowChoicePromptRequestType =
14
16
new RequestType < IShowChoicePromptRequestArgs ,
@@ -27,6 +29,12 @@ export interface IOutputNotificationBody {
27
29
output : string ;
28
30
}
29
31
32
+ interface IExecutionStatusDetails {
33
+ executionOptions : IExecutionOptions ;
34
+ executionStatus : ExecutionStatus ;
35
+ hadErrors : boolean ;
36
+ }
37
+
30
38
interface IChoiceDetails {
31
39
label : string ;
32
40
helpMessage : string ;
@@ -55,6 +63,21 @@ interface IShowInputPromptResponseBody {
55
63
promptCancelled : boolean ;
56
64
}
57
65
66
+ enum ExecutionStatus {
67
+ Pending ,
68
+ Running ,
69
+ Failed ,
70
+ Aborted ,
71
+ Completed ,
72
+ }
73
+
74
+ interface IExecutionOptions {
75
+ writeOutputToHost : boolean ;
76
+ writeErrorsToHost : boolean ;
77
+ addToHistory : boolean ;
78
+ interruptCommandPrompt : boolean ;
79
+ }
80
+
58
81
function showChoicePrompt (
59
82
promptDetails : IShowChoicePromptRequestArgs ,
60
83
client : LanguageClient ) : Thenable < IShowChoicePromptResponseBody > {
@@ -175,6 +198,7 @@ function onInputEntered(responseText: string): IShowInputPromptResponseBody {
175
198
export class ConsoleFeature implements IFeature {
176
199
private commands : vscode . Disposable [ ] ;
177
200
private languageClient : LanguageClient ;
201
+ private resolveStatusBarPromise : ( value ?: { } | PromiseLike < { } > ) => void ;
178
202
179
203
constructor ( ) {
180
204
this . commands = [
@@ -207,6 +231,8 @@ export class ConsoleFeature implements IFeature {
207
231
}
208
232
209
233
public dispose ( ) {
234
+ // Make sure we cancel any status bar
235
+ this . clearStatusBar ( ) ;
210
236
this . commands . forEach ( ( command ) => command . dispose ( ) ) ;
211
237
}
212
238
@@ -220,5 +246,44 @@ export class ConsoleFeature implements IFeature {
220
246
this . languageClient . onRequest (
221
247
ShowInputPromptRequestType ,
222
248
( promptDetails ) => showInputPrompt ( promptDetails , this . languageClient ) ) ;
249
+
250
+ // Set up status bar alerts for when PowerShell is executing a script
251
+ this . languageClient . onNotification (
252
+ ExecutionStatusChangedNotificationType ,
253
+ ( executionStatusDetails ) => {
254
+ switch ( executionStatusDetails . executionStatus ) {
255
+ // If execution has changed to running, make a notification
256
+ case ExecutionStatus . Running :
257
+ this . showExecutionStatus ( "PowerShell" ) ;
258
+ break ;
259
+
260
+ // If the execution has stopped, destroy the previous notification
261
+ case ExecutionStatus . Completed :
262
+ case ExecutionStatus . Aborted :
263
+ case ExecutionStatus . Failed :
264
+ this . clearStatusBar ( ) ;
265
+ break ;
266
+ }
267
+ } ) ;
268
+
269
+ }
270
+
271
+ private showExecutionStatus ( message : string ) {
272
+ vscode . window . withProgress ( {
273
+ location : vscode . ProgressLocation . Window ,
274
+ } , ( progress ) => {
275
+ return new Promise ( ( resolve , reject ) => {
276
+ this . clearStatusBar ( ) ;
277
+
278
+ this . resolveStatusBarPromise = resolve ;
279
+ progress . report ( { message } ) ;
280
+ } ) ;
281
+ } ) ;
282
+ }
283
+
284
+ private clearStatusBar ( ) {
285
+ if ( this . resolveStatusBarPromise ) {
286
+ this . resolveStatusBarPromise ( ) ;
287
+ }
223
288
}
224
289
}
0 commit comments