@@ -3,48 +3,58 @@ open RResult;
3
3
open TopTypes ;
4
4
module J = JsonShort ;
5
5
6
- let getTextDocument = doc => {
7
- let %opt uri = Json.get("uri", doc) |?> Json.string |?> Uri2.parse;
8
- let %opt text = Json.get("text", doc) |?> Json.string;
9
- Some ((uri , text ));
10
- };
6
+ let getTextDocument = doc =>
7
+ switch (Json . get("uri" , doc) |?> Json . string |?> Uri2 . parse) {
8
+ | None => None
9
+ | Some (uri ) =>
10
+ switch (Json . get("text" , doc) |?> Json . string) {
11
+ | None => None
12
+ | Some (text ) => Some ((uri, text))
13
+ }
14
+ };
11
15
12
16
let notificationHandlers :
13
17
list ((string , (state , Json . t ) => result (state , string ))) = [
14
18
(
15
19
"textDocument/didOpen" ,
16
20
(state, params) => {
17
- let %try (uri, text) =
21
+ switch (
18
22
Json . get("textDocument" , params)
19
23
|?> getTextDocument
20
- |> RResult . orError ("Invalid params" );
21
- Hashtbl . replace(state. documentText, uri, text);
22
-
23
- let path = Uri2 . toPath(uri);
24
- if (FindFiles . isSourceFile(path)) {
25
- let %try package = Packages.getPackage(uri, state);
26
- /* let name = FindFiles.getName(path); */
27
- if (!Hashtbl . mem (package .nameForPath , path )) {
28
- /* TODO: figure out what the name should be, and process it. */
29
- package.nameForPath
30
- |> Hashtbl.iter((name, _ ) => Log.log(" > " ++ name));
31
- Log.log("Reloading because you created a new file: " ++ path);
32
- Ok(state);
33
- /* Ok(reloadAllState(state)) */
34
- /* Hashtbl.add(package.nameForPath, path, name);
35
- Hashtbl.add(package.pathsForModule, name, Impl(path, Some(path)));
36
- Hashtbl.replace(state.packagesByRoot, package.basePath, {
37
- ...package,
38
- localModules: [name, ...package.localModules]
39
- });
40
- Ok(state) */
24
+ |> RResult . orError("Invalid params" )
25
+ ) {
26
+ | Error (e ) => Error (e)
27
+ | Ok ((uri , text )) =>
28
+ Hashtbl . replace(state. documentText, uri, text);
29
+ let path = Uri2 . toPath(uri);
30
+ if (FindFiles . isSourceFile(path)) {
31
+ switch (Packages . getPackage(uri, state)) {
32
+ | Error (e ) => Error (e)
33
+ | Ok (package ) =>
34
+ /* let name = FindFiles.getName(path); */
35
+ if (! Hashtbl . mem(package. nameForPath, path)) {
36
+ /* TODO: figure out what the name should be, and process it. */
37
+ package. nameForPath
38
+ |> Hashtbl . iter((name, _) => Log . log(" > " ++ name));
39
+ Log . log("Reloading because you created a new file: " ++ path);
40
+ Ok (state);
41
+ /* Ok(reloadAllState(state)) */
42
+ /* Hashtbl.add(package.nameForPath, path, name);
43
+ Hashtbl.add(package.pathsForModule, name, Impl(path, Some(path)));
44
+ Hashtbl.replace(state.packagesByRoot, package.basePath, {
45
+ ...package,
46
+ localModules: [name, ...package.localModules]
47
+ });
48
+ Ok(state) */
49
+ } else {
50
+ Ok (state);
51
+ }
52
+ };
41
53
} else {
42
54
Ok (state);
43
55
};
44
- } else {
45
- Ok (state);
46
- };
47
- },
56
+ }
57
+ }
48
58
),
49
59
(
50
60
"workspace/didChangeConfiguration" ,
@@ -62,18 +72,34 @@ let notificationHandlers:
62
72
"textDocument/didChange" ,
63
73
(state, params) => {
64
74
open InfixResult ;
65
- let %try doc = params |> RJson.get("textDocument");
66
- let %try uri = RJson.get("uri", doc) |?> RJson.string;
67
- let %try uri = Uri2.parse(uri) |> RResult.orError("Not a uri");
68
- let %try changes = RJson.get("contentChanges", params) |?> RJson.array;
69
- let %try text =
70
- List . nth (changes , List . length (changes ) - 1 )
71
- |> RJson . get ("text" )
72
- |?> RJson . string ;
73
- /* Hmm how do I know if it's modified? */
74
- let state = State . updateContents(uri, text, state);
75
- Ok (state);
76
- },
75
+ switch (params |> RJson . get("textDocument" )) {
76
+ | Error (e ) => Error (e)
77
+ | Ok (doc ) =>
78
+ switch (RJson . get("uri" , doc) |?> RJson . string) {
79
+ | Error (e ) => Error (e)
80
+ | Ok (uri ) =>
81
+ switch (Uri2 . parse(uri) |> RResult . orError("Not a uri" )) {
82
+ | Error (e ) => Error (e)
83
+ | Ok (uri ) =>
84
+ switch (RJson . get("contentChanges" , params) |?> RJson . array) {
85
+ | Error (e ) => Error (e)
86
+ | Ok (changes ) =>
87
+ switch (
88
+ List . nth(changes, List . length(changes) - 1 )
89
+ |> RJson . get("text" )
90
+ |?> RJson . string
91
+ ) {
92
+ | Error (e ) => Error (e)
93
+ | Ok (text ) =>
94
+ /* Hmm how do I know if it's modified? */
95
+ let state = State . updateContents(uri, text, state);
96
+ Ok (state);
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
77
103
),
78
104
(
79
105
"workspace/didChangeWatchedFiles" ,
0 commit comments