55
66import * as nls from 'vs/nls' ;
77import { Action } from 'vs/base/common/actions' ;
8- import * as lifecycle from 'vs/base/common/lifecycle' ;
98import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
109import { IWorkspaceContextService , WorkbenchState } from 'vs/platform/workspace/common/workspace' ;
1110import { IDebugService , State , IEnablement , IBreakpoint , IDebugSession } from 'vs/workbench/contrib/debug/common/debug' ;
@@ -16,16 +15,16 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
1615import { IHistoryService } from 'vs/workbench/services/history/common/history' ;
1716import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService' ;
1817import { startDebugging } from 'vs/workbench/contrib/debug/common/debugUtils' ;
18+ import { IDisposable , dispose } from 'vs/base/common/lifecycle' ;
1919
2020export abstract class AbstractDebugAction extends Action {
2121
22- protected toDispose : lifecycle . IDisposable [ ] ;
22+ protected toDispose : IDisposable [ ] ;
2323
2424 constructor (
2525 id : string , label : string , cssClass : string ,
2626 @IDebugService protected debugService : IDebugService ,
2727 @IKeybindingService protected keybindingService : IKeybindingService ,
28- public weight ?: number
2928 ) {
3029 super ( id , label , cssClass , false ) ;
3130 this . toDispose = [ ] ;
@@ -35,11 +34,11 @@ export abstract class AbstractDebugAction extends Action {
3534 this . updateEnablement ( ) ;
3635 }
3736
38- public run ( e ? : any ) : Promise < any > {
37+ run ( _ : any ) : Promise < any > {
3938 throw new Error ( 'implement me' ) ;
4039 }
4140
42- public get tooltip ( ) : string {
41+ get tooltip ( ) : string {
4342 const keybinding = this . keybindingService . lookupKeybinding ( this . id ) ;
4443 const keybindingLabel = keybinding && keybinding . getLabel ( ) ;
4544
@@ -54,13 +53,13 @@ export abstract class AbstractDebugAction extends Action {
5453 this . enabled = this . isEnabled ( state ) ;
5554 }
5655
57- protected isEnabled ( state : State ) : boolean {
56+ protected isEnabled ( _ : State ) : boolean {
5857 return true ;
5958 }
6059
61- public dispose ( ) : void {
60+ dispose ( ) : void {
6261 super . dispose ( ) ;
63- this . toDispose = lifecycle . dispose ( this . toDispose ) ;
62+ this . toDispose = dispose ( this . toDispose ) ;
6463 }
6564}
6665
@@ -79,7 +78,7 @@ export class ConfigureAction extends AbstractDebugAction {
7978 this . updateClass ( ) ;
8079 }
8180
82- public get tooltip ( ) : string {
81+ get tooltip ( ) : string {
8382 if ( this . debugService . getConfigurationManager ( ) . selectedConfiguration . name ) {
8483 return ConfigureAction . LABEL ;
8584 }
@@ -93,7 +92,7 @@ export class ConfigureAction extends AbstractDebugAction {
9392 this . class = configurationCount > 0 ? 'debug-action configure' : 'debug-action configure notification' ;
9493 }
9594
96- public run ( event ?: any ) : Promise < any > {
95+ run ( event ?: any ) : Promise < any > {
9796 if ( this . contextService . getWorkbenchState ( ) === WorkbenchState . EMPTY ) {
9897 this . notificationService . info ( nls . localize ( 'noFolderDebugConfig' , "Please first open a folder in order to do advanced debug configuration." ) ) ;
9998 return Promise . resolve ( ) ;
@@ -127,15 +126,15 @@ export class StartAction extends AbstractDebugAction {
127126 this . toDispose . push ( this . contextService . onDidChangeWorkbenchState ( ( ) => this . updateEnablement ( ) ) ) ;
128127 }
129128
130- public run ( ) : Promise < boolean > {
129+ run ( ) : Promise < boolean > {
131130 return startDebugging ( this . debugService , this . historyService , this . isNoDebug ( ) ) ;
132131 }
133132
134133 protected isNoDebug ( ) : boolean {
135134 return false ;
136135 }
137136
138- public static isEnabled ( debugService : IDebugService ) {
137+ static isEnabled ( debugService : IDebugService ) {
139138 const sessions = debugService . getModel ( ) . getSessions ( ) ;
140139
141140 if ( debugService . state === State . Initializing ) {
@@ -176,7 +175,7 @@ export class SelectAndStartAction extends AbstractDebugAction {
176175 super ( id , label , '' , debugService , keybindingService ) ;
177176 }
178177
179- public run ( ) : Promise < any > {
178+ run ( ) : Promise < any > {
180179 return this . quickOpenService . show ( 'debug ' ) ;
181180 }
182181}
@@ -189,7 +188,7 @@ export class RemoveBreakpointAction extends Action {
189188 super ( id , label , 'debug-action remove' ) ;
190189 }
191190
192- public run ( breakpoint : IBreakpoint ) : Promise < any > {
191+ run ( breakpoint : IBreakpoint ) : Promise < any > {
193192 return breakpoint instanceof Breakpoint ? this . debugService . removeBreakpoints ( breakpoint . getId ( ) )
194193 : breakpoint instanceof FunctionBreakpoint ? this . debugService . removeFunctionBreakpoints ( breakpoint . getId ( ) ) : this . debugService . removeDataBreakpoints ( breakpoint . getId ( ) ) ;
195194 }
@@ -204,13 +203,13 @@ export class RemoveAllBreakpointsAction extends AbstractDebugAction {
204203 this . toDispose . push ( this . debugService . getModel ( ) . onDidChangeBreakpoints ( ( ) => this . updateEnablement ( ) ) ) ;
205204 }
206205
207- public run ( ) : Promise < any > {
206+ run ( ) : Promise < any > {
208207 return Promise . all ( [ this . debugService . removeBreakpoints ( ) , this . debugService . removeFunctionBreakpoints ( ) , this . debugService . removeDataBreakpoints ( ) ] ) ;
209208 }
210209
211- protected isEnabled ( state : State ) : boolean {
210+ protected isEnabled ( _ : State ) : boolean {
212211 const model = this . debugService . getModel ( ) ;
213- return super . isEnabled ( state ) && ( model . getBreakpoints ( ) . length > 0 || model . getFunctionBreakpoints ( ) . length > 0 || model . getDataBreakpoints ( ) . length > 0 ) ;
212+ return ( model . getBreakpoints ( ) . length > 0 || model . getFunctionBreakpoints ( ) . length > 0 || model . getDataBreakpoints ( ) . length > 0 ) ;
214213 }
215214}
216215
@@ -223,13 +222,13 @@ export class EnableAllBreakpointsAction extends AbstractDebugAction {
223222 this . toDispose . push ( this . debugService . getModel ( ) . onDidChangeBreakpoints ( ( ) => this . updateEnablement ( ) ) ) ;
224223 }
225224
226- public run ( ) : Promise < any > {
225+ run ( ) : Promise < any > {
227226 return this . debugService . enableOrDisableBreakpoints ( true ) ;
228227 }
229228
230- protected isEnabled ( state : State ) : boolean {
229+ protected isEnabled ( _ : State ) : boolean {
231230 const model = this . debugService . getModel ( ) ;
232- return super . isEnabled ( state ) && ( < ReadonlyArray < IEnablement > > model . getBreakpoints ( ) ) . concat ( model . getFunctionBreakpoints ( ) ) . concat ( model . getExceptionBreakpoints ( ) ) . some ( bp => ! bp . enabled ) ;
231+ return ( < ReadonlyArray < IEnablement > > model . getBreakpoints ( ) ) . concat ( model . getFunctionBreakpoints ( ) ) . concat ( model . getExceptionBreakpoints ( ) ) . some ( bp => ! bp . enabled ) ;
233232 }
234233}
235234
@@ -242,13 +241,13 @@ export class DisableAllBreakpointsAction extends AbstractDebugAction {
242241 this . toDispose . push ( this . debugService . getModel ( ) . onDidChangeBreakpoints ( ( ) => this . updateEnablement ( ) ) ) ;
243242 }
244243
245- public run ( ) : Promise < any > {
244+ run ( ) : Promise < any > {
246245 return this . debugService . enableOrDisableBreakpoints ( false ) ;
247246 }
248247
249- protected isEnabled ( state : State ) : boolean {
248+ protected isEnabled ( _ : State ) : boolean {
250249 const model = this . debugService . getModel ( ) ;
251- return super . isEnabled ( state ) && ( < ReadonlyArray < IEnablement > > model . getBreakpoints ( ) ) . concat ( model . getFunctionBreakpoints ( ) ) . concat ( model . getExceptionBreakpoints ( ) ) . some ( bp => bp . enabled ) ;
250+ return ( < ReadonlyArray < IEnablement > > model . getBreakpoints ( ) ) . concat ( model . getFunctionBreakpoints ( ) ) . concat ( model . getExceptionBreakpoints ( ) ) . some ( bp => bp . enabled ) ;
252251 }
253252}
254253
@@ -267,11 +266,11 @@ export class ToggleBreakpointsActivatedAction extends AbstractDebugAction {
267266 } ) ) ;
268267 }
269268
270- public run ( ) : Promise < any > {
269+ run ( ) : Promise < any > {
271270 return this . debugService . setBreakpointsActivated ( ! this . debugService . getModel ( ) . areBreakpointsActivated ( ) ) ;
272271 }
273272
274- protected isEnabled ( state : State ) : boolean {
273+ protected isEnabled ( _ : State ) : boolean {
275274 return ! ! ( this . debugService . getModel ( ) . getFunctionBreakpoints ( ) . length || this . debugService . getModel ( ) . getBreakpoints ( ) . length || this . debugService . getModel ( ) . getDataBreakpoints ( ) . length ) ;
276275 }
277276}
@@ -285,13 +284,13 @@ export class ReapplyBreakpointsAction extends AbstractDebugAction {
285284 this . toDispose . push ( this . debugService . getModel ( ) . onDidChangeBreakpoints ( ( ) => this . updateEnablement ( ) ) ) ;
286285 }
287286
288- public run ( ) : Promise < any > {
287+ run ( ) : Promise < any > {
289288 return this . debugService . setBreakpointsActivated ( true ) ;
290289 }
291290
292291 protected isEnabled ( state : State ) : boolean {
293292 const model = this . debugService . getModel ( ) ;
294- return super . isEnabled ( state ) && ( state === State . Running || state === State . Stopped ) &&
293+ return ( state === State . Running || state === State . Stopped ) &&
295294 ( ( model . getFunctionBreakpoints ( ) . length + model . getBreakpoints ( ) . length + model . getExceptionBreakpoints ( ) . length + model . getDataBreakpoints ( ) . length ) > 0 ) ;
296295 }
297296}
@@ -305,12 +304,12 @@ export class AddFunctionBreakpointAction extends AbstractDebugAction {
305304 this . toDispose . push ( this . debugService . getModel ( ) . onDidChangeBreakpoints ( ( ) => this . updateEnablement ( ) ) ) ;
306305 }
307306
308- public run ( ) : Promise < any > {
307+ run ( ) : Promise < any > {
309308 this . debugService . addFunctionBreakpoint ( ) ;
310309 return Promise . resolve ( ) ;
311310 }
312311
313- protected isEnabled ( state : State ) : boolean {
312+ protected isEnabled ( _ : State ) : boolean {
314313 return ! this . debugService . getViewModel ( ) . getSelectedFunctionBreakpoint ( )
315314 && this . debugService . getModel ( ) . getFunctionBreakpoints ( ) . every ( fbp => ! ! fbp . name ) ;
316315 }
@@ -326,14 +325,14 @@ export class AddWatchExpressionAction extends AbstractDebugAction {
326325 this . toDispose . push ( this . debugService . getViewModel ( ) . onDidSelectExpression ( ( ) => this . updateEnablement ( ) ) ) ;
327326 }
328327
329- public run ( ) : Promise < any > {
328+ run ( ) : Promise < any > {
330329 this . debugService . addWatchExpression ( ) ;
331330 return Promise . resolve ( undefined ) ;
332331 }
333332
334- protected isEnabled ( state : State ) : boolean {
333+ protected isEnabled ( _ : State ) : boolean {
335334 const focusedExpression = this . debugService . getViewModel ( ) . getSelectedExpression ( ) ;
336- return super . isEnabled ( state ) && this . debugService . getModel ( ) . getWatchExpressions ( ) . every ( we => ! ! we . name && we !== focusedExpression ) ;
335+ return this . debugService . getModel ( ) . getWatchExpressions ( ) . every ( we => ! ! we . name && we !== focusedExpression ) ;
337336 }
338337}
339338
@@ -346,13 +345,13 @@ export class RemoveAllWatchExpressionsAction extends AbstractDebugAction {
346345 this . toDispose . push ( this . debugService . getModel ( ) . onDidChangeWatchExpressions ( ( ) => this . updateEnablement ( ) ) ) ;
347346 }
348347
349- public run ( ) : Promise < any > {
348+ run ( ) : Promise < any > {
350349 this . debugService . removeWatchExpressions ( ) ;
351350 return Promise . resolve ( ) ;
352351 }
353352
354- protected isEnabled ( state : State ) : boolean {
355- return super . isEnabled ( state ) && this . debugService . getModel ( ) . getWatchExpressions ( ) . length > 0 ;
353+ protected isEnabled ( _ : State ) : boolean {
354+ return this . debugService . getModel ( ) . getWatchExpressions ( ) . length > 0 ;
356355 }
357356}
358357
@@ -365,10 +364,10 @@ export class FocusSessionAction extends AbstractDebugAction {
365364 @IKeybindingService keybindingService : IKeybindingService ,
366365 @IEditorService private readonly editorService : IEditorService
367366 ) {
368- super ( id , label , '' , debugService , keybindingService , 100 ) ;
367+ super ( id , label , '' , debugService , keybindingService ) ;
369368 }
370369
371- public run ( session : IDebugSession ) : Promise < any > {
370+ run ( session : IDebugSession ) : Promise < any > {
372371 this . debugService . focusStackFrame ( undefined , undefined , session , true ) ;
373372 const stackFrame = this . debugService . getViewModel ( ) . focusedStackFrame ;
374373 if ( stackFrame ) {
@@ -392,17 +391,19 @@ export class CopyValueAction extends Action {
392391 this . _enabled = typeof this . value === 'string' || ( this . value instanceof Variable && ! ! this . value . evaluateName ) ;
393392 }
394393
395- public run ( ) : Promise < any > {
394+ async run ( ) : Promise < any > {
396395 const stackFrame = this . debugService . getViewModel ( ) . focusedStackFrame ;
397396 const session = this . debugService . getViewModel ( ) . focusedSession ;
398397
399398 if ( this . value instanceof Variable && stackFrame && session && this . value . evaluateName ) {
400- return session . evaluate ( this . value . evaluateName , stackFrame . frameId , this . context ) . then ( result => {
401- return this . clipboardService . writeText ( result . body . result ) ;
402- } , err => this . clipboardService . writeText ( this . value . value ) ) ;
399+ try {
400+ const evaluation = await session . evaluate ( this . value . evaluateName , stackFrame . frameId , this . context ) ;
401+ this . clipboardService . writeText ( evaluation . body . result ) ;
402+ } catch ( e ) {
403+ this . clipboardService . writeText ( this . value . value ) ;
404+ }
403405 }
404406
405-
406407 return this . clipboardService . writeText ( this . value ) ;
407408 }
408409}
0 commit comments