Skip to content

Support dot imports#68

Open
applepi-icpc wants to merge 2 commits into
rogpeppe:masterfrom
applepi-icpc:master
Open

Support dot imports#68
applepi-icpc wants to merge 2 commits into
rogpeppe:masterfrom
applepi-icpc:master

Conversation

@applepi-icpc
Copy link
Copy Markdown

Solution for issue #19

@lloiser
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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