-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: can't find proto packages #16600
Comments
This is a side-effect of the pruning of the search space we now do. We have a function which determines whether a package like "fooproto" might appear in a directory as a function of its directory name, considering mostly its final two path components. It ignores case, and drops hyphens and periods, and then looks for substrings. But "fooproto" doesn't appear in "foo/proto". I suppose I could also try concatenating the last two path components and searching that too. But does that solve the general problem? How do protobuf package names & directory names look like in the wild? I haven't been following what the conventions are outside of Google or at least outside of Google open source projects. |
Is this one instance of the general problem that a package whose name differs from its containing directory won't be found by goimports anymore? i.e. if I have
where the Sounds like this is a casualty of the new speed improvements. If so, it's unfortunate but understandable. I didn't run into this with protobuf packages, but with similar auto-generated code, namely https://github.com/keybase/client/tree/master/go/protocol , which has package name It's probably impossible to solve this in general without slowing down goimports again, but I wonder if we could have some sort of convention for auto-generated code, such that the directory name is some function of the package name, e.g. |
Yup.
It's at least fortunate in one way: it gives yet another reason to name your packages the conventional way, making it a bit tedious if you want to violate the norms. I definitely wouldn't penalize people like that on purpose, but if it's necessary to make goimports fast, I think it's quite fine. I wouldn't support any proposal (like |
@dsymonds, can you answer my question in #16600 (comment)? Are there conventions for how people name their proto packages vs. how they end up on disk in their import path? |
I'm not sure there's a well-established convention. We encourage people to always rename proto imports for this kind of reason. If you're going to apply any hack, I'd suggest bypassing the pruning if the import name ends in "pb", which should rarely happen except for protos. |
At $COMPANY our protobuf build scripts move our generated code to a directory that matches the package name specifically to avoid violating the Go convention and to make sure that tools like goimports work. (As far as the special names thing goes, we also name our packages specially using |
Oh, that's an interesting idea, to selectively prune. Or I can at least filter off "pb", and then prune. Does some tool default to the "pb" suffix, or is that just convention? |
It's a strong convention. The part before the "pb" (and sometimes there's nothing before the pb) is human chosen, and isn't always consistent for a given imported package. From memory, golint and other similar tools know the "pb" suffix convention and modify their behaviour a bit. |
/cc @heschik @ianthehat |
Just a note - if there was some convention here that could be added, it would be great. This is a constant pain point of mine. I think that there is a solution where you either special case for Protobuf, or provide some sort of flag to There's two cases for Protobuf that are important:
Is there any way we could re-open this and check this? I'm happy to contribute a PR if so. cc @myitcv as well |
Just as an addition, what I'm proposing: golang/tools@ecd3221...bufdev:proto This would obviously need to be cleaned up, this is doing this in the most inefficient way possible with the least amount of code edits. |
We've recently encountered this problem at my workplace, where it mainly manifests as incorrect removal of in-use imports, a la #29557. IIUC an earlier version of goimports would add import aliases, rewriting |
This bug describes only difficulties adding unusually named packages. You seem to be describing an unrelated bug. Please file a new one. |
Please answer these questions before submitting your issue. Thanks!
go version
)?go version go1.6.2 darwin/amd64
go env
)?Package
fooproto
ingithub.com/danielchatfield/repo/foo/proto
Running
goimports
on the following fails to find the import.The first commit that broke this is
https://github.com/golang/tools/commit/e047ae774b027ae958a270598c5ac2591e457afc
The text was updated successfully, but these errors were encountered: