dfmt icon indicating copy to clipboard operation
dfmt copied to clipboard

Sorting import statements

Open LaurentTreguier opened this issue 7 years ago • 2 comments

This is something I love since I am kind of a maniac sometimes. In Intellij Idea for example, formatting Java code can also sort import statements alphabetically. Would it be difficult to implement in dfmt ? Maybe I'll try to get into the code and try to do something myself, but as I have never touched anything related to code parsing/formatting, for now I have no idea of how hard it could be.

LaurentTreguier avatar Jul 25 '16 19:07 LaurentTreguier

Thumbs up

CZDanol avatar Mar 13 '18 14:03 CZDanol

There is a WIP here: https://github.com/dlang-community/dfmt/pull/302

Due to dfmt's architecture it is actually pretty hard to move statements around. I do it by basically ignoring imports in the tree and putting them out as text not as tokens at the beginning of the enclosing scope.

stefan-koch-sociomantic avatar Mar 13 '18 16:03 stefan-koch-sociomantic

Much like this issue's author (I'm accustomed to the Organize Imports action in VS Code for JavaScript sources), I like to alphabetize my Selective Imports.

I might try to pickup that closed PR.

chances avatar Mar 31 '23 23:03 chances

just like for the reason the original PR was closed, I think this does not belong in dfmt. It's rather a dfix thing or something like that, that users would want to trigger manually. It's also already has an implementation in serve-d, you could just rip that out of there if you want it as standalone tool.

WebFreak001 avatar Apr 01 '23 06:04 WebFreak001