godecimalvscode-debuggerdelve

Is it possible to preview github.com/shopspring/decimal values in VSCode during debugging?


This is a preview of a normal int64/float64 variable in Go in vscode during debugging.

enter image description here

And this is how it looks when using a variable from Decimal library. enter image description here

If that would be possible then debugging would be so much easier. Right now, being a value is not possible without logs and if there are no logs you need to rebuild and restart the project.

Any ideas of how to achieve it - maybe a plugin or some kind of expression? Or maybe someone knows how to write a plugin/extension for that?

Basically to see the value we need to call. var.String() function but it is not possible to call function during viscose debugging. Or I just don't know how.

I have been using this arbitrary-precision package called Decimal (https://github.com/shopspring/decimal) for years and this was a pain and I finally want to make it work.

Yes, in this example you can click expand 3 times then take the value 2345454 and take exp:-3 and just put a dot there in your head and get 2345.453 but this is not ideal and I think it does not always work anyway, especially hard with below-zero values.


Solution

  • Expand @icza's comment.

    call fff.String() does not work for github.com/shopspring/decimal on my computer. It errors with:

    (dlv) call t.String()
    > main.main() ./main.go:20 (PC: 0x49ecbf)
    Command failed: write out of bounds
    

    My system is linux/amd64. And I think it does not work on all 64bit systems.

    There is a bug in the current version of dlv (1.20.2). I just filed a bug report and sent a fix.

    Update:

    The fix has been merged. You can update dlv to get this fix:

    $ go install github.com/go-delve/delve/cmd/dlv@master
    

    Here is the result with this fix:

    vs-code debug view