diff --git a/src/kernel/mconfig.ml b/src/kernel/mconfig.ml index 77c0d9d95..5628a9b0e 100644 --- a/src/kernel/mconfig.ml +++ b/src/kernel/mconfig.ml @@ -838,3 +838,15 @@ let unitname t = | Some prefix -> prefix ^ basename | None -> basename end + +let intf_or_impl t = + let extension = Filename.extension t.query.filename in + try + List.find_map t.merlin.suffixes ~f:(fun (impl, intf) -> + if String.equal extension impl then Some Unit_info.Impl + else if String.equal extension intf then Some Unit_info.Intf + else None) + with Not_found -> Unit_info.Impl + +let unit_info t = + Unit_info.make ~source_file:t.query.filename (intf_or_impl t) (unitname t) diff --git a/src/kernel/mconfig.mli b/src/kernel/mconfig.mli index 1b4430b4a..525e0eaf6 100644 --- a/src/kernel/mconfig.mli +++ b/src/kernel/mconfig.mli @@ -129,3 +129,7 @@ val global_modules : ?include_current:bool -> t -> string list val filename : t -> string val unitname : t -> string + +val intf_or_impl : t -> Unit_info.intf_or_impl + +val unit_info : t -> Unit_info.t diff --git a/src/kernel/mocaml.ml b/src/kernel/mocaml.ml index 4f9fc0fa5..e40877bd2 100644 --- a/src/kernel/mocaml.ml +++ b/src/kernel/mocaml.ml @@ -35,7 +35,7 @@ let setup_reader_config config = let open Mconfig in let open Clflags in let ocaml = config.ocaml in - Env.set_unit_name (Mconfig.unitname config); + Env.set_current_unit (Mconfig.unit_info config); Location.input_name := config.query.filename; fast := ocaml.unsafe; classic := ocaml.classic;