code actions break literate haskell (lhs) files
Your environment
Debian stable, HLS 1.6.1.0, the problem happens with emacs+lsp-mode, and VS Codium+vscode-haskell
(Hence I report it here and not to the editor plugins, hope that makes sense.)
Steps to reproduce
- Create a literate Haskell file
foo.lhswith this content:
This is a comment.
> module Main where
>
> main = putStrLn ("Hello")
-
Note that two code actions are provided, one to add the type signature for
mainand one to remove the redundant bracket. -
Apply either of the two code actions.
Expected behaviour
Applying the two code actions should only modify code within the > blocks and not change or remove comments.
For the type signature we want this result:
This is a comment.
> module Main where
>
> main :: IO ()
> main = putStrLn ("Hello")
For the brackets we want:
This is a comment.
> module Main where
>
> main = putStrLn "Hello"
Actual behaviour
Both code actions "break" the file.
The type signature is added without a > prefix, so it will be a comment and not seen as Haskell code. Moreover, empty lines are needed to separate code from comments, so unlit fails after the change is made:
This is a comment.
> module Main where
>
main :: IO ()
> main = putStrLn ("Hello")
Curiously, applying the hlint code action to remove the brackets works, but it also deletes all > and all comments from the file:
module Main where
main = putStrLn "Hello"
Is there a way to fix this? From https://github.com/haskell/ghcide/commit/44b11667d8593ae84c48ca88e96f4f227deec096 I understand that haskell-language-server uses the unlit stage from ghc and then only looks at the resulting code, so it might be hard or even impossible to get the expected behavior above?
I think this is a facet of https://github.com/haskell/haskell-language-server/issues/689
Currently I think that any preprocessed file doesn't really work properly.