Skip to content

Commit 85c5dab

Browse files
authored
Correctly handle debug-tracker-vscode terminated event (#64)
* #63: Handle session ID and full session info for `onWillStopSession` Signed-off-by: Jens Reinecke <jens.reinecke@arm.com> * changelog Signed-off-by: Jens Reinecke <jens.reinecke@arm.com> * review feedback Signed-off-by: Jens Reinecke <jens.reinecke@arm.com> --------- Signed-off-by: Jens Reinecke <jens.reinecke@arm.com>
1 parent 48eec46 commit 85c5dab

4 files changed

Lines changed: 23 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
### Bug Fixes
66

7-
- [#16](https://github.com/eclipse-cdt-cloud/vscode-peripheral-inspector/issues/60): Rework peripheral read strategy and peripheral-inspector.svdAddrGapThreshold
7+
- [#16](https://github.com/eclipse-cdt-cloud/vscode-peripheral-inspector/issues/60): Rework peripheral read strategy and peripheral-inspector.svdAddrGapThreshold ([Thorsten de Buhr](https://github.com/thorstendb-ARM/))
8+
- [#63](https://github.com/eclipse-cdt-cloud/vscode-peripheral-inspector/issues/63): Peripheral Inspector does not clear on disconnect if using debug-tracker-vscode ([Jens Reinecke](https://github.com/jreineckearm))
89

910
## [v1.7.0] - 2025-03-31
1011

src/debug-tracker.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const DEBUG_TRACKER_EXTENSION = 'mcu-debug.debug-tracker-vscode';
1212
interface IDebuggerTrackerEvent {
1313
event: DebugSessionStatus;
1414
session?: vscode.DebugSession;
15+
sessionId?: string;
1516
}
1617

1718
interface IDebuggerTrackerSubscribeArgBodyV1 {
@@ -44,8 +45,8 @@ export class DebugTracker {
4445
private _onWillStartSession: vscode.EventEmitter<vscode.DebugSession> = new vscode.EventEmitter<vscode.DebugSession>();
4546
public readonly onWillStartSession: vscode.Event<vscode.DebugSession> = this._onWillStartSession.event;
4647

47-
private _onWillStopSession: vscode.EventEmitter<vscode.DebugSession> = new vscode.EventEmitter<vscode.DebugSession>();
48-
public readonly onWillStopSession: vscode.Event<vscode.DebugSession> = this._onWillStopSession.event;
48+
private _onWillStopSession: vscode.EventEmitter<string | vscode.DebugSession> = new vscode.EventEmitter<string | vscode.DebugSession>();
49+
public readonly onWillStopSession: vscode.Event<string | vscode.DebugSession> = this._onWillStopSession.event;
4950

5051
private _onDidStopDebug: vscode.EventEmitter<vscode.DebugSession> = new vscode.EventEmitter<vscode.DebugSession>();
5152
public readonly onDidStopDebug: vscode.Event<vscode.DebugSession> = this._onDidStopDebug.event;
@@ -65,8 +66,11 @@ export class DebugTracker {
6566
if (event.event === DebugSessionStatus.Initializing && event.session) {
6667
this.handleOnWillStartSession(event.session);
6768
}
68-
if (event.event === DebugSessionStatus.Terminated && event.session) {
69-
this.handleOnWillStopSession(event.session);
69+
if (event.event === DebugSessionStatus.Terminated) {
70+
const terminatedEventInfo = event.session ?? event.sessionId;
71+
if (terminatedEventInfo) {
72+
this.handleOnWillStopSession(terminatedEventInfo);
73+
}
7074
}
7175
if (event.event === DebugSessionStatus.Stopped && event.session) {
7276
this.handleOnDidStopDebug(event.session);
@@ -104,7 +108,7 @@ export class DebugTracker {
104108
this._onWillStartSession.fire(session);
105109
}
106110

107-
private handleOnWillStopSession(session: vscode.DebugSession): void {
111+
private handleOnWillStopSession(session: string | vscode.DebugSession): void {
108112
this._onWillStopSession.fire(session);
109113
}
110114

src/model/peripheral/tree/peripheral-configuration-provider.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ export class PeripheralConfigurationProvider {
1313
this.sessionConfigurationEmitter.set(session.id, {});
1414
});
1515
tracker.onWillStopSession(session => {
16-
this.sessionConfiguration.delete(session.id);
17-
const sessionConfigurationPropertyEmitters = this.sessionConfigurationEmitter.get(session.id);
16+
const sessionId = typeof session === 'string' ? session : session.id;
17+
this.sessionConfiguration.delete(sessionId);
18+
const sessionConfigurationPropertyEmitters = this.sessionConfigurationEmitter.get(sessionId);
1819
if (sessionConfigurationPropertyEmitters) {
1920
Object.keys(sessionConfigurationPropertyEmitters).forEach(key => sessionConfigurationPropertyEmitters[key].dispose());
2021
}
21-
this.sessionConfigurationEmitter.delete(session.id);
22+
this.sessionConfigurationEmitter.delete(sessionId);
2223
});
2324
}
2425

src/model/peripheral/tree/peripheral-data-tracker.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,18 @@ export class PeripheralDataTracker {
334334
this.refreshContext();
335335
}
336336

337-
protected onDebugSessionTerminated(session: vscode.DebugSession): void {
338-
if (!this.sessionPeripherals.get(session.id)) {
337+
protected onDebugSessionTerminated(session: string | vscode.DebugSession): void {
338+
const isSessionId = typeof session === 'string';
339+
const sessionId = isSessionId ? session : session.id;
340+
if (!this.sessionPeripherals.get(sessionId)) {
339341
return;
340342
}
341-
const regs = this.sessionPeripherals.get(session.id);
343+
const regs = this.sessionPeripherals.get(sessionId);
342344

343345
if (regs) {
344-
this.oldState.set(session.name, regs.expanded);
345-
this.sessionPeripherals.delete(session.id);
346+
const sessionName = isSessionId ? regs.name : session.name;
347+
this.oldState.set(sessionName, regs.expanded);
348+
this.sessionPeripherals.delete(sessionId);
346349
regs.sessionTerminated(this.context);
347350
this.onDidTerminateEvent.fire({
348351
data: regs,

0 commit comments

Comments
 (0)