Skip to content

Commit 0f84ac1

Browse files
authoredFeb 15, 2025··
Analysis tests fixes (#7295)
* version in compiler analysis is always ReScript v12+ * always use new stdlib modules for autocomplete * migrate away from Js namespace in analysis tests * handle regexps * change test * update more tests * changelog * fix mistak
1 parent 5d9c682 commit 0f84ac1

30 files changed

+1019
-796
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#### :nail_care: Polish
1616

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

1920
#### :bug: Bug fix
2021

@@ -29,6 +30,7 @@
2930
#### :house: Internal
3031

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

3335
# 12.0.0-alpha.8
3436

‎analysis/src/CompletionBackEnd.ml

+6-12
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
10901090
*)
10911091
let completeAsBuiltin =
10921092
match typePath with
1093-
| Some t ->
1094-
TypeUtils.completionPathFromMaybeBuiltin t ~package:full.package
1093+
| Some t -> TypeUtils.completionPathFromMaybeBuiltin t
10951094
| None -> None
10961095
in
10971096
let completionPath =
@@ -1452,9 +1451,10 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
14521451
(* Special casing for things where we want extra things in the completions *)
14531452
let completionItems =
14541453
match path with
1455-
| Pdot (Pdot (Pident m, "Re", _), "t", _) when Ident.name m = "Js" ->
1454+
| Pdot (Pdot (Pident {name = "Js"}, "Re", _), "t", _)
1455+
| Pdot (Pident {name = "RegExp"}, "t", _) ->
14561456
(* regexps *)
1457-
create "%re()" ~insertText:"%re(\"/$0/g\")" ~includesSnippets:true
1457+
create "/<regexp>/g" ~insertText:"/$0/g" ~includesSnippets:true
14581458
~kind:(Label "Regular expression") ~env
14591459
:: completionItems
14601460
| _ -> completionItems
@@ -1801,8 +1801,7 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
18011801
if Debug.verbose () then print_endline "[complete_typed_value]--> Texn";
18021802
[
18031803
create
1804-
(full.package.builtInCompletionModules.exnModulePath @ ["Error(error)"]
1805-
|> ident)
1804+
(["Exn"; "Error(error)"] |> ident)
18061805
~kind:(Label "Catches errors from JavaScript errors.")
18071806
~docstring:
18081807
[
@@ -2244,12 +2243,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
22442243
| _ -> items)))
22452244
| CexhaustiveSwitch {contextPath; exprLoc} ->
22462245
let range = Utils.rangeOfLoc exprLoc in
2247-
let rescriptMajor, rescriptMinor = Packages.getReScriptVersion () in
2248-
let printFailwithStr num =
2249-
if (rescriptMajor = 11 && rescriptMinor >= 1) || rescriptMajor >= 12 then
2250-
"${" ^ string_of_int num ^ ":%todo}"
2251-
else "${" ^ string_of_int num ^ ":failwith(\"todo\")}"
2252-
in
2246+
let printFailwithStr num = "${" ^ string_of_int num ^ ":%todo}" in
22532247
let withExhaustiveItem ~cases ?(startIndex = 0) (c : Completion.t) =
22542248
(* We don't need to write out `switch` here since we know that's what the
22552249
user has already written. Just complete for the rest. *)

‎analysis/src/Packages.ml

-55
Original file line numberDiff line numberDiff line change
@@ -148,61 +148,6 @@ let newBsPackage ~rootPath =
148148
pathsForModule;
149149
opens;
150150
namespace;
151-
builtInCompletionModules =
152-
(if
153-
opens_from_bsc_flags
154-
|> List.find_opt (fun opn ->
155-
match opn with
156-
| ["RescriptCore"] -> true
157-
| _ -> false)
158-
|> Option.is_some
159-
|| fst rescriptVersion >= 12
160-
then
161-
{
162-
arrayModulePath = ["Array"];
163-
optionModulePath = ["Option"];
164-
stringModulePath = ["String"];
165-
intModulePath = ["Int"];
166-
floatModulePath = ["Float"];
167-
promiseModulePath = ["Promise"];
168-
listModulePath = ["List"];
169-
resultModulePath = ["Result"];
170-
exnModulePath = ["Exn"];
171-
regexpModulePath = ["RegExp"];
172-
}
173-
else if
174-
opens_from_bsc_flags
175-
|> List.find_opt (fun opn ->
176-
match opn with
177-
| ["Belt"] -> true
178-
| _ -> false)
179-
|> Option.is_some
180-
then
181-
{
182-
arrayModulePath = ["Array"];
183-
optionModulePath = ["Option"];
184-
stringModulePath = ["Js"; "String2"];
185-
intModulePath = ["Int"];
186-
floatModulePath = ["Float"];
187-
promiseModulePath = ["Js"; "Promise"];
188-
listModulePath = ["List"];
189-
resultModulePath = ["Result"];
190-
exnModulePath = ["Js"; "Exn"];
191-
regexpModulePath = ["Js"; "Re"];
192-
}
193-
else
194-
{
195-
arrayModulePath = ["Js"; "Array2"];
196-
optionModulePath = ["Belt"; "Option"];
197-
stringModulePath = ["Js"; "String2"];
198-
intModulePath = ["Belt"; "Int"];
199-
floatModulePath = ["Belt"; "Float"];
200-
promiseModulePath = ["Js"; "Promise"];
201-
listModulePath = ["Belt"; "List"];
202-
resultModulePath = ["Belt"; "Result"];
203-
exnModulePath = ["Js"; "Exn"];
204-
regexpModulePath = ["Js"; "Re"];
205-
});
206151
uncurried;
207152
}))
208153
| None -> None

