haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.71k stars 368 forks source link

Inline function with guard only pick first guard case #4374

Open guibou opened 3 months ago

guibou commented 3 months ago

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

fendor commented 2 months ago

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

soulomoon commented 2 months ago

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

soulomoon commented 2 months ago

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

guibou commented 2 months ago

Thank you for the test with retrie

michaelpj commented 1 month ago

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

guibou commented 1 month ago

@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 ;)

michaelpj commented 1 month ago

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.