@@ -317,7 +317,26 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
317
317
in
318
318
let scopeValueBinding (vb : Parsetree.value_binding ) =
319
319
scopePattern vb.pvb_pat;
320
- completePattern vb.pvb_pat
320
+ (* Identify relevant destructures for completion, like `let {<com>} = someVar` or `let (true, false) = someFn()`. *)
321
+ match vb with
322
+ | {pvb_pat; pvb_expr} when locHasCursor pvb_pat.ppat_loc -> (
323
+ match
324
+ ( pvb_pat
325
+ |> CompletionPatterns. traversePattern ~pattern Path:[] ~loc HasCursor
326
+ ~first CharBeforeCursorNoWhite ~pos BeforeCursor,
327
+ exprToContextPath pvb_expr )
328
+ with
329
+ | Some (prefix , nestedPattern ), Some ctxPath ->
330
+ setResult
331
+ (Completable. Cpattern
332
+ {
333
+ contextPath = ctxPath;
334
+ prefix;
335
+ nested = List. rev nestedPattern;
336
+ fallback = None ;
337
+ })
338
+ | _ -> () )
339
+ | _ -> ()
321
340
in
322
341
let scopeTypeKind (tk : Parsetree.type_kind ) =
323
342
match tk with
@@ -446,13 +465,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
446
465
scope := ! scope |> Scope. addOpen ~lid: popen_lid.txt
447
466
| Pstr_primitive vd -> scopeValueDescription vd
448
467
| Pstr_value (recFlag , bindings ) ->
449
- (* Identify relevant destructures for completion, like `let {<com>} = someVar` or `let (true, false) = someFn()`. *)
450
- (match bindings with
451
- | [{pvb_pat = {ppat_desc = Ppat_record _ | Ppat_tuple _ }; pvb_expr }] -> (
452
- match exprToContextPath pvb_expr with
453
- | None -> ()
454
- | Some ctxPath -> setLookingForPat ctxPath)
455
- | _ -> () );
456
468
if recFlag = Recursive then bindings |> List. iter scopeValueBinding;
457
469
bindings |> List. iter (fun vb -> iterator.value_binding iterator vb);
458
470
if recFlag = Nonrecursive then bindings |> List. iter scopeValueBinding;
0 commit comments