‎analysis/src/SharedTypes.ml

-14
Original file line numberDiff line numberDiff line change
@@ -483,19 +483,6 @@ type file = string
483483

484484
module FileSet = Set.Make (String)
485485

486-
type builtInCompletionModules = {
487-
arrayModulePath: string list;
488-
optionModulePath: string list;
489-
stringModulePath: string list;
490-
intModulePath: string list;
491-
floatModulePath: string list;
492-
promiseModulePath: string list;
493-
listModulePath: string list;
494-
resultModulePath: string list;
495-
exnModulePath: string list;
496-
regexpModulePath: string list;
497-
}
498-
499486
type package = {
500487
genericJsxModule: string option;
501488
suffix: string;
@@ -504,7 +491,6 @@ type package = {
504491
dependenciesFiles: FileSet.t;
505492
pathsForModule: (file, paths) Hashtbl.t;
506493
namespace: string option;
507-
builtInCompletionModules: builtInCompletionModules;
508494
opens: path list;
509495
uncurried: bool;
510496
rescriptVersion: int * int;

‎analysis/src/TypeUtils.ml

+9-10
Original file line numberDiff line numberDiff line change
@@ -1253,17 +1253,16 @@ let pathToBuiltin path =
12531253
Predef.builtin_idents
12541254
|> List.find_opt (fun (_, i) -> Ident.same i (Path.head path))
12551255

1256-
let completionPathFromMaybeBuiltin path ~package =
1256+
let completionPathFromMaybeBuiltin path =
12571257
match pathToBuiltin path with
1258-
| Some ("array", _) -> Some package.builtInCompletionModules.arrayModulePath
1259-
| Some ("option", _) -> Some package.builtInCompletionModules.optionModulePath
1260-
| Some ("string", _) -> Some package.builtInCompletionModules.stringModulePath
1261-
| Some ("int", _) -> Some package.builtInCompletionModules.intModulePath
1262-
| Some ("float", _) -> Some package.builtInCompletionModules.floatModulePath
1263-
| Some ("promise", _) ->
1264-
Some package.builtInCompletionModules.promiseModulePath
1265-
| Some ("list", _) -> Some package.builtInCompletionModules.listModulePath
1266-
| Some ("result", _) -> Some package.builtInCompletionModules.resultModulePath
1258+
| Some ("array", _) -> Some ["Array"]
1259+
| Some ("option", _) -> Some ["Option"]
1260+
| Some ("string", _) -> Some ["String"]
1261+
| Some ("int", _) -> Some ["Int"]
1262+
| Some ("float", _) -> Some ["Float"]
1263+
| Some ("promise", _) -> Some ["Promise"]
1264+
| Some ("list", _) -> Some ["List"]
1265+
| Some ("result", _) -> Some ["Result"]
12671266
| Some ("dict", _) -> Some ["Dict"]
12681267
| Some ("char", _) -> Some ["Char"]
12691268
| _ -> None

‎tests/analysis_tests/tests-generic-jsx-transform/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/analysis_tests/tests-generic-jsx-transform/src/expected/GenericJsxCompletion.res.txt

+14-14
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Package opens Pervasives.JsxModules.place holder
5959
ContextPath Value[someString]->st <<jsx>>
6060
ContextPath Value[someString]
6161
Path someString
62-
Path Js.String2.st
62+
Path String.st
6363
[{
6464
"label": "GenericJsx.string",
6565
"kind": 12,
@@ -69,17 +69,17 @@ Path Js.String2.st
6969
"sortText": "A",
7070
"insertTextFormat": 2
7171
}, {
72-
"label": "Js.String2.startsWith",
72+
"label": "String.startsWith",
7373
"kind": 12,
7474
"tags": [],
75-
"detail": "(t, t) => bool",
76-
"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"}
75+
"detail": "(string, string) => bool",
76+
"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"}
7777
}, {
78-
"label": "Js.String2.startsWithFrom",
78+
"label": "String.startsWithFrom",
7979
"kind": 12,
8080
"tags": [],
81-
"detail": "(t, t, int) => bool",
82-
"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"}
81+
"detail": "(string, string, int) => bool",
82+
"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"}
8383
}]
8484

