@@ -12,9 +12,6 @@ module Development.IDE.LSP.LanguageServer
12
12
( runLanguageServer
13
13
) where
14
14
15
- import Control.Concurrent.Extra (newBarrier ,
16
- signalBarrier ,
17
- waitBarrier )
18
15
import Control.Concurrent.STM
19
16
import Control.Monad.Extra
20
17
import Control.Monad.IO.Class
@@ -56,12 +53,11 @@ runLanguageServer
56
53
-> IO ()
57
54
runLanguageServer options inH outH getHieDbLoc defaultConfig onConfigurationChange userHandlers getIdeState = do
58
55
59
- -- These barriers are signaled when the threads reading from these chans exit.
60
- -- This should not happen but if it does, we will make sure that the whole server
61
- -- dies and can be restarted instead of losing threads silently.
62
- clientMsgBarrier <- newBarrier
56
+ -- This MVar becomes full when the server thread exits or we receive exit message from client.
57
+ -- LSP loop will be canceled when it's full.
58
+ clientMsgVar <- newEmptyMVar
63
59
-- Forcefully exit
64
- let exit = signalBarrier clientMsgBarrier ()
60
+ let exit = void $ tryPutMVar clientMsgVar ()
65
61
66
62
-- The set of requests ids that we have received but not finished processing
67
63
pendingRequests <- newTVarIO Set. empty
@@ -116,7 +112,7 @@ runLanguageServer options inH outH getHieDbLoc defaultConfig onConfigurationChan
116
112
inH
117
113
outH
118
114
serverDefinition
119
- , void $ waitBarrier clientMsgBarrier
115
+ , void $ readMVar clientMsgVar
120
116
]
121
117
122
118
where
@@ -192,6 +188,7 @@ cancelHandler cancelRequest = LSP.notificationHandler SCancelRequest $ \Notifica
192
188
exitHandler :: IO () -> LSP. Handlers (ServerM c )
193
189
exitHandler exit = LSP. notificationHandler SExit $ const $ do
194
190
(_, ide) <- ask
191
+ liftIO $ logDebug (ideLogger ide) " Received exit message"
195
192
-- flush out the Shake session to record a Shake profile if applicable
196
193
liftIO $ shakeShut ide
197
194
liftIO exit
0 commit comments