Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions analysis/src/Packages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions analysis/src/SharedTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down