From cb6257afbb6d9b54baf22c4319efc5ca403e757c Mon Sep 17 00:00:00 2001 From: Kaarthik Rao Bekal Radhakrishna Date: Thu, 1 Nov 2018 06:35:15 +0100 Subject: [PATCH] Fix for #1990 (#2020) * Fixed copying values from variables in debug mode * fixed missing evaluateName for array type * Fixed evaluateName * Formeatting * Incorporated review comments * Changed fqn -> fullyQualifiedName * Slight refactoring --- src/debugAdapter/goDebug.ts | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index df18adf27..343e4dfd5 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -157,6 +157,7 @@ interface DebugVariable { cap: number; children: DebugVariable[]; unreadable: string; + fullyQualifiedName: string; } interface ListGoroutinesOut { @@ -808,6 +809,7 @@ class GoDebugSession extends DebugSession { } const locals = this.delve.isApiV1 ? out : (out).Variables; verbose('locals', locals); + this.addFullyQualifiedName(locals); let listLocalFunctionArgsIn = { goroutineID: this.debugState.currentGoroutine.id, frame: args.frameId }; this.delve.call('ListFunctionArgs', this.delve.isApiV1 ? [listLocalFunctionArgsIn] : [{ scope: listLocalFunctionArgsIn, cfg: this.delve.loadConfig }], (err, outArgs) => { if (err) { @@ -816,6 +818,7 @@ class GoDebugSession extends DebugSession { } const args = this.delve.isApiV1 ? outArgs : (outArgs).Args; verbose('functionArgs', args); + this.addFullyQualifiedName(args); let vars = args.concat(locals); let scopes = new Array(); @@ -829,8 +832,10 @@ class GoDebugSession extends DebugSession { len: 0, cap: 0, children: vars, - unreadable: '' + unreadable: '', + fullyQualifiedName: '', }; + scopes.push(new Scope('Local', this._variableHandles.create(localVariables), false)); response.body = { scopes }; @@ -850,7 +855,7 @@ class GoDebugSession extends DebugSession { let initdoneIndex = -1; for (let i = 0; i < globals.length; i++) { globals[i].name = globals[i].name.substr(packageName.length + 1); - if (initdoneIndex === -1 && globals[i].name === this.initdone) { + if (initdoneIndex === -1 && globals[i].name === this.initdone) { initdoneIndex = i; } } @@ -869,7 +874,8 @@ class GoDebugSession extends DebugSession { len: 0, cap: 0, children: globals, - unreadable: '' + unreadable: '', + fullyQualifiedName: '', }; scopes.push(new Scope('Global', this._variableHandles.create(globalVariables), false)); this.sendResponse(response); @@ -922,6 +928,12 @@ class GoDebugSession extends DebugSession { variablesReference: 0 }; } else { + if (v.children[0].children.length > 0) { + v.children[0].fullyQualifiedName = v.fullyQualifiedName; + v.children[0].children.forEach(child => { + child.fullyQualifiedName = v.fullyQualifiedName + '.' + child.name; + }); + } return { result: '<' + v.type + '>', variablesReference: v.children[0].children.length > 0 ? this._variableHandles.create(v.children[0]) : 0 @@ -965,6 +977,7 @@ class GoDebugSession extends DebugSession { return { name: '[' + i + ']', value: result, + evaluateName: vari.fullyQualifiedName + '[' + i + ']', variablesReference }; }); @@ -979,15 +992,20 @@ class GoDebugSession extends DebugSession { variables.push({ name: mapKey.result, value: mapValue.result, + evaluateName: vari.fullyQualifiedName + '[' + mapKey.result + ']', variablesReference: mapValue.variablesReference }); } } else { variables = vari.children.map((v, i) => { let { result, variablesReference } = this.convertDebugVariableToProtocolVariable(v, i); + if (v.fullyQualifiedName === undefined) { + v.fullyQualifiedName = vari.fullyQualifiedName + '.' + v.name; + } return { name: v.name, value: result, + evaluateName: v.fullyQualifiedName, variablesReference }; }); @@ -1140,6 +1158,15 @@ class GoDebugSession extends DebugSession { verbose('EvaluateResponse'); }); } + + private addFullyQualifiedName(variables: DebugVariable[]) { + variables.forEach(local => { + local.fullyQualifiedName = local.name; + local.children.forEach(child => { + child.fullyQualifiedName = local.name; + }); + }); + } } function random(low: number, high: number): number {