@@ -21,6 +21,7 @@ import Language.LSP.Server hiding ( Options )
2121#if MIN_VERSION_lsp(2,0,0)
2222import Language.LSP.Protocol.Message ( pattern RequestMessage
2323 , SMethod ( SMethod_CustomMethod , SMethod_TextDocumentHover )
24+ , pattern TRequestMessage
2425 )
2526import Language.LSP.Protocol.Types ( TextDocumentSyncOptions (.. )
2627 , TextDocumentSyncKind ( TextDocumentSyncKind_Incremental )
@@ -29,6 +30,7 @@ import Language.LSP.Protocol.Types ( TextDocumentSyncOptions(..)
2930 , pattern TextDocumentIdentifier
3031 , pattern HoverParams
3132 , pattern InR
33+ , pattern InL
3234 )
3335#else
3436import Language.LSP.Types
@@ -47,7 +49,6 @@ import qualified Server.Handler as Handler
4749import qualified Language.LSP.Server as LSP
4850import Options
4951
50-
5152--------------------------------------------------------------------------------
5253
5354run :: Options -> IO Int
@@ -70,28 +71,79 @@ run options = do
7071 Nothing -> do
7172 runServer (serverDefn options)
7273 where
74+ -- serverDefn :: Options -> ServerDefinition Config
75+ -- serverDefn options =
76+ -- ServerDefinition
77+ -- { defaultConfig = initConfig,
78+ -- #if MIN_VERSION_lsp_types(2,0,0)
79+ -- onConfigChange = \old newRaw -> pure (),
80+ -- #else
81+ -- onConfigurationChange = \old newRaw -> case JSON.fromJSON newRaw of
82+ -- JSON.Error s -> Left $ pack $ "Cannot parse server configuration: " <> s
83+ -- JSON.Success new -> Right new,
84+ -- #endif
85+ -- doInitialize = \ctxEnv _req -> do
86+ -- env <- runLspT ctxEnv (createInitEnv options)
87+ -- switchboard <- Switchboard.new env
88+ -- Switchboard.setupLanguageContextEnv switchboard ctxEnv
89+ -- #if MIN_VERSION_lsp_types(2,0,0)
90+ -- pure $ Right (ctxEnv),
91+ -- #else
92+ -- pure $ Right (ctxEnv, env),
93+ -- #endif
94+ -- #if MIN_VERSION_lsp_types(2,0,0)
95+ -- interpretHandler = \env -> Iso {
96+ -- forward = runLspT env, -- how to convert from IO ~> m
97+ -- backward = liftIO -- how to convert from m ~> IO
98+ -- },
99+ -- #else
100+ -- staticHandlers = handlers,
101+ -- interpretHandler = \(ctxEnv, env) ->
102+ -- Iso (runLspT ctxEnv . runServerM env) liftIO,
103+ -- #endif
104+ -- options = lspOptions
105+ -- }
106+
107+ #if MIN_VERSION_lsp_types(2,0,0)
108+ serverDefn :: Options -> ServerDefinition Config
109+ serverDefn options =
110+ ServerDefinition
111+ {
112+ defaultConfig = initConfig,
113+ onConfigChange = const $ pure () ,
114+ parseConfig = \ old newRaw -> case JSON. fromJSON newRaw of
115+ JSON. Error s -> Left $ pack $ " Cannot parse server configuration: " <> s
116+ JSON. Success new -> Right new,
117+ doInitialize = \ ctxEnv _req -> do
118+ env <- runLspT ctxEnv (createInitEnv options)
119+ switchboard <- Switchboard. new env
120+ Switchboard. setupLanguageContextEnv switchboard ctxEnv
121+ pure $ Right (ctxEnv, env),
122+ configSection = " dummy" ,
123+ #else
73124 serverDefn :: Options -> ServerDefinition Config
74125 serverDefn options =
75126 ServerDefinition
76127 { defaultConfig = initConfig,
77- #if MIN_VERSION_lsp_types(2,0,0)
78- onConfigChange = \ old newRaw -> () ,
79- -- case JSON.fromJSON newRaw of
80- -- JSON.Error s -> () -- putStrLn $ pack $ "Cannot parse server configuration: " <> s
81- -- JSON.Success new -> (),
82- #else
83128 onConfigurationChange = \ old newRaw -> case JSON. fromJSON newRaw of
84129 JSON. Error s -> Left $ pack $ " Cannot parse server configuration: " <> s
85130 JSON. Success new -> Right new,
86- #endif
87131 doInitialize = \ ctxEnv _req -> do
88132 env <- runLspT ctxEnv (createInitEnv options)
89133 switchboard <- Switchboard. new env
90134 Switchboard. setupLanguageContextEnv switchboard ctxEnv
91135 pure $ Right (ctxEnv, env),
92- -- staticHandlers = handlers,
93- -- interpretHandler = \(ctxEnv, env) ->
94- -- Iso (runLspT ctxEnv . runServerM env) liftIO,
136+ #endif
137+ #if MIN_VERSION_lsp_types(2,0,0)
138+ staticHandlers = const handlers,
139+ #else
140+ staticHandlers = handlers,
141+ #endif
142+ interpretHandler = \ (ctxEnv, env) ->
143+ Iso {
144+ forward = runLspT ctxEnv . runServerM env,
145+ backward = liftIO
146+ },
95147 options = lspOptions
96148 }
97149
@@ -130,22 +182,22 @@ handlers = mconcat
130182 [ -- custom methods, not part of LSP
131183 requestHandler agdaCustomMethod $ \ req responder -> do
132184#if MIN_VERSION_lsp_types(2,0,0)
133- return ()
185+ let TRequestMessage _ _i _ params = req
134186#else
135187 let RequestMessage _ _i _ params = req
188+ #endif
136189 response <- Agda. sendCommand params
137190 responder $ Right response
138- #endif
139191 ,
140192 -- hover provider
141193 requestHandler hoverMethod $ \ req responder -> do
142194#if MIN_VERSION_lsp_types(2,0,0)
143- return ()
195+ let TRequestMessage _ _ _ ( HoverParams ( TextDocumentIdentifier uri) pos _workDone) = req
144196#else
145197 let RequestMessage _ _ _ (HoverParams (TextDocumentIdentifier uri) pos _workDone) = req
198+ #endif
146199 result <- Handler. onHover uri pos
147200 responder $ Right result
148- #endif
149201 -- -- syntax highlighting
150202 -- , requestHandler STextDocumentSemanticTokensFull $ \req responder -> do
151203 -- result <- Handler.onHighlight (req ^. (params . textDocument . uri))
0 commit comments