-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop doing action for handles and ignore responses after shutdown #567
Changes from 7 commits
e63e1e0
a1b7bb0
b6d5b04
cd35f7e
2066243
fcc1d06
95e4b0b
7c5febc
c18a370
41d9e21
23cd222
fda5f24
3913962
03240c6
49ec6f4
e9efbc9
a438b4b
d933651
fc18852
ac343e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,7 @@ 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 | ||
join $ liftIO $ atomically $ fmap handleErrors $ runExceptT $ do | ||
val <- except $ eitherDecode jsonStr | ||
pending <- lift $ readTVar pendingResponsesVar | ||
|
@@ -100,8 +101,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 | ||
soulomoon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
writeTVar pendingResponsesVar newMap | ||
pure $ liftIO $ f (res ^. L.result) | ||
where | ||
parser :: ResponseMap -> Value -> Parser (FromClientMessage' (P.Product ServerResponseCallback (Const ResponseMap))) | ||
parser rm = parseClientMessage $ \i -> | ||
|
@@ -449,31 +451,30 @@ handle' :: | |
TClientMessage meth -> | ||
m () | ||
handle' logger mAction m msg = do | ||
maybe (return ()) (\f -> f msg) mAction | ||
shutdown <- isShuttingDown | ||
let allowedMethod m = case (splitClientMethod m, m) of | ||
soulomoon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(IsClientNot, SMethod_Exit) -> True | ||
(IsClientReq, SMethod_Shutdown) -> True | ||
_ -> False | ||
|
||
when (not shutdown || allowedMethod m) $ maybe (return ()) (\f -> f msg) mAction | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be stronger than it needs to be. In particular, it's not a problem if we e.g. update the VFS. It's really only the config callback that's potentially problematic. It's also not enough, since updating the configuration is complicated. This handles the And I still think that servers should just make their config callbacks safe :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right , it is not enough to stop the callback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After reading the relevant issues, Is my understanding correct about config update? There is push model and pull model(new one) in LSP,
What we are doing here is kind of mixed:
soulomoon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
dynReqHandlers <- getsState resRegistrationsReq | ||
dynNotHandlers <- getsState resRegistrationsNot | ||
|
||
env <- getLspEnv | ||
let Handlers{reqHandlers, notHandlers} = resHandlers env | ||
shutdown <- isShuttingDown | ||
|
||
case splitClientMethod m of | ||
-- See Note [Shutdown] | ||
IsClientNot | shutdown, not (allowedMethod m) -> notificationDuringShutdown | ||
where | ||
allowedMethod SMethod_Exit = True | ||
allowedMethod _ = False | ||
IsClientNot -> case pickHandler dynNotHandlers notHandlers of | ||
Just h -> liftIO $ h msg | ||
Nothing | ||
| SMethod_Exit <- m -> exitNotificationHandler logger msg | ||
| otherwise -> missingNotificationHandler | ||
-- See Note [Shutdown] | ||
IsClientReq | shutdown, not (allowedMethod m) -> requestDuringShutdown msg | ||
where | ||
allowedMethod SMethod_Shutdown = True | ||
allowedMethod _ = False | ||
IsClientReq -> case pickHandler dynReqHandlers reqHandlers of | ||
Just h -> liftIO $ h msg (runLspT env . sendResponse msg) | ||
Nothing | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so instead of stop callback to all responses after we shutdown, we are stopping the config update callback here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You convinced me, let's not do this and instead skip both responses and actions like you suggest.