How to see global variables in Visual Studio Code while debugging?
Asked Answered
H

2

8

While debugging Go using delve only the local variables are shown.

I can't see all the global variables.

Are there any settings change to see the list of all variablesenter image description here

Here a is not showing, even when I hover mouse over it its value is not coming.

Hardison answered 17/8, 2018 at 5:43 Comment(1)
To whomever voted to close this as off-topic: How to use programming tools is entirely on-topic. Your off-topic vote is misplaced.Stingo
T
5

Local variable tab will only display local variables as its name suggest it.

But to me, the best thing you could do is to manually add the desired variable to your watch list. Just click on the "+" icon in the watch tab (left pannel) and chose the variable that you want to watch while debugging.

Watch variable list

Some more details are given in this answer

Tranquillize answered 17/8, 2018 at 11:26 Comment(1)
The problem is there are a lot of global variables.So I need a way to list out all variables including local and global that are initialized currently.Hardison
N
5

There is a (hidden) Delve configuration setting you can add to your settings.json file that should show your Global variables; I've only tested this on a simple project with a single main.go file, I'm not sure how reliable this is for more complex projects.

Add below to your settings.json file:

{
  "go.delveConfig": {
    "showGlobalVariables": true,
  }
}

Answer found from @polinasok from their comment on vscode-go Issue #1683

Nolin answered 25/5, 2022 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.