rogpeppe / godef

Print where symbols are defined in Go source code
BSD 3-Clause "New" or "Revised" License
667 stars 141 forks source link

Missing dependency due to a build tag? #46

Open jcrossley3 opened 8 years ago

jcrossley3 commented 8 years ago

Go noob here, so I'm not entirely sure this bug belongs to godef, but we'll start here. My issue is that the emacs go-mode invokes godef and isn't able to find the declaration for a function in the spf13/cobra library, even though I know it's installed. This gist shows the output when godef's -debug flag is passed: https://gist.github.com/b1c4d48bcefbffa573f2da9ed605033c

It appears that godef is complaining about a missing mousetrap dependency. I believe this is missing because cobra's command_win.go file includes a +build windows tag, and I'm on linux.

Am I making any sense? Let me know if this bug is more appropriate in either go-mode's or cobra's repo. Thanks!

bcokert commented 7 years ago

Can confirm - godef doesn't seem to respect build tags, and it fails if any file in the package has build tags who's dependencies haven't been downloaded (even if you're not godef'ing that file).

For an easy to reproduce example, check out the package go get -u engo.io/engo (commit c5aaca512e2827107aadd82c0caabc002e0e6193 in case they fix it). If you import the engo package somewhere, and try to inspect with godef, it'll fail with something like:

2017/06/23 14:30:12 exprType tuple:false pkg: *ast.Ident engo [
2017/06/23 14:30:12 exprType tuple:false pkg: *ast.ImportSpec "engo.io/engo" [
2017/06/23 14:30:12 ] -> 0x0, Type{package "" *ast.ImportSpec "engo.io/engo"}
2017/06/23 14:30:12 ] -> 0xc4200b5f40, Type{package "" *ast.ImportSpec "engo.io/engo"}
2017/06/23 14:30:12 member Type{package "" *ast.ImportSpec "engo.io/engo"} 'Files' {
2017/06/23 14:30:12     /Users/brandono/projects/gohome/src/engo.io/engo/engo_js.go:17:2: cannot find identifier for package "honnef.co/go/js/dom": cannot find package "honnef.co/go/js/dom" in any of:
    /usr/local/Cellar/go/1.7.1/libexec/src/honnef.co/go/js/dom (from $GOROOT)
    /Users/brandono/projects/gohome/src/honnef.co/go/js/dom (from $GOPATH)
2017/06/23 14:30:12     /Users/brandono/projects/gohome/src/engo.io/engo/engo_js.go:18:2: cannot find identifier for package "honnef.co/go/js/xhr": cannot find package "honnef.co/go/js/xhr" in any of:
    /usr/local/Cellar/go/1.7.1/libexec/src/honnef.co/go/js/xhr (from $GOROOT)
    /Users/brandono/projects/gohome/src/honnef.co/go/js/xhr (from $GOPATH)
2017/06/23 14:30:12 } -> <nil>