I'm attempting to integrate ormolu into an interactive editor. When formatting runs, I have to throw away all location information, and this is a jarring experience. Since you have original source locations in the parsed AST, might it be possible to pass in a list of SrcLoc values, and get back a list of the corresponding locations after formatting? This would be awesome.
(I can, of course, try to recover this information after formatting with some kind of a fuzzy diff, but this will by necessity be guessing information after it's been thrown away. Ormolu itself has the information it needs to give a precise answer; that is, it already KNOWS which source location this bit of syntax was at in the original file, at the time that it's rendering the formatted version.)
Note: Long time ago I implemented a similar functionality as part of ud/comment-overhaul branch. It's probably bit-rotten, but maybe something can be salvaged easily.
I'm attempting to integrate ormolu into an interactive editor. When formatting runs, I have to throw away all location information, and this is a jarring experience. Since you have original source locations in the parsed AST, might it be possible to pass in a list of
SrcLoc
values, and get back a list of the corresponding locations after formatting? This would be awesome.(I can, of course, try to recover this information after formatting with some kind of a fuzzy diff, but this will by necessity be guessing information after it's been thrown away. Ormolu itself has the information it needs to give a precise answer; that is, it already KNOWS which source location this bit of syntax was at in the original file, at the time that it's rendering the formatted version.)