Closed mithrandi closed 4 years ago
Its a work in progress, this first level is about understanding how it fits in. If you use haskell-ide-engine, it works as expected.
How can I test that? What is an ghc-option that ought to change ormolu output?
Strictly speaking all the options that are applied to a file should already be in its ModSummary.
i.e., we can already parse the file, with the correct options. So looking into the BIOS for them is violating layering.
Ideally, we should get ormolu to work like brittany, where we give it an already-parsed file, since we have it from the graph.
When I look at the source code, this is already done:
fromDyn :: ParsedModule -> IO [DynOption]
fromDyn pmod =
let
df = ms_hspp_opts $ pm_mod_summary pmod
pp =
let p = D.sPgm_F $ D.settings df
in if null p then [] else ["-pgmF=" <> p]
pm = map (("-fplugin=" <>) . moduleNameString) $ D.pluginModNames df
ex = map (("-X" <>) . show) $ S.toList $ D.extensionFlags df
in
return $ map DynOption $ pp <> pm <> ex
m_parsed <- runAction ideState $ getParsedModule fp
fileOpts <- case m_parsed of
Nothing -> return []
Just pm -> fromDyn pm
It just seems that these options are only passed to the Range formatting and not to the Document Range Formatter. Fixing this seems like a single line change (and deleting a bunch of others), but I would like to test this.
There is an API already (https://hackage.haskell.org/package/ormolu-0.0.5.0/docs/Ormolu-Printer.html) but it seems not ideal for us, yet.
Ok. The internal plugin APIs are under our control, feel free to adapt them if needed.
I guess https://github.com/haskell/haskell-language-server/blob/80bc2e8fac470330479c9e2e2222ebf5a687b95f/src/Ide/Plugin/Ormolu.hs#L118 is why.