@@ -137,7 +137,8 @@ type label = labelled option
137
137
type arg = {label : label ; exp : Parsetree .expression }
138
138
139
139
let findNamedArgCompletable ~(args : arg list ) ~endPos ~posBeforeCursor
140
- ~(contextPath : Completable.contextPath ) ~posAfterFunExpr =
140
+ ~(contextPath : Completable.contextPath ) ~posAfterFunExpr ~charBeforeCursor
141
+ ~debug =
141
142
let allNames =
142
143
List. fold_right
143
144
(fun arg allLabels ->
@@ -149,11 +150,19 @@ let findNamedArgCompletable ~(args : arg list) ~endPos ~posBeforeCursor
149
150
let rec loop args =
150
151
match args with
151
152
| {label = Some labelled ; exp} :: rest ->
153
+ (* Figure out if we're completing the labelled argument name, or assigning to the labelled argument *)
152
154
if
153
155
labelled.posStart < = posBeforeCursor
154
156
&& posBeforeCursor < labelled.posEnd
157
+ && charBeforeCursor <> Some '='
158
+ (* We need to account for empty assignments being parsed as regular labelled arguments without an assignment *)
155
159
then Some (Completable. CnamedArg (contextPath, labelled.name, allNames))
156
- else if exp.pexp_loc |> Loc. hasPos ~pos: posBeforeCursor then None
160
+ else if
161
+ exp.pexp_loc |> Loc. hasPos ~pos: posBeforeCursor
162
+ || charBeforeCursor = Some '='
163
+ then (
164
+ if debug then Printf. printf " found typed context \n " ;
165
+ Some (Completable. CtypedContext contextPath))
157
166
else loop rest
158
167
| {label = None ; exp} :: rest ->
159
168
if exp.pexp_loc |> Loc. hasPos ~pos: posBeforeCursor then None
@@ -592,6 +601,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
592
601
| Some contextPath ->
593
602
findNamedArgCompletable ~context Path ~args
594
603
~end Pos:(Loc. end_ expr.pexp_loc) ~pos BeforeCursor
604
+ ~char BeforeCursor ~debug
595
605
~pos AfterFunExpr:(Loc. end_ funExpr.pexp_loc)
596
606
| None -> None
597
607
in
0 commit comments