Skip to content

Commit b7949aa

Browse files
pepeiborramergify[bot]Ailrun
authored
Correctly handle LSP shutdown/exit (#2486)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Junyoung "Clare" Jang <jjc9310@gmail.com>
1 parent bb73e32 commit b7949aa

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ghcide/src/Development/IDE/LSP/LanguageServer.hs

+7-3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ runLanguageServer options inH outH getHieDbLoc defaultConfig onConfigurationChan
9393
[ ideHandlers
9494
, cancelHandler cancelRequest
9595
, exitHandler exit
96+
, shutdownHandler
9697
]
9798
-- Cancel requests are special since they need to be handled
9899
-- out of order to be useful. Existing handlers are run afterwards.
@@ -185,13 +186,16 @@ cancelHandler :: (SomeLspId -> IO ()) -> LSP.Handlers (ServerM c)
185186
cancelHandler cancelRequest = LSP.notificationHandler SCancelRequest $ \NotificationMessage{_params=CancelParams{_id}} ->
186187
liftIO $ cancelRequest (SomeLspId _id)
187188

188-
exitHandler :: IO () -> LSP.Handlers (ServerM c)
189-
exitHandler exit = LSP.notificationHandler SExit $ const $ do
189+
shutdownHandler :: LSP.Handlers (ServerM c)
190+
shutdownHandler = LSP.requestHandler SShutdown $ \_ resp -> do
190191
(_, ide) <- ask
191192
liftIO $ logDebug (ideLogger ide) "Received exit message"
192193
-- flush out the Shake session to record a Shake profile if applicable
193194
liftIO $ shakeShut ide
194-
liftIO exit
195+
resp $ Right Empty
196+
197+
exitHandler :: IO () -> LSP.Handlers (ServerM c)
198+
exitHandler exit = LSP.notificationHandler SExit $ const $ liftIO exit
195199

196200
modifyOptions :: LSP.Options -> LSP.Options
197201
modifyOptions x = x{ LSP.textDocumentSync = Just $ tweakTDS origTDS

0 commit comments

Comments
 (0)