-
Notifications
You must be signed in to change notification settings - Fork 651
launch.json env option to display numbers as hex while debugging #1801
Changes from all commits
7a701ce
6d29324
d2579a5
2725d1c
8357368
c04c08b
0ad9cac
badfcdd
66e43c7
e89cdbb
83c54b7
e8b84ea
57c84f3
4a9dbf2
467a288
d5cfce6
ec4ade2
9c45da1
d782002
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ import * as logger from 'vscode-debug-logger'; | |
require('console-stamp')(console); | ||
|
||
// This enum should stay in sync with https://golang.org/pkg/reflect/#Kind | ||
|
||
enum GoReflectKind { | ||
Invalid = 0, | ||
Bool, | ||
|
@@ -50,7 +49,6 @@ enum GoReflectKind { | |
|
||
// These types should stay in sync with: | ||
// https://github.com/derekparker/delve/blob/master/service/api/types.go | ||
|
||
interface CommandOut { | ||
State: DebuggerState; | ||
} | ||
|
@@ -492,7 +490,7 @@ class GoDebugSession extends DebugSession { | |
private delve: Delve; | ||
private localPathSeparator: string; | ||
private remotePathSeparator: string; | ||
|
||
private numAsHex: string; | ||
private launchArgs: LaunchRequestArguments; | ||
|
||
public constructor(debuggerLinesStartAt1: boolean, isServer: boolean = false) { | ||
|
@@ -519,6 +517,19 @@ class GoDebugSession extends DebugSession { | |
if (/^(\w:[\\/]|\\\\)/.test(path)) return '\\'; | ||
return path.includes('/') ? '/' : '\\'; | ||
} | ||
protected convertToHex(v) { | ||
let s = v; | ||
if (this.numAsHex === 'hex') { | ||
s = '0x' + parseInt(v).toString(16); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will truncate floating-point numbers. Perhaps this functionality should be limited to integers? |
||
} | ||
else if (this.numAsHex === 'hexdec') { | ||
s = '0x' + parseInt(v).toString(16) + ' (' + v + ')'; | ||
} | ||
else if (this.numAsHex === 'hexascii') { | ||
s = '0x' + parseInt(v).toString(16) + ' (' + String.fromCharCode(v) + ')'; | ||
} | ||
return s; | ||
} | ||
|
||
protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void { | ||
this.launchArgs = args; | ||
|
@@ -533,6 +544,12 @@ class GoDebugSession extends DebugSession { | |
return; | ||
} | ||
|
||
// controls numbers display while debugging | ||
// "hex" (shows hex only), "hexdec" ( shows hex (dec) ), "hexascii" ( shows hex (ascii) ) | ||
// default: shows dec only | ||
// "DBG_SHOW_NUMBERS_HEX": "hex" | ||
this.numAsHex = args.env['DBG_SHOW_NUMBERS_HEX']; | ||
|
||
// Launch the Delve debugger on the program | ||
let localPath = args.program; | ||
let remotePath = args.remotePath || ''; | ||
|
@@ -844,9 +861,14 @@ class GoDebugSession extends DebugSession { | |
result: v.unreadable ? ('<' + v.unreadable + '>') : ('"' + val + '"'), | ||
variablesReference: 0 | ||
}; | ||
} else { | ||
} else if (v.kind === GoReflectKind.Bool) { | ||
return { | ||
result: v.value || ('<' + v.type + '>'), | ||
variablesReference: this._variableHandles.create(v) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is incorrect and will cause boolean types to display like they have child elements. It should remain |
||
}; | ||
} else { | ||
return { | ||
result: this.convertToHex(v.value) || ('<' + v.type + '>'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For types |
||
variablesReference: v.children.length > 0 ? this._variableHandles.create(v) : 0 | ||
}; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sig should be
private convertToHex(v: string): string
. Also missing a new-line character between 519 and 520.