@@ -4,16 +4,17 @@ open TopTypes;
44module J = JsonShort ;
55
66let getTextDocument = doc => {
7- let %opt uri = Json.get("uri", doc) |?> Json.string;
7+ let %opt uri = Json.get("uri", doc) |?> Json.string |?> Uri2.parse ;
88 let %opt text = Json.get("text", doc) |?> Json.string;
99 Some ((uri , text ));
1010};
1111
12- let watchedFileContentsMap = Hashtbl . create(100 );
13-
1412let reloadAllState = state => {
1513 Log . log("RELOADING ALL STATE" );
16- {... TopTypes . empty(), documentText: state. documentText};
14+ {
15+ ... TopTypes . empty(~rootUri=state.rootUri),
16+ documentText: state. documentText,
17+ };
1718};
1819
1920let notificationHandlers :
@@ -27,7 +28,7 @@ let notificationHandlers:
2728 |> RResult . orError ("Invalid params" );
2829 Hashtbl . replace(state. documentText, uri, text);
2930
30- let %try path = Utils.parseUri (uri) |> RResult.orError("Invalid uri" );
31+ let path = Uri2 . toPath (uri);
3132 if (FindFiles . isSourceFile(path)) {
3233 let %try package = Packages.getPackage(uri, state);
3334 /* let name = FindFiles.getName(path); */
@@ -71,6 +72,7 @@ let notificationHandlers:
7172 open InfixResult ;
7273 let %try doc = params |> RJson.get("textDocument");
7374 let %try uri = RJson.get("uri", doc) |?> RJson.string;
75+ let %try uri = Uri2.parse(uri) |> RResult.orError("Not a uri");
7476 let %try changes = RJson.get("contentChanges", params) |?> RJson.array;
7577 let %try text =
7678 List . nth (changes , List . length (changes ) - 1 )
@@ -83,41 +85,8 @@ let notificationHandlers:
8385 ),
8486 (
8587 "workspace/didChangeWatchedFiles" ,
86- (state, params) => {
87- Log . log("Got a watched file change" );
88- let %try changes = RJson.get("changes", params);
89- let %try changes = RJson.array(changes);
90- open InfixResult ;
91- let shouldReload =
92- changes
93- |> List . exists(change =>
94- {
95- let %try uri = RJson.get("uri", change) |?> RJson.string;
96- let isRelevant = Utils . endsWith(uri, "/bsconfig.json" );
97- if (! isRelevant) {
98- Ok (false );
99- } else {
100- let %try path =
101- Utils . parseUri (uri ) |> RResult . orError ("Cannot parse URI" );
102- let %try contents = Files.readFileResult(path);
103- if (!Hashtbl . mem (watchedFileContentsMap , uri )
104- || Hashtbl . find (watchedFileContentsMap , uri ) == contents ) {
105- Ok (false);
106- } else {
107- Hashtbl . replace(watchedFileContentsMap, uri, contents);
108- Log.log("Reloading because a file changed: " ++ uri);
109- Ok(true);
110- };
111- };
112- }
113- |? false
114- );
115-
116- if (shouldReload) {
117- Ok (reloadAllState(state));
118- } else {
119- Ok (state);
120- };
88+ (state, _params) => {
89+ Ok (state);
12190 },
12291 ),
12392] ;
0 commit comments