haskell / haskell-language-server

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

LSP throws exception if a code action is applied in a lhaskell file where the line starts with a `>` #3523

Open Enayaaa opened 1 year ago

Enayaaa commented 1 year ago

Your environment

Which OS do you use? Ubuntu Which version of GHC do you use and how did you install it? 9.2.5 from ghcup How is your project built (alternative: link to the project)?

Which LSP client (editor/plugin) do you use? Neovim+LanguageClient-neovim Which version of HLS do you use and how did you install it? 1.9.1.0 installed with mason.nvim LSP installer and handler plugin Have you configured HLS in any way (especially: a hie.yaml file)? no

Steps to reproduce

Create a .lhs file with following content

> f a = g a
> g = id

Now the first line should have a hint you can apply, namely Eta reduce. Applying the code action results in the following exception:

[ERROR][2023-03-14 14:06:09] ...lsp/handlers.lua:485    "ReactorMessageActionException\nhaskell-language-server-9.2.5: panic! (the 'impossible' happened)\n  (GHC version 9.2.5:\n\tapply\n\nparse error on input `>'\nCall stack:\n    CallStack (from HasCallStack):\n      callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic\n      pprPanic, called at src/Refact/Compat.hs:153:13 in apply-refact-0.12.0.0-6ade9c5a0135a7c47e9fe513b6d967bc72e88f692fb351d416614d8102db1de3:Refact.Compat\n\nPlease report this as a GHC bug:  https://www.haskell.org/ghc/reportabug\n"

Expected behaviour

The hint is applied without any LSP throws an exception and the code is kept in a working state without any errors. If the LSP is supposed to work in lhaskell files, code actions should work too. I also noticed that applying code actions like putting the type signature is applied but no > is put at the start of the line, thus the .lhs file becomes invalid after applying the code action.

Actual behaviour

LHS throws a ReactorMessageActionException.

Debug information

[ERROR][2023-03-14 14:06:09] ...lsp/handlers.lua:485    "ReactorMessageActionException\nhaskell-language-server-9.2.5: panic! (the 'impossible' happened)\n  (GHC version 9.2.5:\n\tapply\n\nparse error on input `>'\nCall stack:\n    CallStack (from HasCallStack):\n      callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic\n      pprPanic, called at src/Refact/Compat.hs:153:13 in apply-refact-0.12.0.0-6ade9c5a0135a7c47e9fe513b6d967bc72e88f692fb351d416614d8102db1de3:Refact.Compat\n\nPlease report this as a GHC bug:  https://www.haskell.org/ghc/reportabug\n"
michaelpj commented 1 year ago

Based on the call stack, it looks like this is an upstream bug in apply-refact. If so, you should be able to reproduce by running hlint --refactor on the command line. If so, please report it upstream.

michaelpj commented 10 months ago

See also https://github.com/haskell/haskell-language-server/issues/689