bennycode / linessorterplus

https://plugins.jetbrains.com/plugin/18564-lines-sorter-plus
5 stars 1 forks source link

FR: sort lines by specified column #10

Open wibotwi opened 1 month ago

wibotwi commented 1 month ago

this is especially useful in SQL for code like

SELECT xxx as X
    , bbb as A
    , aaa as B

If I select two rows, I want it to be sorted as A,B, but default is B,A as is sorts aaa,bbb

Apparently vscode can do this, and my friends laugh at me that IntelliJ cannot do that :(

wibotwi commented 1 month ago

cross posted to linessorter as well, I am not sure you guys share code or not

wibotwi commented 1 month ago

oh I found https://github.com/syllant/idea-plugin-linessorter/issues/16 which led me to https://github.com/krasa/StringManipulation which turned out can do that !

bennycode commented 1 month ago

Hi, can you give me an example how it looks before sorting and how it should look like after sorting? Best, Benny

wibotwi commented 1 month ago

Sure.

Original (easy mode - no comments and no empty lines):

    , bbb as CCC
    , ccc as AAA
    , aaa as BBB

Sorted by column 4:

    , ccc as AAA
    , aaa as BBB
    , bbb as CCC

Turned out StringManipulation plugin can do this. However, in real world we also have comments and empty lines. And we also have first line, which does not start with comma.

Original (real life mode):

SELECT
     ddd as DDD
    , bbb as CCC

    -- comment about column AAA
    , ccc as AAA
    -- comment about column BBB
    , aaa as BBB

Sorted:

SELECT 
    -- comment about column AAA
      ccc as AAA
    -- comment about column BBB
    , aaa as BBB

    , bbb as CCC
    , ddd as DDD