File tree Expand file tree Collapse file tree 4 files changed +37
-5
lines changed
Expand file tree Collapse file tree 4 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -35,12 +35,25 @@ let setup_reader_config config =
3535 let open Mconfig in
3636 let open Clflags in
3737 let ocaml = config.ocaml in
38- let to_unit_info name =
39- Some
40- (name |> Compilation_unit. of_string
41- |> Unit_info. make_dummy ~input_name: name)
38+ let guessed_file_type : Unit_info.intf_or_impl =
39+ (* We guess the file type based on the suffix of the file. This isn't very important
40+ because we'll override the value that we use here later in Mpipeline, where we set
41+ it based on the contents of the file.
42+
43+ At the moment, Merlin doesnt' actually use this value for anything, so it doesn't
44+ matter what we set here. This is just a guard against future changes that might
45+ start depending on this. *)
46+ match String. split_on_char config.query.filename ~sep: '.' |> List. last with
47+ | Some "ml" -> Impl
48+ | Some "mli" -> Intf
49+ | _ -> Impl
4250 in
43- Env. set_unit_name (Mconfig. unitname config |> to_unit_info);
51+ let compilation_unit = Compilation_unit. of_string (Mconfig. unitname config) in
52+ let unit_info =
53+ Unit_info. make_with_known_compilation_unit
54+ ~source_file: config.query.filename guessed_file_type " " compilation_unit
55+ in
56+ Env. set_unit_name (Some unit_info);
4457 Location. input_name := config.query.filename;
4558 fast := ocaml.unsafe;
4659 classic := ocaml.classic;
Original file line number Diff line number Diff line change @@ -270,6 +270,17 @@ let process ?state ?(pp_time = ref 0.0) ?(reader_time = ref 0.0)
270270 let cache_version =
271271 if Option. is_some cache_disabling then None else Some cache_version
272272 in
273+ (* When we loaded the configuration in Mocaml, we guessed whether we're working
274+ with an intf or impl file based on the suffix of the filename. But now we know
275+ based on the contents of the file, so we update the value we wrote before. *)
276+ Env. get_unit_name ()
277+ |> Option. map
278+ ~f:
279+ (Unit_info. modify_kind ~f: (fun _ ->
280+ match result.parsetree with
281+ | `Interface _ -> Intf
282+ | `Implementation _ -> Impl ))
283+ |> Env. set_unit_name;
273284 { Reader. result; config; cache_version }))
274285 in
275286 let ppx =
Original file line number Diff line number Diff line change @@ -152,3 +152,7 @@ let find_normalized_cmi f =
152152 let filename = (modname f |> Compilation_unit. name_as_string) ^ " .cmi" in
153153 let filename = Load_path. find_normalized filename in
154154 { Artifact. filename; modname = modname f; source_file = Some f.source_file }
155+
156+ (* Merlin-only *)
157+
158+ let modify_kind t ~f = { t with kind = f t.kind }
Original file line number Diff line number Diff line change @@ -187,3 +187,7 @@ val find_normalized_cmi: t -> Artifact.t
187187 [Unit_info.Artifact.t], using [dummy_source_file] as the filename if the
188188 artifact doesn't have one attached. *)
189189val of_artifact : dummy_source_file :filename -> intf_or_impl -> Artifact .t -> t
190+
191+ (* Merlin-only *)
192+
193+ val modify_kind : t -> f :(intf_or_impl -> intf_or_impl ) -> t
You can’t perform that action at this time.
0 commit comments