vscode-debug-visualizer icon indicating copy to clipboard operation
vscode-debug-visualizer copied to clipboard

Unable to visualize Go

Open naveensrinivasan opened this issue 5 years ago • 9 comments

I am trying to use the demo to visualize for go. But I am running into this error.

image

The code

package main

import (
	"encoding/json"
	"math/rand"
	"strconv"
	"time"
)

// If you want to visualize large data structures,
// you need to increase Delve's maxStringLen.
// (See here https://github.com/microsoft/vscode-go/issues/868 for more info)
// You can do this by adding the following configuration to your launch.json:
// "dlvLoadConfig": {
//     "followPointers": true,
//     "maxVariableRecurse": 1,
//     "maxStringLen": 5000,
//     "maxArrayValues": 64,
//     "maxStructFields": -1
// }
// For debugging tests, you can set the maxStringLen in settings.json like this:
// "go.delveConfig": {
//     "dlvLoadConfig": {
//         "followPointers": true,
//         "maxVariableRecurse": 1,
//         "maxStringLen": 5000,
//         "maxArrayValues": 64,
//         "maxStructFields": -1
//     },
//     "apiVersion": 2,
//     "showGlobalVariables": true
// }

// Open a new Debug Visualizer and visualize "s"
func main() {
	rand.Seed(time.Now().UnixNano())
	graph := NewGraph()
	var s string
	for i := 0; i < 100; i++ {
		id := strconv.Itoa(i)
		graph.Nodes = append(graph.Nodes, NodeGraphData{
			ID:    id,
			Label: id,
		})
		if i > 0 {
			targetId := rand.Intn(i)
			graph.Edges = append(graph.Edges, EdgeGraphData{
				From: id,
				To:   strconv.Itoa(targetId),
			})
		}
		s = graph.toString()
		_ = s
		//fmt.Printf("%s", s)
	}
}

type Graph struct {
	Kind  map[string]bool `json:"kind"`
	Nodes []NodeGraphData `json:"nodes"`
	Edges []EdgeGraphData `json:"edges"`
}

type NodeGraphData struct {
	ID    string `json:"id"`
	Label string `json:"label,omitempty"`
	Color string `json:"color,omitempty"`
	Shape string `json:"shape,omitempty"`
}

type EdgeGraphData struct {
	From   string `json:"from"`
	To     string `json:"to"`
	Label  string `json:"label,omitempty"`
	ID     string `json:"id"`
	Color  string `json:"color,omitempty"`
	Dashes bool   `json:"dashes,omitempty"`
}

func NewGraph() *Graph {
	return &Graph{
		Kind:  map[string]bool{"graph": true},
		Nodes: []NodeGraphData{},
		Edges: []EdgeGraphData{},
	}
}

func (this *Graph) toString() string {
	rs, _ := json.Marshal(this)
	return string(rs)
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "env": {},
            "args": [],
            "dlvLoadConfig": {
                "followPointers": true,
                "maxVariableRecurse": 1,
                "maxStringLen": 5000,
                "maxArrayValues": 64,
                "maxStructFields": -1
            }
        }
    ]
}

What am I missing?

Thanks for the great tool!

naveensrinivasan avatar Aug 29 '20 19:08 naveensrinivasan

I think this can be solved by configuring the delve debug adapter to use the watch context. The readme describes how to do that ;)

hediet avatar Aug 29 '20 19:08 hediet

Can you please point to the specific section? I am sorry it is not clear to me.

Thanks

naveensrinivasan avatar Aug 29 '20 19:08 naveensrinivasan

"debugVisualizer.debugAdapterConfigurations": {
	"go": {
		"context": "watch"
	}
}

hediet avatar Aug 29 '20 19:08 hediet

Still running into the same issue.

image

naveensrinivasan avatar Aug 29 '20 19:08 naveensrinivasan

Sorry, I forgot to mention, you need to put that setting into the vscode settings!

hediet avatar Aug 29 '20 19:08 hediet

I have it in the vscode settings and still running into an issue.

image

Thanks!

naveensrinivasan avatar Aug 29 '20 20:08 naveensrinivasan

Your settings file should look like this ;) (Note that debugVisualizer.debugAdapterConfigurations is at the root)

image

hediet avatar Aug 29 '20 20:08 hediet

same issue

YLonely avatar Aug 30 '20 13:08 YLonely

Sorry, it didn't work for me!

naveensrinivasan avatar Aug 30 '20 22:08 naveensrinivasan