gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
17.45k stars 725 forks source link

LSP code action: remove all unused imported types and values #3257

Open lpil opened 3 months ago

lpil commented 3 months ago

Discussed in https://github.com/gleam-lang/gleam/discussions/3241

Originally posted by **nicklimmm** June 3, 2024 I often find myself removing the unused imported types and values manually after I'm done with prototyping or refactoring. Gleam can remove all unused imports, but not imported types and values yet. A simple example: ```gleam import gleam/list.{find} // ->`find` is unused import gleam/uri.{type Uri} // -> `Uri` is unused ``` Should become: ```gleam import gleam/list import gleam/uri ``` This would be a good QOL improvement, especially if we are dealing with a lot of imported types and values.
poelstra commented 3 weeks ago

The tracking of unused imports should probably be improved a bit too, because if I have e.g. image

(and not using the option module itself anywhere) then it should mark the full import as being unused, not just the type.

Otherwise, it would only remove type Option, but leave gleam/option in place, which will then be detected as unused.

So the rule should probably be: if the imported module isn't used directly, and if none of its unqualified imports (types, constructors) are used, then the module itself should also be marked as unused.

lpil commented 3 weeks ago

The unused code detection is not good and will be deleted and rewritten from scratch in future.