Skip to content

Commit 3f34b26

Browse files
committed
sketch out global completion config setup
1 parent 974674e commit 3f34b26

15 files changed

+91
-7
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,32 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
11351135
| _ -> false
11361136
else true)
11371137
in
1138+
1139+
(* TODO(config-complete-builtins) This config and config resolution should come from `package` instead. *)
1140+
let pretendPackageBuiltinsConfig =
1141+
Misc.StringMap.of_list
1142+
[("array", ["ArrayUtils"]); ("Fastify.t", ["FastifyExt"])]
1143+
in
1144+
let globallyConfiguredCompletionsForType =
1145+
match
1146+
pretendPackageBuiltinsConfig |> Misc.StringMap.find_opt mainTypeId
1147+
with
1148+
| None -> []
1149+
| Some completionPaths ->
1150+
completionPaths |> List.map (fun p -> String.split_on_char '.' p)
1151+
in
1152+
1153+
let globallyConfiguredCompletions =
1154+
globallyConfiguredCompletionsForType
1155+
|> List.map (fun completionPath ->
1156+
completionsForPipeFromCompletionPath ~envCompletionIsMadeFrom
1157+
~opens ~pos ~scope ~debug ~prefix ~env ~rawOpens ~full
1158+
completionPath)
1159+
|> List.flatten
1160+
|> TypeUtils.filterPipeableFunctions ~synthetic:true ~env ~full
1161+
~targetTypeId:mainTypeId
1162+
in
1163+
11381164
(* Extra completions can be drawn from the @editor.completeFrom attribute. Here we
11391165
find and add those completions as well. *)
11401166
let extraCompletions =
@@ -1154,7 +1180,8 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
11541180
~full ~rawOpens typ
11551181
else []
11561182
in
1157-
jsxCompletions @ pipeCompletions @ extraCompletions))
1183+
jsxCompletions @ pipeCompletions @ extraCompletions
1184+
@ globallyConfiguredCompletions))
11581185
| CTuple ctxPaths ->
11591186
if Debug.verbose () then print_endline "[ctx_path]--> CTuple";
11601187
(* Turn a list of context paths into a list of type expressions. *)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let empty = arr => Array.length(arr) === 0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let x = [1, 2, 3]
2+
3+
// x->em
4+
// ^com
5+
6+
external fastify: Fastify.t = "fastify"
7+
8+
// fastify->doSt
9+
// ^com
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type t
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let doStuff = (t: Fastify.t) => Console.log(t)

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

Whitespace-only changes.

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

