From 1f74f1f96b957af14d2ae71ec7b637b5ecac8f27 Mon Sep 17 00:00:00 2001 From: hra687261 Date: Sat, 17 Jun 2023 19:22:25 +0200 Subject: [PATCH 1/2] Don't load all preludes if one of them is opened Also, preserve the order of prelude files as they were received --- src/lsp/loop.ml | 12 ++++++++++++ src/lsp/server.ml | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lsp/loop.ml b/src/lsp/loop.ml index 407404c7a..7777d9280 100644 --- a/src/lsp/loop.ml +++ b/src/lsp/loop.ml @@ -38,6 +38,18 @@ let finally st e = let process preludes path opt_contents = let dir = Filename.dirname path in let file = Filename.basename path in + let preludes = + let rec aux l = + match l with + | [] -> [] + | State.{ dir = d; source = `File f; _ } :: _ + when String.equal f file && String.equal dir d -> [] + (* When the opened file is one of the prelude files, ignore it and the + following prelude files. *) + | h :: t -> h :: aux t + in + aux preludes + in let l_file : _ State.file = { lang = None; mode = None; dir; loc = Dolmen.Std.Loc.mk_file ""; diff --git a/src/lsp/server.ml b/src/lsp/server.ml index 38e874b44..952dc73a8 100644 --- a/src/lsp/server.ml +++ b/src/lsp/server.ml @@ -34,7 +34,7 @@ let preprocess_uri uri = else uri let mk_prelude files = - List.map ( + List.rev_map ( fun f -> let dir, file = Dolmen_loop.State.split_input (`File f) in Dolmen_loop.State.mk_file dir file From fe107c35fb97302b8648c6a5c2e3aab52b690321 Mon Sep 17 00:00:00 2001 From: hra687261 Date: Tue, 20 Jun 2023 18:23:20 +0200 Subject: [PATCH 2/2] Use `List.map` only to keep order of primitives --- src/lsp/server.ml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lsp/server.ml b/src/lsp/server.ml index 952dc73a8..e895cc6af 100644 --- a/src/lsp/server.ml +++ b/src/lsp/server.ml @@ -8,17 +8,17 @@ exception ServerError of string let parse_settings settings = match settings with | `Assoc [ "preludes", `List l ] -> - List.fold_left ( - fun acc s -> + List.map ( + fun s -> match s with - | `String f -> f :: acc + | `String f -> f | _ -> raise (ServerError ( Format.asprintf "Expected a path to a prelude file as a string, \ instead got %a@." Yojson.Safe.pp s)) - ) [] l + ) l | _ -> raise (ServerError ( Format.asprintf @@ -34,7 +34,7 @@ let preprocess_uri uri = else uri let mk_prelude files = - List.rev_map ( + List.map ( fun f -> let dir, file = Dolmen_loop.State.split_input (`File f) in Dolmen_loop.State.mk_file dir file