From 3c830c9456f3e7c859358a535e11a672f7c047f3 Mon Sep 17 00:00:00 2001 From: xvw Date: Thu, 24 Oct 2024 14:18:28 +0200 Subject: [PATCH 1/5] Reproduce bug of #1113 --- tests/test-dirs/search/issue1113.t | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/test-dirs/search/issue1113.t diff --git a/tests/test-dirs/search/issue1113.t b/tests/test-dirs/search/issue1113.t new file mode 100644 index 0000000000..a6b43d27da --- /dev/null +++ b/tests/test-dirs/search/issue1113.t @@ -0,0 +1,29 @@ + $ cat >main.ml < let f x = succ x + > EOF + + $ $MERLIN single search-by-polarity -filename ./main.ml \ + > -position 5:25 -query "-ezfnifzen +ezfzef" + { + "class": "exception", + "value": "Not_found + Raised at Ocaml_typing__Env.may_lookup_error in file \"src/ocaml/typing/env.ml\", line 2818, characters 7-22 + Called from Ocaml_typing__Env.lookup_type in file \"src/ocaml/typing/env.ml\" (inlined), line 3241, characters 20-62 + Called from Ocaml_typing__Env.find_type_by_name in file \"src/ocaml/typing/env.ml\", line 3326, characters 2-51 + Called from Merlin_analysis__Polarity_search.build_query.prepare in file \"src/analysis/polarity_search.ml\", line 75, characters 19-46 + Called from Merlin_utils__Std.List.filter_map in file \"src/utils/std.ml\", line 108, characters 12-15 + Called from Merlin_analysis__Polarity_search.build_query in file \"src/analysis/polarity_search.ml\", line 80, characters 17-62 + Called from Query_commands.dispatch in file \"src/frontend/query_commands.ml\", line 447, characters 16-55 + Called from Merlin_commands__New_commands.run in file \"src/commands/new_commands.ml\", line 98, characters 15-53 + Called from Merlin_utils__Std.let_ref in file \"src/utils/std.ml\", line 727, characters 8-12 + Re-raised at Merlin_utils__Std.let_ref in file \"src/utils/std.ml\", line 733, characters 4-13 + Called from Merlin_utils__Misc.try_finally in file \"src/utils/misc.ml\", line 45, characters 8-15 + Re-raised at Merlin_utils__Misc.try_finally in file \"src/utils/misc.ml\", line 62, characters 10-24 + Called from Stdlib__Fun.protect in file \"fun.ml\", line 34, characters 8-15 + Re-raised at Stdlib__Fun.protect in file \"fun.ml\", line 39, characters 6-52 + Called from Merlin_kernel__Mocaml.with_state in file \"src/kernel/mocaml.ml\", line 18, characters 8-38 + Re-raised at Merlin_kernel__Mocaml.with_state in file \"src/kernel/mocaml.ml\", line 24, characters 4-15 + Called from Dune__exe__New_merlin.run.(fun) in file \"src/frontend/ocamlmerlin/new/new_merlin.ml\", lines 118-119, characters 16-52 + ", + "notifications": [] + } From 3cfef75f775d8def11c7eac134f25bab63a05756 Mon Sep 17 00:00:00 2001 From: xvw Date: Thu, 24 Oct 2024 14:22:48 +0200 Subject: [PATCH 2/5] Fix exception from #1113 --- src/analysis/polarity_search.ml | 6 ++- tests/test-dirs/search/issue1113.t | 64 +++++++++++++++++++----------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/analysis/polarity_search.ml b/src/analysis/polarity_search.ml index bf3e124c97..b01c971317 100644 --- a/src/analysis/polarity_search.ml +++ b/src/analysis/polarity_search.ml @@ -71,8 +71,10 @@ let build_query ~positive ~negative env = incr r; None) else - let set, _ = Env.find_type_by_name l env in - Some (normalize_path env set) + try + let set, _ = Env.find_type_by_name l env in + Some (normalize_path env set) + with Not_found -> None in let pos_fun = ref 0 and neg_fun = ref 0 in let positive = List.filter_map positive ~f:(prepare pos_fun) in diff --git a/tests/test-dirs/search/issue1113.t b/tests/test-dirs/search/issue1113.t index a6b43d27da..88cc81f5ee 100644 --- a/tests/test-dirs/search/issue1113.t +++ b/tests/test-dirs/search/issue1113.t @@ -3,27 +3,45 @@ > EOF $ $MERLIN single search-by-polarity -filename ./main.ml \ - > -position 5:25 -query "-ezfnifzen +ezfzef" - { - "class": "exception", - "value": "Not_found - Raised at Ocaml_typing__Env.may_lookup_error in file \"src/ocaml/typing/env.ml\", line 2818, characters 7-22 - Called from Ocaml_typing__Env.lookup_type in file \"src/ocaml/typing/env.ml\" (inlined), line 3241, characters 20-62 - Called from Ocaml_typing__Env.find_type_by_name in file \"src/ocaml/typing/env.ml\", line 3326, characters 2-51 - Called from Merlin_analysis__Polarity_search.build_query.prepare in file \"src/analysis/polarity_search.ml\", line 75, characters 19-46 - Called from Merlin_utils__Std.List.filter_map in file \"src/utils/std.ml\", line 108, characters 12-15 - Called from Merlin_analysis__Polarity_search.build_query in file \"src/analysis/polarity_search.ml\", line 80, characters 17-62 - Called from Query_commands.dispatch in file \"src/frontend/query_commands.ml\", line 447, characters 16-55 - Called from Merlin_commands__New_commands.run in file \"src/commands/new_commands.ml\", line 98, characters 15-53 - Called from Merlin_utils__Std.let_ref in file \"src/utils/std.ml\", line 727, characters 8-12 - Re-raised at Merlin_utils__Std.let_ref in file \"src/utils/std.ml\", line 733, characters 4-13 - Called from Merlin_utils__Misc.try_finally in file \"src/utils/misc.ml\", line 45, characters 8-15 - Re-raised at Merlin_utils__Misc.try_finally in file \"src/utils/misc.ml\", line 62, characters 10-24 - Called from Stdlib__Fun.protect in file \"fun.ml\", line 34, characters 8-15 - Re-raised at Stdlib__Fun.protect in file \"fun.ml\", line 39, characters 6-52 - Called from Merlin_kernel__Mocaml.with_state in file \"src/kernel/mocaml.ml\", line 18, characters 8-38 - Re-raised at Merlin_kernel__Mocaml.with_state in file \"src/kernel/mocaml.ml\", line 24, characters 4-15 - Called from Dune__exe__New_merlin.run.(fun) in file \"src/frontend/ocamlmerlin/new/new_merlin.ml\", lines 118-119, characters 16-52 - ", - "notifications": [] + > -position 5:25 -query "-ezfnifzen +ezfzef" | + > tr '\n' ' ' | jq '.value.entries[:10][] | {name,desc}' + { + "name": "CamlinternalOO.dummy_table", + "desc": "CamlinternalOO.table" + } + { + "name": "CamlinternalOO.params", + "desc": "CamlinternalOO.params" + } + { + "name": "__FILE__", + "desc": "string" + } + { + "name": "__FILE__", + "desc": "string" + } + { + "name": "__FUNCTION__", + "desc": "string" + } + { + "name": "__FUNCTION__", + "desc": "string" + } + { + "name": "__LINE__", + "desc": "int" + } + { + "name": "__LINE__", + "desc": "int" + } + { + "name": "__LOC__", + "desc": "string" + } + { + "name": "__LOC__", + "desc": "string" } From 396d818c82a9d2faaae841488f6948721e3baa53 Mon Sep 17 00:00:00 2001 From: xvw Date: Thu, 24 Oct 2024 14:24:09 +0200 Subject: [PATCH 3/5] Add change entry --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index c4dc10442c..5e20e10b31 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ unreleased files (#1854) - Fix occurrences bug in which relative paths in index files are resolved against the PWD rather than the SOURCE_ROOT (#1855) + - Fix exception in polarity search (#???? fixes #1113) merlin 5.2.1 ============ From e79cce62d8a379ab55ada1d4b723c6b306551ea1 Mon Sep 17 00:00:00 2001 From: xvw Date: Thu, 24 Oct 2024 14:26:02 +0200 Subject: [PATCH 4/5] Clarify documentation of polarity search --- CHANGES.md | 2 +- src/commands/new_commands.ml | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5e20e10b31..52009fddc1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,7 +6,7 @@ unreleased files (#1854) - Fix occurrences bug in which relative paths in index files are resolved against the PWD rather than the SOURCE_ROOT (#1855) - - Fix exception in polarity search (#???? fixes #1113) + - Fix exception in polarity search (#1858 fixes #1113) merlin 5.2.1 ============ diff --git a/src/commands/new_commands.ml b/src/commands/new_commands.ml index 836c3334f6..67a11911e1 100644 --- a/src/commands/new_commands.ml +++ b/src/commands/new_commands.ml @@ -569,7 +569,11 @@ let all_commands = ~spec: [ arg "-position" " Position to complete" (marg_position (fun pos (query, _pos) -> (query, pos))); - arg "-query" " Query of the form TODO" + arg "-query" + " Query of the form every input parameters prefixed by `-` \ + and output parameters prefixed by `+`. In example: -string \ + +option will fetch function that takes string and returns an \ + option. (You can't parametrize types in polarity queries)" (Marg.param "string" (fun query (_prefix, pos) -> (query, pos))) ] ~default:("", `None) From 887250540fc606523960824fac50b533e8e6cda0 Mon Sep 17 00:00:00 2001 From: xvw Date: Thu, 24 Oct 2024 14:36:01 +0200 Subject: [PATCH 5/5] Add `search-by-type` comparison --- tests/test-dirs/search/issue1113.t | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/test-dirs/search/issue1113.t b/tests/test-dirs/search/issue1113.t index 88cc81f5ee..2c87dcd63c 100644 --- a/tests/test-dirs/search/issue1113.t +++ b/tests/test-dirs/search/issue1113.t @@ -45,3 +45,57 @@ "name": "__LOC__", "desc": "string" } + + $ $MERLIN single search-by-type -filename ./main.ml \ + > -position 5:25 -limit 10 -query "ezfnifzen -> ezfzef" | + > tr '\n' ' ' | jq '.value[] | {name,type,cost}' + { + "name": "Gc.major", + "type": "unit -> unit", + "cost": 13 + } + { + "name": "Gc.minor", + "type": "unit -> unit", + "cost": 13 + } + { + "name": "Sys.time", + "type": "unit -> float", + "cost": 13 + } + { + "name": "read_int", + "type": "unit -> int", + "cost": 13 + } + { + "name": "read_int", + "type": "unit -> int", + "cost": 13 + } + { + "name": "flush_all", + "type": "unit -> unit", + "cost": 13 + } + { + "name": "flush_all", + "type": "unit -> unit", + "cost": 13 + } + { + "name": "read_line", + "type": "unit -> string", + "cost": 13 + } + { + "name": "read_line", + "type": "unit -> string", + "cost": 13 + } + { + "name": "Bytes.copy", + "type": "bytes -> bytes", + "cost": 13 + }