Skip to content

Commit e22f3e0

Browse files
committed
Stop deduplicating all results
1 parent 4a5aed1 commit e22f3e0

File tree

4 files changed

+151
-8
lines changed

4 files changed

+151
-8
lines changed

src/frontend/query_commands.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,17 @@ let dispatch pipeline (type a) : a Query_protocol.t -> a = function
309309
typedtree's nodes and can provide types for modules appearing in paths.
310310
311311
This introduces two possible sources of duplicate results:
312-
- Sometimes the typedtree nodes in 1 overlaps and we simply remove these.
313312
- The last reconstructed enclosing usually overlaps with the first
314313
typedtree node but the printed types are not always the same (generic /
315314
specialized types). Because systematically printing these types to
316315
compare them can be very expensive in the presence of large modules, we
317316
defer this deduplication to the clients.
317+
- Sometimes the typedtree nodes in 1 overlaps. We choose not to dedpulicate because
318+
if the types are the same, the client is already responsible for deduplication.
319+
If they are different, then they are likely useful to display to the user.
320+
So, we choose to not duplicate results and delegate this to the client.
318321
*)
319-
let enclosing_nodes =
320-
let cmp (loc1, _, _) (loc2, _, _) = Location_aux.compare loc1 loc2 in
321-
(* There might be duplicates in the list: we remove them *)
322-
Type_enclosing.from_nodes ~path |> List.dedup_adjacent ~cmp
323-
in
322+
let enclosing_nodes = Type_enclosing.from_nodes ~path in
324323

325324
(* Enclosings of cursor in given expression *)
326325
let exprs = Misc_utils.reconstruct_identifier pipeline pos expro in

tests/test-dirs/type-enclosing/function-type-error.t

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ type error. The exact output may change slightly -- that's fine.
185185
"type": "int",
186186
"tail": "no"
187187
},
188+
{
189+
"start": {
190+
"line": 1,
191+
"col": 8
192+
},
193+
"end": {
194+
"line": 1,
195+
"col": 40
196+
},
197+
"type": "int -> ?z:int -> int -> int",
198+
"tail": "no"
199+
},
188200
{
189201
"start": {
190202
"line": 1,

tests/test-dirs/type-enclosing/underscore-ids.t

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ in the presence of underscores.
2121
"type": "float",
2222
"tail": "no"
2323
},
24+
{
25+
"start": {
26+
"line": 3,
27+
"col": 2
28+
},
29+
"end": {
30+
"line": 3,
31+
"col": 6
32+
},
33+
"type": "float",
34+
"tail": "no"
35+
},
2436
{
2537
"start": {
2638
"line": 3,
@@ -67,6 +79,18 @@ in the presence of underscores.
6779
"type": "float",
6880
"tail": "no"
6981
},
82+
{
83+
"start": {
84+
"line": 3,
85+
"col": 2
86+
},
87+
"end": {
88+
"line": 3,
89+
"col": 6
90+
},
91+
"type": "float",
92+
"tail": "no"
93+
},
7094
{
7195
"start": {
7296
"line": 3,
@@ -114,6 +138,18 @@ We try several places in the identifier to check the result stability
114138
"type": "float",
115139
"tail": "no"
116140
},
141+
{
142+
"start": {
143+
"line": 3,
144+
"col": 2
145+
},
146+
"end": {
147+
"line": 3,
148+
"col": 9
149+
},
150+
"type": "float",
151+
"tail": "no"
152+
},
117153
{
118154
"start": {
119155
"line": 3,
@@ -160,6 +196,18 @@ We try several places in the identifier to check the result stability
160196
"type": "float",
161197
"tail": "no"
162198
},
199+
{
200+
"start": {
201+
"line": 3,
202+
"col": 2
203+
},
204+
"end": {
205+
"line": 3,
206+
"col": 9
207+
},
208+
"type": "float",
209+
"tail": "no"
210+
},
163211
{
164212
"start": {
165213
"line": 3,
@@ -206,6 +254,18 @@ We try several places in the identifier to check the result stability
206254
"type": "float",
207255
"tail": "no"
208256
},
257+
{
258+
"start": {
259+
"line": 3,
260+
"col": 2
261+
},
262+
"end": {
263+
"line": 3,
264+
"col": 9
265+
},
266+
"type": "float",
267+
"tail": "no"
268+
},
209269
{
210270
"start": {
211271
"line": 3,
@@ -253,6 +313,18 @@ We try several places in the identifier to check the result stability
253313
"type": "float",
254314
"tail": "no"
255315
},
316+
{
317+
"start": {
318+
"line": 3,
319+
"col": 2
320+
},
321+
"end": {
322+
"line": 3,
323+
"col": 9
324+
},
325+
"type": "float",
326+
"tail": "no"
327+
},
256328
{
257329
"start": {
258330
"line": 3,
@@ -316,6 +388,18 @@ We try several places in the identifier to check the result stability
316388
"type": "int option",
317389
"tail": "no"
318390
},
391+
{
392+
"start": {
393+
"line": 2,
394+
"col": 18
395+
},
396+
"end": {
397+
"line": 5,
398+
"col": 17
399+
},
400+
"type": "int option -> int",
401+
"tail": "no"
402+
},
319403
{
320404
"start": {
321405
"line": 2,

tests/test-dirs/type-enclosing/variants.t/run.t

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,32 @@
155155

156156
FIXME: Not satisfying, expected core not more
157157
$ $MERLIN single type-enclosing -position 9:3 -verbosity 0 \
158-
> -filename ./variants.ml < ./variants.ml | jq ".value[0:2]"
158+
> -filename ./variants.ml < ./variants.ml | jq ".value"
159159
[
160+
{
161+
"start": {
162+
"line": 9,
163+
"col": 2
164+
},
165+
"end": {
166+
"line": 9,
167+
"col": 7
168+
},
169+
"type": "more",
170+
"tail": "no"
171+
},
172+
{
173+
"start": {
174+
"line": 9,
175+
"col": 2
176+
},
177+
"end": {
178+
"line": 9,
179+
"col": 7
180+
},
181+
"type": "more",
182+
"tail": "no"
183+
},
160184
{
161185
"start": {
162186
"line": 9,
@@ -184,8 +208,32 @@ FIXME: Not satisfying, expected core not more
184208
]
185209

186210
$ $MERLIN single type-enclosing -position 9:3 -verbosity 1 \
187-
> -filename ./variants.ml < ./variants.ml | jq ".value[0:2]"
211+
> -filename ./variants.ml < ./variants.ml | jq ".value"
188212
[
213+
{
214+
"start": {
215+
"line": 9,
216+
"col": 2
217+
},
218+
"end": {
219+
"line": 9,
220+
"col": 7
221+
},
222+
"type": "[ `A | `B | `C ]",
223+
"tail": "no"
224+
},
225+
{
226+
"start": {
227+
"line": 9,
228+
"col": 2
229+
},
230+
"end": {
231+
"line": 9,
232+
"col": 7
233+
},
234+
"type": "[ `A | `B | `C ]",
235+
"tail": "no"
236+
},
189237
{
190238
"start": {
191239
"line": 9,

0 commit comments

Comments
 (0)