godef icon indicating copy to clipboard operation
godef copied to clipboard

[master] Special treatment for "C" package.

Open hotpxl opened this issue 8 years ago • 10 comments

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.

hotpxl avatar Jul 27 '16 13:07 hotpxl

It works, for me, thx

TargetLiu avatar Aug 01 '16 17:08 TargetLiu

It has no effect in go1.7 linux/amd64.

applee avatar Aug 22 '16 09:08 applee

@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.

hotpxl avatar Aug 22 '16 13:08 hotpxl

This fixed it for me as well. Can this be merged?

muirdm avatar Oct 03 '16 16:10 muirdm

I had the same issue with https://github.com/aarzilli/golua. This PR fixes it. (On 1.7 as well, btw.)

Ambrevar avatar Nov 08 '16 14:11 Ambrevar

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

jwendel avatar Jan 24 '17 04:01 jwendel

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.

bboreham avatar Mar 14 '17 14:03 bboreham

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

shahuwang avatar Mar 23 '17 07:03 shahuwang

@jwendel @shahuwang you might like to try #61 as an alternative solution

bboreham avatar May 04 '17 08:05 bboreham

Now I believe this is obsoleted by #62

bboreham avatar May 25 '17 17:05 bboreham