Skip to content

Commit 8ed930b

Browse files
committed
wait notification for each with-document
introduce notification-channel for this case misc: - use rackunit in hover.rkt - use rackunit
1 parent 0c4caec commit 8ed930b

File tree

8 files changed

+42
-39
lines changed

8 files changed

+42
-39
lines changed

info.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
"racket-index" ;; for cross references (setup/xref)
1616
"html-parsing" ;; for parsing documentation text
1717
))
18-
(define build-deps '("chk-lib"))
18+
(define build-deps '("chk-lib" "rackunit-lib"))
1919
(define pkg-desc "Language Server Protocol implementation for Racket.")
2020
(define version "1.0")

tests/client.rkt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
(provide with-racket-lsp
66
client-send
77
client-wait-response
8+
client-wait-notification
89
make-request
910
make-expected-response
1011
make-notification
@@ -14,10 +15,8 @@
1415
racket/async-channel
1516
racket/match
1617
json
17-
data/queue
1818
"../server.rkt"
19-
"../methods.rkt"
20-
"../msg-io.rkt")
19+
"../methods.rkt")
2120

2221
(define id 0)
2322
(define (Lsp-genid lsp)
@@ -26,6 +25,7 @@
2625

2726
(define server-output-ch (make-parameter #f))
2827
(define response-channel (make-parameter #f))
28+
(define notification-channel (make-parameter #f))
2929

3030
(define/contract (process-message-from-server lsp msg)
3131
(-> any/c jsexpr? void?)
@@ -37,18 +37,21 @@
3737
(handle-server-request lsp msg)]
3838
;; Server notification - queue diagnostic notifications, ignore others
3939
[(hash-table ['method (? string? method)])
40-
(when (equal? method "textDocument/publishDiagnostics")
41-
(async-channel-put (response-channel) msg))]
40+
(match method
41+
["textDocument/publishDiagnostics"
42+
(async-channel-put (notification-channel) msg)]
43+
; ignore unknown method
44+
[_ (void)])]
4245
;; Response - put it to another channel for client-wait-response
43-
[else
44-
(async-channel-put (response-channel) msg)]))
46+
[msg (async-channel-put (response-channel) msg)]))
4547

4648
(define/contract (with-racket-lsp proc)
4749
(-> (-> any/c any/c) void?)
4850
(define ch (make-async-channel))
4951

5052
(parameterize ([server-output-ch ch]
51-
[response-channel (make-async-channel)])
53+
[response-channel (make-async-channel)]
54+
[notification-channel (make-async-channel)])
5255
(set-current-server! (new server% [output-channel ch]))
5356
(define lsp current-server)
5457

@@ -92,6 +95,9 @@
9295
(define js (async-channel-get (response-channel)))
9396
(make-immutable-hasheq (hash->list js)))
9497

98+
(define (client-wait-notification lsp)
99+
(async-channel-get (notification-channel)))
100+
95101
(define/contract (client-should-no-response lsp)
96102
(-> any/c eof-object?)
97103

tests/sync/test.rkt

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#lang racket/base
22

33
(require "../client.rkt"
4-
"../../json-util.rkt"
5-
chk)
4+
"../../json-util.rkt")
65

76
(module+ test
87
(require rackunit
@@ -22,17 +21,16 @@
2221
'text "#lang racke"))))
2322
;; should report "collection not found" diagnostic error
2423
(client-send lsp didopen-req)
25-
(let ([resp (client-wait-response lsp)])
26-
(chk*
27-
(chk (jsexpr-has-key? resp '(params diagnostics)))
28-
(define diagnostics-msg (jsexpr-ref resp '(params diagnostics)))
29-
(check-false (null? diagnostics-msg))
30-
(define dm (with-input-from-string
31-
(jsexpr->string (car diagnostics-msg))
32-
(lambda () (read-json))))
33-
(define resp-no-message (hash-remove dm 'message))
34-
(check-equal? (jsexpr->string resp-no-message)
35-
(jsexpr->string (read-json (open-input-file "diagnostics.json"))))))
24+
(let ([resp (client-wait-notification lsp)])
25+
(check-true (jsexpr-has-key? resp '(params diagnostics)))
26+
(define diagnostics-msg (jsexpr-ref resp '(params diagnostics)))
27+
(check-false (null? diagnostics-msg))
28+
(define dm (with-input-from-string
29+
(jsexpr->string (car diagnostics-msg))
30+
(lambda () (read-json))))
31+
(define resp-no-message (hash-remove dm 'message))
32+
(check-equal? (jsexpr->string resp-no-message)
33+
(jsexpr->string (read-json (open-input-file "diagnostics.json")))))
3634

3735

3836
(define didchange-req
@@ -44,10 +42,9 @@
4442
(list (hasheq 'text "#lang racket")))))
4543
;; should not report any error
4644
(client-send lsp didchange-req)
47-
(let ([resp (client-wait-response lsp)])
48-
(chk*
49-
(chk (jsexpr-has-key? resp '(params diagnostics)))
50-
(chk (null? (jsexpr-ref resp '(params diagnostics))))))
45+
(let ([resp (client-wait-notification lsp)])
46+
(check-true (jsexpr-has-key? resp '(params diagnostics)))
47+
(check-true (null? (jsexpr-ref resp '(params diagnostics)))))
5148

5249

5350
;; no response for didClose request

tests/textDocument/completion/completion.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ END
2121
;; only move cursor to that position is not enough.
2222
(define didchange-req (read-json (open-input-file "change-req.json")))
2323
(client-send lsp didchange-req)
24-
(client-wait-response lsp)
24+
(client-wait-notification lsp)
2525

2626
(define comp-req (read-json (open-input-file "comp-req.json")))
2727
(client-send lsp comp-req)

tests/textDocument/formatting.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ END
3737
'rangeLength 0
3838
'text "\n"))))])
3939
(client-send lsp notif)
40-
(client-wait-response lsp))
40+
(client-wait-notification lsp))
4141

4242
;; Format on type for pre-indented new line 3
4343
(let* ([req (make-request lsp

tests/textDocument/hover.rkt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#lang racket
22

33
(require "../../json-util.rkt"
4-
"with-document.rkt"
5-
chk)
4+
"with-document.rkt")
65

76
(define uri "file:///test.rkt")
87

@@ -30,13 +29,13 @@ END
3029
(client-send lsp hover-req)
3130

3231
(let ([resp (client-wait-response lsp)])
33-
(chk (jsexpr-has-key? resp '(result contents)))
34-
(chk (not (string=? "" (jsexpr-ref resp '(result contents)))))
32+
(check-true (jsexpr-has-key? resp '(result contents)))
33+
(check-false (string=? "" (jsexpr-ref resp '(result contents))))
3534

36-
(chk (jsexpr-has-key? resp '(result range start line)))
37-
(chk (jsexpr-has-key? resp '(result range start character)))
38-
(chk (jsexpr-has-key? resp '(result range end line)))
39-
(chk (jsexpr-has-key? resp '(result range end character)))
35+
(check-true (jsexpr-has-key? resp '(result range start line)))
36+
(check-true (jsexpr-has-key? resp '(result range start character)))
37+
(check-true (jsexpr-has-key? resp '(result range end line)))
38+
(check-true (jsexpr-has-key? resp '(result range end character)))
4039
(check-equal? (jsexpr-ref resp '(result range start line)) 2)
4140
(check-equal? (jsexpr-ref resp '(result range start character)) 1)
4241
(check-equal? (jsexpr-ref resp '(result range end line)) 2)

tests/textDocument/resyntax/resyntax.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ END
2828
(when has-resyntax?
2929
(with-document uri code
3030
(λ (lsp)
31-
(define diag (client-wait-response lsp))
32-
(chk #:= (jsexpr-ref diag '(method)) "textDocument/publishDiagnostics")
31+
(define diag (client-wait-notification lsp))
32+
(check-equal? (jsexpr-ref diag '(method)) "textDocument/publishDiagnostics")
3333
(let ([req (read-json (open-input-file "req.json"))]
3434
[resp (read-json (open-input-file "resp.json"))])
3535
(client-send lsp req)

tests/textDocument/with-document.rkt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(provide with-document
44
client-send
55
client-wait-response
6+
client-wait-notification
67
make-request
78
make-expected-response
89
make-notification)
@@ -22,7 +23,7 @@
2223
'version 0
2324
'text text))))
2425
(client-send lsp didopen-req)
25-
(client-wait-response lsp)
26+
(client-wait-notification lsp)
2627

2728
(proc lsp)
2829

0 commit comments

Comments
 (0)