Elisp调用Go代码并获得不同的结果

huangapple go评论116阅读模式
英文:

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 &lt;the gx.thing we&#39;re godef-jump&#39;ing&gt;.

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 &lt;the gx.thing we&#39;re godef-jump&#39;ing&gt; 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 &quot;github.com/whyrusleeping/gx/gxutil&quot; [
2017/06/20 13:29:14 ] -&gt; 0x0, Type{package &quot;&quot; *ast.ImportSpec gx &quot;github.com/whyrusleeping/gx/gxutil&quot;}
2017/06/20 13:29:14 ] -&gt; 0xc420276140, Type{package &quot;&quot; *ast.ImportSpec gx &quot;github.com/whyrusleeping/gx/gxutil&quot;}
2017/06/20 13:29:14 member Type{package &quot;&quot; *ast.ImportSpec gx &quot;github.com/whyrusleeping/gx/gxutil&quot;} &#39;GetPackageRoot&#39; {
2017/06/20 13:29:14 } -&gt; &amp;{func GetPackageRoot 0xc4203ac3f0 &lt;nil&gt; &lt;nil&gt;}
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 ] -&gt; 0x0, Type{type &quot;&quot; *ast.FuncType func() (string, error)}
2017/06/20 13:29:14 ] -&gt; 0xc420138140, Type{func &quot;&quot; *ast.FuncType func() (string, error)}
2017/06/20 13:29:14 ] -&gt; 0xc420138140, Type{func &quot;github.com/whyrusleeping/gx/gxutil&quot; *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 &quot;github.com/whyrusleeping/gx/gxutil&quot; [
2017/06/20 13:31:18 ] -&gt; 0x0, Type{package &quot;&quot; *ast.ImportSpec gx &quot;github.com/whyrusleeping/gx/gxutil&quot;}
2017/06/20 13:31:18 ] -&gt; 0xc4201fde50, Type{package &quot;&quot; *ast.ImportSpec gx &quot;github.com/whyrusleeping/gx/gxutil&quot;}
2017/06/20 13:31:18 member Type{package &quot;&quot; *ast.ImportSpec gx &quot;github.com/whyrusleeping/gx/gxutil&quot;} &#39;GetPackageRoot&#39; {
2017/06/20 13:31:18 } -&gt; &lt;nil&gt;
2017/06/20 13:31:18 ] -&gt; 0x0, Type{bad &quot;&quot; &lt;nil&gt; }
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 &quot;&quot; *ast.ImportSpec gx &quot;github.com/whyrusleeping/gx/gxutil&quot;} &#39;GetPackageRoot&#39; { 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 &#39;(&quot;PATH&quot; &quot;GOPATH&quot;))

huangapple
  • 本文由 发表于 2017年6月20日 19:46:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/44652207.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定