{-# LANGUAGE ExplicitNamespaces #-}
module Futhark.CLI.LSP (main) where
import Control.Monad.IO.Class (MonadIO (liftIO))
import Data.IORef (newIORef)
import Futhark.LSP.Handlers (handlers)
import Futhark.LSP.State (emptyState)
import Language.LSP.Protocol.Types
( SaveOptions (SaveOptions),
TextDocumentSyncKind (TextDocumentSyncKind_Incremental),
TextDocumentSyncOptions (..),
type (|?) (InR),
)
import Language.LSP.Server
main :: String -> [String] -> IO ()
main :: String -> [String] -> IO ()
main String
_prog [String]
_args = do
IORef State
state_mvar <- State -> IO (IORef State)
forall a. a -> IO (IORef a)
newIORef State
emptyState
Int
_ <-
ServerDefinition () -> IO Int
forall config. ServerDefinition config -> IO Int
runServer (ServerDefinition () -> IO Int) -> ServerDefinition () -> IO Int
forall a b. (a -> b) -> a -> b
$
ServerDefinition
{ onConfigChange :: () -> LspM () ()
onConfigChange = LspM () () -> () -> LspM () ()
forall a b. a -> b -> a
const (LspM () () -> () -> LspM () ()) -> LspM () () -> () -> LspM () ()
forall a b. (a -> b) -> a -> b
$ () -> LspM () ()
forall a. a -> LspM () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (),
configSection :: Text
configSection = Text
"Futhark",
parseConfig :: () -> Value -> Either Text ()
parseConfig = (Value -> Either Text ()) -> () -> Value -> Either Text ()
forall a b. a -> b -> a
const ((Value -> Either Text ()) -> () -> Value -> Either Text ())
-> (Either Text () -> Value -> Either Text ())
-> Either Text ()
-> ()
-> Value
-> Either Text ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either Text () -> Value -> Either Text ()
forall a b. a -> b -> a
const (Either Text () -> () -> Value -> Either Text ())
-> Either Text () -> () -> Value -> Either Text ()
forall a b. (a -> b) -> a -> b
$ () -> Either Text ()
forall a b. b -> Either a b
Right (),
defaultConfig :: ()
defaultConfig = (),
doInitialize :: LanguageContextEnv ()
-> TMessage 'Method_Initialize
-> IO
(Either
(TResponseError 'Method_Initialize) (LanguageContextEnv ()))
doInitialize = \LanguageContextEnv ()
env TMessage 'Method_Initialize
_req -> Either (TResponseError 'Method_Initialize) (LanguageContextEnv ())
-> IO
(Either
(TResponseError 'Method_Initialize) (LanguageContextEnv ()))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either (TResponseError 'Method_Initialize) (LanguageContextEnv ())
-> IO
(Either
(TResponseError 'Method_Initialize) (LanguageContextEnv ())))
-> Either
(TResponseError 'Method_Initialize) (LanguageContextEnv ())
-> IO
(Either
(TResponseError 'Method_Initialize) (LanguageContextEnv ()))
forall a b. (a -> b) -> a -> b
$ LanguageContextEnv ()
-> Either
(TResponseError 'Method_Initialize) (LanguageContextEnv ())
forall a b. b -> Either a b
Right LanguageContextEnv ()
env,
staticHandlers :: ClientCapabilities -> Handlers (LspM ())
staticHandlers = IORef State -> ClientCapabilities -> Handlers (LspM ())
handlers IORef State
state_mvar,
interpretHandler :: LanguageContextEnv () -> LspM () <~> IO
interpretHandler = \LanguageContextEnv ()
env -> (forall a. LspM () a -> IO a)
-> (forall a. IO a -> LspM () a) -> LspM () <~> IO
forall {k} (m :: k -> *) (n :: k -> *).
(forall (a :: k). m a -> n a)
-> (forall (a :: k). n a -> m a) -> m <~> n
Iso (LanguageContextEnv () -> LspT () IO a -> IO a
forall config (m :: * -> *) a.
LanguageContextEnv config -> LspT config m a -> m a
runLspT LanguageContextEnv ()
env) IO a -> LspM () a
forall a. IO a -> LspM () a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO,
options :: Options
options =
Options
defaultOptions
{ optTextDocumentSync = Just syncOptions
}
}
() -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
syncOptions :: TextDocumentSyncOptions
syncOptions :: TextDocumentSyncOptions
syncOptions =
TextDocumentSyncOptions
{ $sel:_openClose:TextDocumentSyncOptions :: Maybe Bool
_openClose = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False,
$sel:_change:TextDocumentSyncOptions :: Maybe TextDocumentSyncKind
_change = TextDocumentSyncKind -> Maybe TextDocumentSyncKind
forall a. a -> Maybe a
Just TextDocumentSyncKind
TextDocumentSyncKind_Incremental,
$sel:_willSave:TextDocumentSyncOptions :: Maybe Bool
_willSave = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False,
$sel:_willSaveWaitUntil:TextDocumentSyncOptions :: Maybe Bool
_willSaveWaitUntil = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False,
$sel:_save:TextDocumentSyncOptions :: Maybe (Bool |? SaveOptions)
_save = (Bool |? SaveOptions) -> Maybe (Bool |? SaveOptions)
forall a. a -> Maybe a
Just ((Bool |? SaveOptions) -> Maybe (Bool |? SaveOptions))
-> (Bool |? SaveOptions) -> Maybe (Bool |? SaveOptions)
forall a b. (a -> b) -> a -> b
$ SaveOptions -> Bool |? SaveOptions
forall a b. b -> a |? b
InR (SaveOptions -> Bool |? SaveOptions)
-> SaveOptions -> Bool |? SaveOptions
forall a b. (a -> b) -> a -> b
$ Maybe Bool -> SaveOptions
SaveOptions (Maybe Bool -> SaveOptions) -> Maybe Bool -> SaveOptions
forall a b. (a -> b) -> a -> b
$ Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
}