@@ -18,6 +18,7 @@ module Ide.Plugin
18
18
, responseError
19
19
) where
20
20
21
+ import Control.Exception (SomeException , catch )
21
22
import Control.Lens ( (^.) )
22
23
import Control.Monad
23
24
import qualified Data.Aeson as J
@@ -206,7 +207,7 @@ executeCommandHandlers ecs = PartialHandlers $ \WithMessage{..} x -> return x{
206
207
-- -> ExecuteCommandParams
207
208
-- -> IO (Either ResponseError Value, Maybe (ServerMethod, ApplyWorkspaceEditParams))
208
209
makeExecuteCommands :: [(PluginId , [PluginCommand ])] -> LSP. LspFuncs Config -> ExecuteCommandProvider
209
- makeExecuteCommands ecs lf ide = do
210
+ makeExecuteCommands ecs lf ide = wrapUnhandledExceptions $ do
210
211
let
211
212
pluginMap = Map. fromList ecs
212
213
parseCmdId :: T. Text -> Maybe (PluginId , CommandId )
@@ -334,6 +335,14 @@ makeExecuteCommands ecs lf ide = do
334
335
335
336
-- | Runs a plugin command given a PluginId, CommandId and
336
337
-- 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
+
337
346
runPluginCommand :: Map. Map PluginId [PluginCommand ]
338
347
-> LSP. LspFuncs Config
339
348
-> IdeState
0 commit comments