forked from jeapostrophe/racket-langserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
responses.rkt
31 lines (27 loc) · 848 Bytes
/
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
#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*))
(provide
(contract-out
[success-response
((or/c number? string?) jsexpr? . -> . jsexpr?)]
[error-response
(->* ((or/c number? string? (json-null)) number? string?)
(any/c)
jsexpr?)]))