@@ -30,13 +30,45 @@ let setPackageTimer = package => {
30
30
31
31
let watchedFileContentsMap = Hashtbl . create(100 );
32
32
33
+ let reloadAllState = state => {
34
+ Log . log("RELOADING ALL STATE" );
35
+ Hashtbl . iter(
36
+ (uri, _) => Hashtbl . replace(state. documentTimers, uri, Unix . gettimeofday() +. recompileDebounceTime),
37
+ state. documentText,
38
+ );
39
+ {
40
+ ... TopTypes . empty(),
41
+ documentText: state. documentText,
42
+ documentTimers: state. documentTimers,
43
+ settings: state. settings,
44
+ };
45
+ };
46
+
33
47
let notificationHandlers : list ((string , (state , Json . t ) => result (state , string ))) = [
34
48
("textDocument/didOpen" , (state, params) => {
35
- (params |> Json . get("textDocument" ) |?> getTextDocument |?>> ((uri, version, text)) => {
36
- Hashtbl . replace(state. documentText, uri, (text, int_of_float(version), true ));
37
- Hashtbl . replace(state. documentTimers, uri, Unix . gettimeofday() +. recompileDebounceTime);
38
- state
39
- }) |> orError("Invalid params" )
49
+ let %try (uri, version, text) = Json.get("textDocument", params) |?> getTextDocument |> Result.orError("Invalid params");
50
+ Hashtbl . replace (state .documentText , uri , (text , int_of_float (version ), true ));
51
+ Hashtbl . replace(state. documentTimers, uri, Unix . gettimeofday() +. recompileDebounceTime);
52
+
53
+ let %try path = Utils.parseUri(uri) |> Result.orError("Invalid uri");
54
+ if (FindFiles . isSourceFile (path )) {
55
+ let%try package = State.getPackage(uri, state);
56
+ let name = FindFiles.getName(path);
57
+ if (!Hashtbl.mem(package.nameForPath, name)) {
58
+ Ok(reloadAllState(state))
59
+ /* Hashtbl.add(package.nameForPath, path, name);
60
+ Hashtbl.add(package.pathsForModule, name, Impl(path, Some(path)));
61
+ Hashtbl.replace(state.packagesByRoot, package.basePath, {
62
+ ...package,
63
+ localModules: [name, ...package.localModules]
64
+ });
65
+ Ok(state) */
66
+ } else {
67
+ Ok (state)
68
+ }
69
+ } else {
70
+ Ok (state)
71
+ }
40
72
}),
41
73
("workspace/didChangeConfiguration" , (state, params) => {
42
74
let nullIfEmpty = item => item == "" ? None : Some (item);
@@ -141,20 +173,7 @@ let notificationHandlers: list((string, (state, Json.t) => result(state, string)
141
173
} |? false );
142
174
143
175
if (shouldReload) {
144
- Log . log("RELOADING ALL STATE" );
145
- Hashtbl . iter((uri, _) =>
146
- Hashtbl . replace(
147
- state. documentTimers,
148
- uri,
149
- Unix . gettimeofday() +. recompileDebounceTime,
150
- ), state. documentText
151
- );
152
- Ok ({
153
- ... TopTypes . empty(),
154
- documentText: state. documentText,
155
- documentTimers: state. documentTimers,
156
- settings: state. settings,
157
- })
176
+ Ok (reloadAllState(state))
158
177
} else {
159
178
Ok (state)
160
179
}
0 commit comments