diff --git a/src/frontend/query_commands.ml b/src/frontend/query_commands.ml index 100aa8354..1e1d8b4f1 100644 --- a/src/frontend/query_commands.ml +++ b/src/frontend/query_commands.ml @@ -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 diff --git a/tests/test-dirs/type-enclosing/generic-types.t b/tests/test-dirs/type-enclosing/generic-types.t index be9fd27df..6c61e62a8 100644 --- a/tests/test-dirs/type-enclosing/generic-types.t +++ b/tests/test-dirs/type-enclosing/generic-types.t @@ -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 { @@ -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 { @@ -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": [] + }