@@ -18,7 +18,6 @@ import qualified Data.Aeson as JSON
1818import Data.Text ( pack )
1919import GHC.IO.IOMode ( IOMode (ReadWriteMode ) )
2020import Language.LSP.Server hiding ( Options )
21- #if MIN_VERSION_lsp(2,0,0)
2221import Language.LSP.Protocol.Message ( pattern RequestMessage
2322 , SMethod ( SMethod_CustomMethod , SMethod_TextDocumentHover )
2423 , pattern TRequestMessage
@@ -32,12 +31,6 @@ import Language.LSP.Protocol.Types ( TextDocumentSyncOptions(..)
3231 , pattern InR
3332 , pattern InL
3433 )
35- #else
36- import Language.LSP.Types
37- hiding ( Options (.. )
38- , TextDocumentSyncClientCapabilities (.. )
39- )
40- #endif
4134import Monad
4235import qualified Network.Simple.TCP as TCP
4336import Network.Socket ( socketToHandle )
@@ -60,51 +53,13 @@ run options = do
6053 \ (sock, _remoteAddr) -> do
6154 -- writeChan (envLogChan env) "[Server] connection established"
6255 handle <- socketToHandle sock ReadWriteMode
63- _ <- runServerWithHandles
64- #if MIN_VERSION_lsp(1,5,0)
65- mempty mempty
66- #endif
67- handle handle (serverDefn options)
56+ _ <- runServerWithHandles mempty mempty handle handle (serverDefn options)
6857 return ()
6958 -- Switchboard.destroy switchboard
7059 return 0
7160 Nothing -> do
7261 runServer (serverDefn options)
7362 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)
10863 serverDefn :: Options -> ServerDefinition Config
10964 serverDefn options =
11065 ServerDefinition
@@ -120,25 +75,7 @@ run options = do
12075 Switchboard. setupLanguageContextEnv switchboard ctxEnv
12176 pure $ Right (ctxEnv, env),
12277 configSection = " dummy" ,
123- #else
124- serverDefn :: Options -> ServerDefinition Config
125- serverDefn options =
126- ServerDefinition
127- { defaultConfig = initConfig,
128- onConfigurationChange = \ old newRaw -> case JSON. fromJSON newRaw of
129- JSON. Error s -> Left $ pack $ " Cannot parse server configuration: " <> s
130- JSON. Success new -> Right new,
131- doInitialize = \ ctxEnv _req -> do
132- env <- runLspT ctxEnv (createInitEnv options)
133- switchboard <- Switchboard. new env
134- Switchboard. setupLanguageContextEnv switchboard ctxEnv
135- pure $ Right (ctxEnv, env),
136- #endif
137- #if MIN_VERSION_lsp_types(2,0,0)
13878 staticHandlers = const handlers,
139- #else
140- staticHandlers = handlers,
141- #endif
14279 interpretHandler = \ (ctxEnv, env) ->
14380 Iso {
14481 forward = runLspT ctxEnv . runServerM env,
@@ -148,11 +85,7 @@ run options = do
14885 }
14986
15087 lspOptions :: LSP. Options
151- #if MIN_VERSION_lsp_types(2,0,0)
15288 lspOptions = defaultOptions { optTextDocumentSync = Just syncOptions }
153- #else
154- lspOptions = defaultOptions { textDocumentSync = Just syncOptions }
155- #endif
15689
15790 -- these `TextDocumentSyncOptions` are essential for receiving notifications from the client
15891 syncOptions :: TextDocumentSyncOptions
@@ -166,11 +99,7 @@ run options = do
16699 }
167100
168101 changeOptions :: TextDocumentSyncKind
169- #if MIN_VERSION_lsp_types(2,0,0)
170102 changeOptions = TextDocumentSyncKind_Incremental
171- #else
172- changeOptions = TdSyncIncremental
173- #endif
174103
175104 -- includes the document content on save, so that we don't have to read it from the disk
176105 saveOptions :: SaveOptions
@@ -181,21 +110,13 @@ handlers :: Handlers (ServerM (LspM Config))
181110handlers = mconcat
182111 [ -- custom methods, not part of LSP
183112 requestHandler agdaCustomMethod $ \ req responder -> do
184- #if MIN_VERSION_lsp_types(2,0,0)
185113 let TRequestMessage _ _i _ params = req
186- #else
187- let RequestMessage _ _i _ params = req
188- #endif
189114 response <- Agda. sendCommand params
190115 responder $ Right response
191116 ,
192117 -- hover provider
193118 requestHandler hoverMethod $ \ req responder -> do
194- #if MIN_VERSION_lsp_types(2,0,0)
195119 let TRequestMessage _ _ _ (HoverParams (TextDocumentIdentifier uri) pos _workDone) = req
196- #else
197- let RequestMessage _ _ _ (HoverParams (TextDocumentIdentifier uri) pos _workDone) = req
198- #endif
199120 result <- Handler. onHover uri pos
200121 responder $ Right result
201122 -- -- syntax highlighting
@@ -204,8 +125,4 @@ handlers = mconcat
204125 -- responder result
205126 ]
206127 where
207- #if MIN_VERSION_lsp_types(2,0,0)
208128 hoverMethod = SMethod_TextDocumentHover
209- #else
210- hoverMethod = STextDocumentHover
211- #endif
0 commit comments