-
Notifications
You must be signed in to change notification settings - Fork 1.7k
suggest identifiers that are not yet imported #25820
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
Comments
Will this suggestion have a |
Yes. |
When implementing this, we should be sure not to suggest test classes when completing in lib directory. |
To correctly implement this we must only suggest unimported types appropriate for the file being edited. More specifically...
The blocking issue is that currently, there is no way for the completion service to know which packages are listed in |
Am I right in thinking that this issue covers auto-completing to methods of types I haven't imported yet? i.e. if I type 'new Foo()..', and 'Foo' is not imported, it will still suggest completions that come from Foo? This is something I miss from IntelliJ's Java behaviour -- it means you can write a whole line of code before going back to add the import. Thanks! |
Yes. Implementing it correctly (see above) means some additional low level functionality in analyzer in addition to the code completion mods. This is something I'd definitely like to see added, but have not had the cycles to get to it. There's a laundry list of things to do and I don't have a good feel for where this one fits in the priority list. |
Thanks. I will stay subscribed ;) |
+1, this would be super handy to make the IDE a more seamless experience. |
+1, it's one of must-have features i am using everyday in Go( Goimports is automatically ran on every save of file to fix imports and format code). |
@davidmorgan, answering on your question in #25820 (comment), my understanding is that answer is "no". This issue is about suggesting imports for top-level declarations from not yet imported libraries. What you are asking is kind of "speculative" resolution of some identifiers, even if there is no corresponding import, pretend that there is one. In theory this could be done, but why? If there is a missing import and you get a compilation error, use the Quick Fix and then get further analysis and code completion. @danrubel is right in #25820 (comment) that we need to suggest only identifiers from libraries that are potentially accessible in the source library. But that's not the same as resolution without imports. |
@scheglov I don't use Java anywhere near as much as I used to, so I don't remember the exact details; but IntelliJ with Java definitely does something along these lines. e.g. if I type This is preferable to a separate step to add the import simply because it's quicker--one quick fix instead of two. I tried and was not able to repro the behaviour I seem to have been describing with suggesting completions on a variable of a not-imported type. Maybe it doesn't do this any more :) or maybe I was mistaken. Thanks. |
What if there are many ThrowableExtension classes in different unimported libraries - does it show the options from all of them, or just a random(?) one? It sounds like interesting behaviour, but if it's more work, there's great value in implementing the simpler version. Note: The API for |
It shows options from all of them--and of course the import that gets added when you pick one is the one corresponding to the completion you picked. |
Yes, that's the plan. |
This is a very big minus so far in terms of development. I feel like I'm back in the olden days of IDE's where i have to find the imports i need while writing my code. Please let us not have to scroll all the way up or try to remember the casing of a class and then hoping cmd + enter / alt + enter has the import ready to you, but wait was it "SomeClass" or "Someclass".. hope you remembered otherwise back to the top of the document you go to search |
I'm just thinking out loud, but here's a compromise idea: If autocompletion doesn't find a match in a library that is already imported, it displays a list of libraries that do have a match. If you select one of them, then that selected library is imported and then it goes back to the current autocomplete behavior. Seems simpler, easier to implement, and perhaps faster (don't have to look in other libraries unless there is no match in the imported libraries), but still gets the job done without having to do a separate import. |
@wmleler this will be far from ideal, but it will be an interesting first step. I've found that I'm mainly dealing with my own files/methods, so, saving me the time to import it manually will be a time-saver. |
Any news to this issue? Manually importing things is just a waste of time which should be fixed for a better developer experience. |
Having to move up and down to add the import for a class is a very bad experience, it is waste of time and distraction from what I am doing. So I think auto import suggestion is a required feature for modern IDE. |
FYI, we implemented this, you probably will get it with the next IntelliJ and Dart SDK build. It will show everything available to you, prioritizing libraries that are already imports (because for these you have already made your choice), and adding new imports with or without import prefix depending on whether the new import will introduce ambiguity or will be shadowed at the port of usage. Bonus point is that because available declarations are cached on the client (IntelliJ), we have to transfer much less data, so completions are faster. I saw improvements from |
@scheglov great! will this also be supported in Android Studio? |
Yes, Android Studio uses the same Dart Analysis Server, and the same Dart plugin for IntelliJ. |
How about Visual Studio Code? How can I make autoimport work there. |
@12people VS Code work is being tracked at Dart-Code/Dart-Code#1060. I'd like to have some additional testing before it's included in a release - if you're interested in trying it out with a preview build, please drop a comment on that issue. |
@passsy, try with the latest Dart SDK 2.2.1-dev.x.x release. |
I can confirm it is now working with
|
Android Studio 3.4.1 seems to be pretty far behind IntelliJ IDEA 2019.1.2 with their Dart plugin version and was lacking this functionality even though it has been available for 2 months. Moving from Android Studio to IntelliJ for Flutter development! |
I am having problem with auto completing the new Extension Functions from dart 2.6.0. I have added a new file called "time.dart" with some extensions, like this: My main file just can't auto complete it. If I try to fix the error I get the following: As soon as I move the extensions to the same file as main, everything works: If I add the import manually, it also works: My Dart for Intellij plugin version is 192.6817.14 |
@shinayser Please open a new issue https://github.com/dart-lang/sdk/issues. Auto-import for extensions probably will not work, because auto-import works syntactically, i.e. we just know top-level names to include. But for extensions we need to match We might implement quick fix. |
A core feature of an IDE tool / SDK has still yet to be implemented... or work if it is. Is there an eta when I can write at normal speeds in dart? |
Which IDE / editor are you using? The functionality is working in several editors, so I'm wondering whether the problem is specific to some editors. Can you provide us with an example of a case in which it fails to work? There are a couple of known exceptions where it doesn't yet work, but the issue was closed because it appears to be working in general and we prefer having finer-grained issues when a piece of a feature is broken. |
No description provided.
The text was updated successfully, but these errors were encountered: