Skip to content

HLS suggests quick fixes but cannot apply them #3241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mfriley opened this issue Oct 4, 2022 · 54 comments · Fixed by #3469
Closed

HLS suggests quick fixes but cannot apply them #3241

mfriley opened this issue Oct 4, 2022 · 54 comments · Fixed by #3469
Labels
level: easy The issue is suited for beginners type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@mfriley
Copy link

mfriley commented Oct 4, 2022

Your environment

  • Arch Linux
  • Emacs 28.2 + Eglot (also tested: lsp-mode, VSCode OSS with Haskell LSP plugin 2.2.1)
  • GHC 9.2.4
  • HLS 1.8.0.0
  • Cabal 3.6.2.0
  • Stack 2.9.1

Steps to reproduce

Write any code that HLS will suggest a quick fix for, such as: f x = id x.

Expected behaviour

HLS should suggest a quick fix, then apply the change after selecting the quick fix.

Actual behaviour

HLS offers the appropriate code actions, but quick fixes throw errors instead of applying the changes to the code. Other code actions, such as "Ignore hint ... in this module" still work. Other HLS features also work.
I have tested this with both Emacs LSP packages as well as VSCode, with identical results in all three cases.

Debug information

Error condition, please check your setup and/or the issue tracker: ReactorMessageActionException ExitFailure 1

@mfriley mfriley added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Oct 4, 2022
@michaelpj
Copy link
Collaborator

Can you be more specific about the action that fails and get us the logs, ideally in debug mode?

@michaelpj michaelpj added status: needs info Not actionable, because there's missing information and removed status: needs triage labels Oct 4, 2022
@mfriley
Copy link
Author

mfriley commented Oct 4, 2022

Sure. When I initiate a code action, and select the "Apply hint" option:

2022-10-04-121546_1920x1080_scrot

It throws these errors:

