haskell / haskell/haskell-language-server

code actions break literate haskell (lhs) files

Open
#2,783 1 comment 0 reactions 0 assignees View on GitHub
component: ghcide type: bug
Dominant language
Haskell
Stars
3k
Forks
455
Avg merge
2d 19h
Merged PRs (30d)
11

Description

### 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")
```

2. Note that two code actions are provided, one to add the type signature for `main` and one to remove the redundant bracket.

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.