tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
958 stars 83 forks source link

Need to track file locations through formatting #433

Open cdsmith opened 4 years ago

cdsmith commented 4 years ago

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.)

utdemir commented 4 years ago

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.