英文:
Elisp Calling Go Code with Different Result
问题
这个问题是关于GitHub问题的,当在一些命名导入的代码上执行godef-jump
时(但不是全部),会出现错误,错误信息为godef: no declaration found for <the gx.thing we're godef-jump'ing>
。
基本上,我在调试中遇到了一些困难。我已经修改了go-mode.el
中的代码,使用godef
的-debug
标志,并且输出结果不同,从命令行界面(CLI)成功执行如下:
$ godef -f main.go gx.GetPackageRoot
/home/tomato/ipfs/src/github.com/whyrusleeping/gx/gxutil/pm.go:50:6
然而,在Emacs中,它失败并显示godef: no declaration found for <the gx.thing we're godef-jump'ing>
错误。
启用调试标志后,CLI的输出如下:
$ godef -debug -t -f /home/tomato/ipfs/src/github.com/whyrusleeping/gx/main.go -o 565
2017/06/20 13:29:14 exprType tuple:false pkg: *ast.SelectorExpr gx.GetPackageRoot [
2017/06/20 13:29:14 exprType tuple:false pkg: *ast.Ident gx [
2017/06/20 13:29:14 exprType tuple:false pkg: *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil" [
2017/06/20 13:29:14 ] -> 0x0, Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"}
2017/06/20 13:29:14 ] -> 0xc420276140, Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"}
2017/06/20 13:29:14 member Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"} 'GetPackageRoot' {
2017/06/20 13:29:14 } -> &{func GetPackageRoot 0xc4203ac3f0 <nil> <nil>}
2017/06/20 13:29:14 exprType tuple:false pkg: *ast.Ident GetPackageRoot [
2017/06/20 13:29:14 exprType tuple:false pkg: *ast.FuncType func() (string, error) [
2017/06/20 13:29:14 ] -> 0x0, Type{type "" *ast.FuncType func() (string, error)}
2017/06/20 13:29:14 ] -> 0xc420138140, Type{func "" *ast.FuncType func() (string, error)}
2017/06/20 13:29:14 ] -> 0xc420138140, Type{func "github.com/whyrusleeping/gx/gxutil" *ast.FuncType func() (string, error)}
/home/tomato/ipfs/src/github.com/whyrusleeping/gx/gxutil/pm.go:50:6
GetPackageRoot func() (string, error)
Emacs的输出如下:
2017/06/20 13:31:18 exprType tuple:false pkg: *ast.SelectorExpr gx.GetPackageRoot [
2017/06/20 13:31:18 exprType tuple:false pkg: *ast.Ident gx [
2017/06/20 13:31:18 exprType tuple:false pkg: *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil" [
2017/06/20 13:31:18 ] -> 0x0, Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"}
2017/06/20 13:31:18 ] -> 0xc4201fde50, Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"}
2017/06/20 13:31:18 member Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"} 'GetPackageRoot' {
2017/06/20 13:31:18 } -> <nil>
2017/06/20 13:31:18 ] -> 0x0, Type{bad "" <nil> }
godef: no declaration found for gx.GetPackageRoot
我使用strace
确认了预期的二进制文件以及预期的标志被调用。
我猜下一步应该是找出调试输出中的2017/06/20 13:29:14 member Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"} 'GetPackageRoot' {
这一行的输出在哪里/如何产生,因为它是下一个不同的调试输出行,但也许有人有更好的想法或者已经看出了这里发生了什么。
英文:
This question is on the back of this GitHub issue, when executing godef-jump
on code on some named imports (but not all), it fails with the error that godef: no declaration found for <the gx.thing we're godef-jump'ing>
.
Basically I'm a bit stuck with where to go next in my debugging. I've changed the code in go-mode.el
to use the -debug
flag with godef
, and the outputs are different, from CLI is successful like this:
$ godef -f main.go gx.GetPackageRoot
/home/tomato/ipfs/src/github.com/whyrusleeping/gx/gxutil/pm.go:50:6
Whereas in Emacs it fails with the godef: no declaration found for <the gx.thing we're godef-jump'ing>
error.
With the debug flag enabled, CLI:
$ godef -debug -t -f /home/tomato/ipfs/src/github.com/whyrusleeping/gx/main.go -o 565
2017/06/20 13:29:14 exprType tuple:false pkg: *ast.SelectorExpr gx.GetPackageRoot [
2017/06/20 13:29:14 exprType tuple:false pkg: *ast.Ident gx [
2017/06/20 13:29:14 exprType tuple:false pkg: *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil" [
2017/06/20 13:29:14 ] -> 0x0, Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"}
2017/06/20 13:29:14 ] -> 0xc420276140, Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"}
2017/06/20 13:29:14 member Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"} 'GetPackageRoot' {
2017/06/20 13:29:14 } -> &{func GetPackageRoot 0xc4203ac3f0 <nil> <nil>}
2017/06/20 13:29:14 exprType tuple:false pkg: *ast.Ident GetPackageRoot [
2017/06/20 13:29:14 exprType tuple:false pkg: *ast.FuncType func() (string, error) [
2017/06/20 13:29:14 ] -> 0x0, Type{type "" *ast.FuncType func() (string, error)}
2017/06/20 13:29:14 ] -> 0xc420138140, Type{func "" *ast.FuncType func() (string, error)}
2017/06/20 13:29:14 ] -> 0xc420138140, Type{func "github.com/whyrusleeping/gx/gxutil" *ast.FuncType func() (string, error)}
/home/tomato/ipfs/src/github.com/whyrusleeping/gx/gxutil/pm.go:50:6
GetPackageRoot func() (string, error)
Emacs:
2017/06/20 13:31:18 exprType tuple:false pkg: *ast.SelectorExpr gx.GetPackageRoot [
2017/06/20 13:31:18 exprType tuple:false pkg: *ast.Ident gx [
2017/06/20 13:31:18 exprType tuple:false pkg: *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil" [
2017/06/20 13:31:18 ] -> 0x0, Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"}
2017/06/20 13:31:18 ] -> 0xc4201fde50, Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"}
2017/06/20 13:31:18 member Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"} 'GetPackageRoot' {
2017/06/20 13:31:18 } -> <nil>
2017/06/20 13:31:18 ] -> 0x0, Type{bad "" <nil> }
godef: no declaration found for gx.GetPackageRoot
I've used strace
to confirm that the expected binary is being called with the expected flags.
I guess the next thing I should do is find out where/how this 2017/06/20 13:29:14 member Type{package "" *ast.ImportSpec gx "github.com/whyrusleeping/gx/gxutil"} 'GetPackageRoot' {
line of output from the debugs is, since it is the next line of debug that differs, but maybe somebody has some better ideas or can already see what's going on here.
答案1
得分: 1
问题是Emacs不知道我的GOPATH
环境变量,通过将以下内容添加到我的初始化文件中的exec-path-from-shell-copy-envs
中解决了这个问题:
(exec-path-from-shell-copy-envs '("PATH" "GOPATH"))
英文:
The issue was that Emacs was not aware of my GOPATH
environment variable, this was resolved by adding this to exec-path-from-shell-copy-envs
in my initialization files, like so:
(exec-path-from-shell-copy-envs '("PATH" "GOPATH"))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论