diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index b3e257b7f..670792189 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -1283,10 +1283,16 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos |> completionsGetTypeEnv with | Some (typ, _envNotUsed) -> ( - let arrayModulePath = ["Js"; "Array2"] in - let listModulePath = ["Belt"; "List"] in - let optionModulePath = ["Belt"; "Option"] in - let stringModulePath = ["Js"; "String2"] in + let { + arrayModulePath; + optionModulePath; + stringModulePath; + intModulePath; + floatModulePath; + promiseModulePath; + } = + package.builtInCompletionModules + in let getModulePath path = let rec loop (path : Path.t) = match path with @@ -1296,9 +1302,15 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos in match path with | Path.Pident id when Ident.name id = "array" -> arrayModulePath - | Path.Pident id when Ident.name id = "list" -> listModulePath | Path.Pident id when Ident.name id = "option" -> optionModulePath | Path.Pident id when Ident.name id = "string" -> stringModulePath + | Path.Pident id when Ident.name id = "int" -> intModulePath + | Path.Pident id when Ident.name id = "float" -> floatModulePath + | Path.Pident id when Ident.name id = "promise" -> promiseModulePath + | Path.Pident id when Ident.name id = "list" -> ["Belt"; "List"] + | Path.Pident id when Ident.name id = "lazy_t" -> ["Lazy"] + | Path.Pident id when Ident.name id = "result" -> ["Belt"; "Result"] + | Path.Pident id when Ident.name id = "char" -> ["Char"] | _ -> ( match loop path with | _ :: rest -> List.rev rest diff --git a/analysis/src/Packages.ml b/analysis/src/Packages.ml index 81b7b0257..2a4bd73bd 100644 --- a/analysis/src/Packages.ml +++ b/analysis/src/Packages.ml @@ -93,6 +93,32 @@ let newBsPackage ~rootPath = pathsForModule; opens; namespace; + builtInCompletionModules = + (if + opens_from_bsc_flags + |> List.find_opt (fun opn -> + match opn with + | ["ReScriptStdLib"] -> true + | _ -> false) + |> Option.is_some + then + { + arrayModulePath = ["Array"]; + optionModulePath = ["Option"]; + stringModulePath = ["String"]; + intModulePath = ["Int"]; + floatModulePath = ["Float"]; + promiseModulePath = ["Promise"]; + } + else + { + arrayModulePath = ["Js"; "Array2"]; + optionModulePath = ["Belt"; "Option"]; + stringModulePath = ["Js"; "String2"]; + intModulePath = ["Belt"; "Int"]; + floatModulePath = ["Belt"; "Float"]; + promiseModulePath = ["Js"; "Promise"]; + }); }))) | None -> None) diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index 1db9a8ca8..906669e78 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -361,12 +361,22 @@ type file = string module FileSet = Set.Make (String) +type builtInCompletionModules = { + arrayModulePath: string list; + optionModulePath: string list; + stringModulePath: string list; + intModulePath: string list; + floatModulePath: string list; + promiseModulePath: string list; +} + type package = { rootPath: filePath; projectFiles: FileSet.t; dependenciesFiles: FileSet.t; pathsForModule: (file, paths) Hashtbl.t; namespace: string option; + builtInCompletionModules: builtInCompletionModules; opens: path list; }