Cool project idea: organise/remove imports
RazvanN
razvan.nitu1305 at gmail.com
Tue Jul 16 15:25:39 UTC 2024
On Thursday, 11 July 2024 at 10:28:35 UTC, Atila Neves wrote:
> It'd be amazing if one could hit a key/key combination and have
> all imports pared down to the absolute minimum (and made
> local). If only I had the time...
>
> Imagine being lazy, typing "import std;" at module-scope,
> writing some code and... boom. "Hand-written" local imports
> everywhere. One can dream.
I have a small program that uses dmd as a library that:
- identifies unused global imports
- provides a list of the symbols that are being used for each
global import
It can easily be updated to also store the location for each of
the usage sites for the imported symbols. By having the location
you can approximate in what function you are in. That being said,
it's not going to work with alias declarations and enums because
those are eagerly substituted by the compiler when doing semantic
analysis (the tool traverses the tree after sema was performed).
I think this small script can be used to at least automatically
transform global imports into selective ones.
The fundamental problem with dmd as a library is that we still
can't properly hook into the compiler internals. We are stuck to
performing sema and then trying to extract information from the
enriched tree, which kind of sucks.
RazvanN
More information about the Digitalmars-d
mailing list