diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index 426262c77..48053e1a0 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -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); + } + 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) + }; + } else { + return { + result: this.convertToHex(v.value) || ('<' + v.type + '>'), variablesReference: v.children.length > 0 ? this._variableHandles.create(v) : 0 }; }