Skip to content

Commit 9636cf0

Browse files
authored
Merge pull request #479 from joyfulmantis/mpjs-metamodel2-no-tresponseerrors
Replace some TResponseError with ResponseError
2 parents ba7e5cb + b0fc6e8 commit 9636cf0

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

lsp-test/src/Language/LSP/Test.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ getDocumentSymbols doc = do
522522
Right (InL xs) -> return (Left xs)
523523
Right (InR (InL xs)) -> return (Right xs)
524524
Right (InR (InR _)) -> return (Right [])
525-
Left err -> throw (UnexpectedResponseError (SomeLspId $ fromJust rspLid) (toUntypedResponseError err))
525+
Left err -> throw (UnexpectedResponseError (SomeLspId $ fromJust rspLid) err)
526526

527527
-- | Returns the code actions in the specified range.
528528
getCodeActions :: TextDocumentIdentifier -> Range -> Session [Command |? CodeAction]
@@ -533,7 +533,7 @@ getCodeActions doc range = do
533533
case rsp ^. result of
534534
Right (InL xs) -> return xs
535535
Right (InR _) -> return []
536-
Left error -> throw (UnexpectedResponseError (SomeLspId $ fromJust $ rsp ^. LSP.id) (toUntypedResponseError error))
536+
Left error -> throw (UnexpectedResponseError (SomeLspId $ fromJust $ rsp ^. LSP.id) error)
537537

538538
-- | Returns all the code actions in a document by
539539
-- querying the code actions at each of the current
@@ -550,7 +550,7 @@ getAllCodeActions doc = do
550550
TResponseMessage _ rspLid res <- request SMethod_TextDocumentCodeAction (CodeActionParams Nothing Nothing doc (diag ^. range) ctx)
551551

552552
case res of
553-
Left e -> throw (UnexpectedResponseError (SomeLspId $ fromJust rspLid) (toUntypedResponseError e))
553+
Left e -> throw (UnexpectedResponseError (SomeLspId $ fromJust rspLid) e)
554554
Right (InL cmdOrCAs) -> pure (acc ++ cmdOrCAs)
555555
Right (InR _) -> pure acc
556556

@@ -725,7 +725,7 @@ getResponseResult :: (ToJSON (ErrorData m)) => TResponseMessage m -> MessageResu
725725
getResponseResult rsp =
726726
case rsp ^. result of
727727
Right x -> x
728-
Left err -> throw $ UnexpectedResponseError (SomeLspId $ fromJust $ rsp ^. LSP.id) (toUntypedResponseError err)
728+
Left err -> throw $ UnexpectedResponseError (SomeLspId $ fromJust $ rsp ^. LSP.id) err
729729

730730
-- | Applies formatting to the specified document.
731731
formatDoc :: TextDocumentIdentifier -> FormattingOptions -> Session ()

lsp-test/test/DummyServer.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,6 @@ handlers =
241241
, requestHandler SMethod_TextDocumentSemanticTokensFull $ \_req resp -> do
242242
let tokens = makeSemanticTokens defaultSemanticTokensLegend [SemanticTokenAbsolute 0 1 2 SemanticTokenTypes_Type []]
243243
case tokens of
244-
Left t -> resp $ Left $ TResponseError ErrorCodes_InternalError t Nothing
244+
Left t -> resp $ Left $ ResponseError ErrorCodes_InternalError t Nothing
245245
Right tokens -> resp $ Right $ InL tokens
246246
]

lsp-types/src/Language/LSP/Protocol/Message/Types.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ data TResponseMessage (m :: Method f Request) =
132132
TResponseMessage
133133
{ _jsonrpc :: Text
134134
, _id :: Maybe (LspId m)
135-
, _result :: Either (TResponseError m) (MessageResult m)
135+
-- TODO: use `TResponseError m` for the error type, this will require quite a lot of adaptation downstream
136+
, _result :: Either ResponseError (MessageResult m)
136137
} deriving stock Generic
137138

138139
deriving stock instance (Eq (MessageResult m), Eq (ErrorData m)) => Eq (TResponseMessage m)

