haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

code actions break literate haskell (lhs) files

Open m4lvin opened this issue 3 years ago • 1 comments

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

  1. Create a literate Haskell file foo.lhs with this content:
This is a comment.

> module Main where
>
> main = putStrLn ("Hello")
  1. Note that two code actions are provided, one to add the type signature for main and one to remove the redundant bracket.

  2. 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?

m4lvin avatar Mar 15 '22 19:03 m4lvin

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.

michaelpj avatar Mar 16 '22 10:03 michaelpj