Skip to content

Commit 9bdaed3

Browse files
committed
contonous dot completion
1 parent 5461f3d commit 9bdaed3

18 files changed

+442
-18
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
10801080
path @ [fieldName]
10811081
|> getCompletionsForPath ~debug ~opens ~full ~pos ~exact
10821082
~completionContext:Field ~env ~scope
1083-
| CPField {contextPath = cp; fieldName; fieldNameLoc; posOfDot} -> (
1083+
| CPField {contextPath = cp; fieldName; posOfDot; exprLoc} -> (
10841084
if Debug.verbose () then print_endline "[dot_completion]--> Triggered";
10851085
let completionsFromCtxPath =
10861086
cp
@@ -1102,10 +1102,28 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
11021102
DotCompletionUtils.fieldCompletionsForDotCompletion typ ~env ~package
11031103
~prefix:fieldName ?posOfDot ~exact
11041104
in
1105+
let cpAsPipeCompletion =
1106+
Completable.CPPipe
1107+
{
1108+
contextPath =
1109+
(match cp with
1110+
| CPApply (c, args) -> CPApply (c, args @ [Asttypes.Nolabel])
1111+
| c -> c);
1112+
id = fieldName;
1113+
inJsx = false;
1114+
lhsLoc = exprLoc;
1115+
}
1116+
in
1117+
let completionsFromPipeCtxPath =
1118+
cpAsPipeCompletion
1119+
|> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos
1120+
~env:envCompletionIsMadeFrom ~exact ~scope
1121+
in
11051122
let pipeCompletions =
1106-
getPipeCompletions ~env ~full ~identifierLoc:fieldNameLoc ?posOfDot
1107-
~envCompletionIsMadeFrom ~debug ~opens ~rawOpens ~scope ~pos
1108-
~inJsx:false ~prefix:fieldName ~formatCompletionsWithPipes:true typ
1123+
completionsFromPipeCtxPath
1124+
|> List.filter_map (fun c ->
1125+
TypeUtils.transformCompletionToPipeCompletion ~synthetic:true
1126+
~env ?posOfDot c)
11091127
in
11101128
fieldCompletions @ pipeCompletions)
11111129
| CPObj (cp, label) -> (

analysis/src/CompletionFrontEnd.ml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,19 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
222222
| Pexp_ident {txt; loc} ->
223223
Some
224224
(CPId {path = Utils.flattenLongIdent txt; completionContext = Value; loc})
225-
| Pexp_field (e1, {txt = Lident name; loc}) -> (
225+
| Pexp_field (e1, {txt = Lident name}) -> (
226226
match exprToContextPath e1 with
227227
| Some contextPath ->
228228
Some
229229
(CPField
230-
{contextPath; fieldName = name; fieldNameLoc = loc; posOfDot = None})
230+
{
231+
contextPath;
232+
fieldName = name;
233+
posOfDot = None;
234+
exprLoc = e1.pexp_loc;
235+
})
231236
| _ -> None)
232-
| Pexp_field (_, {loc; txt = Ldot (lid, name)}) ->
237+
| Pexp_field (e1, {loc; txt = Ldot (lid, name)}) ->
233238
(* Case x.M.field ignore the x part *)
234239
Some
235240
(CPField
@@ -242,8 +247,8 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
242247
loc;
243248
};
244249
fieldName = name;
245-
fieldNameLoc = loc;
246250
posOfDot = None;
251+
exprLoc = e1.pexp_loc;
247252
})
248253
| Pexp_send (e1, {txt}) -> (
249254
match exprToContextPath e1 with
@@ -1170,8 +1175,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
11701175
{
11711176
contextPath;
11721177
fieldName = name;
1173-
fieldNameLoc = fieldName.loc;
11741178
posOfDot;
1179+
exprLoc = e.pexp_loc;
11751180
}
11761181
in
11771182
setResult (Cpath contextPath)
@@ -1193,8 +1198,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
11931198
(* x.M. field ---> M. *) ""
11941199
else if name = "_" then ""
11951200
else name);
1196-
fieldNameLoc = fieldName.loc;
11971201
posOfDot;
1202+
exprLoc = e.pexp_loc;
11981203
}
11991204
in
12001205
setResult (Cpath contextPath)
@@ -1208,13 +1213,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
12081213
{
12091214
contextPath;
12101215
fieldName = "";
1211-
fieldNameLoc =
1212-
{
1213-
loc_start = e.pexp_loc.loc_end;
1214-
loc_end = e.pexp_loc.loc_end;
1215-
loc_ghost = false;
1216-
};
12171216
posOfDot;
1217+
exprLoc = e.pexp_loc;
12181218
}))
12191219
| None -> ())
12201220
| Pexp_apply ({pexp_desc = Pexp_ident compName}, args)

analysis/src/SharedTypes.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ module Completable = struct
615615
contextPath: contextPath;
616616
fieldName: string;
617617
posOfDot: (int * int) option;
618-
fieldNameLoc: Location.t;
618+
exprLoc: Location.t;
619619
}
620620
| CPObj of contextPath * string
621621
| CPAwait of contextPath

