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

test: reproduce issue #1748 #1750

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
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ merlin NEXT_VERSION

+ merlin binary
- destruct: Removal of residual patterns (#1737, fixes #1560)
- Do not erase fields' names when destructing punned record fields (#1734,
- Do not erase fields' names when destructing punned record fields (#1734,
fixes #1661)
- locate: fix an issue when locating the module ident in
an[open_description]. Merlin was using the wrong environment due to the
absence of a node representing the ident. (#1750, fixes #1748)

merlin 4.14
===========
Expand Down
16 changes: 15 additions & 1 deletion src/ocaml/merlin_specific/browse_raw.ml
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,21 @@ let of_node = function
| Module_binding_name _ -> id_fold
| Module_declaration_name _ -> id_fold
| Module_type_declaration_name _ -> id_fold
| Open_description _ -> id_fold
| Open_description od ->
(* We synthezise a [module_ident] node from the [open] infos so that Merlin
does not use the open resulting environment to answer queries about the
module ident. Without this synthetic node Merlin would select the entire
open node when the cursor is hover the ident. See issue #1748 *)
let path, lid = od.open_expr in
let m = {
mod_desc = Tmod_ident (path, lid);
mod_loc = lid.loc;
mod_type = Mty_ident path;
mod_env = Env.empty;
mod_attributes = [];
}
in
app (Module_expr m)
| Open_declaration od ->
app (Module_expr od.open_expr)
| Include_declaration i ->
Expand Down
3 changes: 3 additions & 0 deletions tests/test-dirs/locate/ambiguity/homonyms.t/bar.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Import = struct
type hello = string
end
1 change: 1 addition & 0 deletions tests/test-dirs/locate/ambiguity/homonyms.t/foo.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
open! Import
1 change: 1 addition & 0 deletions tests/test-dirs/locate/ambiguity/homonyms.t/foo.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
open! Import
1 change: 1 addition & 0 deletions tests/test-dirs/locate/ambiguity/homonyms.t/import.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include Bar
39 changes: 39 additions & 0 deletions tests/test-dirs/locate/ambiguity/homonyms.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
This test reproduces issue #1748

$ cat bar.ml
module Import = struct
type hello = string
end

$ cat import.ml
include Bar

$ cat foo.mli
open! Import

$ cat foo.ml
open! Import

$ $OCAMLC -c -bin-annot bar.ml import.ml foo.mli foo.ml

Merlin correctly jump to the Import module. Not the one in Bar.
$ $MERLIN single locate -position 1:10 -look-for implementation \
> -filename foo.ml < foo.ml | jq '.value'
{
"file": "$TESTCASE_ROOT/import.ml",
"pos": {
"line": 1,
"col": 0
}
}

Same in the mli:
$ $MERLIN single locate -position 1:10 -look-for implementation \
> -filename foo.mli < foo.mli | jq '.value'
{
"file": "$TESTCASE_ROOT/import.ml",
"pos": {
"line": 1,
"col": 0
}
}
Loading