Skip to content

Commit cc33803

Browse files
authored
Merge pull request #498 from haskell/mpj/caps-for-handlers
Pass the ClientCapabilities to the static handlers in ServerDefinition
2 parents fac68b8 + 12c1a46 commit cc33803

File tree

11 files changed

+22
-15
lines changed

11 files changed

+22
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ main :: IO Int
7070
main = runServer $ ServerDefinition
7171
{ onConfigurationChange = const $ pure $ Right ()
7272
, doInitialize = \env _req -> pure $ Right env
73-
, staticHandlers = handlers
73+
, staticHandlers = \_caps -> handlers
7474
, interpretHandler = \env -> Iso (runLspT env) liftIO
7575
, options = defaultOptions
7676
}

lsp-test/bench/SimpleBench.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ server = ServerDefinition
3535
{ onConfigurationChange = const $ const $ Right ()
3636
, defaultConfig = ()
3737
, doInitialize = \env _req -> pure $ Right env
38-
, staticHandlers = handlers
38+
, staticHandlers = \_caps -> handlers
3939
, interpretHandler = \env -> Iso (runLspT env) liftIO
4040
, options = defaultOptions
4141
}

lsp-test/func-test/FuncTest.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ main = hspec $ do
3535
{ onConfigurationChange = const $ const $ Right ()
3636
, defaultConfig = ()
3737
, doInitialize = \env _req -> pure $ Right env
38-
, staticHandlers = handlers killVar
38+
, staticHandlers = \_caps -> handlers killVar
3939
, interpretHandler = \env -> Iso (runLspT env) liftIO
4040
, options = defaultOptions
4141
}
@@ -82,7 +82,7 @@ main = hspec $ do
8282
{ onConfigurationChange = const $ const $ Right ()
8383
, defaultConfig = ()
8484
, doInitialize = \env _req -> pure $ Right env
85-
, staticHandlers = handlers
85+
, staticHandlers = \_caps -> handlers
8686
, interpretHandler = \env -> Iso (runLspT env) liftIO
8787
, options = defaultOptions
8888
}

lsp-test/lsp-test.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.4
22
name: lsp-test
3-
version: 0.15.0.0
3+
version: 0.15.0.1
44
synopsis: Functional test framework for LSP servers.
55
description:
66
A test framework for writing tests against
@@ -59,7 +59,7 @@ library
5959
, filepath
6060
, Glob >=0.9 && <0.11
6161
, lens
62-
, lsp ^>=2.0
62+
, lsp ^>=2.1
6363
, lsp-types ^>=2.0
6464
, mtl <2.4
6565
, parser-combinators >=1.2
@@ -102,7 +102,7 @@ test-suite tests
102102
, filepath
103103
, hspec
104104
, lens
105-
, lsp ^>=2.0
105+
, lsp ^>=2.1
106106
, lsp-test
107107
, mtl <2.4
108108
, parser-combinators

lsp-test/test/DummyServer.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ withDummyServer f = do
3131
{ doInitialize = \env _req -> pure $ Right env
3232
, defaultConfig = ()
3333
, onConfigurationChange = const $ pure $ Right ()
34-
, staticHandlers = handlers
34+
, staticHandlers = \_caps -> handlers
3535
, interpretHandler = \env ->
3636
Iso (\m -> runLspT env (runReaderT m handlerEnv)) liftIO
3737
, options = defaultOptions {optExecuteCommandCommands = Just ["doAnEdit"]}

lsp/ChangeLog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Revision history for lsp
22

3-
## 2.0.0.1
3+
## 2.1.0.0
44

55
* Fix handling of optional methods.
6+
* `staticHandlers` now takes the client capabilities as an argument.
7+
These are static across the lifecycle of the server, so this allows
8+
a server to decide at construction e.g. whether to provide handlers
9+
for resolve methods depending on whether the client supports it.
610

711
## 2.0.0.0
812

lsp/example/Reactor.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ run = flip E.catches handlers $ do
9696
J.Success cfg -> Right cfg
9797
, doInitialize = \env _ -> forkIO (reactor stderrLogger rin) >> pure (Right env)
9898
-- Handlers log to both the client and stderr
99-
, staticHandlers = lspHandlers dualLogger rin
99+
, staticHandlers = \_caps -> lspHandlers dualLogger rin
100100
, interpretHandler = \env -> Iso (runLspT env) liftIO
101101
, options = lspOptions
102102
}

lsp/example/Simple.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ main = runServer $ ServerDefinition
4141
{ onConfigurationChange = const $ const $ Right ()
4242
, defaultConfig = ()
4343
, doInitialize = \env _req -> pure $ Right env
44-
, staticHandlers = handlers
44+
, staticHandlers = \_caps -> handlers
4545
, interpretHandler = \env -> Iso (runLspT env) liftIO
4646
, options = defaultOptions
4747
}

lsp/lsp.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: lsp
3-
version: 2.0.0.1
3+
version: 2.1.0.0
44
synopsis: Haskell library for the Microsoft Language Server Protocol
55
description:
66
An implementation of the types, and basic message server to

lsp/src/Language/LSP/Server/Core.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,12 @@ data ServerDefinition config = forall m a.
294294
-- language server implementation the chance to create any processes or
295295
-- start new threads that may be necessary for the server lifecycle. It can
296296
-- also return an error in the initialization if necessary.
297-
, staticHandlers :: Handlers m
297+
, staticHandlers :: ClientCapabilities -> Handlers m
298298
-- ^ Handlers for any methods you want to statically support.
299299
-- The handlers here cannot be unregistered during the server's lifetime
300300
-- and will be registered statically in the initialize request.
301+
-- The handlers provided can depend on the client capabilities, which
302+
-- are static across the lifetime of the server.
301303
, interpretHandler :: a -> (m <~> IO)
302304
-- ^ How to run the handlers in your own monad of choice, @m@.
303305
-- It is passed the result of 'doInitialize', so typically you will want

0 commit comments

Comments
 (0)