From 2d2e7cd1add78ce03e1c3714d5b440777cc98e18 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Thu, 17 Jan 2019 14:42:27 -0800 Subject: [PATCH 1/3] Fix display of shadowed variables while debugging Ensure that shadowed variables have a unique name so they are properly displayed in the variables pane. Each nested scope will enclose the variable name in a pair of parentheses. --- src/debugAdapter/goDebug.ts | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index 042d5a3f1..046c43d4d 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -45,6 +45,14 @@ enum GoReflectKind { UnsafePointer } +enum GoVariableFlags { + VariableEscaped = 1, + VariableShadowed = 2, + VariableConstant = 4, + VariableArgument = 8, + VariableReturnArgument = 16 +} + // These types should stay in sync with: // https://github.com/derekparker/delve/blob/master/service/api/types.go @@ -149,6 +157,8 @@ interface DebugVariable { type: string; realType: string; kind: GoReflectKind; + flags: GoVariableFlags; + DeclLine: number; value: string; len: number; cap: number; @@ -843,7 +853,35 @@ class GoDebugSession extends LoggingDebugSession { log('functionArgs', args); this.addFullyQualifiedName(args); let vars = args.concat(locals); - + // annotate shadowed variables in parentheses + const shadowedVars = new Map>(); + for (let i = 0; i < vars.length; ++i) { + if ((vars[i].flags & GoVariableFlags.VariableShadowed) === 0) { + continue; + } + const varName = vars[i].name; + if (!shadowedVars.has(varName)) { + const indices = new Array(); + indices.push(i); + shadowedVars.set(varName, indices); + } else { + shadowedVars.get(varName).push(i); + } + } + for (const svIndices of shadowedVars.values()) { + // sort by declared line number in descending order + svIndices.sort((lhs: number, rhs: number) => { + return vars[rhs].DeclLine - vars[lhs].DeclLine; + }); + // enclose in parentheses, one pair per scope + for (let scope = 0; scope < svIndices.length; ++scope) { + const svIndex = svIndices[scope]; + // start at -1 so scope of 0 has one pair of parens + for (let count = -1; count < scope; ++count) { + vars[svIndex].name = `(${vars[svIndex].name})`; + } + } + } let scopes = new Array(); let localVariables = { name: 'Local', @@ -851,6 +889,8 @@ class GoDebugSession extends LoggingDebugSession { type: '', realType: '', kind: 0, + flags: 0, + DeclLine: 0, value: '', len: 0, cap: 0, @@ -899,6 +939,8 @@ class GoDebugSession extends LoggingDebugSession { type: '', realType: '', kind: 0, + flags: 0, + DeclLine: 0, value: '', len: 0, cap: 0, From df930aac6e68f7aff7c32ea4fdd6a3df438a2bd9 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Tue, 22 Jan 2019 09:15:21 -0800 Subject: [PATCH 2/3] relocate GoVariableFlags --- src/debugAdapter/goDebug.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index 046c43d4d..b7fbb6457 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -45,14 +45,6 @@ enum GoReflectKind { UnsafePointer } -enum GoVariableFlags { - VariableEscaped = 1, - VariableShadowed = 2, - VariableConstant = 4, - VariableArgument = 8, - VariableReturnArgument = 16 -} - // These types should stay in sync with: // https://github.com/derekparker/delve/blob/master/service/api/types.go @@ -151,6 +143,14 @@ interface EvalOut { Variable: DebugVariable; } +enum GoVariableFlags { + VariableEscaped = 1, + VariableShadowed = 2, + VariableConstant = 4, + VariableArgument = 8, + VariableReturnArgument = 16 +} + interface DebugVariable { name: string; addr: number; From f82dda94186968537edef249faf8b16f68e1f897 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Tue, 22 Jan 2019 14:28:41 -0800 Subject: [PATCH 3/3] Use latest stable version of gometalinter --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d87080ccf..8c4b22607 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,8 +49,7 @@ install: - go get -u -v github.com/cweill/gotests/... - go get -u -v github.com/haya14busa/goplay/cmd/goplay - go get -u -v github.com/davidrjenni/reftools/cmd/fillstruct - - go get -u -v github.com/alecthomas/gometalinter - - gometalinter --install + - curl -fsSL https://git.io/vp6lP | sh -s -- -b $GOPATH/bin script: - npm run lint