Skip to content

Commit

Permalink
Deduce unit info from configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Oct 2, 2024
1 parent 2eeedd1 commit 0ef4371
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/kernel/mconfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions src/kernel/mconfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/kernel/mocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0ef4371

Please sign in to comment.