You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
suggest identifiers that are not yet imported #25820
To correctly implement this we must only suggest unimported types appropriate for the file being edited. More specifically...
when editing a file in the lib/ directory, we should only suggest types in the lib/ directory or in packages in the dependencies: section of the pubspec.yaml.
when editing a file in the bin/, example/, or web/ directories, we should only suggest types in that directory or the lib/ directory or in packages in the dependencies: section of the pubspec.yaml.
when editing other files, we can suggest types anywhere in the package or in either the dependencies: or dev_dependencies: sections of the pubspec.yaml.
when suggesting types from other packages, do not suggest types only accessible from lib/src (internal by convention) similar to what was done for Quick Fix
The blocking issue is that currently, there is no way for the completion service to know which packages are listed in dependencies: or dev_dependencies: sections of the pubspec.yaml.
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.
@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.
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. JetBrains/intellij-plugins#637
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 53 ms for about 1600 completions, to 5 ms when producing 5000+ completions.
Reacted by Günter Zöchbauer, Renann Prado, 𝐒𝐚𝐥𝐚𝐝 𝐓𝐡𝐢𝐞𝐯𝐞𝐬, Emanuel Quimper, Jimmy Robert, examango, Ihor Klimov, Dirk Vanbeveren and BansookNam
Reacted by Pascal Welsch, Renann Prado, 𝐒𝐚𝐥𝐚𝐝 𝐓𝐡𝐢𝐞𝐯𝐞𝐬, Emanuel Quimper, André Vendramini, Dirk Vanbeveren and ndanield
@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.
I just tested version 191.6183.41. Suggestions of Future and List works but I don't get any suggestions for 3rd party classes, i.e. ListMultimap from quiver as shown in the screenshot above. (yes, I added the dependency)
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!
Reacted by Shahzad Akram, AMoskal, Shinji Yamada, Wojciech Rozwadowski, clip, porn and Anthony VEREZ
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
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 on clauses against target expressions.
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.
Activity
alexander-doroshko commentedon Feb 19, 2016
Will this suggestion have a
SourceEditfor the IDE to insert import (or to modifyshow/hidelist)?danrubel commentedon Feb 19, 2016
Yes.
danrubel commentedon Sep 14, 2016
When implementing this, we should be sure not to suggest test classes when completing in lib directory.
danrubel commentedon Oct 10, 2016
To correctly implement this we must only suggest unimported types appropriate for the file being edited. More specifically...
lib/directory, we should only suggest types in thelib/directory or in packages in thedependencies:section of thepubspec.yaml.bin/,example/, orweb/directories, we should only suggest types in that directory or thelib/directory or in packages in thedependencies:section of thepubspec.yaml.dependencies:ordev_dependencies:sections of thepubspec.yaml.lib/src(internal by convention) similar to what was done for Quick FixThe blocking issue is that currently, there is no way for the completion service to know which packages are listed in
dependencies:ordev_dependencies:sections of thepubspec.yaml.davidmorgan commentedon Dec 1, 2016
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!
danrubel commentedon Dec 1, 2016
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.
davidmorgan commentedon Dec 1, 2016
Thanks. I will stay subscribed ;)
manuelF commentedon Dec 2, 2016
+1, this would be super handy to make the IDE a more seamless experience.
hooluupog commentedon Oct 3, 2017
+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).
scheglov commentedon Apr 1, 2018
@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.
9 remaining items
kandroid29 commentedon Feb 26, 2019
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.
scheglov commentedon Feb 26, 2019
FYI, we implemented this, you probably will get it with the next IntelliJ and Dart SDK build.
JetBrains/intellij-plugins#637
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
53 msfor about1600completions, to5 mswhen producing5000+completions.kandroid29 commentedon Feb 26, 2019
@scheglov great! will this also be supported in Android Studio?
scheglov commentedon Feb 26, 2019
Yes, Android Studio uses the same Dart Analysis Server, and the same Dart plugin for IntelliJ.
When specifically, I don't know, maybe @stevemessick ?
12people commentedon Mar 24, 2019
How about Visual Studio Code? How can I make autoimport work there.
DanTup commentedon Mar 25, 2019
@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 commentedon Mar 25, 2019
I just tested version
191.6183.41. Suggestions ofFutureandListworks but I don't get any suggestions for 3rd party classes, i.e.ListMultimapfrom quiver as shown in the screenshot above. (yes, I added the dependency)alexander-doroshko commentedon Apr 1, 2019
@passsy, try with the latest Dart SDK 2.2.1-dev.x.x release.
passsy commentedon Apr 3, 2019
I can confirm it is now working with
#IU-191.6183.87, built on March 27, 20192.2.0(Tue Feb 26 15:04:32 2019 +0100) on "macos_x64"191.6183.88from Apr 02, 2019vrendina commentedon May 28, 2019
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!
shinayser commentedon Oct 14, 2019
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
scheglov commentedon Oct 14, 2019
@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
onclauses against target expressions.We might implement quick fix.
cyberpwnn commentedon Nov 19, 2020
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?
bwilkerson commentedon Nov 19, 2020
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.