microsoft / vscode-go

An extension for VS Code which provides support for the Go language. We have moved to https://github.com/golang/vscode-go
Other
5.93k stars 645 forks source link

Long strings in variable inspection get truncated #868

Closed sirikon closed 6 years ago

sirikon commented 7 years ago

When trying to debug a long string, it gets truncated, and trying to copy it using the right-click context menu, returns the actual truncated value, with "...74 more" string.

VSCode itself adds ellipsis in that element when it's too long, maybe should directly print here the full length variable. Or, at least, when using the "Copy value" context menu, copy the real (and full length) one.

image

Seems like this happens because Delve returns a 'Len' prop shorter than the actual one, and this is like this by design: https://github.com/derekparker/delve/issues/659#issuecomment-256945278

michaelmello commented 7 years ago

So it looks like vscode uses v1 of the delve API: https://github.com/derekparker/delve/blob/master/service/rpc1/server.go

Unfortunately, v1 does not allow the client to change the default length of the variable value, which is set to 64 bytes. image image image

As a workaround, we can simply change the source of delve to return more than 64 bytes.

1.) Navigate to %GOPATH%\src\github.com\derekparker\delve\service\rpc1\server.go 2.) Look for the defaultLoadConfig variable and change the third argument value of 64, which is the field: MaxStringLen. I set mine to 500. image image

3.) Compile and install your modified version of delve. Navigate to %GOPATH%\src\github.com\derekparker\delve\cmd\dlv, and then run the command: go install.

edburns commented 6 years ago

Any idea why this hasn't been merged yet?

lggomez commented 6 years ago

@edburns this is a hack in the delve debugger rather than a fix on the extension side

To fix this on the extension we have to use the delve v2 api call instead of the old one: https://godoc.org/github.com/derekparker/delve/service/rpc2#RPCServer.ListLocalVars https://godoc.org/github.com/derekparker/delve/service/api#LoadConfig

The place to make the change is here. I'm trying to take a look at it

jgfet commented 6 years ago

Why isn't there debug string length key with a value for this in settings that we can just set instead?

lggomez commented 6 years ago

@jgfet because the original delve API did not support this in an explicit way and the vs debug adapter used that version, hence the need to add support to v2 as explained in #1555

The work is already merged to master (still to be released) and the new launch.json configuration options can be seen here: https://github.com/Microsoft/vscode-go/blob/master/package.json#L421-L464

ramya-rao-a commented 6 years ago

With #1555 now complete (thanks to @lggomez!), this bug can be fixed when using the latest update to the Go extension (0.6.81)

Just update your debug configuration as per https://github.com/Microsoft/vscode-go/issues/1555#issuecomment-393366905