generated from dannypsnl-fork/racket-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.rkt
42 lines (37 loc) · 1.58 KB
/
client.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
#lang racket/base
(provide jsonrpc-send!)
(require json
net/url)
; send a jsexpr to a jsonrpc server, receive a jsexpr as response
;
; (jsonrpc-send! "http://127.0.0.1:8123/jsonrpc"
; (hasheq 'method "JSONRPC.Introspect" 'jsonrpc "2.0" 'id "0"))
(define (jsonrpc-send! url payload)
(read-json
(post-pure-port (string->url url)
(string->bytes/utf-8 (jsexpr->string payload))
'("Content-Type: application/json"))))
(module+ main
(jsonrpc-send!
"http://localhost:4389/jsonrpc"
(hasheq 'jsonrpc "2.0"
'id "0"
'method "initialize"
'params (hasheq 'processId 0
'rootUri "file://Users/linzizhuan/dannypsnl/jsonrpc"
'capabilities (hasheq 'hoverProvider #t
'definitionProvider #t
'documentSymbolProvider #t
'documentLinkProvider #t
'documentFormattingProvider #t
'documentRangeFormattingProvider #t))))
(jsonrpc-send!
"http://localhost:4389/jsonrpc"
(hasheq 'jsonrpc "2.0"
'id "1"
'method "textDocument/definition"
'params (hasheq 'textDocument
(hasheq 'uri "file://Users/linzizhuan/dannypsnl/jsonrpc/test.go")
'position
(hasheq 'line 1
'character 0)))))