LSP :: Error condition, please check your setup and/or the [issue tracker](https://github.com/haskell/haskell-language-server/issues): 
ReactorMessageActionException
ExitFailure 1
Error running timer: (error "‘workspace/executeCommand’ with ‘3050:hlint:applyOne’ failed.

(error \"ExitFailure 1\")")

This is the debug output in hls.log:

2022-10-04T17:13:04.542597Z | Debug | Getting hlint ideas for  NormalizedFilePath "/home/<name>/Projects/HaskellBook/applicative1.hs"
2022-10-04T17:13:04.543003Z | Debug | Using extensions for  NormalizedFilePath "/home/<name>/Projects/HaskellBook/applicative1.hs": [ MonomorphismRestriction
                                                                                               , RelaxedPolyRec
                                                                                               , ForeignFunctionInterface
                                                                                               , ImplicitPrelude
                                                                                               , ScopedTypeVariables
                                                                                               , BangPatterns
                                                                                               , RecordPuns
                                                                                               , GADTSyntax
                                                                                               , DoAndIfThenElse
                                                                                               , ConstraintKinds
                                                                                               , PolyKinds
                                                                                               , InstanceSigs
                                                                                               , StandaloneDeriving
                                                                                               , DeriveDataTypeable
                                                                                               , DeriveFunctor
                                                                                               , DeriveTraversable
                                                                                               , DeriveFoldable
                                                                                               , DeriveGeneric
                                                                                               , DeriveLift
                                                                                               , TypeSynonymInstances
                                                                                               , FlexibleContexts
                                                                                               , FlexibleInstances
                                                                                               , ConstrainedClassMethods
                                                                                               , MultiParamTypeClasses
                                                                                               , ExistentialQuantification
                                                                                               , EmptyDataDecls
                                                                                               , KindSignatures
                                                                                               , GeneralizedNewtypeDeriving
                                                                                               , PostfixOperators
                                                                                               , TupleSections
                                                                                               , PatternGuards
                                                                                               , RankNTypes
                                                                                               , TypeOperators
                                                                                               , ExplicitForAll
                                                                                               , TraditionalRecordSyntax
                                                                                               , BinaryLiterals
                                                                                               , HexFloatLiterals
                                                                                               , EmptyCase
                                                                                               , NamedWildCards
                                                                                               , TypeApplications
                                                                                               , EmptyDataDeriving
                                                                                               , NumericUnderscores
                                                                                               , StarIsType
                                                                                               , ImportQualifiedPost
                                                                                               , StandaloneKindSignatures
                                                                                               , FieldSelectors ]
2022-10-04T17:13:04.545305Z | Debug | Finished: applyHint Took: 0.00s
2022-10-04T17:13:04.545411Z | Debug | Generated hlint ideas for for NormalizedFilePath "/home/<name>/Projects/HaskellBook/applicative1.hs": [[Replace {rtype = Expr, pos = SrcSpan {startLine = 42, startCol = 12, endLine = 42, endCol = 41}, subts = [("f",SrcSpan {startLine = 42, startCol = 17, endLine = 42, endCol = 20}),("x",SrcSpan {startLine = 42, startCol = 23, endLine = 42, endCol = 41})], orig = "f <$> x"}]]
2022-10-04T17:13:04.592577Z | Debug | Finished: applyHint Took: 0.00s
2022-10-04T17:13:04.592772Z | Debug | Finished: applyHint Took: 0.00s
2022-10-04T17:13:04.593079Z | Debug | Finished: applyHint Took: 0.00s
2022-10-04T17:13:04.593505Z | Error | ReactorMessageActionException
ExitFailure 1

@michaelpj
Copy link
Collaborator

That is quite odd.

@brandonmlusk
Copy link

I seem to have the same problem as well on Fedora. It is quite odd because everything else seems to work besides the quick fixes.

@michaelpj
Copy link
Collaborator

Does hlint --refactor work from the CLI?

@bristermitten
Copy link

bristermitten commented Oct 10, 2022

Same issue for me, hlint --refactor does work

@AndreiDuma
Copy link

Same here on HLS 1.8.0.0, GHC 9.2.4, hlint v3.5 and refactor v0.10.0.0. I'm using Emacs with eglot as an LSP client. Eglot reports this exchange of messages with HLS:

[client-request] (id:6) Tue Oct 11 09:45:13 2022:
(:jsonrpc "2.0" :id 6 :method "textDocument/codeAction" :params
	  (:textDocument
	   (:uri "file:///Users/andrei/dev/_/haskell/eulerhs/src/Main.hs")
	   :range
	   (:start
	    (:line 0 :character 21)
	    :end
	    (:line 0 :character 21))
	   :context
	   (:diagnostics
	    [(:code "refact:Unused LANGUAGE pragma" :message "Unused LANGUAGE pragma\nFound:\n  {-# LANGUAGE LambdaCase #-}\nWhy not:\n  \n" :range
		    (:end
		     (:character 27 :line 0)
		     :start
		     (:character 0 :line 0))
		    :severity 3 :source "hlint")])))

[server-reply] (id:6) Tue Oct 11 09:45:13 2022:
(:id 6 :jsonrpc "2.0" :result
     [(:diagnostics
       []
       :edit
       (:changes
	(:file:///Users/andrei/dev/_/haskell/eulerhs/src/Main\.hs
	 [(:newText "{-# LANGUAGE LambdaCase #-}\n" :range
		    (:end
		     (:character 0 :line 1)
		     :start
		     (:character 0 :line 1)))]))
       :kind "quickfix" :title "Add \"LambdaCase\"")
      (:command
       (:arguments
	[(:file "file:///Users/andrei/dev/_/haskell/eulerhs/src/Main.hs" :hintTitle "Unused LANGUAGE pragma" :start_pos
		(:character 0 :line 0))]
	:command "90894:hlint:applyOne" :title "Apply hint \"Unused LANGUAGE pragma\"")
       :diagnostics
       [(:code "refact:Unused LANGUAGE pragma" :message "Unused LANGUAGE pragma\nFound:\n  {-# LANGUAGE LambdaCase #-}\nWhy not:\n  \n" :range
	       (:end
		(:character 27 :line 0)
		:start
		(:character 0 :line 0))
	       :severity 3 :source "hlint")]
       :isPreferred t :kind "quickfix" :title "Apply hint \"Unused LANGUAGE pragma\"")
      (:diagnostics
       [(:code "refact:Unused LANGUAGE pragma" :message "Unused LANGUAGE pragma\nFound:\n  {-# LANGUAGE LambdaCase #-}\nWhy not:\n  \n" :range
	       (:end
		(:character 27 :line 0)
		:start
		(:character 0 :line 0))
	       :severity 3 :source "hlint")]
       :edit
       (:changes
	(:file:///Users/andrei/dev/_/haskell/eulerhs/src/Main\.hs
	 [(:newText "{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}\n{-# HLINT ignore \"Unused LANGUAGE pragma\" #-}\n" :range
		    (:end
		     (:character 0 :line 1)
		     :start
		     (:character 0 :line 1)))]))
       :isPreferred :json-false :kind "quickfix" :title "Ignore hint \"Unused LANGUAGE pragma\" in this module")])

[client-request] (id:7) Tue Oct 11 09:45:17 2022:
(:jsonrpc "2.0" :id 7 :method "workspace/executeCommand" :params
	  (:command "90894:hlint:applyOne" :arguments
		    [(:file "file:///Users/andrei/dev/_/haskell/eulerhs/src/Main.hs" :hintTitle "Unused LANGUAGE pragma" :start_pos
			    (:character 0 :line 0))]))

[stderr] Missing file: /private/var/lib/gitlab-runner/builds/7KQsmDei/0/haskell/haskell-language-server/toolchain/.ghcup/ghc/9.2.4/lib/ghc-9.2.4/lib/settings

[server-notification] Tue Oct 11 09:45:17 2022:
(:jsonrpc "2.0" :method "window/showMessage" :params
	  (:message "Error condition, please check your setup and/or the [issue tracker](https://github.com/haskell/haskell-language-server/issues): \nReactorMessageActionException\nExitFailure 1" :type 1))

[server-notification] Tue Oct 11 09:45:17 2022:
(:jsonrpc "2.0" :method "window/logMessage" :params
	  (:message "ReactorMessageActionException\nExitFailure 1" :type 1))

[server-reply] (id:7) ERROR Tue Oct 11 09:45:17 2022:
(:error
 (:code -32603 :message "ExitFailure 1")
 :id 7 :jsonrpc "2.0")

[stderr] 2022-10-11T06:45:17.144114Z | Error | ReactorMessageActionException
[stderr] ExitFailure 1

I added some lines for clarity. I hope this helps.

@michaelpj
Copy link
Collaborator

Aha! That reveals a suspicious line:

[stderr] Missing file: /private/var/lib/gitlab-runner/builds/7KQsmDei/0/haskell/haskell-language-server/toolchain/.ghcup/ghc/9.2.4/lib/ghc-9.2.4/lib/settings

So maybe this is an installation problem? @hasufell do you know what might cause this?

@michaelpj
Copy link
Collaborator

It sounds like maybe something is compiling in the location of a GHC settings file and somehow getting the absolute path to where it was on the gitlab builder that build the bindist 🤔

@hasufell
Copy link
Member

I don't know. This is something to ask the GHC folks @mpickering @bgamari

@mpickering
Copy link
Contributor

Is there something in HLS depending on ghc-paths?

@michaelpj
Copy link
Collaborator

ghcide itself depends on ghc-paths

(I tried putting constraints: ghc-paths < 0.0 in cabal.project, and the first conflict cabal told me about was with ghcide)

@andreabedini
Copy link

andreabedini commented Oct 12, 2022

Subscribing since I am experiencing the same problem. Note that everything works with ghc 8.10.7 and not with 9.2.4.

Also for me the error is

Missing file: /builds/haskell/haskell-language-server/toolchain/.ghcup/ghc/9.2.4/lib/ghc-9.2.4/settings

hls 1.8.0.0 and ghc 9.2.4 as installed via ghcup

@michaelpj
Copy link
Collaborator

If any of you who have this problem have the time, it would be interesting to know whether the problem persists when you tell ghcup to compile HLS for you instead of using the bindist. Hopefully that would pin it down to a bindist problem.

@bristermitten
Copy link

Compiling from source (ghcup compile hls --git-ref master --ghc 9.2.3) does seem to fix this yeah

@andreabedini
Copy link

I tried a slightly different approach (compiling the released version rather than master) and I am surprised I cannot even get an install plan (hls 1.8 as released on hackage).

❯ ghcup run --ghc 9.2.4 -- cabal install haskell-language-server --minimize-conflict-set
Resolving dependencies...
Error: cabal: Could not resolve dependencies:
[__0] trying: haskell-language-server-1.8.0.0 (user goal)
[__1] trying: haskell-language-server:+haddockcomments
[__2] trying: haskell-language-server:+fourmolu
[__3] trying: haskell-language-server:+stylishhaskell
[__4] trying: hls-stylish-haskell-plugin-1.0.1.1 (dependency of
haskell-language-server +stylishhaskell)
[__5] trying: lsp-1.6.0.0 (dependency of haskell-language-server)
[__6] next goal: ghcide (dependency of haskell-language-server)
[__6] rejecting: ghcide-1.8.0.0 (conflict: hls-stylish-haskell-plugin =>
ghcide^>=1.7)
[__6] rejecting: ghcide-1.7.0.0 (conflict: haskell-language-server =>
ghcide^>=1.8)
[__6] skipping: ghcide-1.6.0.1, ghcide-1.6.0.0, ghcide-1.5.0.1, ghcide-1.5.0,
ghcide-1.4.2.3, ghcide-1.4.2.2, ghcide-1.4.2.0, ghcide-1.4.1.0,
ghcide-1.4.0.3, ghcide-1.4.0.2, ghcide-1.4.0.1, ghcide-1.3.0.0,
ghcide-1.2.0.2, ghcide-1.2.0.1, ghcide-1.2.0.0, ghcide-1.1.0.0,
ghcide-1.0.0.0, ghcide-0.7.5.0, ghcide-0.7.4.0, ghcide-0.7.3.0,
ghcide-0.7.2.0, ghcide-0.7.1.0, ghcide-0.7.0.0, ghcide-0.6.0.2,
ghcide-0.6.0.1, ghcide-0.6.0, ghcide-0.5.0, ghcide-0.4.0, ghcide-0.3.0,
ghcide-0.2.0, ghcide-0.1.0, ghcide-0.0.6, ghcide-0.0.5, ghcide-0.0.4,
ghcide-0.0.3, ghcide-0.0.2, ghcide-0.0.1, ghcide-1.4.2.1 (has the same
characteristics that caused the previous version to fail: excluded by
constraint '^>=1.8' from 'haskell-language-server')
[__6] fail (backjumping, conflict set: ghcide, haskell-language-server,
hls-stylish-haskell-plugin)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: ghcide, haskell-language-server, base,
lsp, hls-haddock-comments-plugin, ghc-lib-parser, fourmolu, ghc-exactprint,
retrie, haskell-language-server:fourmolu,
haskell-language-server:haddockcomments, hls-stylish-haskell-plugin,
haskell-language-server:stylishhaskell

(This is the same error you get with ghcup compile hls --version 1.8.0.0 --ghc 9.2.4, just in expanded form).

@Kleidukos
Copy link
Member

Compiling master from scratch with ghcup has fixed the problem for me

@mfriley
Copy link
Author

mfriley commented Oct 16, 2022

Just tried ghcup compile hls --git-ref master --ghc 9.2.4 and it does seem to work now.

@pepeiborra
Copy link
Collaborator

HLS-hlint-plugin and any other plugins that use libdir need this fix: #3120 (comment)

@michaelpj michaelpj added level: easy The issue is suited for beginners and removed status: needs info Not actionable, because there's missing information labels Oct 17, 2022
@andreabedini
Copy link

Ok, so this is not a bindist problem but a 1.8.0.0 bug with ghc 9.2 (that seems to be fixed on master).

  • Is this a fair assessment?
  • Can we expect a bugfix release?

@pepeiborra
Copy link
Collaborator

It's not fixed on master, only one plugin is doing the right thing

@andreabedini
Copy link

But above it's reported that building from master works. It must still be related to bindists.

@michaelpj
Copy link
Collaborator

My possibly wrong understanding is that many of the plugins access the GHC libdir in a way that is fragile, in that it works if the build GHC is available at runtime (e.g. if you compile it yourself) and not if it isn't (e.g. if you have a bindist). So we need to fix the plugins to be less fragile, it's not a problem with the bindist process.

Fortunately we have an example of doing it right that we can copy, which Pepe pointed to.

@polux
Copy link

polux commented Dec 1, 2022

I had the same issue on linux with vscode and ghc 9.4.2. Compiling from master as in #3241 (comment) solved it. More specifically I used HEAD the date of #3241 (comment):

ghcup rm hls 1.8.0.0
ghcup compile hls --git-ref 4cb9ff13912b28c0d9da57edee9cace9f09b55f7 --ghc 9.2.4

@tobeannouncd
Copy link

tobeannouncd commented Dec 16, 2022

I'm getting the same issue with VS Code in W11 under WSL. Reinstalling HLS 1.8.0.0 via GHCup has had no effect.

Missing file: /root/.ghcup/ghc/9.2.4/lib/ghc-9.2.4/settings
2022-12-16T03:14:50.262020Z | Error | ReactorMessageActionException
ExitFailure 1
[Error - 10:14:50 PM] ReactorMessageActionException
ExitFailure 1
[Error - 10:14:50 PM] Request workspace/executeCommand failed.
  Message: ExitFailure 1
  Code: -32603 

That file path looks awfully suspicious considering I'm running under WSL, as it should be ~/.ghcup/ghc/9.2.4/lib/ghc-9.2.4/settings

edit: running ghcup compile hls --git-ref master --ghc 9.2.4 got things working

@adamwojt
Copy link

ghcup compile hls --git-ref master --ghc 9.2.4
this works, thanks.

@ShereKahn
Copy link

FWIW, I have had the same problem yesterday, with ghcup version v0.1.18.0, stack Version 2.9.1, HLS 1.9.0.0, ghc 9.2.5 all installed via ghcup. Forcing the compilation of hls 1.9 with the above stanzas did fix the issue.

@niekvandepas
Copy link

Just wanted to add that the forced compilation trick also worked for me on macOS 13.1 and HLS 1.9.0.0 and GHC 9.4.4:

ghcup rm hls 1.9.0.0
ghcup compile hls --git-ref master --ghc 9.4.4

@maerten
Copy link

maerten commented Jan 7, 2023

The above worked for me after running cabal update.
(Without updating, I got:

[ cabal ] characteristics that caused the previous version to fail: excluded by
[ cabal ] constraint '^>=0.11.0.0' from 'hls-hlint-plugin')
[ cabal ] [__1] fail (backjumping, conflict set: apply-refact, hls-hlint-plugin)
[ cabal ] After searching the rest of the dependency tree exhaustively, these were the
[ cabal ] goals I've had most trouble fulfilling: hls-hlint-plugin, apply-refact

)

@amano-kenji
Copy link

amano-kenji commented Jan 8, 2023

If I try to apply code actions in brick/src, hls-1.9.0.0 fixes the issue.

However, if I try to apply code actions in brick/programs, HLS still shows me ReactorMessageActionException.

You should try applying code actions in https://github.com/jtdaugherty/brick/tree/master/programs

Enable demos flag with cabal configure -f demos.

@keithfancher
Copy link
Contributor

I'm still seeing this with HLS 1.9.0.0 (via ghcup), neovim 0.8.2. Just tried to fix some redundant brackets and got:

Screenshot from 2023-01-09 17-30-49

I'm happy to see there's a workaround! But is there a better fix for this? Seems a strange bug...

@amano-kenji
Copy link

I think the issue was probably fixed for cabal library, but it still exists for cabal executables.

@sondr3
Copy link

sondr3 commented Jan 11, 2023

I'm getting this error as well, using either VSCode or neovim. Manually installing it works fine, but is a hassle I'd rather avoid as the tooling I use in e.g. neovim automatically installs a version that doesn't work.

@cdimitroulas
Copy link

Weird, I was expecting this to go away when a new version was released but seems that 1.9.0.0 didn't do the trick. What needs to be done in order for this to work out of the box rather than requiring the workaround?

@konnik
Copy link

konnik commented Jan 16, 2023

On Ubuntu 20.04.5 LTS (x86_64) I have the same problem with all the latest tools from ghcup :

$ ghcup list -c set
   Tool  Version  Tags                 Notes      
✔✔ ghc   9.4.4    latest,base-4.17.0.0 hls-powered
✔✔ cabal 3.8.1.0  latest                          
✔✔ hls   1.9.0.0  latest,recommended              
✔✔ stack 2.9.3    latest                          
✔✔ ghcup 0.1.19.0 latest,recommended 

Applying quickfix in VSCode gives the following in the log:

Missing file: /builds/haskell/haskell-language-server/toolchain/.ghcup/ghc/9.4.4/lib/ghc-9.4.4/lib/settings
2023-01-16T12:15:57.363833Z | Error | ReactorMessageActionException
ExitFailure 1
[Error - 1:15:57 PM] ReactorMessageActionException
ExitFailure 1
[Error - 1:15:57 PM] Request workspace/executeCommand failed.
  Message: ExitFailure 1
  Code: -32603 

After forcing ghcup to compile HLS 1.9.0.0 for me the quickfixes works in VSCode again:

ghcup rm hls 1.9.0.0
ghcup compile hls -g 1.9.0.0 --ghc 9.4.4 --cabal-update

@hasufell
Copy link
Member

What operating systems are you people on?

@konnik
Copy link

konnik commented Jan 16, 2023

Sorry should have mentioned that. I'm running Ubuntu 20.04.5 LTS x86_64
(have updated my comment with this info)

@hasufell
Copy link
Member

I can reproduce with 9.4.4 and 9.2.5, but not with 8.10.7.

@amano-kenji
Copy link

I am on Gentoo Linux.

@hasufell
Copy link
Member

Thanks, @fendor identified the issue. It's platform agnostic (although I'm not sure if windows is affected in the same way).

