@@ -54,7 +54,7 @@ import UnliftIO.Exception (catchAny)
5454
5555data Log
5656 = LogPluginError PluginId PluginError
57- | LogResponseError PluginId ResponseError
57+ | forall m . A. ToJSON ( ErrorData m ) => LogResponseError PluginId ( TResponseError m )
5858 | LogNoPluginForMethod (Some SMethod )
5959 | LogInvalidCommandIdentifier
6060 | ExceptionInPlugin PluginId (Some SMethod ) SomeException
@@ -73,10 +73,10 @@ instance Pretty Log where
7373 <> pretty method <> " : " <> viaShow exception
7474instance Show Log where show = renderString . layoutCompact . pretty
7575
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 )
7777noPluginHandles recorder m fs' = do
7878 logWith recorder Warning (LogNoPluginForMethod $ Some m)
79- let err = ResponseError (InR ErrorCodes_MethodNotFound ) msg Nothing
79+ let err = TResponseError (InR ErrorCodes_MethodNotFound ) msg Nothing
8080 msg = noPluginHandlesMsg m fs'
8181 return $ Left err
8282 where noPluginHandlesMsg :: SMethod m -> [(PluginId , HandleRequestResult )] -> Text
@@ -112,9 +112,9 @@ exceptionInPlugin plId method exception =
112112 " Exception in plugin " <> T. pack (show plId) <> " while processing " <> T. pack (show method) <> " : " <> T. pack (show exception)
113113
114114-- | 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 )
116116logAndReturnError recorder p errCode msg = do
117- let err = ResponseError errCode msg Nothing
117+ let err = TResponseError errCode msg Nothing
118118 logWith recorder Warning $ LogResponseError p err
119119 pure $ Left err
120120
@@ -176,7 +176,7 @@ executeCommandHandlers recorder ecs = requestHandler SMethod_WorkspaceExecuteCom
176176 _ -> Nothing
177177
178178 -- 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 ))
180180 execCmd ide (ExecuteCommandParams mtoken cmdId args) = do
181181 let cmdParams :: A. Value
182182 cmdParams = case args of
@@ -196,8 +196,10 @@ executeCommandHandlers recorder ecs = requestHandler SMethod_WorkspaceExecuteCom
196196 -- If we have a command, continue to execute it
197197 Just (Command _ innerCmdId innerArgs)
198198 -> execCmd ide (ExecuteCommandParams Nothing innerCmdId innerArgs)
199+ -- TODO: This should be a response error?
199200 Nothing -> return $ Right $ InR Null
200201
202+ -- TODO: This should be a response error?
201203 A. Error _str -> return $ Right $ InR Null
202204
203205 -- Just an ordinary HIE command
@@ -206,9 +208,9 @@ executeCommandHandlers recorder ecs = requestHandler SMethod_WorkspaceExecuteCom
206208 -- Couldn't parse the command identifier
207209 _ -> do
208210 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
210212
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 ))
212214 runPluginCommand ide p com mtoken arg =
213215 case Map. lookup p pluginMap of
214216 Nothing -> logAndReturnError recorder p (InR ErrorCodes_InvalidRequest ) (pluginDoesntExist p)
@@ -314,13 +316,13 @@ runConcurrently msg method fs a b = forConcurrently fs $ \(pid,f) -> otTracedPro
314316 f a b -- See Note [Exception handling in plugins]
315317 `catchAny` (\ e -> pure $ pure $ Left $ PluginInternalError (msg pid method e))
316318
317- combineErrors :: NonEmpty (PluginId , PluginError ) -> ResponseError
319+ combineErrors :: NonEmpty (PluginId , PluginError ) -> TResponseError m
318320combineErrors (x NE. :| [] ) = toResponseError x
319321combineErrors xs = toResponseError $ NE. last $ NE. sortWith (toPriority . snd ) xs
320322
321- toResponseError :: (PluginId , PluginError ) -> ResponseError
323+ toResponseError :: (PluginId , PluginError ) -> TResponseError m
322324toResponseError (PluginId plId, err) =
323- ResponseError (toErrorCode err) (plId <> " : " <> tPretty err) Nothing
325+ TResponseError (toErrorCode err) (plId <> " : " <> tPretty err) Nothing
324326 where tPretty = T. pack . show . pretty
325327
326328logErrors :: Recorder (WithPriority Log ) -> [(PluginId , PluginError )] -> IO ()
0 commit comments