Commit 51e16ea 1 parent 1509ff4 commit 51e16ea Copy full SHA for 51e16ea
File tree 3 files changed +72
-3
lines changed
3 files changed +72
-3
lines changed Original file line number Diff line number Diff line change 3
3
## Fixes
4
4
5
5
- Fix fd leak in running external processes for preprocessing (#1349 )
6
+ - Fix prefix parsing for completion of object methods (#1363 , fixes #1358 )
6
7
7
8
# 1.19.0
8
9
Original file line number Diff line number Diff line change @@ -24,6 +24,15 @@ include struct
24
24
])
25
25
;;
26
26
27
+ (* When completing module paths or record fields Merlin expects the
28
+ beginning of the path and the `.` to be part of the prefix. But when
29
+ accessing an object's methods, the prefix should not contain the `#`
30
+ sign. We use a sub-matching group to that effect.
31
+
32
+ - Prefix for [my_record.|] is ["my_record."] (handled by [name_or_label])
33
+ - Prefix for [my_object#|] is [""] (handled by [method_call]) *)
34
+ let method_call = compile (seq [ char '#' ; Re. group (rep name_char); stop ])
35
+
27
36
(* * matches let%lwt and let* style expressions. See
28
37
here:https://v2.ocaml.org/manual/bindingops.html *)
29
38
let monadic_bind =
@@ -42,8 +51,11 @@ let parse ~pos ~len text =
42
51
(* Attempt to match each of our possible prefix types, the order is important
43
52
because there is some overlap between the regexs*)
44
53
let matched =
45
- List. find_map [ name_or_label; monadic_bind; infix_operator ] ~f: (fun regex ->
46
- Re. exec_opt ~pos ~len regex text)
54
+ List. find_map
55
+ [ name_or_label; method_call; monadic_bind; infix_operator ]
56
+ ~f: (fun regex -> Re. exec_opt ~pos ~len regex text)
47
57
in
48
- matched |> Option. map ~f: (fun x -> Re.Group. get x 0 )
58
+ matched
59
+ |> Option. map ~f: (fun x ->
60
+ if Re.Group. test x 1 then Re.Group. get x 1 else Re.Group. get x 0 )
49
61
;;
Original file line number Diff line number Diff line change @@ -1243,3 +1243,59 @@ let foo param1 =
1243
1243
}
1244
1244
............. | }]
1245
1245
;;
1246
+
1247
+ (* Test case was taken from issue #1358 *)
1248
+ let % expect_test " completion for object methods" =
1249
+ let source = {ocaml| let f (x : < a_method : 'a > ) = x#| ocaml} in
1250
+ let position = Position. create ~line: 0 ~character: 34 in
1251
+ print_completions ~limit: 3 source position;
1252
+ [% expect
1253
+ {|
1254
+ Completions :
1255
+ {
1256
+ " kind" : 14 ,
1257
+ " label" : " in" ,
1258
+ " textEdit" : {
1259
+ " newText" : " in" ,
1260
+ " range" : {
1261
+ " end" : { " character" : 34 , " line" : 0 },
1262
+ " start" : { " character" : 34 , " line" : 0 }
1263
+ }
1264
+ }
1265
+ }
1266
+ {
1267
+ " detail" : " 'a" ,
1268
+ " kind" : 2 ,
1269
+ " label" : " a_method" ,
1270
+ " sortText" : " 0000" ,
1271
+ " textEdit" : {
1272
+ " newText" : " a_method" ,
1273
+ " range" : {
1274
+ " end" : { " character" : 34 , " line" : 0 },
1275
+ " start" : { " character" : 34 , " line" : 0 }
1276
+ }
1277
+ }
1278
+ } | }]
1279
+ ;;
1280
+
1281
+ let % expect_test " completion for object methods" =
1282
+ let source = {ocaml| let f (x : < a_method : 'a; ab_m : 'b > ) = x#ab| ocaml} in
1283
+ let position = Position. create ~line: 0 ~character: 49 in
1284
+ print_completions ~limit: 3 source position;
1285
+ [% expect
1286
+ {|
1287
+ Completions :
1288
+ {
1289
+ " detail" : " 'b" ,
1290
+ " kind" : 2 ,
1291
+ " label" : " ab_m" ,
1292
+ " sortText" : " 0000" ,
1293
+ " textEdit" : {
1294
+ " newText" : " ab_m" ,
1295
+ " range" : {
1296
+ " end" : { " character" : 49 , " line" : 0 },
1297
+ " start" : { " character" : 47 , " line" : 0 }
1298
+ }
1299
+ }
1300
+ } | }]
1301
+ ;;
You can’t perform that action at this time.
0 commit comments