Lines changed: 3 additions & 1 deletion
Large diffs are not rendered by default.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Complete src/CompletionConfiguredBuiltins.res 2:8
2+
posCursor:[2:8] posNoWhite:[2:7] Found expr:[2:3->2:8]
3+
Completable: Cpath Value[x]->em
4+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
5+
Resolved opens 1 Stdlib
6+
ContextPath Value[x]->em
7+
ContextPath Value[x]
8+
Path x
9+
Path Stdlib.Array.em
10+
Path ArrayUtils.em
11+
[{
12+
"label": "ArrayUtils.empty",
13+
"kind": 12,
14+
"tags": [],
15+
"detail": "array<'a> => bool",
16+
"documentation": null
17+
}]
18+
19+
Complete src/CompletionConfiguredBuiltins.res 7:16
20+
posCursor:[7:16] posNoWhite:[7:15] Found expr:[7:3->7:16]
21+
Completable: Cpath Value[fastify]->doSt
22+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
23+
Resolved opens 1 Stdlib
24+
ContextPath Value[fastify]->doSt
25+
ContextPath Value[fastify]
26+
Path fastify
27+
CPPipe pathFromEnv:Fastify found:false
28+
Path Fastify.doSt
29+
Path FastifyExt.doSt
30+
[{
31+
"label": "FastifyExt.doStuff",
32+
"kind": 12,
33+
"tags": [],
34+
"detail": "Fastify.t => unit",
35+
"documentation": null
36+
}]
37+

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ ContextPath Value[String, split](Nolabel, Nolabel)
415415
ContextPath Value[String, split]
416416
Path String.split
417417
Path Stdlib.Array.ma
418+
Path ArrayUtils.ma
418419
[{
419420
"label": "Array.map",
420421
"kind": 12,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ ContextPath Value[someArr]->a <<jsx>>
527527
ContextPath Value[someArr]
528528
Path someArr
529529
Path Stdlib.Array.a
530+
Path ArrayUtils.a
530531
[{
531532
"label": "React.array",
532533
"kind": 12,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ Path withDate
4040
"label": "Date.makeWithYMD()",
4141
"kind": 12,
4242
"tags": [],
43-
"detail": "(~year: int, ~month: int, ~day: int) => t",
43+
"detail": "(~year: int, ~month: int, ~date: int) => t",
4444
"documentation": null,
4545
"insertText": "Date.makeWithYMD($0)",
4646
"insertTextFormat": 2
4747
}, {
4848
"label": "Date.makeWithYMDHM()",
4949
"kind": 12,
5050
"tags": [],
51-
"detail": "(\n ~year: int,\n ~month: int,\n ~day: int,\n ~hours: int,\n ~minutes: int,\n) => t",
51+
"detail": "(\n ~year: int,\n ~month: int,\n ~date: int,\n ~hours: int,\n ~minutes: int,\n) => t",
5252
"documentation": null,
5353
"insertText": "Date.makeWithYMDHM($0)",
5454
"insertTextFormat": 2
@@ -80,7 +80,7 @@ Path withDate
8080
"label": "Date.makeWithYMDHMSM()",
8181
"kind": 12,
8282
"tags": [],
83-
"detail": "(\n ~year: int,\n ~month: int,\n ~day: int,\n ~hours: int,\n ~minutes: int,\n ~seconds: int,\n ~milliseconds: int,\n) => t",
83+
"detail": "(\n ~year: int,\n ~month: int,\n ~date: int,\n ~hours: int,\n ~minutes: int,\n ~seconds: int,\n ~milliseconds: int,\n) => t",
8484
"documentation": null,
8585
"insertText": "Date.makeWithYMDHMSM($0)",
8686
"insertTextFormat": 2
@@ -96,15 +96,15 @@ Path withDate
9696
"label": "Date.makeWithYMDHMS()",
9797
"kind": 12,
9898
"tags": [],
99-
"detail": "(\n ~year: int,\n ~month: int,\n ~day: int,\n ~hours: int,\n ~minutes: int,\n ~seconds: int,\n) => t",
99+
"detail": "(\n ~year: int,\n ~month: int,\n ~date: int,\n ~hours: int,\n ~minutes: int,\n ~seconds: int,\n) => t",
100100
"documentation": null,
101101
"insertText": "Date.makeWithYMDHMS($0)",
102102
"insertTextFormat": 2
103103
}, {
104104
"label": "Date.makeWithYMDH()",
105105
"kind": 12,
106106
"tags": [],
107-
"detail": "(~year: int, ~month: int, ~day: int, ~hours: int) => t",
107+
"detail": "(~year: int, ~month: int, ~date: int, ~hours: int) => t",
108108
"documentation": null,
109109
"insertText": "Date.makeWithYMDH($0)",
110110
"insertTextFormat": 2

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ ContextPath Value[ffff]->u
216216
ContextPath Value[ffff]
217217
Path ffff
218218
Path Stdlib.Array.u
219+
Path ArrayUtils.u
219220
[{
220221
"label": "->Array.unshiftMany",
221222
"kind": 12,
@@ -329,6 +330,7 @@ ContextPath Value[Array, filter](Nolabel, Nolabel)
329330
ContextPath Value[Array, filter]
330331
Path Array.filter
331332
Path Stdlib.Array.filt
333+
Path ArrayUtils.filt
332334
[{
333335
"label": "->Array.filterMap",
334336
"kind": 12,

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

Whitespace-only changes.

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

Whitespace-only changes.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Path t
1313
CPPipe pathFromEnv: found:true
1414
Path RecordCompletion.n
1515
Path Stdlib.Array.m
16+
Path ArrayUtils.m
1617
[{
1718
"label": "Array.map",
1819
"kind": 12,
@@ -54,6 +55,7 @@ Path RecordCompletion.n2
5455
CPPipe pathFromEnv: found:true
5556
Path RecordCompletion.n
5657
Path Stdlib.Array.m
58+
Path ArrayUtils.m
5759
[{
5860
"label": "Array.map",
5961
"kind": 12,

0 commit comments

Comments
 (0)