@@ -18,6 +18,7 @@ module Ide.Plugin
1818 , responseError
1919 ) where
2020
21+ import Control.Exception (SomeException , catch )
2122import Control.Lens ( (^.) )
2223import Control.Monad
2324import qualified Data.Aeson as J
@@ -206,7 +207,7 @@ executeCommandHandlers ecs = PartialHandlers $ \WithMessage{..} x -> return x{
206207-- -> ExecuteCommandParams
207208-- -> IO (Either ResponseError Value, Maybe (ServerMethod, ApplyWorkspaceEditParams))
208209makeExecuteCommands :: [(PluginId , [PluginCommand ])] -> LSP. LspFuncs Config -> ExecuteCommandProvider
209- makeExecuteCommands ecs lf ide = do
210+ makeExecuteCommands ecs lf ide = wrapUnhandledExceptions $ do
210211 let
211212 pluginMap = Map. fromList ecs
212213 parseCmdId :: T. Text -> Maybe (PluginId , CommandId )
@@ -334,6 +335,14 @@ makeExecuteCommands ecs lf ide = do
334335
335336-- | Runs a plugin command given a PluginId, CommandId and
336337-- arguments in the form of a JSON object.
338+ wrapUnhandledExceptions ::
339+ (a -> IO (Either ResponseError J. Value , Maybe b )) ->
340+ a -> IO (Either ResponseError J. Value , Maybe b )
341+ wrapUnhandledExceptions action input =
342+ catch (action input) $ \ (e:: SomeException ) -> do
343+ let resp = ResponseError InternalError (T. pack $ show e) Nothing
344+ return (Left resp, Nothing )
345+
337346runPluginCommand :: Map. Map PluginId [PluginCommand ]
338347 -> LSP. LspFuncs Config
339348 -> IdeState
0 commit comments