Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

godef-jump with named import #200

Closed
tomatopeel opened this issue Jun 19, 2017 · 4 comments
Closed

godef-jump with named import #200

tomatopeel opened this issue Jun 19, 2017 · 4 comments

Comments

@tomatopeel
Copy link

tomatopeel commented Jun 19, 2017

import (
        ...
	gx "github.com/whyrusleeping/gx/gxutil"
        ...
)
...
const PkgFileName = gx.PkgFileName

func LoadPackageFile(path string) (*gx.Package, error) {
	if path == PkgFileName {
		root, err := gx.GetPackageRoot()
                ...
	}

So with the above code from https://github.com/whyrusleeping/gx godef works fine

tomato@think01:gx (master) $ godef -f main.go gx.GetPackageRoot
/home/tomato/ipfs/src/github.com/whyrusleeping/gx/gxutil/pm.go:50:6
tomato@think01:gx (master) $ godef -f main.go gx.PkgFileName
/home/tomato/ipfs/src/github.com/whyrusleeping/gx/gxutil/pm.go:22:7

However go-mode.el is not finding the declaration of gx.PkgFileName or gx.GetPackageRoot. I suspect this is because it's not shaving off the "gx." maybe? I'm not sure.

@tomatopeel
Copy link
Author

tomatopeel commented Jun 19, 2017

So the problem is here

          (call-process-region (point-min)
                               (point-max)
                               godef-command
                               nil
                               outbuf
                               nil
                               "-i"
                               "-t"
                               "-f"
                               (file-truename (buffer-file-name (go--coverage-origin-buffer)))
                               "-o"
                               (number-to-string (position-bytes point)))

https://github.com/dominikh/go-mode.el/blob/master/go-mode.el#L1470-L1481

This causes the *godef* buffer output to be godef: no declaration found for <the gx.thing we're godef-jump'ing>

If I run godef -t -f <full path to main.go> from the CLI there's no issue.

@tomatopeel
Copy link
Author

tomatopeel commented Jun 20, 2017

If I add the -debug flag into the call-process-region call, I get the following:

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

Here's the similar command on the CLI (I've realised I can't test the -i flag properly because I'm not sure how Emacs is streaming to godef, is it the same as catting the file through a pipe? I don't know.):

$ 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)

@jnschaeffer
Copy link

Seems to work for me on my machine.

Steps to reproduce (or not):

  • go get github.com/whyrusleeping/gx
  • In emacs, C-x C-f $GOPATH/src/github.com/whyrusleeping/gx/main.go
  • Move cursor to named definition, e.g. var pm *gx.PM
  • C-c C-j

Doing so takes me to the definition of PM in gxutil/pm.go, which I believe is the desired behavior.

@tomatopeel
Copy link
Author

Figured this out with some help from @jnschaeffer on go-nuts IRC, thanks so much!

It was just that Emacs didn't have my GOPATH env var, added GOPATH to exec-path-from-shell-copy-envs command in my init and it resolved this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants