@@ -172,6 +172,7 @@ initializeRequestHandler logger ServerDefinition{..} vfs sendFunc req = do
172172 resRegistrationsReq <- newTVarIO mempty
173173 resLspId <- newTVarIO 0
174174 resShutdown <- C. newBarrier
175+ resExit <- C. newBarrier
175176 pure LanguageContextState {.. }
176177
177178 -- Call the 'duringInitialization' callback to let the server kick stuff up
@@ -440,6 +441,7 @@ handle logger m msg =
440441 SMethod_WorkspaceDidChangeConfiguration -> handle' logger (Just $ handleDidChangeConfiguration logger) m msg
441442 -- See Note [LSP configuration]
442443 SMethod_Initialized -> handle' logger (Just $ \ _ -> initialDynamicRegistrations logger >> requestConfigUpdate (cmap (fmap LspCore ) logger)) m msg
444+ SMethod_Exit -> exitNotificationHandler logger msg
443445 SMethod_Shutdown -> handle' logger (Just $ \ _ -> signalShutdown) m msg
444446 where
445447 -- See Note [Shutdown]
@@ -466,18 +468,9 @@ handle' ::
466468 m ()
467469handle' logger mAction m msg = do
468470 shutdown <- isShuttingDown
469- -- These are the methods that we are allowed to process during shutdown.
470- -- The reason that we do not include 'shutdown' itself here is because
471- -- by the time we get the first 'shutdown' message, isShuttingDown will
472- -- still be false, so we would still be able to process it.
473- -- This ensures we won't process the second 'shutdown' message and only
474- -- process 'exit' during shutdown.
475- let allowedMethod m = case (splitClientMethod m, m) of
476- (IsClientNot , SMethod_Exit ) -> True
477- _ -> False
478471
479472 case mAction of
480- Just f | not shutdown || allowedMethod m -> f msg
473+ Just f | not shutdown -> f msg
481474 _ -> pure ()
482475
483476 dynReqHandlers <- getsState resRegistrationsReq
@@ -488,14 +481,12 @@ handle' logger mAction m msg = do
488481
489482 case splitClientMethod m of
490483 -- See Note [Shutdown]
491- IsClientNot | shutdown, not (allowedMethod m) -> notificationDuringShutdown
484+ IsClientNot | shutdown -> notificationDuringShutdown
492485 IsClientNot -> case pickHandler dynNotHandlers notHandlers of
493486 Just h -> liftIO $ h msg
494- Nothing
495- | SMethod_Exit <- m -> exitNotificationHandler logger msg
496- | otherwise -> missingNotificationHandler
487+ Nothing | otherwise -> missingNotificationHandler
497488 -- See Note [Shutdown]
498- IsClientReq | shutdown, not (allowedMethod m) -> requestDuringShutdown msg
489+ IsClientReq | shutdown -> requestDuringShutdown msg
499490 IsClientReq -> case pickHandler dynReqHandlers reqHandlers of
500491 Just h -> liftIO $ h msg (runLspT env . sendResponse msg)
501492 Nothing
@@ -556,10 +547,11 @@ progressCancelHandler logger (TNotificationMessage _ _ (WorkDoneProgressCancelPa
556547 logger <& ProgressCancel tid `WithSeverity ` Debug
557548 liftIO cancelAction
558549
559- exitNotificationHandler :: (MonadIO m ) => LogAction m (WithSeverity LspProcessingLog ) -> Handler m Method_Exit
550+ exitNotificationHandler :: (MonadIO m , MonadLsp config0 m ) => LogAction m (WithSeverity LspProcessingLog ) -> Handler m Method_Exit
560551exitNotificationHandler logger _ = do
561- logger <& Exiting `WithSeverity ` Info
562- liftIO exitSuccess
552+ logger <& ShuttingDown `WithSeverity ` Info
553+ b <- resExit . resState <$> getLspEnv
554+ liftIO $ signalBarrier b ()
563555
564556-- | Default Shutdown handler
565557shutdownRequestHandler :: Handler IO Method_Shutdown
0 commit comments