Skip to content

Commit cde8e1e

Browse files
authored
Display banner once debugging has terminated (#2009)
Fixes #2008
1 parent e585a15 commit cde8e1e

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

src/client/common/application/debugService.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import { IDebugService } from './types';
99

1010
@injectable()
1111
export class DebugService implements IDebugService {
12-
public get onDidStartDebugSession(): Event<DebugSession>{
12+
public get onDidStartDebugSession(): Event<DebugSession> {
1313
return debug.onDidStartDebugSession;
1414
}
15+
public get onDidTerminateDebugSession(): Event<DebugSession> {
16+
return debug.onDidTerminateDebugSession;
17+
}
1518
public startDebugging(folder: WorkspaceFolder | undefined, nameOrConfiguration: string | DebugConfiguration): Thenable<boolean> {
1619
return debug.startDebugging(folder, nameOrConfiguration);
1720
}

src/client/common/application/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,11 @@ export interface IDebugService {
539539
* An [event](#Event) which fires when a new [debug session](#DebugSession) has been started.
540540
*/
541541
onDidStartDebugSession: Event<DebugSession>;
542+
543+
/**
544+
* An [event](#Event) which fires when a [debug session](#DebugSession) has terminated.
545+
*/
546+
onDidTerminateDebugSession: Event<DebugSession>;
542547
/**
543548
* Start debugging by using either a named launch or named compound configuration,
544549
* or by directly passing a [DebugConfiguration](#DebugConfiguration).

src/client/debugger/banner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ export class ExperimentalDebuggerBanner implements IExperimentalDebuggerBanner {
3939
return;
4040
}
4141
const debuggerService = this.serviceContainer.get<IDebugService>(IDebugService);
42-
const disposable = debuggerService.onDidStartDebugSession(async e => {
42+
const disposable = debuggerService.onDidTerminateDebugSession(async e => {
4343
if (e.type === ExperimentalDebuggerType) {
4444
const logger = this.serviceContainer.get<ILogger>(ILogger);
45-
await this.onDebugSessionStarted()
45+
await this.onDidTerminateDebugSession()
4646
.catch(ex => logger.logError('Error in debugger Banner', ex));
4747
}
4848
});
@@ -114,7 +114,7 @@ export class ExperimentalDebuggerBanner implements IExperimentalDebuggerBanner {
114114
const num = parseInt(`0x${lastHexValue}`, 16);
115115
return isNaN(num) ? crypto.randomBytes(1).toString('hex').slice(-1) : lastHexValue;
116116
}
117-
private async onDebugSessionStarted(): Promise<void> {
117+
private async onDidTerminateDebugSession(): Promise<void> {
118118
if (!this.enabled) {
119119
return;
120120
}

src/test/debugger/banner.unit.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ suite('Debugging - Banner', () => {
7070
browser.verifyAll();
7171
});
7272
test('Increment Debugger Launch Counter when debug session starts', async () => {
73-
let onDidStartDebugSessionCb: (e: DebugSession) => Promise<void>;
74-
debugService.setup(d => d.onDidStartDebugSession(typemoq.It.isAny()))
75-
.callback(cb => onDidStartDebugSessionCb = cb)
73+
let onDidTerminateDebugSessionCb: (e: DebugSession) => Promise<void>;
74+
debugService.setup(d => d.onDidTerminateDebugSession(typemoq.It.isAny()))
75+
.callback(cb => onDidTerminateDebugSessionCb = cb)
7676
.verifiable(typemoq.Times.once());
7777

7878
const debuggerLaunchCounter = 1234;
@@ -84,15 +84,15 @@ suite('Debugging - Banner', () => {
8484
.verifiable(typemoq.Times.atLeastOnce());
8585

8686
banner.initialize();
87-
await onDidStartDebugSessionCb!({ type: ExperimentalDebuggerType } as any);
87+
await onDidTerminateDebugSessionCb!({ type: ExperimentalDebuggerType } as any);
8888

8989
launchCounterState.verifyAll();
9090
browser.verifyAll();
9191
debugService.verifyAll();
9292
showBannerState.verifyAll();
9393
});
9494
test('Do not Increment Debugger Launch Counter when debug session starts and Banner is disabled', async () => {
95-
debugService.setup(d => d.onDidStartDebugSession(typemoq.It.isAny()))
95+
debugService.setup(d => d.onDidTerminateDebugSession(typemoq.It.isAny()))
9696
.verifiable(typemoq.Times.never());
9797

9898
const debuggerLaunchCounter = 1234;
@@ -147,11 +147,11 @@ suite('Debugging - Banner', () => {
147147
launchThresholdCounterState.verifyAll();
148148
});
149149
test('showBanner must be invoked when shouldShowBanner returns true', async () => {
150-
let onDidStartDebugSessionCb: (e: DebugSession) => Promise<void>;
150+
let onDidTerminateDebugSessionCb: (e: DebugSession) => Promise<void>;
151151
const currentLaunchCounter = 50;
152152

153-
debugService.setup(d => d.onDidStartDebugSession(typemoq.It.isAny()))
154-
.callback(cb => onDidStartDebugSessionCb = cb)
153+
debugService.setup(d => d.onDidTerminateDebugSession(typemoq.It.isAny()))
154+
.callback(cb => onDidTerminateDebugSessionCb = cb)
155155
.verifiable(typemoq.Times.atLeastOnce());
156156
showBannerState.setup(s => s.value).returns(() => true)
157157
.verifiable(typemoq.Times.atLeastOnce());
@@ -166,19 +166,19 @@ suite('Debugging - Banner', () => {
166166
appShell.setup(a => a.showInformationMessage(typemoq.It.isValue(message), typemoq.It.isValue(yes), typemoq.It.isValue(no)))
167167
.verifiable(typemoq.Times.once());
168168
banner.initialize();
169-
await onDidStartDebugSessionCb!({ type: ExperimentalDebuggerType } as any);
169+
await onDidTerminateDebugSessionCb!({ type: ExperimentalDebuggerType } as any);
170170

171171
appShell.verifyAll();
172172
showBannerState.verifyAll();
173173
launchCounterState.verifyAll();
174174
launchThresholdCounterState.verifyAll();
175175
});
176176
test('showBanner must not be invoked the second time after dismissing the message', async () => {
177-
let onDidStartDebugSessionCb: (e: DebugSession) => Promise<void>;
177+
let onDidTerminateDebugSessionCb: (e: DebugSession) => Promise<void>;
178178
let currentLaunchCounter = 50;
179179

180-
debugService.setup(d => d.onDidStartDebugSession(typemoq.It.isAny()))
181-
.callback(cb => onDidStartDebugSessionCb = cb)
180+
debugService.setup(d => d.onDidTerminateDebugSession(typemoq.It.isAny()))
181+
.callback(cb => onDidTerminateDebugSessionCb = cb)
182182
.verifiable(typemoq.Times.atLeastOnce());
183183
showBannerState.setup(s => s.value).returns(() => true)
184184
.verifiable(typemoq.Times.atLeastOnce());
@@ -193,10 +193,10 @@ suite('Debugging - Banner', () => {
193193
.returns(() => Promise.resolve(undefined))
194194
.verifiable(typemoq.Times.once());
195195
banner.initialize();
196-
await onDidStartDebugSessionCb!({ type: ExperimentalDebuggerType } as any);
197-
await onDidStartDebugSessionCb!({ type: ExperimentalDebuggerType } as any);
198-
await onDidStartDebugSessionCb!({ type: ExperimentalDebuggerType } as any);
199-
await onDidStartDebugSessionCb!({ type: ExperimentalDebuggerType } as any);
196+
await onDidTerminateDebugSessionCb!({ type: ExperimentalDebuggerType } as any);
197+
await onDidTerminateDebugSessionCb!({ type: ExperimentalDebuggerType } as any);
198+
await onDidTerminateDebugSessionCb!({ type: ExperimentalDebuggerType } as any);
199+
await onDidTerminateDebugSessionCb!({ type: ExperimentalDebuggerType } as any);
200200

201201
appShell.verifyAll();
202202
showBannerState.verifyAll();

0 commit comments

Comments
 (0)