Skip to content

Commit 390b7db

Browse files
committed
[ change ] Remove code for lsp < 2
1 parent 3cf52e1 commit 390b7db

15 files changed

+109
-153
lines changed

agda-language-server.cabal

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ library
9696
, containers
9797
, directory
9898
, filepath
99-
, lsp
100-
, lsp-types
99+
, lsp >=2
100+
, lsp-types >=2
101101
, mtl
102102
, network
103103
, network-simple
@@ -142,8 +142,8 @@ executable als
142142
, containers
143143
, directory
144144
, filepath
145-
, lsp
146-
, lsp-types
145+
, lsp >=2
146+
, lsp-types >=2
147147
, mtl
148148
, network
149149
, network-simple
@@ -215,8 +215,8 @@ test-suite als-test
215215
, containers
216216
, directory
217217
, filepath
218-
, lsp
219-
, lsp-types
218+
, lsp >=2
219+
, lsp-types >=2
220220
, mtl
221221
, network
222222
, network-simple

package.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ dependencies:
6868
- containers
6969
- directory
7070
- filepath
71-
- lsp-types
72-
- lsp
71+
- lsp-types >= 2
72+
- lsp >= 2
7373
- mtl
7474
- network
7575
- network-simple

src/Agda/Parser.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ import Data.Maybe (fromMaybe)
1818
import Data.Text (Text, unpack)
1919
import qualified Data.Text as Text
2020
import Language.LSP.Server (LspM)
21-
#if MIN_VERSION_lsp(2,0,0)
2221
import qualified Language.LSP.Protocol.Types as LSP
23-
#else
24-
import qualified Language.LSP.Types as LSP
25-
#endif
2622
import Options (Config)
2723

2824
--------------------------------------------------------------------------------

src/Agda/Position.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ import qualified Data.Sequence as Seq
2222
import qualified Data.Strict.Maybe as Strict
2323
import Data.Text ( Text )
2424
import qualified Data.Text as Text
25-
#if MIN_VERSION_lsp(2,0,0)
2625
import qualified Language.LSP.Protocol.Types as LSP
27-
#else
28-
import qualified Language.LSP.Types as LSP
29-
#endif
3026

3127
-- Note: LSP srclocs are 0-base
3228
-- Agda srclocs are 1-base

src/Monad.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ import Data.Maybe ( isJust )
2727
import Language.LSP.Server ( MonadLsp
2828
, getConfig
2929
)
30-
#if MIN_VERSION_lsp(2,0,0)
3130
import qualified Language.LSP.Protocol.Types as LSP
32-
#else
33-
import qualified Language.LSP.Types as LSP
34-
#endif
3531
import Options
3632

3733
--------------------------------------------------------------------------------

src/Server.hs

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import qualified Data.Aeson as JSON
1818
import Data.Text ( pack )
1919
import GHC.IO.IOMode ( IOMode(ReadWriteMode) )
2020
import Language.LSP.Server hiding ( Options )
21-
#if MIN_VERSION_lsp(2,0,0)
2221
import 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
4134
import Monad
4235
import qualified Network.Simple.TCP as TCP
4336
import 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))
181110
handlers = 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

