Skip to content

Commit 67432bb

Browse files
committed
debug viewlet show progress
fixes microsoft#92253
1 parent 61c2257 commit 67432bb

4 files changed

Lines changed: 63 additions & 6 deletions

File tree

src/vs/workbench/contrib/debug/browser/debugSession.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,14 @@ export class DebugSession implements IDebugSession {
603603
}, token);
604604
}
605605

606+
async cancel(progressId: string): Promise<DebugProtocol.CancelResponse> {
607+
if (!this.raw) {
608+
return Promise.reject(new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'cancel')));
609+
}
610+
611+
return this.raw.cancel({ progressId });
612+
}
613+
606614
//---- threads
607615

608616
getThread(threadId: number): Thread | undefined {

src/vs/workbench/contrib/debug/browser/debugViewlet.ts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
import 'vs/css!./media/debugViewlet';
77
import * as nls from 'vs/nls';
8-
import { IAction } from 'vs/base/common/actions';
8+
import { IAction, Action } from 'vs/base/common/actions';
99
import * as DOM from 'vs/base/browser/dom';
10+
import { Event } from 'vs/base/common/event';
1011
import { 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';
1213
import { StartAction, ConfigureAction, SelectAndStartAction, FocusSessionAction } from 'vs/workbench/contrib/debug/browser/debugActions';
1314
import { StartDebugActionViewItem, FocusSessionActionViewItem } from 'vs/workbench/contrib/debug/browser/debugActionViewItems';
1415
import { 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 {

src/vs/workbench/contrib/debug/common/debug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export interface IDebugSession extends ITreeElement {
223223
variables(variablesReference: number, threadId: number | undefined, filter: 'indexed' | 'named' | undefined, start: number | undefined, count: number | undefined): Promise<DebugProtocol.VariablesResponse>;
224224
evaluate(expression: string, frameId?: number, context?: string): Promise<DebugProtocol.EvaluateResponse>;
225225
customRequest(request: string, args: any): Promise<DebugProtocol.Response>;
226+
cancel(progressId: string): Promise<DebugProtocol.CancelResponse>;
226227

227228
restartFrame(frameId: number, threadId: number): Promise<void>;
228229
next(threadId: number): Promise<void>;

src/vs/workbench/contrib/debug/test/common/mockDebug.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ export class MockDebugService implements IDebugService {
134134

135135
export class MockSession implements IDebugSession {
136136

137+
cancel(_progressId: string): Promise<DebugProtocol.CancelResponse> {
138+
throw new Error('Method not implemented.');
139+
}
140+
137141
breakpointsLocations(uri: uri, lineNumber: number): Promise<IPosition[]> {
138142
throw new Error('Method not implemented.');
139143
}

0 commit comments

Comments
 (0)