lsp-types/test/JsonSpec.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ instance {-# OVERLAPPING #-} Arbitrary (Maybe Void) where
140140
instance (ErrorData m ~ Maybe Void) => Arbitrary (TResponseError m) where
141141
arbitrary = TResponseError <$> arbitrary <*> arbitrary <*> pure Nothing
142142

143+
instance Arbitrary ResponseError where
144+
arbitrary = ResponseError <$> arbitrary <*> arbitrary <*> pure Nothing
145+
143146
instance (Arbitrary (MessageResult m), ErrorData m ~ Maybe Void) => Arbitrary (TResponseMessage m) where
144147
arbitrary = TResponseMessage <$> arbitrary <*> arbitrary <*> arbitrary
145148

lsp/src/Language/LSP/Server/Core.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ newtype ClientMessageHandler f (t :: MessageKind) (m :: Method ClientToServer t)
142142
-- | The type of a handler that handles requests and notifications coming in
143143
-- from the server or client
144144
type family Handler (f :: Type -> Type) (m :: Method from t) = (result :: Type) | result -> f t m where
145-
Handler f (m :: Method _from Request) = TRequestMessage m -> (Either (TResponseError m) (MessageResult m) -> f ()) -> f ()
145+
Handler f (m :: Method _from Request) = TRequestMessage m -> (Either ResponseError (MessageResult m) -> f ()) -> f ()
146146
Handler f (m :: Method _from Notification) = TNotificationMessage m -> f ()
147147

148148
-- | How to convert two isomorphic data structures between each other.
@@ -287,7 +287,7 @@ data ServerDefinition config = forall m a.
287287
-- indicating what went wrong. The parsed configuration object will be
288288
-- stored internally and can be accessed via 'config'.
289289
-- It is also called on the `initializationOptions` field of the InitializeParams
290-
, doInitialize :: LanguageContextEnv config -> TMessage Method_Initialize -> IO (Either (TResponseError Method_Initialize) a)
290+
, doInitialize :: LanguageContextEnv config -> TMessage Method_Initialize -> IO (Either ResponseError a)
291291
-- ^ Called *after* receiving the @initialize@ request and *before*
292292
-- returning the response. This callback will be invoked to offer the
293293
-- language server implementation the chance to create any processes or
@@ -319,7 +319,7 @@ data ServerDefinition config = forall m a.
319319
-- | A function that a 'Handler' is passed that can be used to respond to a
320320
-- request with either an error, or the response params.
321321
newtype ServerResponseCallback (m :: Method ServerToClient Request)
322-
= ServerResponseCallback (Either (TResponseError m) (MessageResult m) -> IO ())
322+
= ServerResponseCallback (Either ResponseError (MessageResult m) -> IO ())
323323

324324
-- | Return value signals if response handler was inserted successfully
325325
-- Might fail if the id was already in the map
@@ -344,7 +344,7 @@ sendNotification m params =
344344
sendRequest :: forall (m :: Method ServerToClient Request) f config. MonadLsp config f
345345
=> SServerMethod m
346346
-> MessageParams m
347-
-> (Either (TResponseError m) (MessageResult m) -> f ())
347+
-> (Either ResponseError (MessageResult m) -> f ())
348348
-> f (LspId m)
349349
sendRequest m params resHandler = do
350350
reqId <- IdInt <$> freshLspId

lsp/src/Language/LSP/Server/Processing.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ initializeRequestHandler ServerDefinition{..} vfs sendFunc req = do
163163
makeResponseMessage rid result = TResponseMessage "2.0" (Just rid) (Right result)
164164
makeResponseError origId err = TResponseMessage "2.0" (Just origId) (Left err)
165165

166-
initializeErrorHandler :: (TResponseError Method_Initialize -> IO ()) -> E.SomeException -> IO (Maybe a)
166+
initializeErrorHandler :: (ResponseError -> IO ()) -> E.SomeException -> IO (Maybe a)
167167
initializeErrorHandler sendResp e = do
168-
sendResp $ TResponseError ErrorCodes_InternalError msg Nothing
168+
sendResp $ ResponseError ErrorCodes_InternalError msg Nothing
169169
pure Nothing
170170
where
171171
msg = T.pack $ unwords ["Error on initialize:", show e]
@@ -350,7 +350,7 @@ handle' logger mAction m msg = do
350350
env <- getLspEnv
351351
let Handlers{reqHandlers, notHandlers} = resHandlers env
352352

353-
let mkRspCb :: TRequestMessage (m1 :: Method ClientToServer Request) -> Either (TResponseError m1) (MessageResult m1) -> IO ()
353+
let mkRspCb :: TRequestMessage (m1 :: Method ClientToServer Request) -> Either ResponseError (MessageResult m1) -> IO ()
354354
mkRspCb req (Left err) = runLspT env $ sendToClient $
355355
FromServerRsp (req ^. method) $ TResponseMessage "2.0" (Just (req ^. LSP.id)) (Left err)
356356
mkRspCb req (Right rsp) = runLspT env $ sendToClient $
@@ -370,7 +370,7 @@ handle' logger mAction m msg = do
370370
| SMethod_Shutdown <- m -> liftIO $ shutdownRequestHandler msg (mkRspCb msg)
371371
| otherwise -> do
372372
let errorMsg = T.pack $ unwords ["lsp:no handler for: ", show m]
373-
err = TResponseError ErrorCodes_MethodNotFound errorMsg Nothing
373+
err = ResponseError ErrorCodes_MethodNotFound errorMsg Nothing
374374
sendToClient $
375375
FromServerRsp (msg ^. method) $ TResponseMessage "2.0" (Just (msg ^. LSP.id)) (Left err)
376376

@@ -382,7 +382,7 @@ handle' logger mAction m msg = do
382382
Just h -> liftIO $ h req (mkRspCb req)
383383
Nothing -> do
384384
let errorMsg = T.pack $ unwords ["lsp:no handler for: ", show m]
385-
err = TResponseError ErrorCodes_MethodNotFound errorMsg Nothing
385+
err = ResponseError ErrorCodes_MethodNotFound errorMsg Nothing
386386
sendToClient $
387387
FromServerRsp (req ^. method) $ TResponseMessage "2.0" (Just (req ^. LSP.id)) (Left err)
388388
where

0 commit comments

Comments
 (0)