Source file lsp_base.ml
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
open Common
let std_protocol = ref true
module J = Yojson.Basic
let l = if !std_protocol then [] else l
let _parse_uri str =
let l = String.length str - 7 in
String.(sub str 7 l)
let mk_reply ~id ~result =
`Assoc [ "jsonrpc", `String "2.0"; "id", `Int id; "result", result ]
let mk_event m p =
`Assoc [ "jsonrpc", `String "2.0"; "method", `String m; "params", `Assoc p ]
let mk_range (p : Pos.pos) : J.t =
let open Pos in
let {start_line=line1; start_col=col1; end_line=line2; end_col=col2; _} =
p
in
`Assoc ["start", `Assoc ["line", `Int (line1 - 1); "character", `Int col1];
"end", `Assoc ["line", `Int (line2 - 1); "character", `Int col2]]
let json_of_goal (hyps, concl) =
let json_of_hyp (s,t) = `Assoc ["hname", `String s; "htype", `String t] in
match concl with
| Pure.Typ (meta, typ) ->
`Assoc [
"typeofgoal", `String "Typ"
; "gid", `String meta
; "hyps", `List (List.map json_of_hyp hyps)
; "type", `String typ]
| Pure.Unif (t,u) ->
`Assoc [
"typeofgoal", `String "Unif"
; "hyps", `List (List.map json_of_hyp hyps)
; "constr", `String (t ^ " ≡ " ^ u)]
let json_of_goals ?logs goals =
let logs = match logs with None -> "" | Some s -> s in
match goals with
| None ->
`Assoc [
"logs", `String logs
]
| Some goals ->
`Assoc [
"goals", `List List.(map json_of_goal goals);
"logs" , `String logs
]
let mk_diagnostic
((p : Pos.pos), (lvl : int), (msg : string), (goals : _ option)) : J.t =
let goals = json_of_goals goals in
let range = mk_range p in
`Assoc (mk_extra ["goal_info", goals] @
["range", range;
"severity", `Int lvl;
"message", `String msg;
])
let mk_diagnostics ~uri ~version ld : J.t =
let = mk_extra ["version", `Int version] in
mk_event "textDocument/publishDiagnostics" @@
extra @
["uri", `String uri;
"diagnostics", `List List.(map mk_diagnostic ld)]