diff --git a/CHANGES.md b/CHANGES.md index c4dc10442c..52009fddc1 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 (#1858 fixes #1113) merlin 5.2.1 ============ 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/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) diff --git a/tests/test-dirs/search/issue1113.t b/tests/test-dirs/search/issue1113.t new file mode 100644 index 0000000000..2c87dcd63c --- /dev/null +++ b/tests/test-dirs/search/issue1113.t @@ -0,0 +1,101 @@ + $ cat >main.ml < let f x = succ x + > EOF + + $ $MERLIN single search-by-polarity -filename ./main.ml \ + > -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" + } + + $ $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 + }