@@ -3,7 +3,7 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
3
3
4
4
alias ElixirLS.LanguageServer . { Dialyzer , Server , Protocol , SourceFile , JsonRpc , Tracer , Build }
5
5
import ExUnit.CaptureLog
6
- alias ElixirLS.LanguageServer.Test.ServerTestHelpers
6
+ import ElixirLS.LanguageServer.Test.ServerTestHelpers
7
7
use ElixirLS.Utils.MixTest.Case , async: false
8
8
use Protocol
9
9
@@ -22,7 +22,7 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
22
22
end
23
23
24
24
setup do
25
- server = ServerTestHelpers . start_server ( )
25
+ server = start_server ( )
26
26
{ :ok , _tracer } = start_supervised ( Tracer )
27
27
28
28
{ :ok , % { server: server } }
@@ -34,15 +34,7 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
34
34
file_a = SourceFile.Path . to_uri ( Path . absname ( "lib/a.ex" ) )
35
35
36
36
capture_log ( fn ->
37
- root_uri = SourceFile.Path . to_uri ( File . cwd! ( ) )
38
- Server . receive_packet ( server , initialize_req ( 1 , root_uri , % { } ) )
39
-
40
- Server . receive_packet (
41
- server ,
42
- did_change_configuration ( % {
43
- "elixirLS" => % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyxir_long" }
44
- } )
45
- )
37
+ initialize ( server , % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyxir_long" } )
46
38
47
39
message = assert_receive % { "method" => "textDocument/publishDiagnostics" } , 20000
48
40
@@ -107,15 +99,7 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
107
99
file_c = SourceFile.Path . to_uri ( Path . absname ( "lib/c.ex" ) )
108
100
109
101
capture_log ( fn ->
110
- root_uri = SourceFile.Path . to_uri ( File . cwd! ( ) )
111
- Server . receive_packet ( server , initialize_req ( 1 , root_uri , % { } ) )
112
-
113
- Server . receive_packet (
114
- server ,
115
- did_change_configuration ( % {
116
- "elixirLS" => % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyxir_long" }
117
- } )
118
- )
102
+ initialize ( server , % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyxir_long" } )
119
103
120
104
assert_receive % { "method" => "textDocument/publishDiagnostics" } , 20_000
121
105
@@ -168,15 +152,7 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
168
152
file_a = SourceFile.Path . to_uri ( Path . absname ( "lib/a.ex" ) )
169
153
170
154
capture_log ( fn ->
171
- root_uri = SourceFile.Path . to_uri ( File . cwd! ( ) )
172
- Server . receive_packet ( server , initialize_req ( 1 , root_uri , % { } ) )
173
-
174
- Server . receive_packet (
175
- server ,
176
- did_change_configuration ( % {
177
- "elixirLS" => % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyxir_long" }
178
- } )
179
- )
155
+ initialize ( server , % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyxir_long" } )
180
156
181
157
message = assert_receive % { "method" => "textDocument/publishDiagnostics" } , 20000
182
158
@@ -222,15 +198,7 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
222
198
file_a = SourceFile.Path . to_uri ( Path . absname ( "lib/a.ex" ) )
223
199
224
200
capture_log ( fn ->
225
- root_uri = SourceFile.Path . to_uri ( File . cwd! ( ) )
226
- Server . receive_packet ( server , initialize_req ( 1 , root_uri , % { } ) )
227
-
228
- Server . receive_packet (
229
- server ,
230
- did_change_configuration ( % {
231
- "elixirLS" => % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyxir_short" }
232
- } )
233
- )
201
+ initialize ( server , % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyxir_short" } )
234
202
235
203
message = assert_receive % { "method" => "textDocument/publishDiagnostics" } , 20000
236
204
@@ -262,20 +230,12 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
262
230
end
263
231
264
232
@ tag slow: true , fixture: true
265
- test "reports dialyzer_formatted error" , % { server: server } do
233
+ test "reports dialyzer formatted error" , % { server: server } do
266
234
in_fixture ( __DIR__ , "dialyzer" , fn ->
267
235
file_a = SourceFile.Path . to_uri ( Path . absname ( "lib/a.ex" ) )
268
236
269
237
capture_log ( fn ->
270
- root_uri = SourceFile.Path . to_uri ( File . cwd! ( ) )
271
- Server . receive_packet ( server , initialize_req ( 1 , root_uri , % { } ) )
272
-
273
- Server . receive_packet (
274
- server ,
275
- did_change_configuration ( % {
276
- "elixirLS" => % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyzer" }
277
- } )
278
- )
238
+ initialize ( server , % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyzer" } )
279
239
280
240
message = assert_receive % { "method" => "textDocument/publishDiagnostics" } , 20000
281
241
@@ -313,15 +273,7 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
313
273
file_a = SourceFile.Path . to_uri ( Path . absname ( "apps/app1/lib/app1.ex" ) )
314
274
315
275
capture_log ( fn ->
316
- root_uri = SourceFile.Path . to_uri ( File . cwd! ( ) )
317
- Server . receive_packet ( server , initialize_req ( 1 , root_uri , % { } ) )
318
-
319
- Server . receive_packet (
320
- server ,
321
- did_change_configuration ( % {
322
- "elixirLS" => % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyxir_short" }
323
- } )
324
- )
276
+ initialize ( server , % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyxir_short" } )
325
277
326
278
message = assert_receive % { "method" => "textDocument/publishDiagnostics" } , 20000
327
279
@@ -357,13 +309,7 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
357
309
file_a = SourceFile.Path . to_uri ( Path . absname ( "lib/a.ex" ) )
358
310
359
311
capture_log ( fn ->
360
- root_uri = SourceFile.Path . to_uri ( File . cwd! ( ) )
361
- Server . receive_packet ( server , initialize_req ( 1 , root_uri , % { } ) )
362
-
363
- Server . receive_packet (
364
- server ,
365
- did_change_configuration ( % { "elixirLS" => % { "dialyzerEnabled" => true } } )
366
- )
312
+ initialize ( server , % { "dialyzerEnabled" => true } )
367
313
368
314
assert_receive publish_diagnostics_notif ( ^ file_a , [ _ , _ ] ) , 20000
369
315
@@ -381,16 +327,9 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
381
327
@ tag slow: true , fixture: true
382
328
test "protocol rebuild does not trigger consolidation warnings" , % { server: server } do
383
329
in_fixture ( __DIR__ , "protocols" , fn ->
384
- root_uri = SourceFile.Path . to_uri ( File . cwd! ( ) )
385
330
uri = SourceFile.Path . to_uri ( Path . absname ( "lib/implementations.ex" ) )
386
331
387
- Server . receive_packet ( server , initialize_req ( 1 , root_uri , % { } ) )
388
- Server . receive_packet ( server , notification ( "initialized" ) )
389
-
390
- Server . receive_packet (
391
- server ,
392
- did_change_configuration ( % { "elixirLS" => % { "dialyzerEnabled" => true } } )
393
- )
332
+ initialize ( server , % { "dialyzerEnabled" => true } )
394
333
395
334
assert_receive notification ( "window/logMessage" , % { "message" => "Compile took" <> _ } ) , 5000
396
335
@@ -458,15 +397,7 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
458
397
file_c = SourceFile.Path . to_uri ( Path . absname ( "lib/c.ex" ) )
459
398
460
399
capture_log ( fn ->
461
- root_uri = SourceFile.Path . to_uri ( File . cwd! ( ) )
462
- Server . receive_packet ( server , initialize_req ( 1 , root_uri , % { } ) )
463
-
464
- Server . receive_packet (
465
- server ,
466
- did_change_configuration ( % {
467
- "elixirLS" => % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyxir_long" }
468
- } )
469
- )
400
+ initialize ( server , % { "dialyzerEnabled" => true , "dialyzerFormat" => "dialyxir_long" } )
470
401
471
402
message = assert_receive % { "method" => "textDocument/publishDiagnostics" } , 20000
472
403
@@ -495,19 +426,11 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
495
426
file_c = SourceFile.Path . to_uri ( Path . absname ( "lib/c.ex" ) )
496
427
497
428
capture_log ( fn ->
498
- root_uri = SourceFile.Path . to_uri ( File . cwd! ( ) )
499
- Server . receive_packet ( server , initialize_req ( 1 , root_uri , % { } ) )
500
-
501
- Server . receive_packet (
502
- server ,
503
- did_change_configuration ( % {
504
- "elixirLS" => % {
505
- "dialyzerEnabled" => true ,
506
- "dialyzerFormat" => "dialyxir_long" ,
507
- "suggestSpecs" => true
508
- }
509
- } )
510
- )
429
+ initialize ( server , % {
430
+ "dialyzerEnabled" => true ,
431
+ "dialyzerFormat" => "dialyxir_long" ,
432
+ "suggestSpecs" => true
433
+ } )
511
434
512
435
message = assert_receive % { "method" => "textDocument/publishDiagnostics" } , 20000
513
436
@@ -555,7 +478,7 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
555
478
)
556
479
557
480
assert_receive ( % {
558
- "id" => 1 ,
481
+ "id" => id ,
559
482
"method" => "workspace/applyEdit" ,
560
483
"params" => % {
561
484
"edit" => % {
@@ -575,19 +498,7 @@ defmodule ElixirLS.LanguageServer.DialyzerTest do
575
498
}
576
499
} )
577
500
578
- # TODO something is broken in packet capture
579
- # using JsonRpc.receive_packet causes the packet to be delivered to LanguageServer
580
- # which crashes with no match error
581
- # JsonRpc.receive_packet(
582
- # server,
583
- # response(1, %{"applied" => true})
584
- # )
585
- # instead we fake a callback in JsonRpc server that forwards the response as needed
586
- JsonRpc . handle_call (
587
- { :packet , response ( 1 , % { "applied" => true } ) } ,
588
- nil ,
589
- :sys . get_state ( JsonRpc )
590
- )
501
+ JsonRpc . receive_packet ( response ( id , % { "applied" => true } ) )
591
502
592
503
assert_receive ( % { "id" => 4 , "result" => nil } , 5000 )
593
504
end )
0 commit comments