Skip to content

Commit

Permalink
Large index alwways show the last type.
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Nov 21, 2024
1 parent d6ba564 commit 42ff215
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/frontend/query_commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ let dispatch pipeline (type a) : a Query_protocol.t -> a = function
in
concat_dedup [] small_enclosings enclosing_nodes
in
let index =
(* Clamp the index to [0; number_of_results[ *)
let number_of_results = List.length all_results in
match index with
| Some index when index < 0 -> Some 0
| Some index when index >= number_of_results ->
Some (number_of_results - 1)
| index -> index
in
List.mapi all_results ~f:(fun i (loc, text, tail) ->
let print =
match index with
Expand Down
40 changes: 36 additions & 4 deletions tests/test-dirs/type-enclosing/generic-types.t
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ FIXME? We don't see the generic version
> let _ = List.map Fun.id [3]
> EOF

FIXME With index 0 only the first type is shown but deduplication failed becauser the
next type was not rendered.
With index 0 only the first type is shown and deduplication id working
$ $MERLIN single type-enclosing -position 2:14 -index 0 \
> -filename ./main.ml < ./main.ml
{
Expand Down Expand Up @@ -192,8 +191,7 @@ next type was not rendered.
"notifications": []
}

FIXME With index 1 the list is shorter and the numbering is wrong ! In fact, it
should have been shorter earlier.
And with index=1 the correct type is shown
$ $MERLIN single type-enclosing -position 2:14 -index 1 \
> -filename ./main.ml < ./main.ml
{
Expand Down Expand Up @@ -226,3 +224,37 @@ should have been shorter earlier.
],
"notifications": []
}

And with index>=2 Merlin sticks to the last item
$ $MERLIN single type-enclosing -position 2:14 -index 2 \
> -filename ./main.ml < ./main.ml
{
"class": "return",
"value": [
{
"start": {
"line": 2,
"col": 8
},
"end": {
"line": 2,
"col": 16
},
"type": "(int -> int) -> int list -> int list",
"tail": "no"
},
{
"start": {
"line": 2,
"col": 8
},
"end": {
"line": 2,
"col": 27
},
"type": "int list",
"tail": "no"
}
],
"notifications": []
}

0 comments on commit 42ff215

Please sign in to comment.