@@ -52,7 +52,10 @@ module Language.LSP.Test
52
52
-- ** Initialization
53
53
, initializeResponse
54
54
-- ** Config
55
+ , modifyConfig
55
56
, setConfig
57
+ , modifyConfigSection
58
+ , setConfigSection
56
59
-- ** Documents
57
60
, createDoc
58
61
, openDoc
@@ -148,6 +151,7 @@ import System.Process (ProcessHandle, CreateProcess)
148
151
import qualified System.FilePath.Glob as Glob
149
152
import Control.Monad.State (execState )
150
153
import Data.Traversable (for )
154
+ import Data.String (fromString )
151
155
152
156
-- | Starts a new session.
153
157
--
@@ -411,12 +415,14 @@ setIgnoringConfigurationRequests :: Bool -> Session ()
411
415
setIgnoringConfigurationRequests value = do
412
416
modify (\ ss -> ss { ignoringConfigurationRequests = value })
413
417
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
415
419
-- 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
+
420
426
caps <- asks sessionCapabilities
421
427
let supportsConfiguration = fromMaybe False $ caps ^? L. workspace . _Just . L. configuration . _Just
422
428
-- TODO: make this configurable?
@@ -425,6 +431,21 @@ setConfig newConfig = do
425
431
configToSend = if supportsConfiguration then J. Null else Object newConfig
426
432
sendNotification SMethod_WorkspaceDidChangeConfiguration $ DidChangeConfigurationParams configToSend
427
433
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
+
428
449
-- | /Creates/ a new text document. This is different from 'openDoc'
429
450
-- as it sends a workspace/didChangeWatchedFiles notification letting the server
430
451
-- know that a file was created within the workspace, __provided that the server
0 commit comments