From bd22d7b3dc191c04d6e02be4a7b495170756eac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Fri, 18 Mar 2022 15:38:39 -0300 Subject: [PATCH 1/3] Use [Longident.unflatten] to parse lids --- src/analysis/locate.ml | 2 +- src/analysis/misc_utils.ml | 8 +++++++- src/analysis/misc_utils.mli | 4 ++++ src/analysis/type_enclosing.ml | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/analysis/locate.ml b/src/analysis/locate.ml index 62daa561c1..eb4c84298c 100644 --- a/src/analysis/locate.ml +++ b/src/analysis/locate.ml @@ -794,7 +794,7 @@ let from_path ~config ~env ~namespace ml_or_mli path = let from_string ~config ~env ~local_defs ~pos ?namespaces switch path = File_switching.reset (); let browse = Mbrowse.of_typedtree local_defs in - let lid = Longident.parse path in + let lid = Misc_utils.parse_longident path in let ident, is_label = Longident.keep_suffix lid in match match namespaces with diff --git a/src/analysis/misc_utils.ml b/src/analysis/misc_utils.ml index b5ac18dedd..101feeb87f 100644 --- a/src/analysis/misc_utils.ml +++ b/src/analysis/misc_utils.ml @@ -48,7 +48,6 @@ end = struct maybe_replace_name ?name (Untypeast.lident_of_path path) end - let parenthesize_name name = (* Qualified operators need parentheses *) if name = "" || not (Oprint.parenthesized_ident name) then name else ( @@ -57,3 +56,10 @@ let parenthesize_name name = else "(" ^ name ^ ")" ) + +let parse_longident name = + let l = + if name.[String.length name - 1] = '.' then [name] + else String.split_on_char ~sep:'.' name + in + Longident.unflatten l |> Option.get diff --git a/src/analysis/misc_utils.mli b/src/analysis/misc_utils.mli index 06a02a5db1..15271ce042 100644 --- a/src/analysis/misc_utils.mli +++ b/src/analysis/misc_utils.mli @@ -22,3 +22,7 @@ end (* Add parenthesis to qualified operators *) val parenthesize_name : string -> string + +(* Uses [Longident.unflatten] to parse a longident while preserving infix + identifiers *) +val parse_longident : string -> Longident.t diff --git a/src/analysis/type_enclosing.ml b/src/analysis/type_enclosing.ml index a228241cd8..bf051db685 100644 --- a/src/analysis/type_enclosing.ml +++ b/src/analysis/type_enclosing.ml @@ -84,7 +84,7 @@ let from_reconstructed ~nodes ~cursor ~verbosity exprs = let get_context lident = Context.inspect_browse_tree ~cursor - (Longident.parse lident) + (Misc_utils.parse_longident lident) [nodes] in From d9578470a353e02e169a5e37e5a2ce897625b91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Fri, 18 Mar 2022 15:39:54 -0300 Subject: [PATCH 2/3] Promote fixed #949 test and make it single-file --- tests/test-dirs/locate/issue949.t/issue949.ml | 2 -- tests/test-dirs/locate/issue949.t/run.t | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) delete mode 100644 tests/test-dirs/locate/issue949.t/issue949.ml diff --git a/tests/test-dirs/locate/issue949.t/issue949.ml b/tests/test-dirs/locate/issue949.t/issue949.ml deleted file mode 100644 index f10b2d6883..0000000000 --- a/tests/test-dirs/locate/issue949.t/issue949.ml +++ /dev/null @@ -1,2 +0,0 @@ -module A = struct let (+.) a b = a +. b end -let f x = A.(x +. 1.) diff --git a/tests/test-dirs/locate/issue949.t/run.t b/tests/test-dirs/locate/issue949.t/run.t index fa80cce67a..bfef920ab0 100644 --- a/tests/test-dirs/locate/issue949.t/run.t +++ b/tests/test-dirs/locate/issue949.t/run.t @@ -1,8 +1,20 @@ This test is for testing the behavior of identifiers with a . in them: - $ $MERLIN single locate -look-for ml -position 2:16 ./issue949.ml < ./issue949.ml + $ cat >issue949.ml < module A = struct let (+.) a b = a +. b end + > let f x = A.(x +. 1.) + > EOF + + + $ $MERLIN single locate -look-for ml -position 2:16 ./issue949.ml <./issue949.ml { "class": "return", - "value": "Not in environment ''", + "value": { + "file": "*buffer*", + "pos": { + "line": 1, + "col": 22 + } + }, "notifications": [] } From d4c71c47dba7e22b604b7c46faffdf8de2d6b646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Fri, 18 Mar 2022 15:51:24 -0300 Subject: [PATCH 3/3] Add Changes entry --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 05fb185885..746db662de 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ unreleased + merlin binary - Update internal typer to match OCaml 4.14.1 release. (#1557) + - fix locate calls on infix operators (#1445, fixes #949) merlin 4.7 ==========