Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analysis tests fixes #7295

Merged
merged 8 commits into from
Feb 15, 2025
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#### :nail_care: Polish

- Allow single newline in JSX. https://github.com/rescript-lang/rescript/pull/7269
- Editor: Always complete from Core first. Use actual native regex syntax in code snippets for regexps. https://github.com/rescript-lang/rescript/pull/7295

#### :bug: Bug fix

Expand All @@ -29,6 +30,7 @@
#### :house: Internal

- Remove ignore in res_scanner.ml . https://github.com/rescript-lang/rescript/pull/7280
- Use the new stdlib modules in the analysis tests. https://github.com/rescript-lang/rescript/pull/7295

# 12.0.0-alpha.8

Expand Down
18 changes: 6 additions & 12 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1090,8 +1090,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
*)
let completeAsBuiltin =
match typePath with
| Some t ->
TypeUtils.completionPathFromMaybeBuiltin t ~package:full.package
| Some t -> TypeUtils.completionPathFromMaybeBuiltin t
| None -> None
in
let completionPath =
Expand Down Expand Up @@ -1452,9 +1451,10 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
(* Special casing for things where we want extra things in the completions *)
let completionItems =
match path with
| Pdot (Pdot (Pident m, "Re", _), "t", _) when Ident.name m = "Js" ->
| Pdot (Pdot (Pident {name = "Js"}, "Re", _), "t", _)
| Pdot (Pident {name = "RegExp"}, "t", _) ->
(* regexps *)
create "%re()" ~insertText:"%re(\"/$0/g\")" ~includesSnippets:true
create "/<regexp>/g" ~insertText:"/$0/g" ~includesSnippets:true
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do this now since regexp syntax is now 1st class.

~kind:(Label "Regular expression") ~env
:: completionItems
| _ -> completionItems
Expand Down Expand Up @@ -1801,8 +1801,7 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
if Debug.verbose () then print_endline "[complete_typed_value]--> Texn";
[
create
(full.package.builtInCompletionModules.exnModulePath @ ["Error(error)"]
|> ident)
(["Exn"; "Error(error)"] |> ident)
~kind:(Label "Catches errors from JavaScript errors.")
~docstring:
[
Expand Down Expand Up @@ -2244,12 +2243,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
| _ -> items)))
| CexhaustiveSwitch {contextPath; exprLoc} ->
let range = Utils.rangeOfLoc exprLoc in
let rescriptMajor, rescriptMinor = Packages.getReScriptVersion () in
let printFailwithStr num =
if (rescriptMajor = 11 && rescriptMinor >= 1) || rescriptMajor >= 12 then
"${" ^ string_of_int num ^ ":%todo}"
else "${" ^ string_of_int num ^ ":failwith(\"todo\")}"
in
let printFailwithStr num = "${" ^ string_of_int num ^ ":%todo}" in
let withExhaustiveItem ~cases ?(startIndex = 0) (c : Completion.t) =
(* We don't need to write out `switch` here since we know that's what the
user has already written. Just complete for the rest. *)
Expand Down
55 changes: 0 additions & 55 deletions analysis/src/Packages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -148,61 +148,6 @@ let newBsPackage ~rootPath =
pathsForModule;
opens;
namespace;
builtInCompletionModules =
(if
opens_from_bsc_flags
|> List.find_opt (fun opn ->
match opn with
| ["RescriptCore"] -> true
| _ -> false)
|> Option.is_some
|| fst rescriptVersion >= 12
then
{
arrayModulePath = ["Array"];
optionModulePath = ["Option"];
stringModulePath = ["String"];
intModulePath = ["Int"];
floatModulePath = ["Float"];
promiseModulePath = ["Promise"];
listModulePath = ["List"];
resultModulePath = ["Result"];
exnModulePath = ["Exn"];
regexpModulePath = ["RegExp"];
}
else if
opens_from_bsc_flags
|> List.find_opt (fun opn ->
match opn with
| ["Belt"] -> true
| _ -> false)
|> Option.is_some
then
{
arrayModulePath = ["Array"];
optionModulePath = ["Option"];
stringModulePath = ["Js"; "String2"];
intModulePath = ["Int"];
floatModulePath = ["Float"];
promiseModulePath = ["Js"; "Promise"];
listModulePath = ["List"];
resultModulePath = ["Result"];
exnModulePath = ["Js"; "Exn"];
regexpModulePath = ["Js"; "Re"];
}
else
{
arrayModulePath = ["Js"; "Array2"];
optionModulePath = ["Belt"; "Option"];
stringModulePath = ["Js"; "String2"];
intModulePath = ["Belt"; "Int"];
floatModulePath = ["Belt"; "Float"];
promiseModulePath = ["Js"; "Promise"];
listModulePath = ["Belt"; "List"];
resultModulePath = ["Belt"; "Result"];
exnModulePath = ["Js"; "Exn"];
regexpModulePath = ["Js"; "Re"];
});
Comment on lines -151 to -205
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