mpickering/apply-refact#134

@IgorArnaut
Copy link

Still doesn't work on Windows 10.

@fendor
Copy link
Collaborator

fendor commented Jan 18, 2023

A fix will most likely ship with the next release, in the current release, this issue will persist. To fix it for you locally, you may build hls from source via ghcup

@hasufell
Copy link
Member

I think we should do a point release.

@Abastro
Copy link

Abastro commented Jan 19, 2023

Sorry for asking this, but can I get ETA for a fix? This is slightly annoying but not worthy enough for me to justify build from source.

@hasufell
Copy link
Member

Sorry for asking this, but can I get ETA for a fix?

We're volunteers. Whenever we feel like. I'm currently rewriting the CI and I hope releases will get easier that way.

@niekvandepas
Copy link

Sorry for asking this, but can I get ETA for a fix? This is slightly annoying but not worthy enough for me to justify build from source.

Am I missing something? The fix suggested in this thread is a two-liner. It probably took you longer to write this comment than it would've taken you to build from source.

@amano-kenji
Copy link

So, will this be automatically fixed when we get a new release of haskell language server?

@fendor
Copy link
Collaborator

fendor commented Jan 27, 2023

Yes, it should be!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level: easy The issue is suited for beginners type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

Successfully merging a pull request may close this issue.