haskell / haskell/haskell-language-server

Class plugin breaks code when used at last line of a file that does not end with a line terminator

Closed
#5,059 0 comments 0 reactions 1 assignee Claimed by @Aster89 View on GitHub
type: bug
Dominant language
Haskell
Stars
3k
Forks
455
Avg merge
4d 3h
Merged PRs (30d)
12

Description

### Your environment

Which OS do you use? up-to-date ArchLinux

Which version of GHC do you use and how did you install it? 9.14.1 from GHCup

How is your project built (alternative: link to the project)? N/A

Which LSP client (editor/plugin) do you use? VSCode + the standard Haskell plugin, I think

Which version of HLS do you use and how did you install it? 2.14.0.0 from GHCup

Have you configured HLS in any way (especially: a `hie.yaml` file)? No

### Steps to reproduce

Create this file, say `ModuleA.hs`:
```haskell
module ModuleA where
data Foo = Foo
instance Show Foo where
```
**_making sure that there's no line terminator at the end of it_**, i.e. making sure that
```bash
git diff <(tail -1 WrongModuleA.hs | od -a) <(tail -1 ModuleA.hs | od -a)
```
```diff
0000000 i n s t a n c e sp S h o w sp F o
-0000020 o sp w h e r e nl
-0000030
+0000020 o sp w h e r e
+0000027
```
You can create one by simply saving the file in VSCode witout leaving an empty line at the end of the file.

Then tell HLS to add `show` and its signature

### Expected behaviour

The result should be
```haskell
-- like above
instance Show Foo where
show :: Foo -> String
show = _
```

### Actual behaviour

[… but it is this (see GIF)](https://ibb.co/MDkFZgps):
```haskell
-- like above
instance Show Foo where show :: Foo -> String
show = _
```

### Debug information

I think this bug affects/might affect and maybe _is_ affecting other existing plugins.

Surely [it _is_ affecting, as proved by the tests](https://github.com/haskell/haskell-language-server/actions/runs/33015704178/job/98333302415?pr=5014) the [case split plugin](https://github.com/haskell/haskell-language-server/pull/5014) I'm working on.

I don't understand why a similar test I wrote for the class split plugin [is not failing](https://github.com/haskell/haskell-language-server/pull/5058/changes), though!

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.