Skip to content

Commit 011dd84

Browse files
committed
comments and cleanup
1 parent b26a607 commit 011dd84

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

analysis/src/CompletionBackEnd.ml

+4
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,9 @@ let completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
16461646
~kind:(Value typ) ~env ();
16471647
]
16481648
| Some (Trecord {env; fields; typeExpr}) -> (
1649+
(* As we're completing for a record, we'll need a hint (completionContext)
1650+
here to figure out whether we should complete for a record field, or
1651+
the record body itself. *)
16491652
match completionContext with
16501653
| Some (Completable.RecordField {seenFields}) ->
16511654
fields
@@ -1750,6 +1753,7 @@ let getJsxLabels ~componentPath ~findTypeOfValue ~package =
17501753
typ |> getLabels
17511754
| None -> []
17521755

1756+
(** This moves through a pattern via a set of instructions, trying to resolve the type at the end of the pattern. *)
17531757
let rec resolveNestedPattern typ ~env ~package ~nested =
17541758
match nested with
17551759
| [] -> Some (typ, env, None)

analysis/src/CompletionFrontEnd.ml

+7-7
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
428428
match !lookingForPat with
429429
| Some (Completable.Cpattern ({nested = None} as p)) ->
430430
lookingForPat := Some (Cpattern {p with nested = Some [patternPat]})
431-
| Some (Completable.Cpattern ({nested = Some nested} as p)) ->
431+
| Some (Cpattern ({nested = Some nested} as p)) ->
432432
lookingForPat :=
433433
Some (Cpattern {p with nested = Some (nested @ [patternPat])})
434434
| _ -> ()
@@ -444,7 +444,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
444444
setResult cpattern
445445
| _ -> ()
446446
in
447-
447+
(* Identifies expressions where we can do typed pattern or expr completion. *)
448448
let typedCompletionExpr (exp : Parsetree.expression) =
449449
if
450450
exp.pexp_loc
@@ -478,7 +478,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
478478
| Some ctxPath -> setLookingForPat ctxPath)
479479
| _ -> unsetLookingForPat
480480
in
481-
481+
(* Tracks the path through a pattern for where the cursor is. *)
482482
let typedCompletionPat (pat : Parsetree.pattern) =
483483
if
484484
pat.ppat_loc
@@ -488,21 +488,21 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
488488
match pat.ppat_desc with
489489
| Ppat_var {txt} -> commitFoundPat ~prefix:txt ()
490490
| Ppat_tuple patterns -> (
491-
let patCount = ref (-1) in
491+
let patCount = ref None in
492492
let patCountWithPatHole = ref None in
493493
patterns
494494
|> List.iteri (fun index p ->
495495
match
496496
p.Parsetree.ppat_loc
497497
|> CursorPosition.classifyLoc ~pos:posBeforeCursor
498498
with
499-
| HasCursor -> patCount := index
499+
| HasCursor -> patCount := Some index
500500
| EmptyLoc -> patCountWithPatHole := Some index
501501
| _ -> ());
502502
match (!patCount, !patCountWithPatHole) with
503-
| patCount, _ when patCount > -1 ->
503+
| Some patCount, _ ->
504504
appendNestedPat (Completable.PTupleItem {itemNum = patCount})
505-
| _, Some patHoleCount ->
505+
| None, Some patHoleCount ->
506506
appendNestedPat (Completable.PTupleItem {itemNum = patHoleCount})
507507
| _ -> ())
508508
| Ppat_record ([], _) ->

0 commit comments

Comments
 (0)