analysis/tests/src/DotPipeCompletionSpec.res

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,12 @@ let ffff: builtinType = []
8080
let nnn: typeOutsideModule = {nname: "hello"}
8181
// nnn.
8282
// ^com
83+
84+
// Continuous completion
85+
let xxxx = [1, 2]
86+
87+
// xxxx->Js.Array2.filter(v => v > 10).filt
88+
// ^com
89+
90+
// xxxx->Js.Array2.filter(v => v > 10)->Js.Array2.joinWith(",").includ
91+
// ^com

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,9 @@ Resolved opens 1 pervasives
723723
ContextPath Value[r].""
724724
ContextPath Value[r]
725725
Path r
726+
ContextPath Value[r]->
727+
ContextPath Value[r]
728+
Path r
726729
CPPipe pathFromEnv: found:true
727730
Path Completion.
728731
[{
@@ -748,6 +751,9 @@ Resolved opens 1 pervasives
748751
ContextPath Value[Objects, Rec, recordVal].""
749752
ContextPath Value[Objects, Rec, recordVal]
750753
Path Objects.Rec.recordVal
754+
ContextPath Value[Objects, Rec, recordVal]->
755+
ContextPath Value[Objects, Rec, recordVal]
756+
Path Objects.Rec.recordVal
751757
CPPipe pathFromEnv:Rec found:true
752758
Path Objects.Rec.
753759
[{
@@ -832,6 +838,18 @@ ContextPath Value[q].aa.""
832838
ContextPath Value[q].aa
833839
ContextPath Value[q]
834840
Path q
841+
ContextPath Value[q]->aa
842+
ContextPath Value[q]
843+
Path q
844+
CPPipe pathFromEnv: found:true
845+
Path Completion.aa
846+
ContextPath Value[q].aa->
847+
ContextPath Value[q].aa
848+
ContextPath Value[q]
849+
Path q
850+
ContextPath Value[q]->aa
851+
ContextPath Value[q]
852+
Path q
835853
CPPipe pathFromEnv: found:true
836854
Path Completion.aa
837855
CPPipe pathFromEnv: found:true
@@ -860,6 +878,18 @@ ContextPath Value[q].aa.n
860878
ContextPath Value[q].aa
861879
ContextPath Value[q]
862880
Path q
881+
ContextPath Value[q]->aa
882+
ContextPath Value[q]
883+
Path q
884+
CPPipe pathFromEnv: found:true
885+
Path Completion.aa
886+
ContextPath Value[q].aa->n
887+
ContextPath Value[q].aa
888+
ContextPath Value[q]
889+
Path q
890+
ContextPath Value[q]->aa
891+
ContextPath Value[q]
892+
Path q
863893
CPPipe pathFromEnv: found:true
864894
Path Completion.aa
865895
CPPipe pathFromEnv: found:true
@@ -1088,6 +1118,10 @@ ContextPath Value[FAO, forAutoObject]["forAutoLabel"].""
10881118
ContextPath Value[FAO, forAutoObject]["forAutoLabel"]
10891119
ContextPath Value[FAO, forAutoObject]
10901120
Path FAO.forAutoObject
1121+
ContextPath Value[FAO, forAutoObject]["forAutoLabel"]->
1122+
ContextPath Value[FAO, forAutoObject]["forAutoLabel"]
1123+
ContextPath Value[FAO, forAutoObject]
1124+
Path FAO.forAutoObject
10911125
CPPipe pathFromEnv:FAR found:true
10921126
Path FAR.
10931127
[{
@@ -1115,6 +1149,10 @@ ContextPath Value[FAO, forAutoObject]["forAutoLabel"].forAuto
11151149
ContextPath Value[FAO, forAutoObject]["forAutoLabel"]
11161150
ContextPath Value[FAO, forAutoObject]
11171151
Path FAO.forAutoObject
1152+
ContextPath Value[FAO, forAutoObject]["forAutoLabel"]->forAuto
1153+
ContextPath Value[FAO, forAutoObject]["forAutoLabel"]
1154+
ContextPath Value[FAO, forAutoObject]
1155+
Path FAO.forAutoObject
11181156
CPPipe pathFromEnv:FAR found:true
11191157
Path FAR.forAuto
11201158
CPPipe pathFromEnv:ForAuto found:false
@@ -1198,6 +1236,9 @@ Resolved opens 3 pervasives Completion.res Completion.res
11981236
ContextPath Value[_z].""
11991237
ContextPath Value[_z]
12001238
Path _z
1239+
ContextPath Value[_z]->
1240+
ContextPath Value[_z]
1241+
Path _z
12011242
CPPipe pathFromEnv: found:true
12021243
Path Completion.
12031244
[{
@@ -1358,6 +1399,9 @@ Resolved opens 3 pervasives Completion.res Completion.res
13581399
ContextPath Value[funRecord].someFun
13591400
ContextPath Value[funRecord]
13601401
Path funRecord
1402+
ContextPath Value[funRecord]->someFun
1403+
ContextPath Value[funRecord]
1404+
Path funRecord
13611405
CPPipe pathFromEnv: found:true
13621406
Path Completion.someFun
13631407
Found type for function (~name: string) => unit
@@ -1380,6 +1424,10 @@ ContextPath Value[retAA](Nolabel).""
13801424
ContextPath Value[retAA](Nolabel)
13811425
ContextPath Value[retAA]
13821426
Path retAA
1427+
ContextPath Value[retAA](Nolabel, Nolabel)->
1428+
ContextPath Value[retAA](Nolabel, Nolabel)
1429+
ContextPath Value[retAA]
1430+
Path retAA
13831431
CPPipe pathFromEnv: found:true
13841432
Path Completion.
13851433
[{
@@ -1912,6 +1960,9 @@ Resolved opens 3 pervasives Completion.res Completion.res
19121960
ContextPath Value[funRecord].""
19131961
ContextPath Value[funRecord]
19141962
Path funRecord
1963+
ContextPath Value[funRecord]->
1964+
ContextPath Value[funRecord]
1965+
Path funRecord
19151966
CPPipe pathFromEnv: found:true
19161967
Path Completion.
19171968
[{
@@ -2166,6 +2217,9 @@ Resolved opens 3 pervasives Completion.res Completion.res
21662217
ContextPath Value[rWithDepr].so
21672218
ContextPath Value[rWithDepr]
21682219
Path rWithDepr
2220+
ContextPath Value[rWithDepr]->so
2221+
ContextPath Value[rWithDepr]
2222+
Path rWithDepr
21692223
CPPipe pathFromEnv: found:true
21702224
Path Completion.so
21712225
[{

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,9 @@ Resolved opens 1 pervasives
946946
ContextPath Value[fff].someOpt
947947
ContextPath Value[fff]
948948
Path fff
949+
ContextPath Value[fff]->someOpt
950+
ContextPath Value[fff]
951+
Path fff
949952
CPPipe pathFromEnv: found:true
950953
Path CompletionExpressions.someOpt
951954
[{
@@ -1417,6 +1420,9 @@ Resolved opens 2 pervasives CompletionSupport.res
14171420
ContextPath Value[someTyp].""
14181421
ContextPath Value[someTyp]
14191422
Path someTyp
1423+
ContextPath Value[someTyp]->
1424+
ContextPath Value[someTyp]
1425+
Path someTyp
14201426
CPPipe pathFromEnv: found:true
14211427
Path CompletionExpressions.
14221428
[{
@@ -1474,6 +1480,9 @@ Resolved opens 2 pervasives CompletionSupport.res
14741480
ContextPath Value[someTyp].""
14751481
ContextPath Value[someTyp]
14761482
Path someTyp
1483+
ContextPath Value[someTyp]->
1484+
ContextPath Value[someTyp]
1485+
Path someTyp
14771486
CPPipe pathFromEnv: found:true
14781487
Path CompletionExpressions.
14791488
[{

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Resolved opens 1 pervasives
77
ContextPath Value[n].""
88
ContextPath Value[n]
99
Path n
10+
ContextPath Value[n]->
11+
ContextPath Value[n]
12+
Path n
1013
CPPipe pathFromEnv:SomeModule found:true
1114
Path SomeModule.
1215
[{
@@ -38,6 +41,9 @@ Resolved opens 1 pervasives
3841
ContextPath Value[nn].""
3942
ContextPath Value[nn]
4043
Path nn
44+
ContextPath Value[nn]->
45+
ContextPath Value[nn]
46+
Path nn
4147
CPPipe pathFromEnv:SomeOtherModule found:true
4248
Path SomeOtherModule.
4349
Path CompletionFromModule.SomeOtherModule.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Resolved opens 1 pervasives
77
ContextPath Value[CompletionFromModule, n].""
88
ContextPath Value[CompletionFromModule, n]
99
Path CompletionFromModule.n
10+
ContextPath Value[CompletionFromModule, n]->
11+
ContextPath Value[CompletionFromModule, n]
12+
Path CompletionFromModule.n
1013
CPPipe pathFromEnv:SomeModule found:true
1114
Path CompletionFromModule.SomeModule.
1215
[{
@@ -38,6 +41,9 @@ Resolved opens 1 pervasives
3841
ContextPath Value[CompletionFromModule, nn].""
3942
ContextPath Value[CompletionFromModule, nn]
4043
Path CompletionFromModule.nn
44+
ContextPath Value[CompletionFromModule, nn]->
45+
ContextPath Value[CompletionFromModule, nn]
46+
Path CompletionFromModule.nn
4147
CPPipe pathFromEnv:SomeOtherModule found:true
4248
Path CompletionFromModule.SomeOtherModule.
4349
Path CompletionFromModule.SomeOtherModule.

0 commit comments

Comments
 (0)