Skip to content

Replace Barrier with MVar in lsp main #1668

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

Merged
merged 2 commits into from
Apr 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions ghcide/src/Development/IDE/LSP/LanguageServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ module Development.IDE.LSP.LanguageServer
( runLanguageServer
) where

import Control.Concurrent.Extra (newBarrier,
signalBarrier,
waitBarrier)
import Control.Concurrent.STM
import Control.Monad.Extra
import Control.Monad.IO.Class
Expand Down Expand Up @@ -56,12 +53,11 @@ runLanguageServer
-> IO ()
runLanguageServer options inH outH getHieDbLoc defaultConfig onConfigurationChange userHandlers getIdeState = do

-- These barriers are signaled when the threads reading from these chans exit.
-- This should not happen but if it does, we will make sure that the whole server
-- dies and can be restarted instead of losing threads silently.
clientMsgBarrier <- newBarrier
-- This MVar becomes full when the server thread exits or we receive exit message from client.
-- LSP loop will be canceled when it's full.
clientMsgVar <- newEmptyMVar
-- Forcefully exit
let exit = signalBarrier clientMsgBarrier ()
let exit = void $ tryPutMVar clientMsgVar ()

-- The set of requests ids that we have received but not finished processing
pendingRequests <- newTVarIO Set.empty
Expand Down Expand Up @@ -116,7 +112,7 @@ runLanguageServer options inH outH getHieDbLoc defaultConfig onConfigurationChan
inH
outH
serverDefinition
, void $ waitBarrier clientMsgBarrier
, void $ readMVar clientMsgVar
]

where
Expand Down Expand Up @@ -192,6 +188,7 @@ cancelHandler cancelRequest = LSP.notificationHandler SCancelRequest $ \Notifica
exitHandler :: IO () -> LSP.Handlers (ServerM c)
exitHandler exit = LSP.notificationHandler SExit $ const $ do
(_, ide) <- ask
liftIO $ logDebug (ideLogger ide) "Received exit message"
-- flush out the Shake session to record a Shake profile if applicable
liftIO $ shakeShut ide
liftIO exit
Expand Down