@@ -54,7 +54,7 @@ import UnliftIO.Exception (catchAny)
54
54
55
55
data Log
56
56
= LogPluginError PluginId PluginError
57
- | LogResponseError PluginId ResponseError
57
+ | forall m . A. ToJSON ( ErrorData m ) => LogResponseError PluginId ( TResponseError m )
58
58
| LogNoPluginForMethod (Some SMethod )
59
59
| LogInvalidCommandIdentifier
60
60
| ExceptionInPlugin PluginId (Some SMethod ) SomeException
@@ -73,10 +73,10 @@ instance Pretty Log where
73
73
<> pretty method <> " : " <> viaShow exception
74
74
instance Show Log where show = renderString . layoutCompact . pretty
75
75
76
- noPluginHandles :: Recorder (WithPriority Log ) -> SMethod m -> [(PluginId , HandleRequestResult )] -> IO (Either ResponseError c )
76
+ noPluginHandles :: Recorder (WithPriority Log ) -> SMethod m -> [(PluginId , HandleRequestResult )] -> IO (Either ( TResponseError m ) c )
77
77
noPluginHandles recorder m fs' = do
78
78
logWith recorder Warning (LogNoPluginForMethod $ Some m)
79
- let err = ResponseError (InR ErrorCodes_MethodNotFound ) msg Nothing
79
+ let err = TResponseError (InR ErrorCodes_MethodNotFound ) msg Nothing
80
80
msg = noPluginHandlesMsg m fs'
81
81
return $ Left err
82
82
where noPluginHandlesMsg :: SMethod m -> [(PluginId , HandleRequestResult )] -> Text
@@ -112,9 +112,9 @@ exceptionInPlugin plId method exception =
112
112
" Exception in plugin " <> T. pack (show plId) <> " while processing " <> T. pack (show method) <> " : " <> T. pack (show exception)
113
113
114
114
-- | Build a ResponseError and log it before returning to the caller
115
- logAndReturnError :: Recorder (WithPriority Log ) -> PluginId -> (LSPErrorCodes |? ErrorCodes ) -> Text -> LSP. LspT Config IO (Either ResponseError a )
115
+ logAndReturnError :: A. ToJSON ( ErrorData m ) => Recorder (WithPriority Log ) -> PluginId -> (LSPErrorCodes |? ErrorCodes ) -> Text -> LSP. LspT Config IO (Either ( TResponseError m ) a )
116
116
logAndReturnError recorder p errCode msg = do
117
- let err = ResponseError errCode msg Nothing
117
+ let err = TResponseError errCode msg Nothing
118
118
logWith recorder Warning $ LogResponseError p err
119
119
pure $ Left err
120
120
@@ -176,7 +176,7 @@ executeCommandHandlers recorder ecs = requestHandler SMethod_WorkspaceExecuteCom
176
176
_ -> Nothing
177
177
178
178
-- The parameters to the HLS command are always the first element
179
- execCmd :: IdeState -> ExecuteCommandParams -> LSP. LspT Config IO (Either ResponseError (A. Value |? Null ))
179
+ execCmd :: IdeState -> ExecuteCommandParams -> LSP. LspT Config IO (Either ( TResponseError Method_WorkspaceExecuteCommand ) (A. Value |? Null ))
180
180
execCmd ide (ExecuteCommandParams mtoken cmdId args) = do
181
181
let cmdParams :: A. Value
182
182
cmdParams = case args of
@@ -196,8 +196,10 @@ executeCommandHandlers recorder ecs = requestHandler SMethod_WorkspaceExecuteCom
196
196
-- If we have a command, continue to execute it
197
197
Just (Command _ innerCmdId innerArgs)
198
198
-> execCmd ide (ExecuteCommandParams Nothing innerCmdId innerArgs)
199
+ -- TODO: This should be a response error?
199
200
Nothing -> return $ Right $ InR Null
200
201
202
+ -- TODO: This should be a response error?
201
203
A. Error _str -> return $ Right $ InR Null
202
204
203
205
-- Just an ordinary HIE command
@@ -206,9 +208,9 @@ executeCommandHandlers recorder ecs = requestHandler SMethod_WorkspaceExecuteCom
206
208
-- Couldn't parse the command identifier
207
209
_ -> do
208
210
logWith recorder Warning LogInvalidCommandIdentifier
209
- return $ Left $ ResponseError (InR ErrorCodes_InvalidParams ) " Invalid command identifier" Nothing
211
+ return $ Left $ TResponseError (InR ErrorCodes_InvalidParams ) " Invalid command identifier" Nothing
210
212
211
- runPluginCommand :: IdeState -> PluginId -> CommandId -> Maybe ProgressToken -> A. Value -> LSP. LspT Config IO (Either ResponseError (A. Value |? Null ))
213
+ runPluginCommand :: IdeState -> PluginId -> CommandId -> Maybe ProgressToken -> A. Value -> LSP. LspT Config IO (Either ( TResponseError Method_WorkspaceExecuteCommand ) (A. Value |? Null ))
212
214
runPluginCommand ide p com mtoken arg =
213
215
case Map. lookup p pluginMap of
214
216
Nothing -> logAndReturnError recorder p (InR ErrorCodes_InvalidRequest ) (pluginDoesntExist p)
@@ -314,13 +316,13 @@ runConcurrently msg method fs a b = forConcurrently fs $ \(pid,f) -> otTracedPro
314
316
f a b -- See Note [Exception handling in plugins]
315
317
`catchAny` (\ e -> pure $ pure $ Left $ PluginInternalError (msg pid method e))
316
318
317
- combineErrors :: NonEmpty (PluginId , PluginError ) -> ResponseError
319
+ combineErrors :: NonEmpty (PluginId , PluginError ) -> TResponseError m
318
320
combineErrors (x NE. :| [] ) = toResponseError x
319
321
combineErrors xs = toResponseError $ NE. last $ NE. sortWith (toPriority . snd ) xs
320
322
321
- toResponseError :: (PluginId , PluginError ) -> ResponseError
323
+ toResponseError :: (PluginId , PluginError ) -> TResponseError m
322
324
toResponseError (PluginId plId, err) =
323
- ResponseError (toErrorCode err) (plId <> " : " <> tPretty err) Nothing
325
+ TResponseError (toErrorCode err) (plId <> " : " <> tPretty err) Nothing
324
326
where tPretty = T. pack . show . pretty
325
327
326
328
logErrors :: Recorder (WithPriority Log ) -> [(PluginId , PluginError )] -> IO ()
0 commit comments