8585
Complete src/GenericJsxCompletion.res 20:24
@@ -106,7 +106,7 @@ Resolved opens 1 GenericJsx
106106
ContextPath Value[someString]->st <<jsx>>
107107
ContextPath Value[someString]
108108
Path someString
109-
Path Js.String2.st
109+
Path String.st
110110
[{
111111
"label": "string",
112112
"kind": 12,
@@ -116,16 +116,16 @@ Path Js.String2.st
116116
"sortText": "A",
117117
"insertTextFormat": 2
118118
}, {
119-
"label": "Js.String2.startsWith",
119+
"label": "String.startsWith",
120120
"kind": 12,
121121
"tags": [],
122-
"detail": "(t, t) => bool",
123-
"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"}
122+
"detail": "(string, string) => bool",
123+
"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"}
124124
}, {
125-
"label": "Js.String2.startsWithFrom",
125+
"label": "String.startsWithFrom",
126126
"kind": 12,
127127
"tags": [],
128-
"detail": "(t, t, int) => bool",
129-
"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"}
128+
"detail": "(string, string, int) => bool",
129+
"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"}
130130
}]
131131

‎tests/analysis_tests/tests/src/Completion.res

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module MyList = Belt.List
1+
module MyList = List
22
// MyList.m
33
// ^com
44
// Array.
@@ -45,7 +45,7 @@ let fa: ForAuto.t = 34
4545
// fa->
4646
// ^com
4747

48-
// "hello"->Js.Dict.u
48+
// "hello"->String.in
4949
// ^com
5050

5151
module O = {
@@ -142,7 +142,7 @@ let foo = {
142142
type z = int
143143
let v = 44
144144
}
145-
exception MyException(int, string, float, array<Js.Json.t>)
145+
exception MyException(int, string, float, array<JSON.t>)
146146
let _ = raise(MyException(2, "", 1.0, []))
147147
add((x: Inner.z), Inner.v + y)
148148
}
@@ -170,8 +170,8 @@ module WithChildren = {
170170
// <WithChildren
171171
// ^com
172172

173-
// type t = Js.n
174-
// ^com
173+
// type t = Null.
174+
// ^com
175175
// type t = ForAuto.
176176
// ^com
177177

@@ -389,7 +389,6 @@ let _ = x =>
389389
// ^com
390390

391391
let _ = _ => {
392-
open Js
393392
// []->ma
394393
// ^com
395394
()
@@ -415,7 +414,7 @@ let onClick = evt => {
415414
evt->ReactEvent.Synthetic.preventDefault
416415
// SomeLocalModule.
417416
// ^com
418-
Js.log("Hello")
417+
Console.log("Hello")
419418
}
420419

421420
// let _ = 123->t

‎tests/analysis_tests/tests/src/CompletionDicts.res

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
// let dict = Js.Dict.fromArray([])
2-
// ^com
1+
// let dict = Dict.fromArray([])
2+
// ^com
33

4-
// let dict = Js.Dict.fromArray([()])
5-
// ^com
4+
// let dict = Dict.fromArray([()])
5+
// ^com
66

7-
// let dict = Js.Dict.fromArray([("key", )])
8-
// ^com
7+
// let dict = Dict.fromArray([("key", )])
8+
// ^com
99

1010
// ^in+
11-
let dict = Js.Dict.fromArray([
11+
let dict = Dict.fromArray([
1212
("key", true),
1313
// ("key2", )
1414
// ^com

‎tests/analysis_tests/tests/src/CompletionExpressions.res

+4-4
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ let something = {
183183
let second2 = 1
184184
ignore(second)
185185
ignore(second2)
186-
Js.log(s)
187-
// ^com
186+
Console.log(s)
187+
// ^com
188188
}
189189

190190
let fff: recordWithOptionalField = {
@@ -314,7 +314,7 @@ open CompletionSupport
314314
// CompletionSupport.makeTestHidden()
315315
// ^com
316316

317-
let mkStuff = (r: Js.Re.t) => {
317+
let mkStuff = (r: RegExp.t) => {
318318
ignore(r)
319319
"hello"
320320
}
@@ -343,7 +343,7 @@ module Money: {
343343

344344
let make = (): t => zero
345345

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

348348
let plus = (m1, _) => m1
349349
}

‎tests/analysis_tests/tests/src/CompletionInferValues.res

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ module Div = {
4848
// let _ = <div onMouseEnter={event => { let btn = event->JsxEvent.Mouse.button; btn->t }} />
4949
// ^com
5050

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

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

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

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

151151
// Regular completion works
152152
// let renderer = CompletionSupport2.makeRenderer(~prepare=() => "hello",~render=({support}) => {support.},())

‎tests/analysis_tests/tests/src/CompletionJsx.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ module SomeComponent = {
2020
// ^com
2121
// {"Some string"->st}
2222
// ^com
23-
// {"Some string"->Js.String2.trim->st}
24-
// ^com
23+
// {"Some string"->String.trim->st}
24+
// ^com
2525
// {someInt->}
2626
// ^com
2727
// {12->}

0 commit comments

Comments
 (0)
Please sign in to comment.