From 2c8423f28616745b87edc1c51e5df132ab23e691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Tue, 15 Oct 2024 15:02:31 +0200 Subject: [PATCH] Use new information from uids to jump to the correct file. --- src/analysis/locate.ml | 8 +++++++- tests/test-dirs/locate/issue1848.t | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/analysis/locate.ml b/src/analysis/locate.ml index 51f3830b3..4713f4035 100644 --- a/src/analysis/locate.ml +++ b/src/analysis/locate.ml @@ -510,9 +510,15 @@ let find_loc_of_uid ~config ~local_defs uid comp_unit = end else begin log ~title "Loading the cmt file for unit %S" comp_unit; + let ml_or_mli = + match uid with + | Item { from = Intf; _ } -> `MLI + | _ -> config.ml_or_mli + in + let config = { config with ml_or_mli } in match load_cmt ~config comp_unit with | Ok (_pos_fname, cmt) -> - log ~title "Shapes successfully loaded, looking for %a" Logger.fmt + log ~title "Cmt successfully loaded, looking for %a" Logger.fmt (fun fmt -> Shape.Uid.print fmt uid); begin match Shape.Uid.Tbl.find_opt cmt.cmt_uid_to_decl uid with diff --git a/tests/test-dirs/locate/issue1848.t b/tests/test-dirs/locate/issue1848.t index da2d95fe9..748107055 100644 --- a/tests/test-dirs/locate/issue1848.t +++ b/tests/test-dirs/locate/issue1848.t @@ -26,15 +26,15 @@ Locate the Bar on line 4 > end > EOF -The expected location is 2:7 of foo.ml, but it instead goes to 1:9, which is the -constructor Foo +FIXME Module type Bar in foo.mli is a correct answer, but since there is only +one corresponding implementation we could jump there instead. $ $MERLIN single locate -position 4:28 -look-for ml \ > -filename test1.ml < test1.ml | jq .value { - "file": "$TESTCASE_ROOT/foo.ml", + "file": "$TESTCASE_ROOT/foo.mli", "pos": { "line": 1, - "col": 9 + "col": 7 } }