Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Fix for #1990 #2020

Merged
merged 9 commits into from
Nov 1, 2018
38 changes: 35 additions & 3 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ interface DebugVariable {
cap: number;
children: DebugVariable[];
unreadable: string;
fqn: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does fqn stand for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fully Qualified Name.Should I change the field name to Fully Qualified Name?

}

interface ListGoroutinesOut {
Expand Down Expand Up @@ -808,6 +809,14 @@ class GoDebugSession extends DebugSession {
}
const locals = this.delve.isApiV1 ? <DebugVariable[]>out : (<ListVarsOut>out).Variables;
verbose('locals', locals);
locals.every(local => {
local.fqn = local.name;
local.children.every(child => {
child.fqn = local.name;
return true;
});
return true;
})
let listLocalFunctionArgsIn = { goroutineID: this.debugState.currentGoroutine.id, frame: args.frameId };
this.delve.call<DebugVariable[] | ListFunctionArgsOut>('ListFunctionArgs', this.delve.isApiV1 ? [listLocalFunctionArgsIn] : [{ scope: listLocalFunctionArgsIn, cfg: this.delve.loadConfig }], (err, outArgs) => {
if (err) {
Expand All @@ -816,8 +825,17 @@ class GoDebugSession extends DebugSession {
}
const args = this.delve.isApiV1 ? <DebugVariable[]>outArgs : (<ListFunctionArgsOut>outArgs).Args;
verbose('functionArgs', args);
args.every(local => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I repeated this instead of creating a function because of the const and my understanding is that const variables can't be reassigned right? js noob here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of which const? The one on args?
The const only means that you cannot re-assign the array object. But it doesnt stop you from iterating over the contents and changing them.

local.fqn = local.name;
local.children.every(child => {
child.fqn = local.name;
return true;
});
return true;
})
let vars = args.concat(locals);


let scopes = new Array<Scope>();
let localVariables = {
name: 'Local',
Expand All @@ -829,8 +847,10 @@ class GoDebugSession extends DebugSession {
len: 0,
cap: 0,
children: vars,
unreadable: ''
unreadable: '',
fqn: '',
};

scopes.push(new Scope('Local', this._variableHandles.create(localVariables), false));
response.body = { scopes };

Expand All @@ -850,7 +870,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;
}
}
Expand All @@ -869,7 +889,8 @@ class GoDebugSession extends DebugSession {
len: 0,
cap: 0,
children: globals,
unreadable: ''
unreadable: '',
fqn: '',
};
scopes.push(new Scope('Global', this._variableHandles.create(globalVariables), false));
this.sendResponse(response);
Expand Down Expand Up @@ -922,6 +943,13 @@ class GoDebugSession extends DebugSession {
variablesReference: 0
};
} else {
if (v.children[0].children.length > 0) {
v.children[0].fqn = v.fqn;
v.children[0].children.every(child => {
child.fqn = v.fqn + '.' + child.name;
return true;
});
}
return {
result: '<' + v.type + '>',
variablesReference: v.children[0].children.length > 0 ? this._variableHandles.create(v.children[0]) : 0
Expand Down Expand Up @@ -965,6 +993,7 @@ class GoDebugSession extends DebugSession {
return {
name: '[' + i + ']',
value: result,
evaluateName: vari.fqn + '[' + i + ']',
variablesReference
};
});
Expand All @@ -979,15 +1008,18 @@ class GoDebugSession extends DebugSession {
variables.push({
name: mapKey.result,
value: mapValue.result,
evaluateName: vari.fqn + '[' + mapKey.result + ']',
variablesReference: mapValue.variablesReference
});
}
} else {
variables = vari.children.map((v, i) => {
let { result, variablesReference } = this.convertDebugVariableToProtocolVariable(v, i);
v.fqn = v.fqn == undefined ? vari.fqn + '.' + v.name : v.fqn;
return {
name: v.name,
value: result,
evaluateName: v.fqn == undefined ? vari.fqn + '.' + v.name : v.fqn,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cant we just use v.fqn here as it already has the right value?

variablesReference
};
});
Expand Down