diff --git a/src/analysis/locate.ml b/src/analysis/locate.ml index ae6926b61a..243cb14d6c 100644 --- a/src/analysis/locate.ml +++ b/src/analysis/locate.ml @@ -44,6 +44,8 @@ module File : sig val cmt : string -> t val cmti : string -> t + val is_source : t -> bool + val of_filename : string -> t option val alternate : t -> t @@ -62,6 +64,10 @@ end = struct | CMT of string | CMTI of string + let is_source = function + | ML _ | MLL _ | MLI _ -> true + | CMT _ | CMTI _ -> false + let file_path_to_mod_name f = Misc.unitname (Filename.basename f) @@ -242,7 +248,8 @@ module Utils = struct List.dedup_adjacent files ~cmp:String.compare let find_file_with_path ~config ?(with_fallback=false) file path = - if File.name file = Misc.unitname Mconfig.(config.query.filename) then + if File.is_source file && + File.name file = Misc.unitname Mconfig.(config.query.filename) then Some Mconfig.(config.query.filename) else let attempt_search src_suffix_pair = @@ -892,7 +899,7 @@ let get_doc ~config ~env ~local_defs ~comments ~pos = begin match uid with | Some (Shape.Uid.Item { comp_unit; _ } as uid) | Some (Shape.Uid.Compilation_unit comp_unit as uid) - when Env.get_unit_name () <> comp_unit -> + -> log ~title:"get_doc" "the doc (%a) you're looking for is in another compilation unit (%s)" Logger.fmt (fun fmt -> Shape.Uid.print fmt uid) comp_unit; @@ -929,6 +936,7 @@ let get_doc ~config ~env ~local_defs ~comments ~pos = log ~title:"get_doc" "looking for the doc of '%s'" path; begin match from_string ~config ~env ~local_defs ~pos `MLI path with | `Found (uid, _, pos) -> + log ~title:"get_doc" "looking for the doc of '%s'" path; let loc : Location.t = { loc_start = pos; loc_end = pos; loc_ghost = true } in diff --git a/tests/test-dirs/document/issue1540.t b/tests/test-dirs/document/issue1540.t new file mode 100644 index 0000000000..ba46d51270 --- /dev/null +++ b/tests/test-dirs/document/issue1540.t @@ -0,0 +1,23 @@ + $ cat >doc.mli < (** whatever decl *) + > val id : unit -> unit + > EOF + + $ cat >doc.ml < (** whatever *) + > let id () = () + > let _ = id () + > EOF + +FIXME: Merlin should return the docstring + $ $MERLIN single document -position 2:5 \ + > -filename doc.ml -filename doc.ml