godef
godef copied to clipboard
[master] Special treatment for "C" package.
Fixes #41 (at least for me).
import "C"
is not a real package. So godef
cannot correctly parse any package that says import "C"
. This adds a special treatment for this package and circumvents this problem.
It works, for me, thx
It has no effect in go1.7 linux/amd64.
@applee How does it look on your side? It's a hard-coded workaround for "C". It cannot jump to definition on "C" but at least parses for other definitions.
This fixed it for me as well. Can this be merged?
I had the same issue with https://github.com/aarzilli/golua. This PR fixes it. (On 1.7 as well, btw.)
At least for me, this patch doesn't work anymore with vendor directories.
D:\go\bin\godef.exe -debug -f main.go net.LookupIP
2017/01/23 21:33:57 exprType tuple:false pkg: *ast.SelectorExpr net.LookupIP [
2017/01/23 21:33:57 exprType tuple:false pkg: *ast.Ident net [
2017/01/23 21:33:57 exprType tuple:false pkg: *ast.ImportSpec "net" [
2017/01/23 21:33:57 ] -> 0x0, Type{package "" *ast.ImportSpec "net"}
2017/01/23 21:33:57 ] -> 0xc04219ee60, Type{package "" *ast.ImportSpec "net"}
2017/01/23 21:33:57 member Type{package "" *ast.ImportSpec "net"} 'LookupIP' {
2017/01/23 21:33:57 C:\go\src\net\interface_bsd.go:12:2: cannot find identifier for package "golang_org/x/net/route": no buildable Go source files in C:\go\src\vendor\golang_org\x\net\route
2017/01/23 21:33:57 } -> <nil>
2017/01/23 21:33:57 ] -> 0x0, Type{bad "" <nil> }
parseLocalPackage error: no more package files found
2017/01/23 21:33:57 exprType tuple:false pkg: *ast.SelectorExpr net.LookupIP [
2017/01/23 21:33:57 exprType tuple:false pkg: *ast.Ident net [
2017/01/23 21:33:57 exprType tuple:false pkg: *ast.ImportSpec "net" [
2017/01/23 21:33:57 ] -> 0x0, Type{package "" *ast.ImportSpec "net"}
2017/01/23 21:33:57 ] -> 0xc04219ee60, Type{package "" *ast.ImportSpec "net"}
2017/01/23 21:33:57 member Type{package "" *ast.ImportSpec "net"} 'LookupIP' {
2017/01/23 21:33:57 C:\go\src\net\interface_bsd.go:12:2: cannot find identifier for package "golang_org/x/net/route": no buildable Go source files in C:\go\src\vendor\golang_org\x\net\route
2017/01/23 21:33:57 } -> <nil>
2017/01/23 21:33:57 ] -> 0x0, Type{bad "" <nil> }
godef: no declaration found for net.LookupIP
Since the go
subtree is a copy of that part of the Go distribution, it seemed to me that overriding the pathToName
function would be nicer than hacking the code to override the result, but unfortunately types.DefaultImporter
has a hard-coded reference to DefaultImportPathToName
, and it proved too hard to extract a copy of DefaultImporter
without dragging half the rest of the library with it.
I am encountering this problem, too. My OS System is Mint Qiana, which based on Ubuntu 14.04
Distributor ID: LinuxMint
Description: Linux Mint 17 Qiana
Release: 17
Codename: qiana
Go version is 1.8 ( also wrong in 1.7, too).
With godef --debug -f main.go net.LookIP
, the debug log shows:
2017/03/23 15:03:13 exprType tuple:false pkg: *ast.SelectorExpr net.LookIP [
2017/03/23 15:03:13 exprType tuple:false pkg: *ast.Ident net [
2017/03/23 15:03:13 exprType tuple:false pkg: *ast.ImportSpec "net" [
2017/03/23 15:03:13 ] -> 0x0, Type{package "" *ast.ImportSpec "net"}
2017/03/23 15:03:13 ] -> 0xc42013de00, Type{package "" *ast.ImportSpec "net"}
2017/03/23 15:03:13 member Type{package "" *ast.ImportSpec "net"} 'LookIP' {
2017/03/23 15:03:13 /home/shahuwang/go/src/net/cgo_openbsd.go:12:8: cannot find identifier for package "C": cannot find package "C" in any of:
/home/shahuwang/go/src/vendor/C (vendor tree)
/home/shahuwang/go/src/C (from $GOROOT)
/home/shahuwang/github/src/C (from $GOPATH)
2017/03/23 15:03:13 } -> <nil>
2017/03/23 15:03:13 ] -> 0x0, Type{bad "" <nil> }
2017/03/23 15:03:13 exprType tuple:false pkg: *ast.SelectorExpr net.LookIP [
2017/03/23 15:03:13 exprType tuple:false pkg: *ast.Ident net [
2017/03/23 15:03:13 exprType tuple:false pkg: *ast.ImportSpec "net" [
2017/03/23 15:03:13 ] -> 0x0, Type{package "" *ast.ImportSpec "net"}
2017/03/23 15:03:13 ] -> 0xc42013de00, Type{package "" *ast.ImportSpec "net"}
2017/03/23 15:03:13 member Type{package "" *ast.ImportSpec "net"} 'LookIP' {
2017/03/23 15:03:13 /home/shahuwang/go/src/net/cgo_openbsd.go:12:8: cannot find identifier for package "C": cannot find package "C" in any of:
/home/shahuwang/go/src/vendor/C (vendor tree)
/home/shahuwang/go/src/C (from $GOROOT)
/home/shahuwang/github/src/C (from $GOPATH)
2017/03/23 15:03:13 } -> <nil>
2017/03/23 15:03:13 ] -> 0x0, Type{bad "" <nil> }
godef: no declaration found for net.LookIP
#44 fixes the "C" import problem, but hit another problem:
2017/03/23 15:10:59 exprType tuple:false pkg: *ast.SelectorExpr net.LookIP [
2017/03/23 15:10:59 exprType tuple:false pkg: *ast.Ident net [
2017/03/23 15:10:59 exprType tuple:false pkg: *ast.ImportSpec "net" [
2017/03/23 15:10:59 ] -> 0x0, Type{package "" *ast.ImportSpec "net"}
2017/03/23 15:10:59 ] -> 0xc42012fe00, Type{package "" *ast.ImportSpec "net"}
2017/03/23 15:10:59 member Type{package "" *ast.ImportSpec "net"} 'LookIP' {
2017/03/23 15:10:59 /home/shahuwang/go/src/net/interface_bsd.go:12:2: cannot find identifier for package "golang_org/x/net/route": no buildable Go source files in /home/shahuwang/go/src/vendor/golang_org/x/net/route
2017/03/23 15:10:59 } -> <nil>
2017/03/23 15:10:59 ] -> 0x0, Type{bad "" <nil> }
2017/03/23 15:10:59 exprType tuple:false pkg: *ast.SelectorExpr net.LookIP [
2017/03/23 15:10:59 exprType tuple:false pkg: *ast.Ident net [
2017/03/23 15:10:59 exprType tuple:false pkg: *ast.ImportSpec "net" [
2017/03/23 15:10:59 ] -> 0x0, Type{package "" *ast.ImportSpec "net"}
2017/03/23 15:10:59 ] -> 0xc42012fe00, Type{package "" *ast.ImportSpec "net"}
2017/03/23 15:10:59 member Type{package "" *ast.ImportSpec "net"} 'LookIP' {
2017/03/23 15:10:59 /home/shahuwang/go/src/net/interface_bsd.go:12:2: cannot find identifier for package "golang_org/x/net/route": no buildable Go source files in /home/shahuwang/go/src/vendor/golang_org/x/net/route
2017/03/23 15:10:59 } -> <nil>
2017/03/23 15:10:59 ] -> 0x0, Type{bad "" <nil> }
godef: no declaration found for net.LookIP
@jwendel @shahuwang you might like to try #61 as an alternative solution
Now I believe this is obsoleted by #62