Skip to content

Commit 26b646c

Browse files
committed
Merge branch 'master' into doc-tests-fix
# Conflicts: # .github/workflows/ci.yml
2 parents 7b4c67a + 8ee10cc commit 26b646c

35 files changed

+1136
-1023
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ jobs:
135135
- name: Use Node.js
136136
uses: actions/setup-node@v4
137137
with:
138-
node-version: 18
138+
node-version-file: .nvmrc
139139

140140
- name: Get artifact dir name
141141
run: node .github/workflows/get_artifact_dir_name.js
@@ -167,7 +167,7 @@ jobs:
167167
key: ${{ env.opam_cache_key }}
168168

169169
- name: Use OCaml ${{matrix.ocaml_compiler}}
170-
uses: ocaml/setup-ocaml@v3.1.4
170+
uses: ocaml/setup-ocaml@v3.2.2
171171
if: steps.cache-opam-env.outputs.cache-hit != 'true'
172172
with:
173173
ocaml-compiler: ${{matrix.ocaml_compiler}}
@@ -244,11 +244,6 @@ jobs:
244244
fi
245245
shell: bash
246246

247-
# see https://github.com/ocaml/setup-ocaml/issues/815
248-
- name: "Windows: set SHELLOPTS=igncr"
249-
if: runner.os == 'Windows'
250-
run: echo "SHELLOPTS=igncr" >>"$GITHUB_ENV"
251-
252247
- name: Build compiler
253248
if: runner.os != 'Linux'
254249
run: opam exec -- dune build --display quiet --profile release
@@ -409,7 +404,7 @@ jobs:
409404
- name: Use Node.js
410405
uses: actions/setup-node@v4
411406
with:
412-
node-version: 18
407+
node-version-file: .nvmrc
413408

414409
- name: NPM install
415410
run: npm ci --ignore-scripts
@@ -469,7 +464,7 @@ jobs:
469464
- name: Use Node.js
470465
uses: actions/setup-node@v4
471466
with:
472-
node-version: 18
467+
node-version-file: .nvmrc
473468

474469
- name: Download artifacts
475470
uses: actions/download-artifact@v4
@@ -503,7 +498,7 @@ jobs:
503498
- name: Use Node.js
504499
uses: actions/setup-node@v4
505500
with:
506-
node-version: 18
501+
node-version-file: .nvmrc
507502
registry-url: https://registry.npmjs.org # Needed to make auth work for publishing
508503

509504
- name: Download artifacts

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18

