-
Notifications
You must be signed in to change notification settings - Fork 1.9k
auto_import: multiple assist actions to select import container #795
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
Conversation
|
LGTM but I think the order should be file > modules > function since that order corresponds more to the natural file structure and most people put imports at the top of the file. If ordered in that way the order of arrow keys to your chosen option is also more natural. |
|
Are all of those guaranteed valid? I didn't think the stuff imported into parent modules would be in scope? |
|
Sigh. Sometimes I forget that rust isn't C#. |
Nope. I plan to use name resolution in the future to provide only valid scopes and other improvements. At the moment auto import is only syntactic, it relies on people knowing what they are doing. |
|
Hm, I think this doesn't quite strike the right balance of "usefulness / attention" in this form. The general big problem with IDEs is that, although you can suggest a ton of stuff to the user, they can process only so much of it. So an intention which is always available but used only rarely is a net negative. In this case, I think we almost always want to add import to the start of enclosing module: local imports are extremely rare, and importing "across" modules seems even less likely. Its interesting that IntelliJ has a nice UI for such situations: you can "expand" a particular assist option from the menu to get a list of various flavors of the assist. But LSP does not support this yet. So I am inclined to close. |
|
Yes the fact that LSP has no "second level" actions is a problem here and for others assists I have in mind. This somewhat circumvent that limitation. @matklad I'm thinking of two alternatives for this particular PR:
Tell me if you think one of these is reasonable, otherewise I'm fine if you close this. |
|
Just to ask, is there any situation you'd ever want I'm trying to think of a situation but I can't ever imagine it. If we don't have complete information then it makes sense - but it seems like this would be suggested even if we know for sure that the cursor is in a child module? |
|
[Maybe it was not clear for the first post, but this PR only show scopes containing the cursor] @daboross the current implementation shows only options that contains the cursor. that will show: Both |
|
If you were to add the import in the file in that situation, it wouldn't actually resolve, because named modules don't inherit the scope of their parent (anonymous modules do, though). On the other hand, a common situation might be mod test {
use super::*;
std::fmt::Debug<|>
}, in which case importing in the file would work... |
|
Yes. Currently in that hypotetical situation you need to import two times the same thing, one for the file and one with the |
|
Alright, thanks! That answers my question. I hadn't thought of the What I meant was that, for example, in this code you mentioned "import std::fmt::Debug in the current file" would have no use. But it does in the case that |
Not that even inside test modules with So I suggest closing this and filing the first commit as a separate PR! |
|
@matklad Ok, then. |
|
yep, we should imports to the current module by default! |
This make auto_import assist to produce multiple actions to select in which module/function to perform auto import.
For example, if we have:
you will see the following actions in this order:
The priority here is modules > file > functions.