55
66import 'vs/css!./media/debugViewlet' ;
77import * as nls from 'vs/nls' ;
8- import { IAction } from 'vs/base/common/actions' ;
8+ import { IAction , Action } from 'vs/base/common/actions' ;
99import * as DOM from 'vs/base/browser/dom' ;
10+ import { Event } from 'vs/base/common/event' ;
1011import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar' ;
11- import { IDebugService , VIEWLET_ID , State , BREAKPOINTS_VIEW_ID , IDebugConfiguration , DEBUG_PANEL_ID , CONTEXT_DEBUG_UX , CONTEXT_DEBUG_UX_KEY } from 'vs/workbench/contrib/debug/common/debug' ;
12+ import { IDebugService , VIEWLET_ID , State , BREAKPOINTS_VIEW_ID , IDebugConfiguration , DEBUG_PANEL_ID , CONTEXT_DEBUG_UX , CONTEXT_DEBUG_UX_KEY , IDebugSession } from 'vs/workbench/contrib/debug/common/debug' ;
1213import { StartAction , ConfigureAction , SelectAndStartAction , FocusSessionAction } from 'vs/workbench/contrib/debug/browser/debugActions' ;
1314import { StartDebugActionViewItem , FocusSessionActionViewItem } from 'vs/workbench/contrib/debug/browser/debugActionViewItems' ;
1415import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
@@ -43,6 +44,7 @@ export class DebugViewPaneContainer extends ViewPaneContainer {
4344 private paneListeners = new Map < string , IDisposable > ( ) ;
4445 private debugToolBarMenu : IMenu | undefined ;
4546 private disposeOnTitleUpdate : IDisposable | undefined ;
47+ private progressEvents : { event : DebugProtocol . ProgressStartEvent , session : IDebugSession } [ ] = [ ] ;
4648
4749 constructor (
4850 @IWorkbenchLayoutService layoutService : IWorkbenchLayoutService ,
@@ -79,6 +81,34 @@ export class DebugViewPaneContainer extends ViewPaneContainer {
7981 this . updateTitleArea ( ) ;
8082 }
8183 } ) ) ;
84+
85+ let progressListener : IDisposable ;
86+ this . _register ( this . debugService . getViewModel ( ) . onDidFocusSession ( session => {
87+ if ( progressListener ) {
88+ progressListener . dispose ( ) ;
89+ }
90+ if ( session ) {
91+ progressListener = session . onDidProgressStart ( async progressStartEvent => {
92+ // Update title area to show the cancel progress action
93+ this . progressEvents . push ( { session : session , event : progressStartEvent } ) ;
94+ this . cancelAction . tooltip = nls . localize ( 'cancelProgress' , "Cancel {0}" , progressStartEvent . body . title ) ;
95+ this . updateTitleArea ( ) ;
96+ await this . progressService . withProgress ( { location : VIEWLET_ID } , ( ) => {
97+ return new Promise ( r => {
98+ // Show progress until a progress end event comes or the session ends
99+ const listener = Event . any ( Event . filter ( session . onDidProgressEnd , e => e . body . progressId === progressStartEvent . body . progressId ) ,
100+ session . onDidEndAdapter ) ( ( ) => {
101+ listener . dispose ( ) ;
102+ r ( ) ;
103+ } ) ;
104+ } ) ;
105+ } ) ;
106+ this . cancelAction . tooltip = nls . localize ( 'cancel' , "Cancel" ) ;
107+ this . progressEvents = this . progressEvents . filter ( pe => pe . event . body . progressId !== progressStartEvent . body . progressId ) ;
108+ this . updateTitleArea ( ) ;
109+ } ) ;
110+ }
111+ } ) ) ;
82112 }
83113
84114 create ( parent : HTMLElement ) : void {
@@ -111,6 +141,14 @@ export class DebugViewPaneContainer extends ViewPaneContainer {
111141 return this . _register ( this . instantiationService . createInstance ( OpenDebugPanelAction , OpenDebugPanelAction . ID , OpenDebugPanelAction . LABEL ) ) ;
112142 }
113143
144+ @memoize
145+ private get cancelAction ( ) : Action {
146+ return this . _register ( new Action ( 'debug.cancelProgress' , nls . localize ( 'cancel' , "Cancel" ) , 'debug-action codicon codicon-stop' , true , async ( ) => {
147+ let { event, session } = this . progressEvents [ this . progressEvents . length - 1 ] ;
148+ await session . cancel ( event . body . progressId ) ;
149+ } ) ) ;
150+ }
151+
114152 @memoize
115153 private get selectAndStartAction ( ) : SelectAndStartAction {
116154 return this . _register ( this . instantiationService . createInstance ( SelectAndStartAction , SelectAndStartAction . ID , nls . localize ( 'startAdditionalSession' , "Start Additional Session" ) ) ) ;
@@ -120,6 +158,8 @@ export class DebugViewPaneContainer extends ViewPaneContainer {
120158 if ( CONTEXT_DEBUG_UX . getValue ( this . contextKeyService ) === 'simple' ) {
121159 return [ ] ;
122160 }
161+
162+ let result : IAction [ ] ;
123163 if ( ! this . showInitialDebugActions ) {
124164
125165 if ( ! this . debugToolBarMenu ) {
@@ -133,14 +173,18 @@ export class DebugViewPaneContainer extends ViewPaneContainer {
133173 }
134174 this . disposeOnTitleUpdate = disposable ;
135175
136- return actions ;
176+ result = actions ;
177+ } else if ( this . contextService . getWorkbenchState ( ) === WorkbenchState . EMPTY ) {
178+ result = [ this . toggleReplAction ] ;
179+ } else {
180+ result = [ this . startAction , this . configureAction , this . toggleReplAction ] ;
137181 }
138182
139- if ( this . contextService . getWorkbenchState ( ) === WorkbenchState . EMPTY ) {
140- return [ this . toggleReplAction ] ;
183+ if ( this . progressEvents . length ) {
184+ result . unshift ( this . cancelAction ) ;
141185 }
142186
143- return [ this . startAction , this . configureAction , this . toggleReplAction ] ;
187+ return result ;
144188 }
145189
146190 get showInitialDebugActions ( ) : boolean {
0 commit comments