Skip to content

Commit 5892575

Browse files
committed
Stateful ignoring
1 parent 4945a6a commit 5892575

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lsp-test/src/Language/LSP/Test.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ module Language.LSP.Test
2929
, runSessionWithConfigCustomProcess
3030
, runSessionWithHandles
3131
, runSessionWithHandles'
32+
, setIgnoringLogNotifications
33+
, setIgnoringConfigurationRequests
3234
-- ** Config
3335
, SessionConfig(..)
3436
, defaultConfig
@@ -401,6 +403,14 @@ sendResponse = sendMessage
401403
initializeResponse :: Session (TResponseMessage Method_Initialize)
402404
initializeResponse = ask >>= (liftIO . readMVar) . initRsp
403405

406+
setIgnoringLogNotifications :: Bool -> Session ()
407+
setIgnoringLogNotifications value = do
408+
modify (\ss -> ss { ignoringLogNotifications = value })
409+
410+
setIgnoringConfigurationRequests :: Bool -> Session ()
411+
setIgnoringConfigurationRequests value = do
412+
modify (\ss -> ss { ignoringConfigurationRequests = value })
413+
404414
-- | Set the client config. This will send a notification to the server that the
405415
-- config has changed.
406416
setConfig :: Value

lsp-test/src/Language/LSP/Test/Session.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ data SessionState = SessionState
192192
-- ^ The capabilities that the server has dynamically registered with us so
193193
-- far
194194
, curProgressSessions :: !(Set.Set ProgressToken)
195+
, ignoringLogNotifications :: Bool
196+
, ignoringConfigurationRequests :: Bool
195197
}
196198

197199
class Monad m => HasState s m where
@@ -277,7 +279,7 @@ runSession' serverIn serverOut mServerProc serverHandler config caps rootDir exi
277279
mainThreadId <- myThreadId
278280

279281
let context = SessionContext serverIn absRootDir messageChan timeoutIdVar reqMap initRsp config caps
280-
initState vfs = SessionState 0 vfs mempty False Nothing mempty (lspConfig config) mempty
282+
initState vfs = SessionState 0 vfs mempty False Nothing mempty (lspConfig config) mempty (ignoreLogNotifications config) (ignoreConfigurationRequests config)
281283
runSession' ses = initVFS $ \vfs -> runSessionMonad context (initState vfs) ses
282284

283285
errorHandler = throwTo mainThreadId :: SessionException -> IO ()
@@ -306,7 +308,7 @@ runSession' serverIn serverOut mServerProc serverHandler config caps rootDir exi
306308

307309
updateStateC :: ConduitM FromServerMessage FromServerMessage (StateT SessionState (ReaderT SessionContext IO)) ()
308310
updateStateC = awaitForever $ \msg -> do
309-
context <- ask @SessionContext
311+
state <- get @SessionState
310312
updateState msg
311313
case msg of
312314
FromServerMess SMethod_WindowWorkDoneProgressCreate req ->
@@ -334,7 +336,7 @@ updateStateC = awaitForever $ \msg -> do
334336

335337
_ -> sendMessage @_ @(TResponseError Method_WorkspaceConfiguration) $ TResponseError (InL LSPErrorCodes_RequestFailed) "No configuration" Nothing
336338
_ -> pure ()
337-
unless ((ignoreLogNotifications (config context) && isLogNotification msg) || (ignoreConfigurationRequests (config context) && isConfigRequest msg)) $
339+
unless ((ignoringLogNotifications state && isLogNotification msg) || (ignoringConfigurationRequests state && isConfigRequest msg)) $
338340
yield msg
339341

340342
where

0 commit comments

Comments
 (0)