@@ -53,7 +53,6 @@ import Control.Monad.Trans.State (StateT, runStateT, execState)
5353import qualified Control.Monad.Trans.State as State
5454import qualified Data.ByteString.Lazy.Char8 as B
5555import Data.Aeson hiding (Error , Null )
56- import qualified Data.Aeson as J
5756import Data.Aeson.Encode.Pretty
5857import Data.Aeson.Lens ()
5958import Data.Conduit as Conduit
@@ -115,8 +114,8 @@ data SessionConfig = SessionConfig
115114 -- ^ Trace the messages sent and received to stdout, defaults to False.
116115 -- Can be overriden with the environment variable @LSP_TEST_LOG_MESSAGES@.
117116 , logColor :: Bool -- ^ Add ANSI color to the logged messages, defaults to True.
118- , lspConfig :: Value
119- -- ^ The initial LSP config as JSON value, defaults to Null .
117+ , lspConfig :: Object
118+ -- ^ The initial LSP config as JSON value, defaults to the empty object .
120119 -- This should include the config section for the server if it has one, i.e. if
121120 -- the server has a 'mylang' config section, then the config should be an object
122121 -- with a 'mylang' key whose value is the actual config for the server. You
@@ -134,7 +133,7 @@ data SessionConfig = SessionConfig
134133
135134-- | The configuration used in 'Language.LSP.Test.runSession'.
136135defaultConfig :: SessionConfig
137- defaultConfig = SessionConfig 60 False False True J. Null True True Nothing
136+ defaultConfig = SessionConfig 60 False False True mempty True True Nothing
138137
139138instance Default SessionConfig where
140139 def = defaultConfig
@@ -188,9 +187,9 @@ data SessionState = SessionState
188187 -- Used for providing exception information
189188 , lastReceivedMessage :: ! (Maybe FromServerMessage )
190189 , curDynCaps :: ! (Map. Map T. Text SomeRegistration )
191- , curLspConfig :: Value
192190 -- ^ The capabilities that the server has dynamically registered with us so
193191 -- far
192+ , curLspConfig :: Object
194193 , curProgressSessions :: ! (Set. Set ProgressToken )
195194 , ignoringLogNotifications :: Bool
196195 , ignoringConfigurationRequests :: Bool
@@ -317,24 +316,20 @@ updateStateC = awaitForever $ \msg -> do
317316 sendMessage $ TResponseMessage " 2.0" (Just $ r ^. L. id ) (Right $ ApplyWorkspaceEditResult True Nothing Nothing )
318317 FromServerMess SMethod_WorkspaceConfiguration r -> do
319318 let requestedSections = mapMaybe (\ i -> i ^? L. section . _Just) $ r ^. L. params . L. items
320- c <- curLspConfig <$> get @ SessionState
321- case c of
322- Object o -> do
323- -- check for each requested section whether we have it
324- let configsOrErrs = (flip fmap ) requestedSections $ \ section ->
325- case o ^. at (fromString $ T. unpack section) of
326- Just config -> Right config
327- Nothing -> Left section
328-
329- let (errs, configs) = partitionEithers configsOrErrs
330-
331- -- we have to return exactly the number of sections requested, so if we can't find all of them then that's an error
332- if null errs
333- then sendMessage $ TResponseMessage " 2.0" (Just $ r ^. L. id ) (Right configs)
334- else sendMessage @ _ @ (TResponseError Method_WorkspaceConfiguration ) $
335- TResponseError (InL LSPErrorCodes_RequestFailed ) (" No configuration for requested sections: " <> (T. pack $ show errs)) Nothing
336-
337- _ -> sendMessage @ _ @ (TResponseError Method_WorkspaceConfiguration ) $ TResponseError (InL LSPErrorCodes_RequestFailed ) " No configuration" Nothing
319+ o <- curLspConfig <$> get @ SessionState
320+ -- check for each requested section whether we have it
321+ let configsOrErrs = (flip fmap ) requestedSections $ \ section ->
322+ case o ^. at (fromString $ T. unpack section) of
323+ Just config -> Right config
324+ Nothing -> Left section
325+
326+ let (errs, configs) = partitionEithers configsOrErrs
327+
328+ -- we have to return exactly the number of sections requested, so if we can't find all of them then that's an error
329+ if null errs
330+ then sendMessage $ TResponseMessage " 2.0" (Just $ r ^. L. id ) (Right configs)
331+ else sendMessage @ _ @ (TResponseError Method_WorkspaceConfiguration ) $
332+ TResponseError (InL LSPErrorCodes_RequestFailed ) (" No configuration for requested sections: " <> (T. pack $ show errs)) Nothing
338333 _ -> pure ()
339334 unless ((ignoringLogNotifications state && isLogNotification msg) || (ignoringConfigurationRequests state && isConfigRequest msg)) $
340335 yield msg
0 commit comments