@@ -75,28 +75,6 @@ let findJsxPropsCompletable ~jsxProps ~endPos ~posBeforeCursor ~posAfterCompName
75
75
in
76
76
loop jsxProps.props
77
77
78
- let rec skipLineComment ~pos ~i str =
79
- if i < String. length str then
80
- match str.[i] with
81
- | '\n' -> Some ((fst pos + 1 , 0 ), i + 1 )
82
- | _ -> skipLineComment ~pos: (fst pos, snd pos + 1 ) ~i: (i + 1 ) str
83
- else None
84
-
85
- let rec skipComment ~pos ~i ~depth str =
86
- if i < String. length str then
87
- match str.[i] with
88
- | '\n' -> skipComment ~depth ~pos: (fst pos + 1 , 0 ) ~i: (i + 1 ) str
89
- | '/' when i + 1 < String. length str && str.[i + 1 ] = '*' ->
90
- skipComment ~depth: (depth + 1 ) ~pos: (fst pos, snd pos + 2 ) ~i: (i + 2 ) str
91
- | '*' when i + 1 < String. length str && str.[i + 1 ] = '/' ->
92
- if depth > 1 then
93
- skipComment ~depth: (depth - 1 )
94
- ~pos: (fst pos, snd pos + 2 )
95
- ~i: (i + 2 ) str
96
- else Some ((fst pos, snd pos + 2 ), i + 2 )
97
- | _ -> skipComment ~depth ~pos: (fst pos, snd pos + 1 ) ~i: (i + 1 ) str
98
- else None
99
-
100
78
let extractJsxProps ~(compName : Longident.t Location.loc ) ~args =
101
79
let thisCaseShouldNotHappen =
102
80
{
@@ -147,9 +125,7 @@ type label = labelled option
147
125
type arg = {label : label ; exp : Parsetree .expression }
148
126
149
127
let findExpApplyCompletable ~(args : arg list ) ~endPos ~posBeforeCursor
150
- ~(funName : Longident.t Location.loc ) =
151
- let funPath = Utils. flattenLongIdent funName.txt in
152
- let posAfterFunName = Loc. end_ funName.loc in
128
+ ~(contextPath : Completable.contextPath ) ~posAfterFunExpr =
153
129
let allNames =
154
130
List. fold_right
155
131
(fun arg allLabels ->
@@ -164,18 +140,15 @@ let findExpApplyCompletable ~(args : arg list) ~endPos ~posBeforeCursor
164
140
if
165
141
labelled.posStart < = posBeforeCursor
166
142
&& posBeforeCursor < labelled.posEnd
167
- then
168
- Some
169
- (Completable. CnamedArg
170
- (Completable. CPId (funPath, Value ), labelled.name, allNames))
143
+ then Some (Completable. CnamedArg (contextPath, labelled.name, allNames))
171
144
else if exp.pexp_loc |> Loc. hasPos ~pos: posBeforeCursor then None
172
145
else loop rest
173
146
| {label = None ; exp} :: rest ->
174
147
if exp.pexp_loc |> Loc. hasPos ~pos: posBeforeCursor then None
175
148
else loop rest
176
149
| [] ->
177
- if posAfterFunName < = posBeforeCursor && posBeforeCursor < endPos then
178
- Some (CnamedArg (Completable. CPId (funPath, Value ) , " " , allNames))
150
+ if posAfterFunExpr < = posBeforeCursor && posBeforeCursor < endPos then
151
+ Some (CnamedArg (contextPath , " " , allNames))
179
152
else None
180
153
in
181
154
loop args
@@ -574,10 +547,11 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
574
547
setPipeResult ~lhs ~id: " " |> ignore
575
548
| Pexp_apply ({pexp_desc = Pexp_ident {txt = Lident "|." } } , [_; _]) ->
576
549
()
577
- | Pexp_apply ({ pexp_desc = Pexp_ident funName } , args ) ->
550
+ | Pexp_apply (funExpr , args ) ->
578
551
let args = extractExpApplyArgs ~args in
579
552
if debug then
580
- Printf. printf " Pexp_apply ...%s (%s)\n " (Loc. toString funName.loc)
553
+ Printf. printf " Pexp_apply ...%s (%s)\n "
554
+ (Loc. toString funExpr.pexp_loc)
581
555
(args
582
556
|> List. map (fun {label; exp} ->
583
557
Printf. sprintf " %s...%s"
@@ -590,9 +564,14 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
590
564
(Loc. toString exp.pexp_loc))
591
565
|> String. concat " , " );
592
566
let expApplyCompletable =
593
- findExpApplyCompletable ~fun Name ~args
594
- ~end Pos:(Loc. end_ expr.pexp_loc) ~pos BeforeCursor
567
+ match exprToContextPath funExpr with
568
+ | Some contextPath ->
569
+ findExpApplyCompletable ~context Path ~args
570
+ ~end Pos:(Loc. end_ expr.pexp_loc) ~pos BeforeCursor
571
+ ~pos AfterFunExpr:(Loc. end_ funExpr.pexp_loc)
572
+ | None -> None
595
573
in
574
+
596
575
setResultOpt expApplyCompletable
597
576
| Pexp_send (lhs , {txt; loc} ) -> (
598
577
(* e["txt"]
0 commit comments