Skip to content

Commit 4200241

Browse files
committed
more piping
1 parent 971e708 commit 4200241

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

analysis/src/CompletionFrontEndNew.ml

+18-13
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ module CompletionContext = struct
188188
ctxPath = [];
189189
}
190190

191-
let withResetCtx completionContext =
191+
let resetCtx completionContext =
192192
{completionContext with currentlyExpecting = Unit; ctxPath = []}
193193

194194
let withScope scope completionContext = {completionContext with scope}
@@ -597,7 +597,7 @@ and completeValueBinding ~(completionContext : CompletionContext.t)
597597
in
598598
(* Always reset the context when completing value bindings,
599599
since they create their own context. *)
600-
let completionContext = CompletionContext.withResetCtx completionContext in
600+
let completionContext = CompletionContext.resetCtx completionContext in
601601
if locHasPos vb.pvb_pat.ppat_loc then
602602
(* Completing the pattern of the binding. `let {<com>} = someRecordVariable`.
603603
Ensure the context carries the root type of `someRecordVariable`. *)
@@ -831,7 +831,7 @@ and completeExpr ~completionContext (expr : Parsetree.expression) :
831831
if locHasPos condition.pexp_loc then
832832
(* TODO: I guess we could set looking for to "bool" here, since it's the if condition *)
833833
completeExpr
834-
~completionContext:(CompletionContext.withResetCtx completionContext)
834+
~completionContext:(CompletionContext.resetCtx completionContext)
835835
condition
836836
else if locHasPos then_.pexp_loc then completeExpr ~completionContext then_
837837
else
@@ -857,7 +857,7 @@ and completeExpr ~completionContext (expr : Parsetree.expression) :
857857
| Pexp_sequence (evalExpr, nextExpr) ->
858858
if locHasPos evalExpr.pexp_loc then
859859
completeExpr
860-
~completionContext:(CompletionContext.withResetCtx completionContext)
860+
~completionContext:(CompletionContext.resetCtx completionContext)
861861
evalExpr
862862
else if locHasPos nextExpr.pexp_loc then
863863
completeExpr ~completionContext nextExpr
@@ -875,7 +875,7 @@ and completeExpr ~completionContext (expr : Parsetree.expression) :
875875
match completePipe lhs ~id:"" with
876876
| None -> None
877877
| Some cpipe ->
878-
completionContext |> CompletionContext.withResetCtx
878+
completionContext |> CompletionContext.resetCtx
879879
|> CompletionResult.ctxPath cpipe)
880880
| Pexp_apply
881881
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}},
@@ -888,7 +888,7 @@ and completeExpr ~completionContext (expr : Parsetree.expression) :
888888
match completePipe lhs ~id with
889889
| None -> None
890890
| Some cpipe ->
891-
completionContext |> CompletionContext.withResetCtx
891+
completionContext |> CompletionContext.resetCtx
892892
|> CompletionResult.ctxPath cpipe)
893893
| Pexp_apply
894894
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u"); loc = opLoc}},
@@ -897,17 +897,22 @@ and completeExpr ~completionContext (expr : Parsetree.expression) :
897897
match completePipe lhs ~id:"" with
898898
| None -> None
899899
| Some cpipe ->
900-
completionContext |> CompletionContext.withResetCtx
900+
completionContext |> CompletionContext.resetCtx
901901
|> CompletionResult.ctxPath cpipe)
902-
| Pexp_apply ({pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}}, [_; _])
903-
->
904-
(* Ignore any other pipe. *)
905-
None
902+
| Pexp_apply
903+
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}},
904+
[(_, lhs); (_, rhs)] ) ->
905+
(* Descend into pipe parts if none of the special cases above works
906+
but the cursor is somewhere here. *)
907+
let completionContext = completionContext |> CompletionContext.resetCtx in
908+
if locHasPos lhs.pexp_loc then completeExpr ~completionContext lhs
909+
else if locHasPos rhs.pexp_loc then completeExpr ~completionContext rhs
910+
else None
906911
| Pexp_apply (fnExpr, args) -> (
907912
if locHasPos fnExpr.pexp_loc then
908913
(* someFn<com>(). Cursor in the function expression itself. *)
909914
completeExpr
910-
~completionContext:(CompletionContext.withResetCtx completionContext)
915+
~completionContext:(CompletionContext.resetCtx completionContext)
911916
fnExpr
912917
else
913918
(* Check if the args has the cursor. *)
@@ -925,7 +930,7 @@ and completeExpr ~completionContext (expr : Parsetree.expression) :
925930
(* TODO: Complete labelled argument names, pipes *)
926931
let makeCompletionContextWithArgumentLabel argumentLabel
927932
~functionContextPath =
928-
completionContext |> CompletionContext.withResetCtx
933+
completionContext |> CompletionContext.resetCtx
929934
|> CompletionContext.currentlyExpectingOrReset
930935
(Some
931936
(Type (CFunctionArgument {functionContextPath; argumentLabel})))

analysis/src/new-completions-todo.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
## Questions
22

33
- Figure out location for completeExpr - when do we need to check locs, and when not?
4+
- Pipe PPX transform, should we run it ourselves in the editor tooling?

analysis/tests/src/CompletionNew.res

+3
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,6 @@ type fn = (~name: string=?, string) => bool
124124

125125
// let x = foo->
126126
// ^co2
127+
128+
// let x = foo->M
129+
// ^co2

analysis/tests/src/expected/CompletionNew.res.txt

+5
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,8 @@ Result: CtxPath: (CId(Value)=foo)->
166166
Scope: 0 items
167167
Looking for type: Unit
168168

169+
Complete2 src/CompletionNew.res 127:17
170+
Result: Cexpression: ctxPath: CId(Module)=M, rootType: Unit, prefix: "M"
171+
Scope: 0 items
172+
Looking for type: Unit
173+

0 commit comments

Comments
 (0)