2

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.

Zeke Lu
  • 6,349
  • 1
  • 17
  • 23
Alex
  • 78
  • 1
  • 6
  • 1
    You could try adding a watch expression, calling its `String()` method: `call fff.String()`. It does not always work for me though (it works for types in the standard lib such as `big.Int`). – icza May 10 '23 at 22:25

1 Answers1

1

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

Zeke Lu
  • 6,349
  • 1
  • 17
  • 23
  • 1
    This is amazing. I have been living with this for years. I have to say that this is kinda freaky but I have been using Decimal everywhere even if I can just use float64. So living without being able to preview it was very painful. And you not only pointed out a problem but reported it and solved it too. Brilliant! I truly wish you all the best in work and in life. – Alex May 14 '23 at 01:09