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

Support dot imports #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

applepi-icpc
Copy link

Solution for issue #19

@lloiser
Copy link

lloiser commented Oct 30, 2017

@rogpeppe any updates on it? I have tested it for a while now and I haven't found any problems.

@rogpeppe
Copy link
Owner

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.

@applepi-icpc
Copy link
Author

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

@rogpeppe
Copy link
Owner

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 .

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

Successfully merging this pull request may close these issues.

3 participants