src/Server/Handler.hs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ import Data.Text ( Text
5555
import qualified Data.Text as Text
5656
import Language.LSP.Server ( LspM )
5757
import qualified Language.LSP.Server as LSP
58-
#if MIN_VERSION_lsp(2,0,0)
5958
import qualified Language.LSP.Protocol.Types as LSP
60-
#else
61-
import qualified Language.LSP.Types as LSP
62-
#endif
6359
import qualified Language.LSP.VFS as VFS
6460
import Monad
6561
import Options ( Config
@@ -107,62 +103,34 @@ inferTypeOfText filepath text = runCommandM $ do
107103

108104
render <$> prettyATop typ
109105

110-
#if MIN_VERSION_lsp_types(2,0,0)
111106
onHover :: LSP.Uri -> LSP.Position -> ServerM (LspM Config) (LSP.Hover LSP.|? LSP.Null)
112-
#else
113-
onHover :: LSP.Uri -> LSP.Position -> ServerM (LspM Config) (Maybe LSP.Hover)
114-
#endif
115107
onHover uri pos = do
116108
result <- LSP.getVirtualFile (LSP.toNormalizedUri uri)
117109
case result of
118-
#if MIN_VERSION_lsp_types(2,0,0)
119110
Nothing -> return $ LSP.InR LSP.Null
120-
#else
121-
Nothing -> return Nothing
122-
#endif
123111
Just file -> do
124112
let source = VFS.virtualFileText file
125113
let offsetTable = makeToOffset source
126114
let agdaPos = toAgdaPositionWithoutFile offsetTable pos
127115
lookupResult <- Parser.tokenAt uri source agdaPos
128116
case lookupResult of
129-
#if MIN_VERSION_lsp_types(2,0,0)
130117
Nothing -> return $ LSP.InR LSP.Null
131-
#else
132-
Nothing -> return Nothing
133-
#endif
134118
Just (_token, text) -> do
135119
case LSP.uriToFilePath uri of
136-
#if MIN_VERSION_lsp_types(2,0,0)
137120
Nothing -> return $ LSP.InR LSP.Null
138-
#else
139-
Nothing -> return Nothing
140-
#endif
141121
Just filepath -> do
142122
let range = LSP.Range pos pos
143123
inferResult <- inferTypeOfText filepath text
144124
case inferResult of
145125
Left err -> do
146126
let content = hoverContent $ "Error: " <> pack err
147-
#if MIN_VERSION_lsp_types(2,0,0)
148127
return $ LSP.InL $ LSP.Hover content (Just range)
149-
#else
150-
return $ Just $ LSP.Hover content (Just range)
151-
#endif
152128
Right typeString -> do
153129
let content = hoverContent $ pack typeString
154-
#if MIN_VERSION_lsp_types(2,0,0)
155130
return $ LSP.InL $ LSP.Hover content (Just range)
156-
#else
157-
return $ Just $ LSP.Hover content (Just range)
158-
#endif
159131
where
160132
hoverContent =
161-
#if MIN_VERSION_lsp_types(2,0,0)
162133
LSP.InL . LSP.mkMarkdownCodeBlock "agda-language-server"
163-
#else
164-
LSP.HoverContents . LSP.markedUpContent "agda-language-server"
165-
#endif
166134
--------------------------------------------------------------------------------
167135
-- Helper functions for converting stuff to SemanticTokenAbsolute
168136

@@ -171,11 +139,7 @@ fromHighlightingInfo :: IR.HighlightingInfo -> LSP.SemanticTokenAbsolute
171139
fromHighlightingInfo (IR.HighlightingInfo start end aspects isTokenBased note defSrc)
172140
= LSP.SemanticTokenAbsolute 1 1 3 kw []
173141
where
174-
#if MIN_VERSION_lsp_types(2,0,0)
175142
kw = LSP.SemanticTokenTypes_Keyword
176-
#else
177-
kw = LSP.SttKeyword
178-
#endif
179143

180144
-- HighlightingInfo
181145
-- Int -- starting offset

src/Switchboard.hs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE DataKinds #-}
33
{-# LANGUAGE PolyKinds #-}
4-
5-
#if MIN_VERSION_lsp_types(2,0,0)
64
{-# LANGUAGE TypeApplications #-}
7-
#endif
85

96
module Switchboard (Switchboard, new, setupLanguageContextEnv, destroy, agdaCustomMethod ) where
107

@@ -17,13 +14,9 @@ import qualified Agda
1714
import qualified Data.Aeson as JSON
1815
import qualified Data.Text.IO as Text
1916
import Language.LSP.Server
20-
#if MIN_VERSION_lsp(2,0,0)
2117
import Data.Proxy (Proxy(Proxy))
2218
import Language.LSP.Protocol.Message
2319
import Language.LSP.Protocol.Types
24-
#else
25-
import Language.LSP.Types
26-
#endif
2720
hiding (TextDocumentSyncClientCapabilities (..))
2821
import Data.IORef
2922
import Options (Config)
@@ -82,10 +75,5 @@ keepSendindResponse env ctxEnvIORef = forever $ do
8275
-- writeChan (envLogChan env) $ "[Response] >>>> " <> pack (show value)
8376
callback ()
8477

85-
#if MIN_VERSION_lsp_types(2,0,0)
8678
agdaCustomMethod :: SMethod ('Method_CustomMethod "agda")
8779
agdaCustomMethod = SMethod_CustomMethod (Proxy @"agda")
88-
#else
89-
agdaCustomMethod :: SMethod 'CustomMethod
90-
agdaCustomMethod = SCustomMethod "agda"
91-
#endif

stack-9.2-Agda-2.6.2.2.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ packages:
88

99
extra-deps:
1010
- Agda-2.6.2.2
11+
- lsp-2.7.0.0@sha256:2a64b40a69fd9638056ca552d5660203019473061cff1d09dccc0c94e40a275c,3834
12+
- lsp-types-2.3.0.0@sha256:ca17a686bda5dc7ff04105ca7081dce5a90bcd050c8800a13efd68b7f0901f1c,34215
13+
- mod-0.2.0.1@sha256:eeb316fef3a8c12f4e83bbeeea748e74d75fca54d4498d574ace92e464adb05a,2409
14+
- row-types-1.0.1.2@sha256:4d4c7cb95d06a32b28ba977852d52a26b4c1f695ef083a6fd874ab6d79933b64,3071
1115

1216
flags:
1317
agda-language-server:

0 commit comments

Comments
 (0)