diff --git a/src/dune_rules/merlin/merlin.ml b/src/dune_rules/merlin/merlin.ml index e0d074029958..80b5ce7ae4ea 100644 --- a/src/dune_rules/merlin/merlin.ml +++ b/src/dune_rules/merlin/merlin.ml @@ -596,6 +596,21 @@ module Unprocessed = struct ~f:(pp_flags ctx ~expander t.config.libname) ;; + let add_lib_dirs sctx mode ~init libs = + Action_builder.of_memo + (let open Memo.O in + Memo.parallel_map (Lib.Set.to_list libs) ~f:(fun lib -> + let+ dirs = src_dirs sctx lib in + lib, dirs) + >>| List.fold_left ~init ~f:(fun (src_dirs, obj_dirs) (lib, more_src_dirs) -> + ( Path.Set.union src_dirs more_src_dirs + , let public_cmi_dir = + let info = Lib.info lib in + obj_dir_of_lib `Public mode (Lib_info.obj_dir info) + in + Path.Set.add obj_dirs public_cmi_dir ))) + ;; + let process ({ modules ; ident = _ @@ -658,35 +673,10 @@ module Unprocessed = struct in let+ flags = flags and+ src_dirs, obj_dirs = - Action_builder.of_memo - (let open Memo.O in - Memo.parallel_map (Lib.Set.to_list requires) ~f:(fun lib -> - let+ dirs = src_dirs sctx lib in - lib, dirs) - >>| List.fold_left - ~init:(Path.set_of_source_paths source_dirs, objs_dirs) - ~f:(fun (src_dirs, obj_dirs) (lib, more_src_dirs) -> - ( Path.Set.union src_dirs more_src_dirs - , let public_cmi_dir = - let info = Lib.info lib in - obj_dir_of_lib `Public mode (Lib_info.obj_dir info) - in - Path.Set.add obj_dirs public_cmi_dir ))) + let init = Path.set_of_source_paths source_dirs, objs_dirs in + add_lib_dirs sctx mode ~init requires and+ hidden_src_dirs, hidden_obj_dirs = - Action_builder.of_memo - (let open Memo.O in - Memo.parallel_map (Lib.Set.to_list requires_hidden) ~f:(fun lib -> - let+ dirs = src_dirs sctx lib in - lib, dirs) - >>| List.fold_left - ~init:(Path.Set.empty, Path.Set.empty) - ~f:(fun (src_dirs, obj_dirs) (lib, more_src_dirs) -> - ( Path.Set.union src_dirs more_src_dirs - , let public_cmi_dir = - let info = Lib.info lib in - obj_dir_of_lib `Public mode (Lib_info.obj_dir info) - in - Path.Set.add obj_dirs public_cmi_dir ))) + add_lib_dirs sctx mode ~init:(Path.Set.empty, Path.Set.empty) requires_hidden in let src_dirs = Path.Set.union src_dirs (Path.Set.of_list_map ~f:Path.source more_src_dirs)