Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always fetch doc from mlis #1573

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/analysis/locate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions tests/test-dirs/document/issue1540.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$ cat >doc.mli <<EOF
> (** whatever decl *)
> val id : unit -> unit
> EOF

$ cat >doc.ml <<EOF
> (** whatever *)
> let id () = ()
> let _ = id ()
> EOF

FIXME: Merlin should return the docstring
$ $MERLIN single document -position 2:5 \
> -filename doc.ml <doc.ml | jq '.value'
"No documentation available"

$ $MERLIN single document -position 3:9 \
> -filename doc.ml <doc.ml
{
"class": "return",
"value": "whatever decl",
"notifications": []
}