Skip to content

Commit

Permalink
block the response call back
Browse files Browse the repository at this point in the history
  • Loading branch information
soulomoon committed Apr 9, 2024
1 parent 2066243 commit fcc1d06
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lsp/src/Language/LSP/Server/Processing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ instance Pretty LspProcessingLog where
processMessage :: (m ~ LspM config) => LogAction m (WithSeverity LspProcessingLog) -> BSL.ByteString -> m ()
processMessage logger jsonStr = do
pendingResponsesVar <- LspT $ asks $ resPendingResponses . resState
shutdown <- isShuttingDown
logger <& LspMessage ("processMessage ["<> show shutdown <> "]: "<> show jsonStr) `WithSeverity` Debug
join $ liftIO $ atomically $ fmap handleErrors $ runExceptT $ do
val <- except $ eitherDecode jsonStr
pending <- lift $ readTVar pendingResponsesVar
Expand All @@ -102,8 +104,9 @@ processMessage logger jsonStr = do
FromClientMess m mess ->
pure $ handle logger m mess
FromClientRsp (P.Pair (ServerResponseCallback f) (Const !newMap)) res -> do
writeTVar pendingResponsesVar newMap
pure $ liftIO $ f (res ^. L.result)
unless shutdown <$> do
writeTVar pendingResponsesVar newMap
pure $ liftIO $ f (res ^. L.result)
where
parser :: ResponseMap -> Value -> Parser (FromClientMessage' (P.Product ServerResponseCallback (Const ResponseMap)))
parser rm = parseClientMessage $ \i ->
Expand Down Expand Up @@ -457,7 +460,6 @@ handle' logger mAction m msg = do
(IsClientReq, SMethod_Shutdown) -> True
_ -> False

logger <& LspMessage (show m) `WithSeverity` Debug
when (not shutdown || allowedMethod m) $ maybe (return ()) (\f -> f msg) mAction

dynReqHandlers <- getsState resRegistrationsReq
Expand Down

0 comments on commit fcc1d06

Please sign in to comment.