Skip to content

Commit 62435b3

Browse files
committed
Convert Protocol to unmonad
1 parent 58af533 commit 62435b3

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/rescript-editor-support/Protocol.re

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,32 @@ module J = JsonShort;
22

33
let rgetPosition = pos => {
44
open RResult.InfixResult;
5-
let%try line = RJson.get("line", pos) |?> RJson.number;
6-
let%try character = RJson.get("character", pos) |?> RJson.number;
7-
Ok((int_of_float(line), int_of_float(character)));
5+
switch (RJson.get("line", pos) |?> RJson.number) {
6+
| Error(e) => Error(e)
7+
| Ok(line) =>
8+
switch (RJson.get("character", pos) |?> RJson.number) {
9+
| Error(e) => Error(e)
10+
| Ok(character) => Ok((int_of_float(line), int_of_float(character)))
11+
}
12+
}
813
};
914

1015
let rPositionParams = params => {
1116
open RResult.InfixResult;
12-
let%try uri =
13-
RJson.get("textDocument", params) |?> RJson.get("uri") |?> RJson.string;
14-
let%try uri = Uri2.parse(uri) |> RResult.orError("Not a uri");
15-
let%try pos = RJson.get("position", params) |?> rgetPosition;
16-
Ok((uri, pos));
17+
switch (
18+
RJson.get("textDocument", params) |?> RJson.get("uri") |?> RJson.string
19+
) {
20+
| Error(e) => Error(e)
21+
| Ok(uri) =>
22+
switch (Uri2.parse(uri) |> RResult.orError("Not a uri")) {
23+
| Error(e) => Error(e)
24+
| Ok(uri) =>
25+
switch (RJson.get("position", params) |?> rgetPosition) {
26+
| Error(e) => Error(e)
27+
| Ok(pos) => Ok((uri, pos))
28+
}
29+
}
30+
}
1731
};
1832

1933
let posOfLexing = ({Lexing.pos_lnum, pos_cnum, pos_bol}) =>

0 commit comments

Comments
 (0)