haskell / haskell-language-server

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

dont propose to restart ghc when not available #4006

Open teto opened 8 months ago

teto commented 8 months ago

Is your enhancement request related to a problem?

I have almost nothing in my global PATH and configure tooling on a per-project basis. Only when entering a development shell (via nix develop), I get my LSP, compilers etc. available.

My current issue is that whenever I open my haskell projects with neovim for a quick look/edit without entering the nix-shell, I get this annoying popup "Failed to find the GHC version of this Cabal project.". This takes the focus and thus I first have to escape the prompt before doing anything. Restarting is bound to fail as there is no ghc in PATH

image

Describe the solution you'd like

I would like to be able to disable the prompt but still get the error. If there is a LSP knob for that, it should be in hls but maybe it's something to configure in neovim, I am not sure yet.

Describe alternatives you've considered

None

Additional context

First (wrongly) reported at https://github.com/mrcjkb/haskell-tools.nvim/issues/338#issuecomment-1903928432

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initializeError

michaelpj commented 8 months ago

Yes, I think there is a knob in the spec. We can set the error data on the response error that we send to the initialize request with a field to say whether or not the client should retry. I think the default assumption is "yes", so it's probably helpful to explicitly say "no" since probably that's usually the right answer.

michaelpj commented 8 months ago

I'm actually not sure there are any errors where we want the client to blindly restart?

fendor commented 8 months ago

The intention of this command was to give users some time to look at the error, fix their environment, and then press "try to restart". Previously, vscode would just restart HLS 5 times, fail and then show an additional error message over our own, distracting further from the issue at hand.

I don't have an issue with adding a setting to disable the current behaviour, but I do think the "try to restart" should stay the default.

teto commented 8 months ago

Could this be configured through initializationOptions ? initializeParams I dont mind the warning, just the prompt that steals focus.

michaelpj commented 8 months ago

Huh, so it's actually something we send and not automatic retry handling by the client? Then ignore everything I said :joy:

fendor commented 8 months ago

Could this be configured through initializationOptions ? initializeParams I dont mind the warning, just the prompt that steals focus.

Not trivially, in the case of setup errors, e.g. the wrapper had to error out before finding the correct HLS version, we are not handling the initialiseOptions but only send that request.

See https://github.com/haskell/haskell-language-server/issues/2589 for a little bit of context for that feature.