Skip to content

Commit 0051096

Browse files
Read autocompleteConfig from rescript.json
1 parent 3b228c5 commit 0051096

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

analysis/src/CompletionBackEnd.ml

+1-6
Original file line numberDiff line numberDiff line change
@@ -1136,14 +1136,9 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
11361136
else true)
11371137
in
11381138

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
11441139
let globallyConfiguredCompletionsForType =
11451140
match
1146-
pretendPackageBuiltinsConfig |> Misc.StringMap.find_opt mainTypeId
1141+
package.autocompleteConfig |> Misc.StringMap.find_opt mainTypeId
11471142
with
11481143
| None -> []
11491144
| Some completionPaths ->

analysis/src/Packages.ml

+23
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ let newBsPackage ~rootPath =
6666
| _ -> None)
6767
| None -> None
6868
in
69+
let autocompleteConfig =
70+
match config |> Json.get "editor" with
71+
| Some editorConfig -> (
72+
match editorConfig |> Json.get "autocompleteConfig" with
73+
| Some (Object map) ->
74+
map
75+
|> List.fold_left
76+
(fun acc (key, value) ->
77+
match value with
78+
| Json.Array items ->
79+
let values =
80+
items
81+
|> List.filter_map (function
82+
| Json.String s -> Some s
83+
| _ -> None)
84+
in
85+
Misc.StringMap.add key values acc
86+
| _ -> acc)
87+
Misc.StringMap.empty
88+
| _ -> Misc.StringMap.empty)
89+
| None -> Misc.StringMap.empty
90+
in
6991
let uncurried = uncurried = Some true in
7092
match libBs with
7193
| None -> None
@@ -158,6 +180,7 @@ let newBsPackage ~rootPath =
158180
opens;
159181
namespace;
160182
uncurried;
183+
autocompleteConfig;
161184
}))
162185
| None -> None
163186
in

analysis/src/SharedTypes.ml

+1
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ type package = {
494494
opens: path list;
495495
uncurried: bool;
496496
rescriptVersion: int * int;
497+
autocompleteConfig: file list Misc.StringMap.t;
497498
}
498499

499500
let allFilesInPackage package =

0 commit comments

Comments
 (0)