@@ -258,12 +258,34 @@ let reconstruct_identifier_from_tokens tokens pos =
258
258
look_for_dot [item] items
259
259
260
260
(* RPAREN UIDENT means that we are in presence of a functor application. *)
261
- | (RPAREN , _, end_pos) :: ((UIDENT s , _, _ ) as _item ) :: items
261
+ | (RPAREN , _, end_pos) :: ((UIDENT _ , _, _ ) as item ) :: items
262
262
when acc <> [] ->
263
- let app, start_pos, items =
264
- look_for_apply ~inside_paren: true [ s; " )" ] items
265
- in
266
- look_for_dot ((UIDENT app, start_pos, end_pos ) :: acc) items
263
+ let param_items, items = group_until_lparen [item] items in
264
+ begin try
265
+ begin try
266
+ (* Is the cursor on the parameter ? *)
267
+ look_for_dot [] (List. rev param_items)
268
+ with Not_found ->
269
+ (* Is the cursor on the functor or before ? *)
270
+ look_for_component [] items
271
+ end
272
+ with Not_found ->
273
+ (* The cursor must be after the application [M.N(F).|t]
274
+ We make a single component with the applciation and continue *)
275
+ match items with
276
+ | (UIDENT f , start_pos , _ ) :: items ->
277
+ let app =
278
+ let param = List. map ~f: (function
279
+ | (DOT, _ , _ ) -> " ."
280
+ | (UIDENT s , _ , _ ) -> s
281
+ | _ -> raise Not_found
282
+ ) param_items
283
+ in
284
+ Format. sprintf " %s(%s)" f (String. concat ~sep: " " param)
285
+ in
286
+ look_for_dot ((UIDENT app, start_pos, end_pos ) :: acc) items
287
+ | _ -> raise Not_found
288
+ end
267
289
268
290
(* An operator alone is an identifier on its own *)
269
291
| (token, _, _ as item) :: items
@@ -276,16 +298,9 @@ let reconstruct_identifier_from_tokens tokens pos =
276
298
277
299
| [] -> raise Not_found
278
300
279
- (* FIXME: this function treats applications as a single component ["M(N.P)"].
280
- This prevent jumping to M, N or P. *)
281
- and look_for_apply ~inside_paren acc = function
282
- | (LPAREN, _ , _ ) :: items when inside_paren ->
283
- look_for_apply ~inside_paren: false (" (" :: acc) items
284
- | (UIDENT s , _ , _ ) :: items when inside_paren ->
285
- look_for_apply ~inside_paren (s :: " ." :: acc) items
286
- | (UIDENT s , start_pos , _ ) :: items when not inside_paren ->
287
- let item = String. concat ~sep: " " (s :: acc) in
288
- item, start_pos, items
301
+ and group_until_lparen acc = function
302
+ | (LPAREN,_ ,_ ) :: items -> acc, items
303
+ | item :: items -> group_until_lparen (item::acc) items
289
304
| _ -> raise Not_found
290
305
291
306
and look_for_dot acc = function
0 commit comments