builtInCompletionModules are not needed now that Core is in the compiler repo. But, we are going to make these configurable through the project config soon.

uncurried;
}))
| None -> None
Expand Down
14 changes: 0 additions & 14 deletions analysis/src/SharedTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -483,19 +483,6 @@ 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;
listModulePath: string list;
resultModulePath: string list;
exnModulePath: string list;
regexpModulePath: string list;
}

type package = {
genericJsxModule: string option;
suffix: string;
Expand All @@ -504,7 +491,6 @@ type package = {
dependenciesFiles: FileSet.t;
pathsForModule: (file, paths) Hashtbl.t;
namespace: string option;
builtInCompletionModules: builtInCompletionModules;
opens: path list;
uncurried: bool;
rescriptVersion: int * int;
Expand Down
19 changes: 9 additions & 10 deletions analysis/src/TypeUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1253,17 +1253,16 @@ let pathToBuiltin path =
Predef.builtin_idents
|> List.find_opt (fun (_, i) -> Ident.same i (Path.head path))

let completionPathFromMaybeBuiltin path ~package =
let completionPathFromMaybeBuiltin path =
match pathToBuiltin path with
| Some ("array", _) -> Some package.builtInCompletionModules.arrayModulePath
| Some ("option", _) -> Some package.builtInCompletionModules.optionModulePath
| Some ("string", _) -> Some package.builtInCompletionModules.stringModulePath
| Some ("int", _) -> Some package.builtInCompletionModules.intModulePath
| Some ("float", _) -> Some package.builtInCompletionModules.floatModulePath
| Some ("promise", _) ->
Some package.builtInCompletionModules.promiseModulePath
| Some ("list", _) -> Some package.builtInCompletionModules.listModulePath
| Some ("result", _) -> Some package.builtInCompletionModules.resultModulePath
| Some ("array", _) -> Some ["Array"]
| Some ("option", _) -> Some ["Option"]
| Some ("string", _) -> Some ["String"]
| Some ("int", _) -> Some ["Int"]
| Some ("float", _) -> Some ["Float"]
| Some ("promise", _) -> Some ["Promise"]
| Some ("list", _) -> Some ["List"]
| Some ("result", _) -> Some ["Result"]
| Some ("dict", _) -> Some ["Dict"]
| Some ("char", _) -> Some ["Char"]
| _ -> None

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Package opens Pervasives.JsxModules.place holder
ContextPath Value[someString]->st <<jsx>>
ContextPath Value[someString]
Path someString
Path Js.String2.st
Path String.st
[{
"label": "GenericJsx.string",
"kind": 12,
Expand All @@ -69,17 +69,17 @@ Path Js.String2.st
"sortText": "A",
"insertTextFormat": 2
}, {
"label": "Js.String2.startsWith",
"label": "String.startsWith",
"kind": 12,
"tags": [],
"detail": "(t, t) => bool",
"documentation": {"kind": "markdown", "value": "\nES2015: `startsWith(str, substr)` returns `true` if the `str` starts with\n`substr`, `false` otherwise.\n\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)\non MDN.\n\n## Examples\n\n```rescript\nJs.String2.startsWith(\"ReScript\", \"Re\") == true\nJs.String2.startsWith(\"ReScript\", \"\") == true\nJs.String2.startsWith(\"JavaScript\", \"Re\") == false\n```\n"}
"detail": "(string, string) => bool",
"documentation": {"kind": "markdown", "value": "\n`startsWith(str, substr)` returns `true` if the `str` starts with `substr`,\n`false` otherwise.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWith(\"BuckleScript\", \"Buckle\") == true\nString.startsWith(\"BuckleScript\", \"\") == true\nString.startsWith(\"JavaScript\", \"Buckle\") == false\n```\n"}
}, {
"label": "Js.String2.startsWithFrom",
"label": "String.startsWithFrom",
"kind": 12,
"tags": [],
"detail": "(t, t, int) => bool",
"documentation": {"kind": "markdown", "value": "\nES2015: `startsWithFrom(str, substr, n)` returns `true` if the `str` starts\nwith `substr` starting at position `n`, false otherwise. If `n` is negative,\nthe search starts at the beginning of `str`.\n\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)\non MDN.\n\n## Examples\n\n```rescript\nJs.String2.startsWithFrom(\"ReScript\", \"Scri\", 2) == true\nJs.String2.startsWithFrom(\"ReScript\", \"\", 2) == true\nJs.String2.startsWithFrom(\"JavaScript\", \"Scri\", 2) == false\n```\n"}
"detail": "(string, string, int) => bool",
"documentation": {"kind": "markdown", "value": "\n`startsWithFrom(str, substr, n)` returns `true` if the `str` starts\nwith `substr` starting at position `n`, `false` otherwise. If `n` is negative,\nthe search starts at the beginning of `str`.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWithFrom(\"BuckleScript\", \"kle\", 3) == true\nString.startsWithFrom(\"BuckleScript\", \"\", 3) == true\nString.startsWithFrom(\"JavaScript\", \"Buckle\", 2) == false\n```\n"}
}]

Complete src/GenericJsxCompletion.res 20:24
Expand All @@ -106,7 +106,7 @@ Resolved opens 1 GenericJsx
ContextPath Value[someString]->st <<jsx>>
ContextPath Value[someString]
Path someString
Path Js.String2.st
Path String.st
[{
"label": "string",
"kind": 12,
Expand All @@ -116,16 +116,16 @@ Path Js.String2.st
"sortText": "A",
"insertTextFormat": 2
}, {
"label": "Js.String2.startsWith",
"label": "String.startsWith",
"kind": 12,
"tags": [],
"detail": "(t, t) => bool",
"documentation": {"kind": "markdown", "value": "\nES2015: `startsWith(str, substr)` returns `true` if the `str` starts with\n`substr`, `false` otherwise.\n\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)\non MDN.\n\n## Examples\n\n```rescript\nJs.String2.startsWith(\"ReScript\", \"Re\") == true\nJs.String2.startsWith(\"ReScript\", \"\") == true\nJs.String2.startsWith(\"JavaScript\", \"Re\") == false\n```\n"}
"detail": "(string, string) => bool",
"documentation": {"kind": "markdown", "value": "\n`startsWith(str, substr)` returns `true` if the `str` starts with `substr`,\n`false` otherwise.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWith(\"BuckleScript\", \"Buckle\") == true\nString.startsWith(\"BuckleScript\", \"\") == true\nString.startsWith(\"JavaScript\", \"Buckle\") == false\n```\n"}
}, {
"label": "Js.String2.startsWithFrom",
"label": "String.startsWithFrom",
"kind": 12,
"tags": [],
"detail": "(t, t, int) => bool",
"documentation": {"kind": "markdown", "value": "\nES2015: `startsWithFrom(str, substr, n)` returns `true` if the `str` starts\nwith `substr` starting at position `n`, false otherwise. If `n` is negative,\nthe search starts at the beginning of `str`.\n\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)\non MDN.\n\n## Examples\n\n```rescript\nJs.String2.startsWithFrom(\"ReScript\", \"Scri\", 2) == true\nJs.String2.startsWithFrom(\"ReScript\", \"\", 2) == true\nJs.String2.startsWithFrom(\"JavaScript\", \"Scri\", 2) == false\n```\n"}
"detail": "(string, string, int) => bool",
"documentation": {"kind": "markdown", "value": "\n`startsWithFrom(str, substr, n)` returns `true` if the `str` starts\nwith `substr` starting at position `n`, `false` otherwise. If `n` is negative,\nthe search starts at the beginning of `str`.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWithFrom(\"BuckleScript\", \"kle\", 3) == true\nString.startsWithFrom(\"BuckleScript\", \"\", 3) == true\nString.startsWithFrom(\"JavaScript\", \"Buckle\", 2) == false\n```\n"}
}]

13 changes: 6 additions & 7 deletions tests/analysis_tests/tests/src/Completion.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module MyList = Belt.List
module MyList = List
// MyList.m
// ^com
// Array.
Expand Down Expand Up @@ -45,7 +45,7 @@ let fa: ForAuto.t = 34
// fa->
// ^com

// "hello"->Js.Dict.u
// "hello"->String.in
// ^com

module O = {
Expand Down Expand Up @@ -142,7 +142,7 @@ let foo = {
type z = int
let v = 44
}
exception MyException(int, string, float, array<Js.Json.t>)
exception MyException(int, string, float, array<JSON.t>)
let _ = raise(MyException(2, "", 1.0, []))
add((x: Inner.z), Inner.v + y)
}
Expand Down Expand Up @@ -170,8 +170,8 @@ module WithChildren = {
// <WithChildren
// ^com

// type t = Js.n
// ^com
// type t = Null.
// ^com
// type t = ForAuto.
// ^com

Expand Down Expand Up @@ -389,7 +389,6 @@ let _ = x =>
// ^com

let _ = _ => {
open Js
// []->ma
// ^com
()
Expand All @@ -415,7 +414,7 @@ let onClick = evt => {
evt->ReactEvent.Synthetic.preventDefault
// SomeLocalModule.
// ^com
Js.log("Hello")
Console.log("Hello")
}

// let _ = 123->t
Expand Down
14 changes: 7 additions & 7 deletions tests/analysis_tests/tests/src/CompletionDicts.res
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// let dict = Js.Dict.fromArray([])
// ^com
// let dict = Dict.fromArray([])
// ^com

// let dict = Js.Dict.fromArray([()])
// ^com
// let dict = Dict.fromArray([()])
// ^com

// let dict = Js.Dict.fromArray([("key", )])
// ^com
// let dict = Dict.fromArray([("key", )])
// ^com

// ^in+
let dict = Js.Dict.fromArray([
let dict = Dict.fromArray([
("key", true),
// ("key2", )
// ^com
Expand Down
8 changes: 4 additions & 4 deletions tests/analysis_tests/tests/src/CompletionExpressions.res
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ let something = {
let second2 = 1
ignore(second)
ignore(second2)
Js.log(s)
// ^com
Console.log(s)
// ^com
}

let fff: recordWithOptionalField = {
Expand Down Expand Up @@ -314,7 +314,7 @@ open CompletionSupport
// CompletionSupport.makeTestHidden()
// ^com

let mkStuff = (r: Js.Re.t) => {
let mkStuff = (r: RegExp.t) => {
ignore(r)
"hello"
}
Expand Down Expand Up @@ -343,7 +343,7 @@ module Money: {

let make = (): t => zero

let fromInt = (int): t => int->Js.Int.toString
let fromInt = (int): t => int->Int.toString

let plus = (m1, _) => m1
}
Expand Down
12 changes: 6 additions & 6 deletions tests/analysis_tests/tests/src/CompletionInferValues.res
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ module Div = {
// let _ = <div onMouseEnter={event => { let btn = event->JsxEvent.Mouse.button; btn->t }} />
// ^com

// let _ = <div onMouseEnter={event => { let btn = event->JsxEvent.Mouse.button->Belt.Int.toString; btn->spl }} />
// ^com
// let _ = <div onMouseEnter={event => { let btn = event->JsxEvent.Mouse.button->Int.toString; btn->spl }} />
// ^com

// let _ = <div onMouseEnter={event => { let btn = event->JsxEvent.Mouse.button->Belt.Int.toString->Js.String2.split("/"); btn->ma }} />
// ^com
// let _ = <div onMouseEnter={event => { let btn = event->JsxEvent.Mouse.button->Int.toString->String.split("/"); btn->ma }} />
// ^com

type someVariant = One | Two | Three(int, string)
type somePolyVariant = [#one | #two | #three(int, string)]
Expand Down Expand Up @@ -145,8 +145,8 @@ let fn3 = (~cb: sameFileRecord => unit) => {
// ^com

// Handles pipe chains as input for switch
// let x = 123; switch x->Belt.Int.toString->Js.String2.split("/") { | }
// ^com
// let x = 123; switch x->Belt.Int.toString->String.split("/") { | }
// ^com

// Regular completion works
// let renderer = CompletionSupport2.makeRenderer(~prepare=() => "hello",~render=({support}) => {support.},())
Expand Down
4 changes: 2 additions & 2 deletions tests/analysis_tests/tests/src/CompletionJsx.res
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module SomeComponent = {
// ^com
// {"Some string"->st}
// ^com
// {"Some string"->Js.String2.trim->st}
// ^com
// {"Some string"->String.trim->st}
// ^com
// {someInt->}
// ^com
// {12->}
Expand Down
Loading
Loading