X-Git-Url: https://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest%2FSession.hs;h=2b6da8e5086ac5770e5c89196a9bd5e742cb916a;hb=cb75f5731bd7d85b1f1c684cbb2ce90cf82a1e34;hp=07b33e888c5c3eb44f931ce138e87c2569acdcea;hpb=6f69337aa146eedf0bca00d7a1d7bb507ef95c56;p=lsp-test.git diff --git a/src/Language/Haskell/LSP/Test/Session.hs b/src/Language/Haskell/LSP/Test/Session.hs index 07b33e8..2b6da8e 100644 --- a/src/Language/Haskell/LSP/Test/Session.hs +++ b/src/Language/Haskell/LSP/Test/Session.hs @@ -70,7 +70,6 @@ import System.Directory import System.IO import System.Process (ProcessHandle()) import System.Timeout -import System.IO.Temp -- | A session representing one instance of launching and connecting to a server. -- @@ -96,11 +95,14 @@ data SessionConfig = SessionConfig , logMessages :: Bool -- ^ Trace the messages sent and received to stdout, defaults to False. , logColor :: Bool -- ^ Add ANSI color to the logged messages, defaults to True. , lspConfig :: Maybe Value -- ^ The initial LSP config as JSON value, defaults to Nothing. + -- ^ Whether or not to ignore 'ShowMessageNotification' and 'LogMessageNotification', defaults to False. + -- @since 0.9.0.0 + , ignoreLogNotifications :: Bool } -- | The configuration used in 'Language.Haskell.LSP.Test.runSession'. defaultConfig :: SessionConfig -defaultConfig = SessionConfig 60 False False True Nothing +defaultConfig = SessionConfig 60 False False True Nothing False instance Default SessionConfig where def = defaultConfig @@ -182,15 +184,20 @@ runSession context state (Session session) = runReaderT (runStateT conduit state chanSource = do msg <- liftIO $ readChan (messageChan context) + unless (ignoreLogNotifications (config context) && isLogNotification msg) $ yield msg chanSource + isLogNotification (ServerMessage (NotShowMessage _)) = True + isLogNotification (ServerMessage (NotLogMessage _)) = True + isLogNotification _ = False + watchdog :: ConduitM SessionMessage FromServerMessage (StateT SessionState (ReaderT SessionContext IO)) () watchdog = Conduit.awaitForever $ \msg -> do curId <- curTimeoutId <$> get case msg of ServerMessage sMsg -> yield sMsg - TimeoutMessage tId -> when (curId == tId) $ throw Timeout + TimeoutMessage tId -> when (curId == tId) $ lastReceivedMessage <$> get >>= throw . Timeout -- | An internal version of 'runSession' that allows for a custom handler to listen to the server. -- It also does not automatically send initialize and exit messages. @@ -291,7 +298,7 @@ updateState (ReqApplyWorkspaceEdit r) = do ctx <- ask -- if its not open, open it - unless (toNormalizedUri uri `Map.member` (vfsMap oldVFS)) $ do + unless (toNormalizedUri uri `Map.member` vfsMap oldVFS) $ do let fp = fromJust $ uriToFilePath uri contents <- liftIO $ T.readFile fp let item = TextDocumentItem (filePathToUri fp) "" 0 contents @@ -363,3 +370,4 @@ logMsg t msg = do showPretty = B.unpack . encodePretty +