| |
| Posted by Jonathan M Davis in reply to Alexandru Ermicioi | PermalinkReply |
|
Jonathan M Davis
Posted in reply to Alexandru Ermicioi
| On Thursday, July 11, 2024 4:43:28 AM MDT Alexandru Ermicioi via Digitalmars-d wrote:
> 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.
>
> That must be one of core features not just amazing.
> Java, php, typescript, kotlin, groovy, and any other language
> with good ide functionality have this.
>
> As reference on feature set and configurability I'd suggest to look at java import optimizer found in Jetbrains IDE.
We could certainly get partway there, but I'm not sure that it's even actually possible in D to get all of the way there thanks to templates and conditional compilation. You can create local imports for non-templated stuff, and for the conditional code branches that are actually compiled, you could add local imports, but removing the top-level imports would break the uncompiled conditional branches in many cases, and since what happens with those conditional branches depends on state that you don't necessarily have access to, you can't necessarily automate adding the correct imports - at least not if you want to actually use selective imports rather than just copying all of the top-level imports which _might_ be needed.
Attempts have been made in the past to do stuff like provide a tool for removing unused imports (which is essentially the same problem), and they've never fully worked, because D's conditional compilation gets in the way. It's the kind of thing that's much easier to do with a simpler, less powerful language.
- Jonathan M Davis
|