@@ -255,7 +255,7 @@ setupLSP recorder defaultRoot getHieDbLoc userHandlers getIdeState clientMsgVar
255255 , ctxGetHieDbLoc = getHieDbLoc
256256 , ctxGetIdeState = getIdeState
257257 , ctxUntilReactorStopSignal = untilReactorStopSignal
258- , ctxconfirmReactorShutdown = confirmReactorShutdown
258+ , ctxConfirmReactorShutdown = confirmReactorShutdown
259259 , ctxForceShutdown = exit
260260 , ctxClearReqId = clearReqId
261261 , ctxWaitForCancel = waitForCancel
@@ -281,7 +281,7 @@ handleInit initParams env (TRequestMessage _ _ m params) = otTracedHandler "Init
281281 recorder = ctxRecorder initParams
282282 defaultRoot = ctxDefaultRoot initParams
283283 untilReactorStopSignal = ctxUntilReactorStopSignal initParams
284- lifetimeConfirm = ctxconfirmReactorShutdown initParams
284+ lifetimeConfirm = ctxConfirmReactorShutdown initParams
285285 root <- case LSP. resRootPath env of
286286 Just lspRoot | lspRoot /= defaultRoot -> setCurrentDirectory lspRoot >> return lspRoot
287287 _ -> pure defaultRoot
@@ -290,38 +290,40 @@ handleInit initParams env (TRequestMessage _ _ m params) = otTracedHandler "Init
290290 logWith recorder Info $ LogRegisteringIdeConfig initConfig
291291 ideMVar <- newEmptyMVar
292292
293- let
293+ let
294294 handleServerExceptionOrShutDown me = do
295295 -- shutdown shake
296296 tryReadMVar ideMVar >>= mapM_ shutdown
297- case me of
298- Left e -> do
299- lifetimeConfirm " due to exception in reactor thread"
300- logWith recorder Error $ LogReactorThreadException e
301- ctxForceShutdown initParams
302- _ -> do
303- lifetimeConfirm " due to shutdown message"
304- return ()
305-
306- exceptionInHandler e = do
307- logWith recorder Error $ LogReactorMessageActionException e
308-
309- checkCancelled :: forall m . LspId m -> IO () -> (TResponseError m -> IO () ) -> IO ()
310- checkCancelled _id act k =
311- let sid = SomeLspId _id
312- in flip finally (ctxClearReqId initParams sid) $
313- catch (do
314- -- We could optimize this by first checking if the id
315- -- is in the cancelled set. However, this is unlikely to be a
316- -- bottleneck and the additional check might hide
317- -- issues with async exceptions that need to be fixed.
318- cancelOrRes <- race (ctxWaitForCancel initParams sid) act
319- case cancelOrRes of
320- Left () -> do
321- logWith recorder Debug $ LogCancelledRequest sid
322- k $ TResponseError (InL LSPErrorCodes_RequestCancelled ) " " Nothing
323- Right res -> pure res
324- ) $ \ (e :: SomeException ) -> do
297+ case me of
298+ Left e -> do
299+ lifetimeConfirm " due to exception in reactor thread"
300+ logWith recorder Error $ LogReactorThreadException e
301+ ctxForceShutdown initParams
302+ _ -> do
303+ lifetimeConfirm " due to shutdown message"
304+ return ()
305+
306+ exceptionInHandler e = do
307+ logWith recorder Error $ LogReactorMessageActionException e
308+
309+ checkCancelled :: forall m . LspId m -> IO () -> (TResponseError m -> IO () ) -> IO ()
310+ checkCancelled _id act k =
311+ let sid = SomeLspId _id
312+ in flip finally (ctxClearReqId initParams sid) $
313+ catch
314+ (do
315+ -- We could optimize this by first checking if the id
316+ -- is in the cancelled set. However, this is unlikely to be a
317+ -- bottleneck and the additional check might hide
318+ -- issues with async exceptions that need to be fixed.
319+ cancelOrRes <- race (ctxWaitForCancel initParams sid) act
320+ case cancelOrRes of
321+ Left () -> do
322+ logWith recorder Debug $ LogCancelledRequest sid
323+ k $ TResponseError (InL LSPErrorCodes_RequestCancelled ) " " Nothing
324+ Right res -> pure res
325+ )
326+ $ \ (e :: SomeException ) -> do
325327 exceptionInHandler e
326328 k $ TResponseError (InR ErrorCodes_InternalError ) (T. pack $ show e) Nothing
327329 _ <- flip forkFinally handleServerExceptionOrShutDown $ do
@@ -386,4 +388,3 @@ modifyOptions x = x{ LSP.optTextDocumentSync = Just $ tweakTDS origTDS
386388 tweakTDS tds = tds{_openClose= Just True , _change= Just TextDocumentSyncKind_Incremental , _save= Just $ InR $ SaveOptions Nothing }
387389 origTDS = fromMaybe tdsDefault $ LSP. optTextDocumentSync x
388390 tdsDefault = TextDocumentSyncOptions Nothing Nothing Nothing Nothing Nothing
389-
0 commit comments