@@ -51,15 +51,18 @@ import UnliftIO.Exception (catchAny)
51
51
--
52
52
53
53
data Log
54
- = LogPluginError PluginId ResponseError
54
+ = LogPluginError PluginId ResponseError
55
55
| LogNoPluginForMethod (Some SMethod )
56
56
| LogInvalidCommandIdentifier
57
+ | ExceptionInPlugin PluginId (Some SMethod ) SomeException
57
58
instance Pretty Log where
58
59
pretty = \ case
59
60
LogPluginError (PluginId pId) err -> pretty pId <> " :" <+> prettyResponseError err
60
61
LogNoPluginForMethod (Some method) ->
61
62
" No plugin enabled for " <> pretty (show method)
62
63
LogInvalidCommandIdentifier -> " Invalid command identifier"
64
+ ExceptionInPlugin plId (Some method) exception ->
65
+ " Exception in plugin " <> viaShow plId <> " while processing " <> viaShow method <> " : " <> viaShow exception
63
66
64
67
instance Show Log where show = renderString . layoutCompact . pretty
65
68
@@ -103,6 +106,13 @@ logAndReturnError recorder p errCode msg = do
103
106
logWith recorder Warning $ LogPluginError p err
104
107
pure $ Left err
105
108
109
+ -- | Logs the provider error before returning it to the caller
110
+ logAndReturnError' :: Recorder (WithPriority Log ) -> (LSPErrorCodes |? ErrorCodes ) -> Log -> LSP. LspT Config IO (Either ResponseError a )
111
+ logAndReturnError' recorder errCode msg = do
112
+ let err = ResponseError errCode (fromString $ show msg) Nothing
113
+ logWith recorder Warning $ msg
114
+ pure $ Left err
115
+
106
116
-- | Map a set of plugins to the underlying ghcide engine.
107
117
asGhcIdePlugin :: Recorder (WithPriority Log ) -> IdePlugins IdeState -> Plugin Config
108
118
asGhcIdePlugin recorder (IdePlugins ls) =
@@ -203,7 +213,7 @@ executeCommandHandlers recorder ecs = requestHandler SMethod_WorkspaceExecuteCom
203
213
A. Error err -> logAndReturnError recorder p (InR ErrorCodes_InvalidParams ) (failedToParseArgs com p err arg)
204
214
A. Success a ->
205
215
f ide a `catchAny`
206
- (\ e -> pure $ Left $ ResponseError (InR ErrorCodes_InternalError ) (exceptionInPlugin p SMethod_WorkspaceApplyEdit e) Nothing )
216
+ (\ e -> logAndReturnError' recorder (InR ErrorCodes_InternalError ) (ExceptionInPlugin p ( Some SMethod_WorkspaceApplyEdit ) e))
207
217
208
218
-- ---------------------------------------------------------------------
209
219
@@ -266,7 +276,10 @@ extensibleNotificationPlugins recorder xs = mempty { P.pluginHandlers = handlers
266
276
Just fs -> do
267
277
-- We run the notifications in order, so the core ghcide provider
268
278
-- (which restarts the shake process) hopefully comes last
269
- mapM_ (\ (pid,_,f) -> otTracedProvider pid (fromString $ show m) $ f ide vfs params) fs
279
+ mapM_ (\ (pid,_,f) -> otTracedProvider pid (fromString $ show m) $ f ide vfs params
280
+ `catchAny`
281
+ (\ e -> logWith recorder Warning (ExceptionInPlugin pid (Some m) e))) fs
282
+
270
283
271
284
-- ---------------------------------------------------------------------
272
285
0 commit comments