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

Inline function with guard only pick first guard case

Open guibou opened this issue 1 year ago • 7 comments

Your environment

Which OS do you use? Linux Which version of GHC do you use and how did you install it?

Tested with ghc 9.6.5 and 9.8.2 installed with nix.

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

Single file

Which LSP client (editor/plugin) do you use?

neovim + neovim-lsp

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

2.9.0.0 installed from nixpkgs.

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

No hie file, single file support

Steps to reproduce

The following file:

foo x y
  | x == 0 = y
  | otherwise = x + y

bar = foo 1 2

The code action on the foo call, called inline foo

Expected behaviour

foo (in bar)should be replaced by equivalent piece of code, so I assume something like:

bar = if 1 == 0 then 2 else 1 + 2

(or something equivalent).

Actual behaviour

Looks like only the first case of foo implementation is taken into account, and hence, I get:

bar = 2

See for yourself:

https://github.com/user-attachments/assets/a0ad59d3-4c41-41e0-b71b-9f606181efa7

Debug information

guibou avatar Aug 03 '24 13:08 guibou

Hi, thanks for the bug report! Iirc, this feature is implemented by retrie. Is this reproducible with retrie as well, or only in HLS?

fendor avatar Aug 05 '24 07:08 fendor

I manually test it in retrie, It is retrie's problem.

soulomoon avatar Aug 05 '24 08:08 soulomoon

Issue created in retire https://github.com/facebookincubator/retrie/issues/71

soulomoon avatar Aug 05 '24 08:08 soulomoon

Thank you for the test with retrie

guibou avatar Aug 13 '24 10:08 guibou

Given that retrie is apparently not being actively maintained, perhaps we should deprecate the retrie plugin?

michaelpj avatar Sep 04 '24 12:09 michaelpj

@michaelpj

Given that retrie is apparently not being actively maintained, perhaps we should deprecate the retrie plugin?

Yes, for sure. However, the fold / unfold (e.g. replace symbol by implementation) is part of our refactoring logic (we export "deprecated" pattern synonyms and "smart constructor" and ask our (internal) users to just unfold at call site using the code action.

This thing is a terrific quality of life tool. Do you think a subset of retrie can be imported into HLS in order to keep at least the "replace by implementation" code action?

edit I really have the feeling that I'm programming with "The Rocq Prover" in my haskell editor and that's something which makes me like my job ;)

guibou avatar Sep 05 '24 04:09 guibou

I mean, we don't need to take it out urgently, perhaps retrie will continue to work for a while. But in the long run either someone needs to keep it going or write a replacement.

michaelpj avatar Sep 05 '24 08:09 michaelpj