Skip to content

Commit 2e1c244

Browse files
committed
add test for configuration
1 parent c2c6e6c commit 2e1c244

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

ocaml-lsp-server/test/e2e-new/dune

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
completion
5151
doc_to_md
5252
document_flow
53+
dune_context
5354
for_ppx
5455
hover_extended
5556
inlay_hints
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
open Test.Import
2+
3+
let client_capabilities = ClientCapabilities.create ()
4+
5+
let uri = DocumentUri.of_path "test.ml"
6+
7+
let test ?extra_env text req =
8+
let handler =
9+
Client.Handler.make
10+
~on_notification:(fun client _notification ->
11+
Client.state client;
12+
Fiber.return ())
13+
()
14+
in
15+
Test.run ~handler ?extra_env (fun client ->
16+
let run_client () =
17+
Client.start
18+
client
19+
(InitializeParams.create ~capabilities:client_capabilities ())
20+
in
21+
let run () =
22+
let* (_ : InitializeResult.t) = Client.initialized client in
23+
let textDocument =
24+
TextDocumentItem.create ~uri ~languageId:"ocaml" ~version:0 ~text
25+
in
26+
let* () =
27+
Client.notification
28+
client
29+
(TextDocumentDidOpen
30+
(DidOpenTextDocumentParams.create ~textDocument))
31+
in
32+
let* () = req client in
33+
let* () = Client.request client Shutdown in
34+
Client.stop client
35+
in
36+
Fiber.fork_and_join_unit run_client run)
37+
38+
let print_hover hover =
39+
match hover with
40+
| None -> print_endline "no hover response"
41+
| Some hover ->
42+
hover |> Hover.yojson_of_t
43+
|> Yojson.Safe.pretty_to_string ~std:false
44+
|> print_endline
45+
46+
let change_config client params =
47+
Client.notification client (ChangeConfiguration params)
48+
49+
let hover client position =
50+
Client.request
51+
client
52+
(TextDocumentHover
53+
{ HoverParams.position
54+
; textDocument = TextDocumentIdentifier.create ~uri
55+
; workDoneToken = None
56+
})
57+
58+
let%expect_test "supports changing Dune context configuration" =
59+
let source =
60+
{ocaml|
61+
type foo = int option
62+
63+
let foo_value : foo = Some 1
64+
|ocaml}
65+
in
66+
let position = Position.create ~line:3 ~character:4 in
67+
let req client =
68+
let* () =
69+
change_config
70+
client
71+
(DidChangeConfigurationParams.create
72+
~settings:
73+
(`Assoc
74+
[ ("duneContext", `Assoc [ ("value", `String "alt") ]) ]))
75+
in
76+
let* resp = hover client position in
77+
let () = print_hover resp in
78+
Fiber.return ()
79+
in
80+
test source req;
81+
[%expect
82+
{|
83+
{
84+
"contents": { "kind": "plaintext", "value": "foo" },
85+
"range": {
86+
"end": { "character": 13, "line": 3 },
87+
"start": { "character": 4, "line": 3 }
88+
}
89+
} |}]

0 commit comments

Comments
 (0)