{-# LANGUAGE DataKinds #-}

module Unison.LSP.Configuration where

import Data.Aeson
import Data.Text qualified as Text
import Language.LSP.Protocol.Message qualified as Msg
import Unison.LSP.Types
import Unison.Prelude

-- | Handle configuration changes.
updateConfig :: (Applicative m) => Config -> m ()
updateConfig :: forall (m :: * -> *). Applicative m => Config -> m ()
updateConfig Config
_newConfig = () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()

parseConfig :: Config -> Value -> Either Text Config
parseConfig :: Config -> Value -> Either Text Config
parseConfig Config
_oldConfig Value
newConfig = case Value -> Result Config
forall a. FromJSON a => Value -> Result a
fromJSON Value
newConfig of
  Error String
err -> Text -> Either Text Config
forall a b. a -> Either a b
Left (Text -> Either Text Config) -> Text -> Either Text Config
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
err
  Success Config
a -> Config -> Either Text Config
forall a b. b -> Either a b
Right Config
a

-- | We could use this notification to cancel/update work-in-progress,
-- but we don't actually need to update the config here, that's handled by the lsp library
-- automatically.
workspaceConfigurationChanged :: Msg.TNotificationMessage 'Msg.Method_WorkspaceDidChangeConfiguration -> Lsp ()
workspaceConfigurationChanged :: TNotificationMessage 'Method_WorkspaceDidChangeConfiguration
-> Lsp ()
workspaceConfigurationChanged TNotificationMessage 'Method_WorkspaceDidChangeConfiguration
_m = do
  () -> Lsp ()
forall a. a -> Lsp a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()