.ocamlformat-ignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
compiler/js_parser/**
22
compiler/ml/cmt_format.ml
3-
compiler/ml/pprintast.ml
43
compiler/core/js_name_of_module_id.ml
54
compiler/core/js_pass_debug.ml
65
compiler/core/lam_util.ml

CHANGELOG.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,38 @@
1010
> - :house: [Internal]
1111
> - :nail_care: [Polish]
1212
13-
# 12.0.0-alpha.6 (Unreleased)
14-
- Fix exponential notation syntax. https://github.com/rescript-lang/rescript/pull/7174
13+
# 12.0.0-alpha.7 (Unreleased)
14+
15+
#### :house: Internal
16+
17+
- AST cleanup: use inline record for Pexp_fun. https://github.com/rescript-lang/rescript/pull/7213
18+
19+
# 12.0.0-alpha.6
20+
21+
#### :rocket: New Feature
22+
1523
- Add `Option.all` & `Result.all` helpers. https://github.com/rescript-lang/rescript/pull/7181
16-
- Add `@react.componentWithProps` that explicitly handles the props with shared props: https://github.com/rescript-lang/rescript/pull/7203
24+
- Add `@react.componentWithProps` for React component functions taking a props record instead of labeled arguments. https://github.com/rescript-lang/rescript/pull/7203
1725

1826
#### :bug: Bug fix
27+
28+
- Fix exponential notation syntax. https://github.com/rescript-lang/rescript/pull/7174
1929
- Fix bug where a ref assignment is moved ouside a conditional. https://github.com/rescript-lang/rescript/pull/7176
2030
- Fix nullable to opt conversion. https://github.com/rescript-lang/rescript/pull/7193
2131

2232
#### :house: Internal
33+
2334
- Use latest compiler for tests. https://github.com/rescript-lang/rescript/pull/7186
2435
- Added infra to modernise AST: theres' Parsetree, Parsetree0 (legacy), and conversion functions to keep compatibility with PPX. https://github.com/rescript-lang/rescript/pull/7185
25-
- Ast cleanup: remove exp object and exp unreachable. https://github.com/rescript-lang/rescript/pull/7189
26-
- Ast cleanup: explicit representation for optional record fields in types. https://github.com/rescript-lang/rescript/pull/7190 https://github.com/rescript-lang/rescript/pull/7191
36+
- AST cleanup: remove exp object and exp unreachable. https://github.com/rescript-lang/rescript/pull/7189
37+
- AST cleanup: explicit representation for optional record fields in types. https://github.com/rescript-lang/rescript/pull/7190 https://github.com/rescript-lang/rescript/pull/7191
2738
- AST cleanup: first-class expression and patterns for records with optional fields. https://github.com/rescript-lang/rescript/pull/7192
2839
- AST cleanup: Represent the arity of uncurried function definitions directly in the AST. https://github.com/rescript-lang/rescript/pull/7197
2940
- AST cleanup: Remove Pexp_function from the AST. https://github.com/rescript-lang/rescript/pull/7198
3041
- Remove unused code from Location and Rescript_cpp modules. https://github.com/rescript-lang/rescript/pull/7150
3142
- Build with OCaml 5.2.1. https://github.com/rescript-lang/rescript-compiler/pull/7201
3243
- AST cleanup: Remove `Function$` entirely for function definitions. https://github.com/rescript-lang/rescript/pull/7200
33-
- AST cleanup: store arity in function type https://github.com/rescript-lang/rescript/pull/7195
44+
- AST cleanup: store arity in function type. https://github.com/rescript-lang/rescript/pull/7195
3445
- AST cleanup: remove explicit uses of `function$` in preparation for removing the type entirely. https://github.com/rescript-lang/rescript/pull/7206
3546
- AST cleanup: remove `function$` entirely. https://github.com/rescript-lang/rescript/pull/7208
3647

analysis/README.md

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,89 @@ See main CONTRIBUTING.md's repo structure. Additionally, `examples/` is a conven
1212

1313
## Usage
1414

15-
At root:
16-
```sh
17-
./rescript-editor-analysis.exe --help
18-
19-
# or
20-
15+
```shell
2116
dune exec -- rescript-editor-analysis --help
2217
```
2318

2419
## History
2520

2621
This project is based on a fork of [Reason Language Server](https://github.com/jaredly/reason-language-server).
22+
23+
## Tests
24+
25+
### Prerequisites
26+
27+
- Ensure the compiler is built (`make build` in the repository root).
28+
- Ensure the library is built (`make lib` in the repository root).
29+
30+
### Running the Tests
31+
32+
Run `make test` in `tests/analysis_tests/tests`.
33+
34+
### Key Concept
35+
36+
The tests in the `tests/analysis_tests/tests` folder are based on the `dune exec -- rescript-editor-analysis test` command. This special subcommand processes a file and executes specific editor analysis functionality based on special syntax found in code comments.
37+
38+
Consider the following code:
39+
40+
```res
41+
let a = 5
42+
// a.
43+
// ^com
44+
```
45+
46+
After building the ReScript project (**⚠️ this is a requirement**), you can execute `dune exec -- rescript-editor-analysis test Sample.res`, and completion will be performed for the cursor position indicated by `^`. The `com` directive requests completion. To see other commands, check out the pattern match in the `test` function in [Commands.ml](./src/Commands.ml).
47+
48+
> [!WARNING]
49+
> Ensure there are no spaces in the code comments, as the commands are captured by a regular expression that expects spaces and not tabs!
50+
51+
Here’s how it works: once a command is found in a comment, a copy of the source file is created inside a temporary directory, where the line above `^com` is uncommented. The corresponding analysis functionality is then processed, typically with `~debug:true`. With debug enabled, code paths like
52+
53+
```ml
54+
if Debug.verbose () then
55+
print_endline "[complete_typed_value]--> Tfunction #other";
56+
```
57+
58+
will print to stdout. This is helpful for observing what happens during the analysis.
59+
60+
When you run `make test` (from the `tests/analysis_tests` folder), `dune exec -- rescript-editor-analysis test <file>` will be executed for each `*.res` file in `analysis/tests/src`. The stdout will be compared to the corresponding `analysis/tests/src/expected` file. If `git diff` indicates changes, `make test` will fail, as these differences might be unintentional.
61+
62+
## Testing on Your Own Projects
63+
64+
To use a local version of `rescript-editor-analysis`, the targeted project needs to be compiled with the local compiler.
65+
66+
Install your local ReScript with `npm i /path/to/your-local-rescript-repo`.
67+
Reinstall the dependencies and run `npx rescript` in your project. This ensures the project is compiled with the same compiler version that the `rescript-editor-analysis` will process.
68+
69+
## Debugging
70+
71+
It is possible to debug `analysis` via [ocamlearlybird](https://github.com/hackwaly/ocamlearlybird).
72+
73+
1. Install `opam install earlybird`.
74+
2. Install the [earlybird extension](https://marketplace.visualstudio.com/items?itemName=hackwaly.ocamlearlybird).
75+
3. Create a launch configuration (`.vscode/launch.json`):
76+
77+
```json
78+
{
79+
"version": "0.2.0",
80+
"configurations": [
81+
{
82+
"name": "Debug analysis",
83+
"type": "ocaml.earlybird",
84+
"request": "launch",
85+
"program": "${workspaceFolder}/_build/default/analysis/bin/main.bc",
86+
"stopOnEntry": true,
87+
"cwd": "/projects/your-project",
88+
"env": {
89+
"CAML_LD_LIBRARY_PATH": "${workspaceFolder}/_build/default/compiler/ext"
90+
},
91+
"arguments": [
92+
"test",
93+
"src/Main.res"
94+
]
95+
}
96+
]
97+
}
98+
```
99+
100+
The `CAML_LD_LIBRARY_PATH` environment variable is required to tell OCaml where `dllext_stubs.so` can be loaded from.

analysis/src/CompletionFrontEnd.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
13181318
match exprToContextPath lhs with
13191319
| Some contextPath -> setResult (Cpath (CPObj (contextPath, label)))
13201320
| None -> ())
1321-
| Pexp_fun (lbl, defaultExpOpt, pat, e, _) ->
1321+
| Pexp_fun
1322+
{arg_label = lbl; default = defaultExpOpt; lhs = pat; rhs = e} ->
13221323
let oldScope = !scope in
13231324
(match (!processingFun, !currentCtxPath) with
13241325
| None, Some ctxPath -> processingFun := Some (ctxPath, 0)

analysis/src/DumpAst.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ and printExprItem expr ~pos ~indentation =
213213
| None -> ""
214214
| Some expr -> "," ^ printExprItem expr ~pos ~indentation)
215215
^ ")"
216-
| Pexp_fun (arg, _maybeDefaultArgExpr, pattern, nextExpr, _) ->
216+
| Pexp_fun {arg_label = arg; lhs = pattern; rhs = nextExpr} ->
217217
"Pexp_fun(\n"
218218
^ addIndentation (indentation + 1)
219219
^ "arg: "

analysis/src/Hint.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ let inlay ~path ~pos ~maxLength ~debug =
6161
| Pexp_apply _ | Pexp_match _ | Pexp_construct _ | Pexp_ifthenelse _
6262
| Pexp_array _ | Pexp_ident _ | Pexp_try _ | Pexp_lazy _
6363
| Pexp_send _ | Pexp_field _ | Pexp_open _
64-
| Pexp_fun (_, _, _, _, Some _) );
64+
| Pexp_fun {arity = Some _} );
6565
};
6666
} ->
6767
push vb.pvb_pat.ppat_loc Type

analysis/src/Xform.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ module AddBracesToFn = struct
261261
| _ -> false
262262
in
263263
(match e.pexp_desc with
264-
| Pexp_fun (_, _, _, bodyExpr, _)
264+
| Pexp_fun {rhs = bodyExpr}
265265
when Loc.hasPos ~pos bodyExpr.pexp_loc
266266
&& isBracedExpr bodyExpr = false
267267
&& isFunction bodyExpr = false ->
@@ -303,9 +303,9 @@ module AddTypeAnnotation = struct
303303
in
304304
let rec processFunction ~argNum (e : Parsetree.expression) =
305305
match e.pexp_desc with
306-
| Pexp_fun (argLabel, _, pat, e, _) ->
306+
| Pexp_fun {arg_label; lhs = pat; rhs = e} ->
307307
let isUnlabeledOnlyArg =
308-
argNum = 1 && argLabel = Nolabel
308+
argNum = 1 && arg_label = Nolabel
309309
&&
310310
match e.pexp_desc with
311311
| Pexp_fun _ -> false

compiler/common/bs_version.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
* You should have received a copy of the GNU Lesser General Public License
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24-
let version = "12.0.0-alpha.6"
24+
let version = "12.0.0-alpha.7"
2525
let header = "// Generated by ReScript, PLEASE EDIT WITH CARE"
2626
let package_name = ref "rescript"

0 commit comments

Comments
 (0)