-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Optimize imports command doesn't resolve imports automatically #30296
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
@JFixby, IDE's 'Optimize imports' effectively delegates to Dart Analyser's Organize Directives action. Its purpose is to remove unused imports and sort directives. By design it doesn't add imports and doesn't fix any red code. To fix red code navigate there (e.g. press F2) and see if there are appropriate quick fixes (Alt+Enter). |
Well, I have past experience with Eclipse IDE. Eclipse fixes red code and auto-resolves imports. |
Please treat it as a feature request and re-open. |
@JFixby how is the action called in Eclipse that removes unused imports, sorts them and adds missing imports in one shot? In the IntelliJ world, there has never been such. 'Optimize Imports' in IntelliJ means remove unused and sort. However, IntelliJ's Java support has 'Add unambiguous imports on the fly' feature. With it enabled, imports appear automatically as soon as it is an obvious and the only way to fix a red reference. With it disabled it is anyway rather easy to add missing import in Java because the IDE shows you a tooltip like this: Ok, I reopen the issue and move it to area-analyzer. Let @bwilkerson decide. I suggest to keep Organize Directives as is, its current behavior matches IntelliJ's workflow. We may think about easier importing, something like what Java support in IntelliJ has. But I wouldn't like to rethink IntelliJ's 'Optimize Imports' action. |
Different IDEs - different workflows. In IntelliJ Optimize Imports is rarely used itself, but often in the scope of the Reformat Code action, in one shot. And neither Reformat Code nor Optimize Imports change the semantics of the written code. Features like 'Add unambiguous imports on the fly' (default = false) and 'Show import popup' (default = true) and finally Quick Fixes do this job in Java support instead. |
Speaking of workflows: clicking |
Reproduction steps:
Example project: https://github.com/JFixby/DartImportsExample
class A located in the
lib/folderA/class_a_file.dart
content:
class C located in the
lib/class_c_depends_on_a.dart
depends on the Acontent:
What was done
click
Code -> Optimize imports
What is expected
File
class_c_depends_on_a.dart
gets a new lineimport 'package:project_a/folderA/class_a_file.dart';
What is actually happening
nothing
Setup
IDEA version: community 2017.2
Dart plugin: 172.3317.48
The text was updated successfully, but these errors were encountered: