1
-
2
1
open Rpc . J ;
3
2
4
3
let pos = (~line, ~character) => o([ ("line" , i(line)), ("character" , i(character))] );
5
4
6
5
let range = (~start, ~end_) => o([ ("start" , start), ("end" , end_)] );
7
6
8
7
open Infix ;
9
- let getTextDocument = doc => Json . get("uri" , doc) |?> Json . string
10
- |?> uri => Json . get("version" , doc) |?> Json . number
11
- |?> version => Json . get("text" , doc) |?> Json . string
12
- |?>> text => (uri, version, text);
13
-
14
- let getPosition = pos => Json . get("line" , pos) |?> Json . number
15
- |?> line => Json . get("character" , pos) |?> Json . number
16
- |?>> character => (int_of_float(line), int_of_float(character));
17
-
18
- let rgetPosition = pos => (Result . InfixResult . (RJson . get("line" , pos) |?> RJson . number
19
- |?> line => RJson . get("character" , pos) |?> RJson . number
20
- |?>> character => (int_of_float(line), int_of_float(character))));
21
-
22
- let rgetRange = pos => (Result . InfixResult . (RJson . get("start" , pos) |?> rgetPosition
23
- |?> start => RJson . get("end" , pos) |?> rgetPosition
24
- |?>> end_ => (start, end_)));
25
-
26
- let rPositionParams = params => Result . InfixResult . (
27
- RJson . get("textDocument" , params) |?> RJson . get("uri" ) |?> RJson . string
28
- |?> uri => RJson . get("position" , params) |?> rgetPosition
29
- |?>> pos => (uri, pos)
30
- );
31
-
32
- let posOfLexing = ({Lexing . pos_lnum, pos_cnum, pos_bol}) => o([
33
- ("line" , i(pos_lnum - 1 )),
34
- ("character" , i(pos_cnum - pos_bol))
35
- ] );
36
-
37
- let tupleOfLexing = ({Lexing . pos_lnum, pos_cnum, pos_bol}) => (
38
- pos_lnum - 1 ,
39
- pos_cnum - pos_bol
40
- );
41
-
42
- let markup = text => Json . Object ([ ("kind" , Json . String ("markdown" )), ("value" , Json . String (text))] );
43
-
44
- let rangeOfLoc = ({Location . loc_start, loc_end}) => o([
45
- ("start" , posOfLexing(loc_start)),
46
- ("end" , posOfLexing(loc_end))
47
- ] );
48
-
49
- let locationOfLoc = (~fname=?, {Location . loc_start: {Lexing . pos_fname}} as loc) => o([
8
+
9
+ let getTextDocument = (doc) =>
10
+ Json . get("uri" , doc)
11
+ |?> Json . string
12
+ |?> (
13
+ (uri) =>
14
+ Json . get("version" , doc)
15
+ |?> Json . number
16
+ |?> (
17
+ (version) => Json . get("text" , doc) |?> Json . string |?>> ((text) => (uri, version, text))
18
+ )
19
+ );
20
+
21
+ let getPosition = (pos) =>
22
+ Json . get("line" , pos)
23
+ |?> Json . number
24
+ |?> (
25
+ (line) =>
26
+ Json . get("character" , pos)
27
+ |?> Json . number
28
+ |?>> ((character) => (int_of_float(line), int_of_float(character)))
29
+ );
30
+
31
+ let rgetPosition = (pos) =>
32
+ Result . InfixResult . (
33
+ RJson . get("line" , pos)
34
+ |?> RJson . number
35
+ |?> (
36
+ (line) =>
37
+ RJson . get("character" , pos)
38
+ |?> RJson . number
39
+ |?>> ((character) => (int_of_float(line), int_of_float(character)))
40
+ )
41
+ );
42
+
43
+ let rgetRange = (pos) =>
44
+ Result . InfixResult . (
45
+ RJson . get("start" , pos)
46
+ |?> rgetPosition
47
+ |?> ((start) => RJson . get("end" , pos) |?> rgetPosition |?>> ((end_) => (start, end_)))
48
+ );
49
+
50
+ let rPositionParams = (params) =>
51
+ Result . InfixResult . (
52
+ RJson . get("textDocument" , params)
53
+ |?> RJson . get("uri" )
54
+ |?> RJson . string
55
+ |?> ((uri) => RJson . get("position" , params) |?> rgetPosition |?>> ((pos) => (uri, pos)))
56
+ );
57
+
58
+ let posOfLexing = ({Lexing . pos_lnum, pos_cnum, pos_bol}) =>
59
+ o([ ("line" , i(pos_lnum - 1 )), ("character" , i(pos_cnum - pos_bol))] );
60
+
61
+ let tupleOfLexing = ({Lexing . pos_lnum, pos_cnum, pos_bol}) => (pos_lnum - 1 , pos_cnum - pos_bol);
62
+
63
+ let markup = (text) =>
64
+ Json . Object ([ ("kind" , Json . String ("markdown" )), ("value" , Json . String (text))] );
65
+
66
+ let rangeOfLoc = ({Location . loc_start, loc_end}) =>
67
+ o([ ("start" , posOfLexing(loc_start)), ("end" , posOfLexing(loc_end))] );
68
+
69
+ let locationOfLoc = (~fname=?, {Location . loc_start: {Lexing . pos_fname}} as loc) =>
70
+ o([
50
71
("range" , rangeOfLoc(loc)),
51
- ("uri" , s((switch fname { | Some (x ) => x | None => "file://" ++ pos_fname}))),
52
- ] );
53
-
54
- let rangeOfInts = (l0, c0, l1, c1) => o([
55
- ("start" , pos(~line= l0, ~character= c0)),
56
- ("end" , pos(~line= l1, ~character= c1)),
57
- ] );
58
-
59
- let locationContains = ({Location . loc_start, loc_end}, pos) => {
60
- tupleOfLexing(loc_start) <= pos &&
61
- tupleOfLexing(loc_end) >= pos
62
- };
72
+ (
73
+ "uri" ,
74
+ s(
75
+ switch fname {
76
+ | Some (x ) => x
77
+ | None => "file://" ++ pos_fname
78
+ }
79
+ )
80
+ )
81
+ ] );
82
+
83
+ let rangeOfInts = (l0, c0, l1, c1) =>
84
+ o([ ("start" , pos(~line= l0, ~character= c0)), ("end" , pos(~line= l1, ~character= c1))] );
85
+
86
+ let locationContains = ({Location . loc_start, loc_end}, pos) =>
87
+ tupleOfLexing(loc_start) <= pos && tupleOfLexing(loc_end) >= pos;
88
+
89
+ let symbolKind = (kind) =>
90
+ switch kind {
91
+ | ` File => 1
92
+ | ` Module => 2
93
+ | ` Namespace => 3
94
+ | ` Package => 4
95
+ | ` Class => 5
96
+ | ` Method => 6
97
+ | ` Property => 7
98
+ | ` Field => 8
99
+ | ` Constructor => 9
100
+ | ` Enum => 10
101
+ | ` Interface => 11
102
+ | ` Function => 12
103
+ | ` Variable => 13
104
+ | ` Constant => 14
105
+ | ` String => 15
106
+ | ` Number => 16
107
+ | ` Boolean => 17
108
+ | ` Array => 18
109
+ | ` Object => 19
110
+ | ` Key => 20
111
+ | ` Null => 21
112
+ | ` EnumMember => 22
113
+ | ` Struct => 23
114
+ | ` Event => 24
115
+ | ` Operator => 25
116
+ | ` TypeParameter => 26
117
+ };
118
+
119
+ let rec variableKind = (t) =>
120
+ switch t. Types . desc {
121
+ | Tlink (t ) => variableKind(t)
122
+ | Tsubst (t ) => variableKind(t)
123
+ | Tarrow (_ ) => ` Function
124
+ | Ttuple (_ ) => ` Array
125
+ | Tconstr (_ ) => ` Variable
126
+ | Tobject (_ ) => ` Object
127
+ | Tnil => ` Null
128
+ | Tvariant (_ ) => ` EnumMember
129
+ | Tpoly (_ ) => ` EnumMember
130
+ | Tpackage (_ ) => ` Module
131
+ | _ => ` Variable
132
+ };
133
+
134
+ let typeKind = (t) =>
135
+ switch t. Types . type_kind {
136
+ | Type_open
137
+ | Type_abstract => ` TypeParameter
138
+ | Type_record (_ ) => ` Interface
139
+ | Type_variant (_ ) => ` Enum
140
+ };
0 commit comments