Skip to content

Commit 64e8dc6

Browse files
committed
Try another another thing
1 parent 91c4104 commit 64e8dc6

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

lsp-test/func-test/FuncTest.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ main = hspec $ do
109109
_ -> error "Shouldn't be here"
110110
]
111111

112-
server <- async $ void $ runServerWithHandles logger (L.hoistLogAction liftIO logger) hinRead houtWrite definition
112+
server <- async $ runServerWithHandles logger (L.hoistLogAction liftIO logger) hinRead houtWrite definition
113113

114114
let config = Test.defaultConfig
115115
{ Test.initialWorkspaceFolders = Just [wf0]
@@ -126,6 +126,4 @@ main = hspec $ do
126126
changeFolders [wf1] []
127127
changeFolders [wf2] [wf1]
128128

129-
Left e <- waitCatch server
130-
fromException e `shouldBe` Just ExitSuccess
131-
129+
wait server

lsp/example/Reactor.hs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,15 @@ import Control.Concurrent
6060
--
6161

6262
main :: IO ()
63-
main = do
64-
run >>= \case
65-
0 -> exitSuccess
66-
c -> exitWith . ExitFailure $ c
63+
main = run
6764

6865
-- ---------------------------------------------------------------------
6966

7067
data Config = Config { fooTheBar :: Bool, wibbleFactor :: Int }
7168
deriving (Generic, J.ToJSON, J.FromJSON, Show)
7269

73-
run :: IO Int
74-
run = flip E.catches handlers $ do
70+
run :: IO ()
71+
run = do
7572

7673
rin <- atomically newTChan :: IO (TChan ReactorInput)
7774

@@ -111,9 +108,6 @@ run = flip E.catches handlers $ do
111108
serverDefinition
112109

113110
where
114-
handlers = [ E.Handler ioExcept
115-
, E.Handler someExcept
116-
]
117111
ioExcept (e :: E.IOException) = print e >> return 1
118112
someExcept (e :: E.SomeException) = print e >> return 1
119113

lsp/example/Simple.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ handlers = mconcat
3434
responder (Right $ Just rsp)
3535
]
3636

37-
main :: IO Int
37+
main :: IO ()
3838
main = runServer $ ServerDefinition
3939
{ onConfigurationChange = const $ const $ Right ()
4040
, defaultConfig = ()

lsp/src/Language/LSP/Server/Control.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ instance Pretty LspServerLog where
5353
-- (1) reads from stdin;
5454
-- (2) writes to stdout; and
5555
-- (3) logs to stderr and to the client, with some basic filtering.
56-
runServer :: forall config . ServerDefinition config -> IO Int
56+
runServer :: forall config . ServerDefinition config -> IO ()
5757
runServer =
5858
runServerWithHandles
5959
ioLogger
@@ -81,7 +81,7 @@ runServerWithHandles ::
8181
-> Handle
8282
-- ^ Handle to write output to.
8383
-> ServerDefinition config
84-
-> IO Int -- exit code
84+
-> IO ()
8585
runServerWithHandles ioLogger logger hin hout serverDefinition = do
8686

8787
hSetBuffering hin NoBuffering
@@ -111,7 +111,7 @@ runServerWith ::
111111
-> (BS.ByteString -> IO ())
112112
-- ^ Function to provide output to.
113113
-> ServerDefinition config
114-
-> IO Int -- exit code
114+
-> IO ()
115115
runServerWith ioLogger logger clientIn clientOut serverDefinition = do
116116

117117
ioLogger <& Starting `WithSeverity` Info
@@ -134,11 +134,10 @@ runServerWith ioLogger logger clientIn clientOut serverDefinition = do
134134
sendMsg
135135
recvMsg
136136

137-
_ <- forkIO serverIn
138137
-- Bind all the threads together so that any of them terminating will terminate everything
139138
_ <- Async.withAsync serverOut $ \a1 ->
140-
Async.withAsync processingLoop $ \a3 ->
141-
Async.waitAny [a1, a3]
139+
Async.withAsync serverIn $ \a2 ->
140+
Async.withAsync processingLoop $ \a3 ->
141+
Async.waitAny [a1, a2, a3]
142142

143143
ioLogger <& Stopping `WithSeverity` Info
144-
return 0

lsp/src/Language/LSP/Server/Processing.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ processingLoop ioLogger logger vfs serverDefinition sendMsg recvMsg = do
107107
Just env -> runLspT env $ forever $ do
108108
msg <- liftIO recvMsg
109109
processMessage logger msg
110+
`E.catch`
111+
(\(_ :: RequestedShutdown) -> pure ())
110112

111113
processMessage :: (m ~ LspM config) => LogAction m (WithSeverity LspProcessingLog) -> Value -> m ()
112114
processMessage logger val = do
@@ -423,10 +425,14 @@ progressCancelHandler logger (NotificationMessage _ _ (WorkDoneProgressCancelPar
423425
logger <& ProgressCancel tid `WithSeverity` Debug
424426
liftIO cancelAction
425427

428+
data RequestedShutdown = RequestedShutdown
429+
deriving (Show)
430+
instance E.Exception RequestedShutdown
431+
426432
exitNotificationHandler :: (MonadIO m) => LogAction m (WithSeverity LspProcessingLog) -> Handler m Exit
427433
exitNotificationHandler logger _ = do
428434
logger <& Exiting `WithSeverity` Info
429-
liftIO exitSuccess
435+
liftIO $ E.throwIO RequestedShutdown
430436

431437
-- | Default Shutdown handler
432438
shutdownRequestHandler :: Handler IO Shutdown

0 commit comments

Comments
 (0)