Closed emlautarom1 closed 8 months ago
For now, my workaround is to format the entire file on save. In VSCode's settings.json
, add the following:
"[haskell]": {
"editor.formatOnSaveMode": "file",
}
Note that I'm able to format selections by selecting a range of text and using the Format Selection
command. My guess is that VSCode is sending different information between the command and it's automatic "format on save" feature, the later causing issues for fourmolu
/ormolu
.
Could you take a look at the message logs and see what different messages VSCode is sending in the two cases? I would indeed expect them to be the same.
Ok, after further investigation it seems like the problem also exist when using the Format Selection
command. A minimal reproducible example is as follows:
x = case () of
() -> ()
() -> ()
lineFormat Selection
.HLS fails to invoke the formatter with the following error:
2024-02-20T13:29:55.151918Z | Error | fourmolu: Internal Error: OrmoluParsingFailed (RealSrcSpan SrcSpanOneLine "/home/emlautarom1/Development/Haskell/myapp/app/Main.hs" 249 4 6 Nothing) "[GHC-58481] parse error on input `->'"
[Error - 10:29:55 AM] Request textDocument/rangeFormatting failed.
Message: fourmolu: Internal Error: OrmoluParsingFailed (RealSrcSpan SrcSpanOneLine "/home/emlautarom1/Development/Haskell/myapp/app/Main.hs" 249 4 6 Nothing) "[GHC-58481] parse error on input `->'"
Code: -32603
This seems to be an issue with Ormolu/Fourmolu and not HLS related.
Yes, that seems right. It looks like we're using native support in ormolu
/fourmolu
for formatting ranges, so I think it is indeed a bug.
Closing as it's tracked upstream.
Today I've upgrade to GHC 9.x from 8.10.4, together with HLS and Cabal. Before the upgrade, I was able to format my code using
fourmolu
alongside VSCode's"editor.formatOnSaveMode": "modificationsIfAvailable"
option, which only formats part of the code that has been changed (sometimes I want to decide how to format certain code instead of my formatter).After upgrading, this option no longer works forcing me to format the entire modified Haskell file.
Your environment
Which OS do you use?
Which version of GHC do you use and how did you install it?
How is your project built (alternative: link to the project)?
Which LSP client (editor/plugin) do you use?
Which version of HLS do you use and how did you install it?
Have you configured HLS in any way (especially: a
hie.yaml
file)?Steps to reproduce
This requires VSCode's with the
"editor.formatOnSaveMode": "modificationsIfAvailable"
option set in thesettings.json
file.Expected behaviour
Modified lines should be formatted.
Actual behaviour
HLS throws and error and does not format the code as intended.
Debug information