From 3d0210e510d6f59496f4036389e5f1a28d0dd368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Tue, 6 Dec 2022 14:21:46 +0100 Subject: [PATCH 1/2] Add a test test to illustrate issue with decl. comments --- tests/test-dirs/document/issue1540.t | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/test-dirs/document/issue1540.t diff --git a/tests/test-dirs/document/issue1540.t b/tests/test-dirs/document/issue1540.t new file mode 100644 index 0000000000..302fddf64a --- /dev/null +++ b/tests/test-dirs/document/issue1540.t @@ -0,0 +1,25 @@ + $ 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 Date: Tue, 6 Dec 2022 15:33:41 +0100 Subject: [PATCH 2/2] Improve doc fetching --- src/analysis/locate.ml | 12 ++++++++++-- tests/test-dirs/document/issue1540.t | 4 +--- 2 files changed, 11 insertions(+), 5 deletions(-) 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 index 302fddf64a..ba46d51270 100644 --- a/tests/test-dirs/document/issue1540.t +++ b/tests/test-dirs/document/issue1540.t @@ -14,12 +14,10 @@ FIXME: Merlin should return the docstring > -filename doc.ml -filename doc.ml