dhall-lang / dhall-haskell

Maintainable configuration files
https://dhall-lang.org/
BSD 3-Clause "New" or "Revised" License
912 stars 213 forks source link

Catch exceptions in lsp handlers to prevent server from shutting down #2419

Closed PanAeon closed 2 years ago

PanAeon commented 2 years ago

Should fix #2418 and dhall-lang/vscode-dhall-lsp-server#37

The problem was that exceptions which were handled in the interpretHandler basically shut down the entire server, so after a few attempts vscode just gave up and the server was entirely shut down.

I've tried to keep top ExceptT monad as it is very handy and move error handling into the request handlers themselves. Since they have to return something, I first tried to just respond with an error, like: respond (Left (ServerError {..})). Unfortunately it immediately brings up output panel with protocol error messages, which is quite annoying, and likely should be resolved for some serious errors that need user attention. In the end I've decided on returning an empty value in the handleErrorWithDefault. I'm a bit rusty with haskell, so there may be more elegant solution.

Also I've added stubs for missing handlers to prevent annoying error messages which bring up Output panel.

P.S.: I've played a bit in VSCode and diagnostics feels like really snappy and responsive. The only thing that is still annoying is in case of a failed import whole file is in error not just the offending import location, otherwise it's really good.