You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: analysis/README.md
+80-6Lines changed: 80 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -12,15 +12,89 @@ See main CONTRIBUTING.md's repo structure. Additionally, `examples/` is a conven
12
12
13
13
## Usage
14
14
15
-
At root:
16
-
```sh
17
-
./rescript-editor-analysis.exe --help
18
-
19
-
# or
20
-
15
+
```shell
21
16
dune exec -- rescript-editor-analysis --help
22
17
```
23
18
24
19
## History
25
20
26
21
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
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`):
0 commit comments