haskell / haskell-language-server

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

Formatters block on session setup #4168

Open michaelpj opened 2 months ago

michaelpj commented 2 months ago

At the moment, most of our formatter plugins require the GHC session in order to acquire the DynFlags for a module. This is even true for the CLI modes - most of the plugins still get the flags so that they can pass them to the CLI executable.

This means that formatting is generally going to block until the session is set up. This isn't great: in particular, it's not uncommon to have some kind of format-on-save set up, and that means you can't save a file until HLS is finished setting up! (I think there's also a client problem there: I think it should be the client's responsibility to time out formatting in that case)

So it would be nice if this didn't happen. The best thing I can think of doing is just to let the formatters do whatever they do if they don't get the flags specified. That presumably means guessing them from cabal files etc, but crucially in a way that doesn't block on HLS. It would also make them more likely to line up with how a CLI formatter would operate. Or at least if we're in the CLI mode I think we shouldn't take the flags from HLS, since the whole point is to match what the CLI formatter does.

Thoughts from formatting plugin maintainers? @georgefst @peterbecich ?

michaelpj commented 2 months ago

See https://github.com/haskell/haskell-language-server/pull/4170

michaelpj commented 2 months ago

We could also have an option, of course, although generally better to just do the right thing.