Skip to content

Commit

Permalink
Factor duplicated logic
Browse files Browse the repository at this point in the history
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
  • Loading branch information
voodoos committed May 15, 2024
1 parent 8dea06e commit e2531ee
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions src/dune_rules/merlin/merlin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = _
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e2531ee

Please sign in to comment.