Skip to content

Commit

Permalink
Merge pull request #1858 from xvw/fix-1113
Browse files Browse the repository at this point in the history
Fix #1113
  • Loading branch information
voodoos authored Oct 24, 2024
2 parents 0821c50 + 8872505 commit a36f42a
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
============
Expand Down
6 changes: 4 additions & 2 deletions src/analysis/polarity_search.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/commands/new_commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,11 @@ let all_commands =
~spec:
[ arg "-position" "<position> Position to complete"
(marg_position (fun pos (query, _pos) -> (query, pos)));
arg "-query" "<string> Query of the form TODO"
arg "-query"
"<string> 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)
Expand Down
101 changes: 101 additions & 0 deletions tests/test-dirs/search/issue1113.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
$ cat >main.ml <<EOF
> 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
}

0 comments on commit a36f42a

Please sign in to comment.