Skip to content

Commit

Permalink
Add setConfig as an analogue to getConfig (haskell#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgujjula committed Apr 13, 2022
1 parent 8db20a5 commit bddb5b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions lsp/src/Language/LSP/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Language.LSP.Server

, getClientCapabilities
, getConfig
, setConfig
, getRootPath
, getWorkspaceFolders

Expand Down
8 changes: 7 additions & 1 deletion lsp/src/Language/LSP/Server/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,18 @@ freshLspId = do
-- ---------------------------------------------------------------------

-- | The current configuration from the client as set via the @initialize@ and
-- @workspace/didChangeConfiguration@ requests.
-- @workspace/didChangeConfiguration@ requests, as well as by calls to
-- 'setConfig'.
getConfig :: MonadLsp config m => m config
getConfig = getsState resConfig

{-# INLINE getConfig #-}

setConfig :: MonadLsp config m => (config -> (a,config)) -> m a
setConfig = stateState resConfig

{-# INLINE setConfig #-}

getClientCapabilities :: MonadLsp config m => m J.ClientCapabilities
getClientCapabilities = resClientCapabilities <$> getLspEnv

Expand Down
2 changes: 1 addition & 1 deletion lsp/src/Language/LSP/Server/Processing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ shutdownRequestHandler = \_req k -> do
handleConfigChange :: Message WorkspaceDidChangeConfiguration -> LspM config ()
handleConfigChange req = do
parseConfig <- LspT $ asks resParseConfig
res <- stateState resConfig $ \oldConfig -> case parseConfig oldConfig (req ^. LSP.params . LSP.settings) of
res <- setConfig $ \oldConfig -> case parseConfig oldConfig (req ^. LSP.params . LSP.settings) of
Left err -> (Left err, oldConfig)
Right !newConfig -> (Right (), newConfig)
case res of
Expand Down

0 comments on commit bddb5b6

Please sign in to comment.