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
x/tools/cmd/goimports: prioritize closer package #17557
Comments
I'd be happy to take this one on. To be clear, std lib imports should still have priority over others, am I right? @bradfitz |
Not necessarily. If there are two files in a package, and you're editing import io "github.com/altstdlib/io" ... then you'd probably want to do the same thing as the other file in the same package. goimports already scans that and knows that info. I think there's a TODO yet, but it has the info. But otherwise, if it's not already being used, then stdlib should win, instead of closest. |
Thanks, I'll get to it :) |
@alexcarol what is the status of this issue ? |
@aravindc26 i haven't been able to get around the issue, I might work on it at some point, but if you want to work on the issue yourself you're welcome to do so, sorry for the inconvenience :/ |
@aravindc26: Were you planning to work on this, or are you just interested in the outcome? |
@alexcarol @gavrie let me work on this issue :) |
CL https://golang.org/cl/37070 mentions this issue. |
1. Prefer imports from within the same package 2. Prefer imports that are closer to the current package fixes golang/go#17557 Change-Id: Iec55a294d396feac6234be307e08608b8559f65c
1. Prefer imports from within the same package with validation 2. Prefer imports that are closer to the current package fixes golang/go#17557 Change-Id: Iec55a294d396feac6234be307e08608b8559f65c
Has there been any traction on this issue? It's irritating the living daylights out of me. We have a trio of projects that share similar structures, and thus have identically named packages in a number of places. Goimports happily imports the out-of-project versions instead of the local versions ~90% of the time. |
CL https://golang.org/cl/47836 mentions this issue. |
Works like magic! For anyone wanting to use this now, you can upgrade your goimports now by doing the following: go get -u -v golang.org/x/tools/imports
go install golang.org/x/tools/cmd/goimports/... Thanks for resolving this one! |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?Go version 1.7.3
What operating system and processor architecture are you using (
go env
)?Windows 10 Home 64-bit, with Sublime Text IDE (with GoSublime)
What did you do?
Had different projects, each containing a package with the same name, and then in one of the projects, created a go file that used of one of the packages and called goimports to suggest an import line.
What did you expect to see?
I was hoping to see goimports suggesting an import line that is closer to the current file. In this case, it should suggest the package in the current project.
Or if there are multiple packages with the same name within the same project, it should suggest an import line that is closer to the current file.
What did you see instead?
Goimports currently suggests a random import line for packages with the same name, which is often inaccurate at times. It often suggests a same-name package from different projects, which is irrelevant.
If goimports can understand which import line is closer, it will appear to better understand the context of the package being imported and act more intelligently.
The text was updated successfully, but these errors were encountered: