Skip to content

Commit e7671ff

Browse files
committed
reload all state when a new file is created
1 parent 758f3e0 commit e7671ff

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

src/lsp/NotificationHandlers.re

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,45 @@ let setPackageTimer = package => {
3030

3131
let watchedFileContentsMap = Hashtbl.create(100);
3232

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+
3347
let notificationHandlers: list((string, (state, Json.t) => result(state, string))) = [
3448
("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+
}
4072
}),
4173
("workspace/didChangeConfiguration", (state, params) => {
4274
let nullIfEmpty = item => item == "" ? None : Some(item);
@@ -141,20 +173,7 @@ let notificationHandlers: list((string, (state, Json.t) => result(state, string)
141173
} |? false);
142174

143175
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))
158177
} else {
159178
Ok(state)
160179
}

src/util/Infix.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let (|.!) = (fn, message, arg) => fn(arg) |! message;
2121
let (|?<) = (o, fn) => switch o { | None => () | Some(v) => fn(v) };
2222

2323
let fileConcat = (a, b) => {
24-
if (b != "" && b.[0] == '.' && String.length(b) >= 2 && b.[1] == '/') {
24+
if (b != "" && b.[0] == '.' && String.length(b) >= 2 && b.[1] == Filename.dir_sep.[0]) {
2525
Filename.concat(a, String.sub(b, 2, String.length(b) - 2))
2626
} else {
2727
Filename.concat(a, b);

0 commit comments

Comments
 (0)