Skip to content

Commit f659ae6

Browse files
committed
sketch out global completion config setup
1 parent 8f8b2f9 commit f659ae6

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
@@ -467,6 +467,7 @@ ContextPath Value[someArr]->a <<jsx>>
467467
ContextPath Value[someArr]
468468
Path someArr
469469
Path Stdlib.Array.a
470+
Path ArrayUtils.a
470471
[{
471472
"label": "React.array",
472473
"kind": 12,

0 commit comments

Comments
 (0)