haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.71k stars 368 forks source link

Ormolu plugin does not respect GHC options #48

Closed mithrandi closed 4 years ago

mithrandi commented 4 years ago

I guess https://github.com/haskell/haskell-language-server/blob/80bc2e8fac470330479c9e2e2222ebf5a687b95f/src/Ide/Plugin/Ormolu.hs#L118 is why.

alanz commented 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.

fendor commented 4 years ago

How can I test that? What is an ghc-option that ought to change ormolu output?

alanz commented 4 years ago

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.

fendor commented 4 years ago

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.

alanz commented 4 years ago

Ok. The internal plugin APIs are under our control, feel free to adapt them if needed.