英文:
Is it possible to preview github.com/shopspring/decimal values in VSCode during debugging?
问题
这是在使用VSCode进行调试时,Go语言中普通的int64
/float64
变量的预览。
如果能够实现这个功能,调试将会变得更加容易。目前,如果没有日志,无法直接查看变量的值,需要重新构建和重启项目。
有没有什么办法可以实现这个功能?也许可以使用插件或者某种表达式?
或者也许有人知道如何编写一个插件/扩展来实现这个功能?
基本上,要查看变量的值,我们需要调用var.String()
函数,但在VSCode的调试过程中无法调用函数。或者我只是不知道如何调用。
我多年来一直在使用一个叫做Decimal的任意精度包(https://github.com/shopspring/decimal),这一直是个问题,我终于想让它工作起来。
是的,在这个例子中,你可以点击展开3次,然后取值2345454,取exp:-3,然后在你的脑海中加上一个小数点,得到2345.453,但这并不理想,而且我认为它并不总是有效,特别是对于负值来说更困难。
英文:
This is a preview of a normal int64
/float64
variable in Go in vscode during debugging.
And this is how it looks when using a variable from Decimal library.
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.
答案1
得分: 1
扩展@icza的评论。
在我的电脑上,call fff.String()
对于github.com/shopspring/decimal
不起作用。它报错如下:
(dlv) call t.String()
> main.main() ./main.go:20 (PC: 0x49ecbf)
Command failed: write out of bounds
我的系统是linux/amd64
。我认为它在所有64位系统上都不起作用。
在当前版本的dlv
(1.20.2)中存在一个错误。我刚刚提交了一个错误报告并发送了一个修复方案。
更新:
修复已合并。您可以更新dlv
以获取此修复:
$ go install github.com/go-delve/delve/cmd/dlv@master
使用此修复后的结果如下:
英文:
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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论