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

Inline variable refactor doesn't work for let bindings inside do block

Open BogdanYarotsky opened this issue 1 year ago • 4 comments

Your environment

Which OS do you use? MacOS

Which version of GHC do you use and how did you install it? Tested with GHC 9.4.8 installed with ghcup.

How is your project built (alternative: link to the project)? Cabal (exe + lib + tests). Link: https://github.com/BogdanYarotsky/async-http-client/blob/main/app/Main.hs

Which LSP client (editor/plugin) do you use? VS Code + Haskell extension

Which version of HLS do you use and how did you install it? 2.9.0.1 installed from ghcup.

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

Steps to reproduce

  1. Enter the following code
data Uri = Uri
  { host :: String,
    path :: String
  }

simpleHttpGet :: Uri -> IO String
simpleHttpGet uri' = 
  return "doesn't matter"

main :: IO ()
main = do
  let path' = "/"
  response <- simpleHttpGet (Uri "example.com" path')
  putStrLn response
  1. Try to inline the let binding inside a do block using a code action.

Expected behavior

In the example path’ should be replaced with “/“ in the place of invocation (Uri constructor) like this:


main = do
  response <- simpleHttpGet (Uri "example.com" "/")
  putStrLn response


Actual behavior

2 cryptic error messages from HLS and no changes to the code:

  1. retrie: Internal Error: Retrie - inline produced no changes
  2. Error condition, please check your setup and/or the issue tracker: retrie: Internal Error: Retrie - inline produced no changes

Please check the video below:

https://github.com/user-attachments/assets/60cf71b5-9814-42df-824f-48579ddf51c9

May be related to issue #4374

BogdanYarotsky avatar Sep 21 '24 19:09 BogdanYarotsky

Also tested with latest GHC (9.10.1), the code action is missing all together. image

BogdanYarotsky avatar Sep 21 '24 19:09 BogdanYarotsky

Hi, thank you for your bug report!

This looks like it is a bug with hls-retrie-plugin, which is powered by https://github.com/facebookincubator/retrie.

The CodeAction doesn't show up at all with GHC 9.10.1 because retrie doesn't work with 9.10.1

fendor avatar Sep 22 '24 09:09 fendor

Hi @fendor, thank you for a quick reply! Is there anything I can do to help with the fix of this issue? I would be happy to contribute.

BogdanYarotsky avatar Sep 22 '24 10:09 BogdanYarotsky

Unfortunately, the issue is complicated and likely not easy to fix. You can try to reproduce the issue with only the retrie executable and open a bug report. If you manage to write a reproducer, you can try to look into the retrie codebase, maybe write a failing test case and start on a fix.

However, support for 9.10.1 is an even bigger challenge https://github.com/facebookincubator/retrie/pull/64, and potentially impossible due to changes to ghc-exactprint. Additionally, retrie seems to be no longer actively developed (only maintenance work afaict), and we have discussed dropping the hls-retrie-plugin for that reason.

fendor avatar Sep 22 '24 10:09 fendor