Skip to content

Commit 739e5f8

Browse files
authored
Handle custom radix event (#221)
* handling custom event for radix change * making both commands available when a third radix option is chosen Fixes #219
1 parent a08366e commit 739e5f8

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@
7777
"command": "cdt.debug.setOutputRadixToHex",
7878
"category": "CDT-GDB",
7979
"title": "Set Global Output Radix to Hex",
80-
"enablement": "cdt.debug.outputRadix == 'decimal'"
80+
"enablement": "cdt.debug.outputRadix != 'hexadecimal'"
8181
},
8282
{
8383
"command": "cdt.debug.setOutputRadixToDecimal",
8484
"category": "CDT-GDB",
8585
"title": "Set Global Output Radix to Decimal",
86-
"enablement": "cdt.debug.outputRadix == 'hexadecimal'"
86+
"enablement": "cdt.debug.outputRadix != 'decimal'"
8787
},
8888
{
8989
"title": "CDT-GDB: Set Hardware Breakpoint",
@@ -900,36 +900,36 @@
900900
"debug/watch/context": [
901901
{
902902
"command": "cdt.debug.setOutputRadixToHex",
903-
"when": "inDebugMode && cdt.debug.outputRadix == 'decimal' && (debugType == gdb || debugType == gdbtarget)",
903+
"when": "inDebugMode && cdt.debug.outputRadix != 'hexadecimal' && (debugType == gdb || debugType == gdbtarget)",
904904
"group": "z_commands"
905905
},
906906
{
907907
"command": "cdt.debug.setOutputRadixToDecimal",
908-
"when": "inDebugMode && cdt.debug.outputRadix == 'hexadecimal' && (debugType == gdb || debugType == gdbtarget)",
908+
"when": "inDebugMode && cdt.debug.outputRadix != 'decimal' && (debugType == gdb || debugType == gdbtarget)",
909909
"group": "z_commands"
910910
}
911911
],
912912
"debug/variables/context": [
913913
{
914914
"command": "cdt.debug.setOutputRadixToHex",
915-
"when": "inDebugMode && cdt.debug.outputRadix == 'decimal' && (debugType == gdb || debugType == gdbtarget)",
915+
"when": "inDebugMode && cdt.debug.outputRadix != 'hexadecimal' && (debugType == gdb || debugType == gdbtarget)",
916916
"group": "z_commands"
917917
},
918918
{
919919
"command": "cdt.debug.setOutputRadixToDecimal",
920-
"when": "inDebugMode && cdt.debug.outputRadix == 'hexadecimal' && (debugType == gdb || debugType == gdbtarget)",
920+
"when": "inDebugMode && cdt.debug.outputRadix != 'decimal' && (debugType == gdb || debugType == gdbtarget)",
921921
"group": "z_commands"
922922
}
923923
],
924924
"editor/context": [
925925
{
926926
"command": "cdt.debug.setOutputRadixToHex",
927-
"when": "inDebugMode && cdt.debug.outputRadix == 'decimal' && (debugType == gdb || debugType == gdbtarget)",
927+
"when": "inDebugMode && cdt.debug.outputRadix != 'hexadecimal' && (debugType == gdb || debugType == gdbtarget)",
928928
"group": "z_commands"
929929
},
930930
{
931931
"command": "cdt.debug.setOutputRadixToDecimal",
932-
"when": "inDebugMode && cdt.debug.outputRadix == 'hexadecimal' && (debugType == gdb || debugType == gdbtarget)",
932+
"when": "inDebugMode && cdt.debug.outputRadix != 'decimal' && (debugType == gdb || debugType == gdbtarget)",
933933
"group": "z_commands"
934934
},
935935
{

src/switchRadix.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import * as vscode from 'vscode';
1212
import { DebugProtocol } from '@vscode/debugprotocol';
1313

14-
type Radix = 'hexadecimal' | 'decimal';
14+
type Radix = 'hexadecimal' | 'decimal' | 'others';
1515

1616
export class SwitchRadix {
1717
private _sessionsMap: Map<string, Radix> = new Map();
@@ -20,9 +20,25 @@ export class SwitchRadix {
2020
vscode.debug.onDidStartDebugSession((session) => this.addCurrentRadixContext(session));
2121
vscode.debug.onDidTerminateDebugSession((session) => this._sessionsMap.delete(session.id));
2222
vscode.commands.executeCommand('setContext', 'cdt.debug.outputRadix', 'decimal');
23+
vscode.debug.onDidReceiveDebugSessionCustomEvent((event) => this.handleOnDidReceiveCustomEvent(event));
2324
this.registerCommands(context);
2425
}
2526

27+
private handleOnDidReceiveCustomEvent(event: vscode.DebugSessionCustomEvent) {
28+
if(event.session.type === 'gdb' || event.session.type === 'gdbtarget') {
29+
if (event.event === 'OutputRadixUpdated') {
30+
if(event.body.radix === '16' || event.body.radix === '10') {
31+
const radix = event.body.radix === '16' ? 'hexadecimal' : 'decimal';
32+
this._sessionsMap.set(event.session.id, radix);
33+
vscode.commands.executeCommand('setContext', 'cdt.debug.outputRadix', radix);
34+
} else {
35+
vscode.commands.executeCommand('setContext', 'cdt.debug.outputRadix', 'others');
36+
this._sessionsMap.set(event.session.id, 'others');
37+
}
38+
}
39+
}
40+
}
41+
2642
private addCurrentRadixContext(session: vscode.DebugSession) {
2743
if (!this._sessionsMap.has(session.id)) {
2844
this._sessionsMap.set(session.id, 'decimal');
@@ -38,7 +54,6 @@ export class SwitchRadix {
3854
const existingSessionRadix = this._sessionsMap.get(session.id);
3955
if (existingSessionRadix) {
4056
vscode.commands.executeCommand('setContext', 'cdt.debug.outputRadix', existingSessionRadix);
41-
this.handleSetOutputRadix(existingSessionRadix);
4257
return;
4358
}
4459
}

0 commit comments

Comments
 (0)