-
Notifications
You must be signed in to change notification settings - Fork 254
Road to auto-imports #742
Description
I'd particularly love to have automatic import functionality in Rls clients. We need to provide clients a few things to do that
CodeActions/CodeLens:
- Remove unused import (per unused import) upstream issue
- Add import - cannot find declared type
- Add import - failed to resolve type or module upstream issue
- Remove all unused imports in file on each unused diagnostics (available when more than 1 exists in the file)
- Add all missing imports in file (where no choice of import exists)
- "Order imports" Rustfmt only the imports with
reorder_imported
,reorder_imported_names
(available when this would change something) - "Organise imports": Remove all unused + "Order imports"
With these it would be possible to enable automatic import functionality in clients where they run "Organise imports" + Add imports actions on change/open current file whenever the project is without compile error.
Implementation ideas
I think rustc should provide basic add & remove import suggestions. It currently provides 1/2 add import suggestions. Or should we implement the missing functionality here?
With the above Rls could fairly easily provide the do-all-in-file functionality.
Ordering import without ordering the rest of the code requires the range format functionality that currently doesn't work very well. With that it should be possible.