Skip to content

Commit 75ce70a

Browse files
authored
Add pipe completions from current module (#7471)
* Add pipe completions from current module * Update snapshot * Fix snapshot
1 parent fd26d3a commit 75ce70a

28 files changed

+359
-2
lines changed

analysis/src/CompletionBackEnd.ml

+8-1
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,15 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
11731173
~full ~rawOpens typ
11741174
else []
11751175
in
1176+
(* Add completions from the current module. *)
1177+
let currentModuleCompletions =
1178+
completionsForPipeFromCompletionPath ~envCompletionIsMadeFrom
1179+
~opens:[] ~pos ~scope ~debug ~prefix ~env ~rawOpens ~full []
1180+
|> TypeUtils.filterPipeableFunctions ~synthetic:true ~env ~full
1181+
~targetTypeId:mainTypeId
1182+
in
11761183
jsxCompletions @ pipeCompletions @ extraCompletions
1177-
@ globallyConfiguredCompletions))
1184+
@ currentModuleCompletions @ globallyConfiguredCompletions))
11781185
| CTuple ctxPaths ->
11791186
if Debug.verbose () then print_endline "[ctx_path]--> CTuple";
11801187
(* Turn a list of context paths into a list of type expressions. *)

tests/analysis_tests/tests-generic-jsx-transform/src/expected/GenericJsxCompletion.res.txt

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ ContextPath Value[someString]->st <<jsx>>
6363
ContextPath Value[someString]
6464
Path someString
6565
Path Stdlib.String.st
66+
Path st
6667
[{
6768
"label": "GenericJsx.string",
6869
"kind": 12,
@@ -104,6 +105,7 @@ ContextPath Value[someString]->st <<jsx>>
104105
ContextPath Value[someString]
105106
Path someString
106107
Path Stdlib.String.st
108+
Path st
107109
[{
108110
"label": "string",
109111
"kind": 12,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module X = {
2+
type t
3+
}
4+
5+
module Y = {
6+
open X
7+
8+
let z = (x: t) => ""
9+
10+
let a = (x:t) => {
11+
// x.
12+
// ^com
13+
()
14+
}
15+
16+
let b = (x:t) => 4
17+
}

tests/analysis_tests/tests/src/expected/CompletePrioritize1.res.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ContextPath Value[a]
88
Path a
99
CPPipe pathFromEnv:Test found:true
1010
Path Test.
11+
Path
1112
[{
1213
"label": "Test.name",
1314
"kind": 12,

tests/analysis_tests/tests/src/expected/CompletePrioritize2.res.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ContextPath Value[ax]
88
Path ax
99
CPPipe pathFromEnv:Test found:true
1010
Path Test.
11+
Path
1112
[{
1213
"label": "Test.add",
1314
"kind": 12,

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

+31
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ ContextPath array<int>->m
634634
ContextPath array<int>
635635
Path Stdlib.Array.m
636636
Path ArrayUtils.m
637+
Path m
637638
[{
638639
"label": "Array.map",
639640
"kind": 12,
@@ -656,6 +657,7 @@ Resolved opens 1 Stdlib
656657
ContextPath string->toU
657658
ContextPath string
658659
Path Stdlib.String.toU
660+
Path toU
659661
[{
660662
"label": "String.toUpperCase",
661663
"kind": 12,
@@ -673,6 +675,7 @@ ContextPath Value[op]->e
673675
ContextPath Value[op]
674676
Path op
675677
Path Stdlib.Option.e
678+
Path e
676679
[{
677680
"label": "Option.equal",
678681
"kind": 12,
@@ -693,6 +696,7 @@ ContextPath Value[fa]
693696
Path fa
694697
CPPipe pathFromEnv:ForAuto found:true
695698
Path ForAuto.
699+
Path
696700
[{
697701
"label": "ForAuto.abc",
698702
"kind": 12,
@@ -932,6 +936,7 @@ ContextPath Value[r]
932936
Path r
933937
CPPipe pathFromEnv: found:true
934938
Path Completion.
939+
Path
935940
[{
936941
"label": "x",
937942
"kind": 5,
@@ -960,6 +965,7 @@ ContextPath Value[Objects, Rec, recordVal]
960965
Path Objects.Rec.recordVal
961966
CPPipe pathFromEnv:Rec found:true
962967
Path Objects.Rec.
968+
Path
963969
[{
964970
"label": "xx",
965971
"kind": 5,
@@ -1046,6 +1052,7 @@ ContextPath Value[q]
10461052
Path q
10471053
CPPipe pathFromEnv: found:true
10481054
Path Completion.aa
1055+
Path aa
10491056
ContextPath Value[q].aa->
10501057
ContextPath Value[q].aa
10511058
ContextPath Value[q]
@@ -1055,8 +1062,10 @@ ContextPath Value[q]
10551062
Path q
10561063
CPPipe pathFromEnv: found:true
10571064
Path Completion.aa
1065+
Path aa
10581066
CPPipe pathFromEnv: found:true
10591067
Path Completion.
1068+
Path
10601069
[{
10611070
"label": "x",
10621071
"kind": 5,
@@ -1086,6 +1095,7 @@ ContextPath Value[q]
10861095
Path q
10871096
CPPipe pathFromEnv: found:true
10881097
Path Completion.aa
1098+
Path aa
10891099
ContextPath Value[q].aa->n
10901100
ContextPath Value[q].aa
10911101
ContextPath Value[q]
@@ -1095,8 +1105,10 @@ ContextPath Value[q]
10951105
Path q
10961106
CPPipe pathFromEnv: found:true
10971107
Path Completion.aa
1108+
Path aa
10981109
CPPipe pathFromEnv: found:true
10991110
Path Completion.n
1111+
Path n
11001112
[{
11011113
"label": "name",
11021114
"kind": 5,
@@ -1307,6 +1319,7 @@ ContextPath Value[FAO, forAutoObject]
13071319
Path FAO.forAutoObject
13081320
CPPipe pathFromEnv:FAR found:true
13091321
Path FAR.
1322+
Path
13101323
[{
13111324
"label": "forAuto",
13121325
"kind": 5,
@@ -1338,8 +1351,10 @@ ContextPath Value[FAO, forAutoObject]
13381351
Path FAO.forAutoObject
13391352
CPPipe pathFromEnv:FAR found:true
13401353
Path FAR.forAuto
1354+
Path forAuto
13411355
CPPipe pathFromEnv:ForAuto found:false
13421356
Path ForAuto.
1357+
Path
13431358
[{
13441359
"label": "ForAuto.abc",
13451360
"kind": 12,
@@ -1352,6 +1367,12 @@ Path ForAuto.
13521367
"tags": [],
13531368
"detail": "(t, int) => t",
13541369
"documentation": null
1370+
}, {
1371+
"label": "myAmazingFunction",
1372+
"kind": 12,
1373+
"tags": [],
1374+
"detail": "(int, int) => int",
1375+
"documentation": null
13551376
}]
13561377

13571378
Complete src/Completion.res 230:55
@@ -1424,6 +1445,7 @@ ContextPath Value[_z]
14241445
Path _z
14251446
CPPipe pathFromEnv: found:true
14261447
Path Completion.
1448+
Path
14271449
[{
14281450
"label": "x",
14291451
"kind": 5,
@@ -1586,6 +1608,7 @@ ContextPath Value[funRecord]
15861608
Path funRecord
15871609
CPPipe pathFromEnv: found:true
15881610
Path Completion.someFun
1611+
Path someFun
15891612
Found type for function (~name: string) => unit
15901613
[{
15911614
"label": "name",
@@ -1612,6 +1635,7 @@ ContextPath Value[retAA]
16121635
Path retAA
16131636
CPPipe pathFromEnv: found:true
16141637
Path Completion.
1638+
Path
16151639
[{
16161640
"label": "x",
16171641
"kind": 5,
@@ -2191,6 +2215,7 @@ ContextPath Value[funRecord]
21912215
Path funRecord
21922216
CPPipe pathFromEnv: found:true
21932217
Path Completion.
2218+
Path
21942219
[{
21952220
"label": "someFun",
21962221
"kind": 5,
@@ -2217,6 +2242,7 @@ ContextPath array->ma
22172242
ContextPath array
22182243
Path Stdlib.Array.ma
22192244
Path ArrayUtils.ma
2245+
Path ma
22202246
[{
22212247
"label": "Array.map",
22222248
"kind": 12,
@@ -2369,6 +2395,7 @@ Resolved opens 3 Stdlib Completion Completion
23692395
ContextPath int->t
23702396
ContextPath int
23712397
Path Stdlib.Int.t
2398+
Path t
23722399
[{
23732400
"label": "Int.toStringWithRadix",
23742401
"kind": 12,
@@ -2440,6 +2467,7 @@ Resolved opens 3 Stdlib Completion Completion
24402467
ContextPath float->t
24412468
ContextPath float
24422469
Path Stdlib.Float.t
2470+
Path t
24432471
[{
24442472
"label": "Float.toStringWithRadix",
24452473
"kind": 12,
@@ -2512,6 +2540,7 @@ ContextPath Value[ok]->g
25122540
ContextPath Value[ok]
25132541
Path ok
25142542
Path Stdlib.Result.g
2543+
Path g
25152544
[{
25162545
"label": "Result.getExn",
25172546
"kind": 12,
@@ -2547,6 +2576,7 @@ ContextPath Value[rWithDepr]
25472576
Path rWithDepr
25482577
CPPipe pathFromEnv: found:true
25492578
Path Completion.so
2579+
Path so
25502580
[{
25512581
"label": "someInt",
25522582
"kind": 5,
@@ -2606,6 +2636,7 @@ ContextPath Value[uncurried](Nolabel)
26062636
ContextPath Value[uncurried]
26072637
Path uncurried
26082638
Path Stdlib.Int.toS
2639+
Path toS
26092640
[{
26102641
"label": "Int.toStringWithRadix",
26112642
"kind": 12,

tests/analysis_tests/tests/src/expected/CompletionConfiguredBuiltins.res.txt

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ContextPath Value[x]
88
Path x
99
Path Stdlib.Array.em
1010
Path ArrayUtils.em
11+
Path em
1112
[{
1213
"label": "ArrayUtils.empty",
1314
"kind": 12,
@@ -27,6 +28,7 @@ Path fastify
2728
CPPipe pathFromEnv:Fastify found:false
2829
Path Fastify.doSt
2930
Path FastifyExt.doSt
31+
Path doSt
3032
[{
3133
"label": "FastifyExt.doStuff",
3234
"kind": 12,

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

+3
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ ContextPath Value[fff]
10121012
Path fff
10131013
CPPipe pathFromEnv: found:true
10141014
Path CompletionExpressions.someOpt
1015+
Path someOpt
10151016
[{
10161017
"label": "someOptField",
10171018
"kind": 5,
@@ -1486,6 +1487,7 @@ ContextPath Value[someTyp]
14861487
Path someTyp
14871488
CPPipe pathFromEnv: found:true
14881489
Path CompletionExpressions.
1490+
Path
14891491
[{
14901492
"label": "test",
14911493
"kind": 5,
@@ -1546,6 +1548,7 @@ ContextPath Value[someTyp]
15461548
Path someTyp
15471549
CPPipe pathFromEnv: found:true
15481550
Path CompletionExpressions.
1551+
Path
15491552
[{
15501553
"label": "test",
15511554
"kind": 5,

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

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ContextPath Value[n]
1212
Path n
1313
CPPipe pathFromEnv:SomeModule found:true
1414
Path SomeModule.
15+
Path
1516
[{
1617
"label": "name",
1718
"kind": 5,
@@ -47,6 +48,7 @@ Path nn
4748
CPPipe pathFromEnv:SomeOtherModule found:true
4849
Path SomeOtherModule.
4950
Path CompletionFromModule.SomeOtherModule.
51+
Path
5052
[{
5153
"label": "nname",
5254
"kind": 5,
@@ -129,6 +131,7 @@ Path nnn
129131
CPPipe pathFromEnv: found:true
130132
Path CompletionFromModule.
131133
Path CompletionFromModule.SomeOtherModule.
134+
Path
132135
[{
133136
"label": "SomeOtherModule.getNName",
134137
"kind": 12,
@@ -155,6 +158,7 @@ Path nnn
155158
CPPipe pathFromEnv: found:true
156159
Path CompletionFromModule.
157160
Path CompletionFromModule.SomeOtherModule.
161+
Path
158162
[{
159163
"label": "getNName",
160164
"kind": 12,

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

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ContextPath Value[CompletionFromModule, n]
1212
Path CompletionFromModule.n
1313
CPPipe pathFromEnv:SomeModule found:true
1414
Path CompletionFromModule.SomeModule.
15+
Path
1516
[{
1617
"label": "name",
1718
"kind": 5,
@@ -47,6 +48,7 @@ Path CompletionFromModule.nn
4748
CPPipe pathFromEnv:SomeOtherModule found:true
4849
Path CompletionFromModule.SomeOtherModule.
4950
Path CompletionFromModule.SomeOtherModule.
51+
Path
5052
[{
5153
"label": "nname",
5254
"kind": 5,
@@ -114,6 +116,7 @@ Path CompletionFromModule.nnn
114116
CPPipe pathFromEnv: found:true
115117
Path CompletionFromModule.
116118
Path CompletionFromModule.SomeOtherModule.
119+
Path
117120
[{
118121
"label": "CompletionFromModule.SomeOtherModule.getNName",
119122
"kind": 12,
@@ -140,6 +143,7 @@ Path CompletionFromModule.nnn
140143
CPPipe pathFromEnv: found:true
141144
Path CompletionFromModule.
142145
Path CompletionFromModule.SomeOtherModule.
146+
Path
143147
[{
144148
"label": "getNName",
145149
"kind": 12,

tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt

+3
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ ContextPath Value[thisGetsBrokenLoc]
438438
Path thisGetsBrokenLoc
439439
CPPipe pathFromEnv:JsxEvent.Mouse found:false
440440
Path JsxEvent.Mouse.a
441+
Path a
441442
[{
442443
"label": "JsxEvent.Mouse.altKey",
443444
"kind": 12,
@@ -461,6 +462,7 @@ ContextPath Value[reassignedWorks]
461462
Path reassignedWorks
462463
CPPipe pathFromEnv:JsxEvent.Mouse found:false
463464
Path JsxEvent.Mouse.a
465+
Path a
464466
[{
465467
"label": "JsxEvent.Mouse.altKey",
466468
"kind": 12,
@@ -482,6 +484,7 @@ ContextPath Value[fineModuleVal]
482484
Path fineModuleVal
483485
CPPipe pathFromEnv:FineModule found:true
484486
Path FineModule.
487+
Path
485488
[{
486489
"label": "FineModule.setToFalse",
487490
"kind": 12,

0 commit comments

Comments
 (0)