@@ -52,7 +52,10 @@ module Language.LSP.Test
5252 -- ** Initialization
5353 , initializeResponse
5454 -- ** Config
55+ , modifyConfig
5556 , setConfig
57+ , modifyConfigSection
58+ , setConfigSection
5659 -- ** Documents
5760 , createDoc
5861 , openDoc
@@ -148,6 +151,7 @@ import System.Process (ProcessHandle, CreateProcess)
148151import qualified System.FilePath.Glob as Glob
149152import Control.Monad.State (execState )
150153import Data.Traversable (for )
154+ import Data.String (fromString )
151155
152156-- | Starts a new session.
153157--
@@ -411,12 +415,14 @@ setIgnoringConfigurationRequests :: Bool -> Session ()
411415setIgnoringConfigurationRequests value = do
412416 modify (\ ss -> ss { ignoringConfigurationRequests = value })
413417
414- -- | Set the client config. This will send a notification to the server that the
418+ -- | Modify the client config. This will send a notification to the server that the
415419-- config has changed.
416- setConfig :: Object
417- -> Session ()
418- setConfig newConfig = do
419- modify (\ ss -> ss { curLspConfig = newConfig})
420+ modifyConfig :: (Object -> Object ) -> Session ()
421+ modifyConfig f = do
422+ oldConfig <- curLspConfig <$> get
423+ let newConfig = f oldConfig
424+ modify (\ ss -> ss { curLspConfig = newConfig })
425+
420426 caps <- asks sessionCapabilities
421427 let supportsConfiguration = fromMaybe False $ caps ^? L. workspace . _Just . L. configuration . _Just
422428 -- TODO: make this configurable?
@@ -425,6 +431,21 @@ setConfig newConfig = do
425431 configToSend = if supportsConfiguration then J. Null else Object newConfig
426432 sendNotification SMethod_WorkspaceDidChangeConfiguration $ DidChangeConfigurationParams configToSend
427433
434+ -- | Set the client config. This will send a notification to the server that the
435+ -- config has changed.
436+ setConfig :: Object -> Session ()
437+ setConfig newConfig = modifyConfig (const newConfig)
438+
439+ -- | Modify a client config section (if already present, otherwise does nothing).
440+ -- This will send a notification to the server that the config has changed.
441+ modifyConfigSection :: String -> (Value -> Value ) -> Session ()
442+ modifyConfigSection section f = modifyConfig (\ o -> o & ix (fromString section) %~ f)
443+
444+ -- | Set a client config section. This will send a notification to the server that the
445+ -- config has changed.
446+ setConfigSection :: String -> Value -> Session ()
447+ setConfigSection section settings = modifyConfig (\ o -> o & at(fromString section) ?~ settings)
448+
428449-- | /Creates/ a new text document. This is different from 'openDoc'
429450-- as it sends a workspace/didChangeWatchedFiles notification letting the server
430451-- know that a file was created within the workspace, __provided that the server
0 commit comments