Skip to content

Commit 92d5930

Browse files
authored
complete builtins from the new stdlib if availabile (#620)
* special case completion for built ins when ReScriptJs is automatically opened * handle more built ins * change target package name to new ReScriptStdLib * look in appropriate opens location
1 parent 6687afc commit 92d5930

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,16 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12831283
|> completionsGetTypeEnv
12841284
with
12851285
| Some (typ, _envNotUsed) -> (
1286-
let arrayModulePath = ["Js"; "Array2"] in
1287-
let listModulePath = ["Belt"; "List"] in
1288-
let optionModulePath = ["Belt"; "Option"] in
1289-
let stringModulePath = ["Js"; "String2"] in
1286+
let {
1287+
arrayModulePath;
1288+
optionModulePath;
1289+
stringModulePath;
1290+
intModulePath;
1291+
floatModulePath;
1292+
promiseModulePath;
1293+
} =
1294+
package.builtInCompletionModules
1295+
in
12901296
let getModulePath path =
12911297
let rec loop (path : Path.t) =
12921298
match path with
@@ -1296,9 +1302,15 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12961302
in
12971303
match path with
12981304
| Path.Pident id when Ident.name id = "array" -> arrayModulePath
1299-
| Path.Pident id when Ident.name id = "list" -> listModulePath
13001305
| Path.Pident id when Ident.name id = "option" -> optionModulePath
13011306
| Path.Pident id when Ident.name id = "string" -> stringModulePath
1307+
| Path.Pident id when Ident.name id = "int" -> intModulePath
1308+
| Path.Pident id when Ident.name id = "float" -> floatModulePath
1309+
| Path.Pident id when Ident.name id = "promise" -> promiseModulePath
1310+
| Path.Pident id when Ident.name id = "list" -> ["Belt"; "List"]
1311+
| Path.Pident id when Ident.name id = "lazy_t" -> ["Lazy"]
1312+
| Path.Pident id when Ident.name id = "result" -> ["Belt"; "Result"]
1313+
| Path.Pident id when Ident.name id = "char" -> ["Char"]
13021314
| _ -> (
13031315
match loop path with
13041316
| _ :: rest -> List.rev rest

analysis/src/Packages.ml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,32 @@ let newBsPackage ~rootPath =
9393
pathsForModule;
9494
opens;
9595
namespace;
96+
builtInCompletionModules =
97+
(if
98+
opens_from_bsc_flags
99+
|> List.find_opt (fun opn ->
100+
match opn with
101+
| ["ReScriptStdLib"] -> true
102+
| _ -> false)
103+
|> Option.is_some
104+
then
105+
{
106+
arrayModulePath = ["Array"];
107+
optionModulePath = ["Option"];
108+
stringModulePath = ["String"];
109+
intModulePath = ["Int"];
110+
floatModulePath = ["Float"];
111+
promiseModulePath = ["Promise"];
112+
}
113+
else
114+
{
115+
arrayModulePath = ["Js"; "Array2"];
116+
optionModulePath = ["Belt"; "Option"];
117+
stringModulePath = ["Js"; "String2"];
118+
intModulePath = ["Belt"; "Int"];
119+
floatModulePath = ["Belt"; "Float"];
120+
promiseModulePath = ["Js"; "Promise"];
121+
});
96122
})))
97123
| None -> None)
98124

analysis/src/SharedTypes.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,22 @@ type file = string
361361

362362
module FileSet = Set.Make (String)
363363

364+
type builtInCompletionModules = {
365+
arrayModulePath: string list;
366+
optionModulePath: string list;
367+
stringModulePath: string list;
368+
intModulePath: string list;
369+
floatModulePath: string list;
370+
promiseModulePath: string list;
371+
}
372+
364373
type package = {
365374
rootPath: filePath;
366375
projectFiles: FileSet.t;
367376
dependenciesFiles: FileSet.t;
368377
pathsForModule: (file, paths) Hashtbl.t;
369378
namespace: string option;
379+
builtInCompletionModules: builtInCompletionModules;
370380
opens: path list;
371381
}
372382

0 commit comments

Comments
 (0)