haskell / haskell/haskell-language-server

Regression: "Add constraint to instance context" code action drops module qualifiers

Open
#5,085 1 comment 1 reaction 0 assignees View on GitHub
component: hls-refactor-plugin Hackathon 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?**
NixOS

**How is your project built (alternative: link to the project)?**
https://codeberg.org/ozkutuk/hls-instance-action-repro

**Which LSP client (editor/plugin) do you use?**
Neovim + native LSP

**Which version of HLS do you use and how did you install it?**
HEAD, compiled from source. Issue is also present on HLS 2.15.

### Steps to reproduce

Prepare the two files as shown below, and invoke the code action specified by the comment. I have also created this reproducer as a git repo that you can clone and try right away: https://codeberg.org/ozkutuk/hls-instance-action-repro

```hs
-- MyFunctor.hs

module MyFunctor where

class Functor f where
myFmap :: (a -> b) -> f a -> f b

-- MyLib.hs

module MyLib where

import qualified MyFunctor

data Foo a = Foo a

instance Functor Foo where
fmap = MyFunctor.myFmap
-- ^ Invoke code action to add constraint to the instance context
```

### Expected behaviour

The instance should look like:

```hs
instance MyFunctor.Functor Foo => Functor Foo where
fmap = MyFunctor.myFmap
```

### Actual behaviour

```hs
instance Functor Foo => Functor Foo where
fmap = MyFunctor.myFmap
```

### Debug information

It works as expected until HLS 2.14.

Contributor guide

No contributing guide indexed for this repository

Research direction

Clone the linked reproducer and open MyLib.hs with MyFunctor.hs available, then invoke the “add constraint to the instance context” code action at the marked line. Compare the generated instance with the expected qualified constraint and investigate the behavior change between HLS 2.14 and 2.15. Done means the action preserves the MyFunctor. qualifier while retaining the existing instance declaration.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.