Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Road to auto-imports #742

@alexheretic

Description

@alexheretic

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIndicates new feature requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions