Skip to content

Commit

Permalink
send message in server exception too
Browse files Browse the repository at this point in the history
  • Loading branch information
pepeiborra committed Dec 13, 2021
1 parent e70fb03 commit 9d875c2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions ghcide/src/Development/IDE/LSP/LanguageServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,23 @@ runLanguageServer options inH outH getHieDbLoc defaultConfig onConfigurationChan
let handleServerException (Left e) = do
logError logger $
T.pack $ "Fatal error in server thread: " <> show e
sendErrorMessage e
exitClientMsg
handleServerException _ = pure ()

uncaughtError (e :: SomeException) = do
logError logger $ T.pack $
"Unexpected exception on notification, please report!\n" ++
"Exception: " ++ show e
sendErrorMessage (e :: SomeException) = do
LSP.runLspT env $ LSP.sendNotification SWindowShowMessage $
ShowMessageParams MtError $ T.unlines
[ "Unhandled error, please [report](" <> issueTrackerUrl <> "): "
[ "Unhandled exception, please [report](" <> issueTrackerUrl <> "): "
, T.pack(show e)
]

exceptionInHandler e = do
logError logger $ T.pack $
"Unexpected exception, please report!\n" ++
"Exception: " ++ show e
sendErrorMessage e

logger = ideLogger ide

checkCancelled _id act k =
Expand All @@ -169,7 +174,7 @@ runLanguageServer options inH outH getHieDbLoc defaultConfig onConfigurationChan
k $ ResponseError RequestCancelled "" Nothing
Right res -> pure res
) $ \(e :: SomeException) -> do
uncaughtError e
exceptionInHandler e
k $ ResponseError InternalError (T.pack $ show e) Nothing
_ <- flip forkFinally handleServerException $ runWithDb logger dbLoc $ \hiedb hieChan -> do
putMVar dbMVar (hiedb,hieChan)
Expand All @@ -178,7 +183,7 @@ runLanguageServer options inH outH getHieDbLoc defaultConfig onConfigurationChan
-- We dispatch notifications synchronously and requests asynchronously
-- This is to ensure that all file edits and config changes are applied before a request is handled
case msg of
ReactorNotification act -> handle uncaughtError act
ReactorNotification act -> handle exceptionInHandler act
ReactorRequest _id act k -> void $ async $ checkCancelled _id act k
pure $ Right (env,ide)

Expand Down

0 comments on commit 9d875c2

Please sign in to comment.