Support dot imports
Solution for issue #19
@rogpeppe any updates on it? I have tested it for a while now and I haven't found any problems.
It doesn't look as if it will work properly to me. If issue #19 is to be fixed, I think it needs to be done at a lower level. Consider this example:
package foo
type Foo struct{
A int
}
package bar
import . "foo"
type Bar struct {
Foo
}
package main
import "bar"
func main() {
var b bar.Bar
b.A = 99
}
I haven't tried it, but I strongly suspect that if used the code in this PR and tried jumping to the definition of A on the b.A = 99 line, it wouldn't work.
To do it right, I think the fix needs to go into the github.com/rogpeppe/godef/go/parser package.
By the way, IMHO no-one should use dot imports. You never need them. That's the main reason why I haven't spent more time trying to fix the issue, although if someone does present a decent PR that properly fixes the issue (and has some decent tests, ideally), I'd be happy to accept it.
@rogpeppe Yes, you're right. I mistakenly thought that only dot imports in current file need to be processed, and I neglected the case you have given.
Some projects that I'm working on used dot imports to help their refactoring. Some developers want to move some types and functions out of a package into a new one, without changing too much existing codes. So I think maybe dot import is useful in some situations.
Thank you. I will try to fix this problem.
Some developers want to move some types and functions out of a package into a new one, without changing too much existing codes.
I'd suggest using gofmt -r to refactor code like that. For example:
gofmt -r 'MovedFunction -> externalPackage.MovedFunction' -w .