-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
responses.rkt
49 lines (43 loc) · 1.29 KB
/
responses.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#lang racket/base
(require json
racket/contract/base)
(define not-given (gensym 'not-given))
;; Constructor for a response object representing success.
(define (success-response id result)
(hasheq 'jsonrpc "2.0"
'id id
'result result))
;; Constructor for a response object representing failure.
(define (error-response id code message [data not-given])
(define err (hasheq 'code code
'message message))
(define err* (if (eq? data not-given)
err
(hash-set err 'data data)))
(hasheq 'jsonrpc "2.0"
'id id
'error err*))
(define Diag-Error 1)
(define Diag-Warning 2)
(define Diag-Information 3)
(define Diag-Hint 4)
;; Constructor for a response object representing diagnostics.
(define (diagnostics-message uri diags)
(hasheq 'jsonrpc "2.0"
'method "textDocument/publishDiagnostics"
'params (hasheq 'uri uri
'diagnostics diags)))
(provide
Diag-Error
Diag-Warning
Diag-Information
Diag-Hint
(contract-out
[success-response
((or/c number? string?) jsexpr? . -> . jsexpr?)]
[error-response
(->* ((or/c number? string? (json-null)) number? string?)
(any/c)
jsexpr?)]
[diagnostics-message
(string? list? . -> . jsexpr?)]))