-
Notifications
You must be signed in to change notification settings - Fork 469
Support doc comment before variant #7535
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
Merged
shulhi
merged 11 commits into
rescript-lang:master
from
shulhi:fix/doc-comment-before-variant
Jun 16, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
df85b05
WIP
shulhi 9cb1d26
Format doc comment before bar
shulhi 4cfae9d
Adjust loc
shulhi d90616e
Update test files
shulhi 5649bc8
Lookahead if we are in variant
shulhi 6e01830
Cleanup
shulhi 44786dd
Remove loc adjustment hack
shulhi 97a6748
Update test files
shulhi 372d90a
Update CHANGELOG
shulhi de54923
Resolve review feedback
shulhi c23f36b
Update tests
shulhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"mcpServers": { | ||
"ocamllsp": { | ||
"type": "stdio", | ||
"command": "mcp-language-server", | ||
"args": [ | ||
"--workspace", | ||
"/Users/shulhi/Dev/rescript/rescript-compiler", | ||
"--lsp", | ||
"ocamllsp" | ||
], | ||
"env": {} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# CLAUDE.md | ||
|
||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
||
## Project Overview | ||
|
||
This is the ReScript compiler repository - a robustly typed language that compiles to efficient and human-readable JavaScript. ReScript is built using OCaml and includes a complete toolchain with compiler, build system, syntax parser, and standard library. | ||
|
||
## Build Commands | ||
|
||
### Basic Development | ||
```bash | ||
# Build compiler and copy executables | ||
make | ||
|
||
# Build in watch mode | ||
make watch | ||
|
||
# Build everything including standard library | ||
make lib | ||
|
||
# Build artifacts and update artifact list | ||
make artifacts | ||
``` | ||
|
||
### Testing | ||
```bash | ||
# Run all tests | ||
make test | ||
|
||
# Run specific test types | ||
make test-syntax # Syntax parser tests | ||
make test-syntax-roundtrip # Roundtrip syntax tests | ||
make test-gentype # GenType tests | ||
make test-analysis # Analysis tests | ||
make test-tools # Tools tests | ||
make test-rewatch # Rewatch tests | ||
|
||
# Run single file test | ||
./cli/bsc.js myTestFile.res | ||
|
||
# View parse/typed trees for debugging | ||
./cli/bsc.js -dparsetree myTestFile.res | ||
./cli/bsc.js -dtypedtree myTestFile.res | ||
``` | ||
|
||
### Code Quality | ||
```bash | ||
# Format code | ||
make format | ||
|
||
# Check formatting | ||
make checkformat | ||
|
||
# Lint with Biome | ||
npm run check | ||
npm run check:all | ||
|
||
# TypeScript type checking | ||
npm run typecheck | ||
``` | ||
|
||
### Clean Operations | ||
```bash | ||
make clean # Clean OCaml build artifacts | ||
make clean-all # Clean everything including Rust/gentype | ||
``` | ||
|
||
## Compiler Architecture | ||
|
||
The ReScript compiler follows this high-level pipeline: | ||
|
||
``` | ||
ReScript Source (.res) | ||
↓ (ReScript Parser - compiler/syntax/) | ||
Surface Syntax Tree | ||
↓ (Frontend transformations - compiler/frontend/) | ||
Surface Syntax Tree | ||
↓ (OCaml Type Checker - compiler/ml/) | ||
Typedtree | ||
↓ (Lambda compilation - compiler/core/lam_*) | ||
Lambda IR | ||
↓ (JS compilation - compiler/core/js_*) | ||
JS IR | ||
↓ (JS output - compiler/core/js_dump*) | ||
JavaScript Code | ||
``` | ||
|
||
### Key Directories | ||
|
||
- **`compiler/syntax/`** - ReScript syntax parser (MIT licensed, separate from main LGPL) | ||
- **`compiler/frontend/`** - AST transformations, external FFI processing, built-in attributes | ||
- **`compiler/ml/`** - OCaml compiler infrastructure (type checker, typedtree, etc.) | ||
- **`compiler/core/`** - Core compilation: | ||
- `lam_*` files: Lambda IR compilation and optimization passes | ||
- `js_*` files: JavaScript IR and code generation | ||
- **`compiler/ext/`** - Extended utilities and data structures | ||
- **`compiler/bsb/`** - Build system implementation | ||
- **`compiler/gentype/`** - TypeScript generation | ||
- **`runtime/`** - ReScript standard library (written in ReScript) | ||
- **`lib/`** - Compiled JavaScript output of standard library | ||
- **`analysis/`** - Language server and tooling support | ||
|
||
### Build System Components | ||
|
||
- **`compiler/bsb_exe/`** - Main ReScript build tool entry point | ||
- **`compiler/bsc/`** - Compiler binary entry point | ||
- **`rewatch/`** - File watcher (written in Rust) | ||
- **`ninja/`** - Vendored Ninja build system | ||
|
||
## Development Setup Notes | ||
|
||
- Uses OCaml 5.3.0+ with opam for compiler development | ||
- Uses dune as build system with specific profiles (dev, release, browser) | ||
- Node.js 20+ required for JavaScript tooling | ||
- Rust toolchain needed for rewatch file watcher | ||
- Python ≤3.11 required for building ninja | ||
|
||
## Coding Conventions | ||
|
||
- **OCaml code**: snake_case (e.g., `to_string`) | ||
- **ReScript code**: camelCase (e.g., `toString`) | ||
- Use DCO sign-off for all commits: `Signed-Off-By: Your Name <email>` | ||
|
||
## Testing Strategy | ||
|
||
- **Mocha tests** (`tests/tests/`) - Runtime library unit tests | ||
- **Build system tests** (`tests/build_tests/`) - Integration tests | ||
- **OUnit tests** (`tests/ounit_tests/`) - Compiler unit tests | ||
- **Expectation tests** - Plain `.res` files that check compilation output | ||
- Always include appropriate tests with new features/changes | ||
|
||
## Performance Notes | ||
|
||
The compiler is designed for fast feedback loops and scales to large codebases. When making changes: | ||
- Avoid introducing meaningless symbols | ||
- Maintain readable JavaScript output | ||
- Consider compilation speed impact | ||
- Use appropriate optimization passes in the Lambda and JS IRs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
type x = | ||
/** first group */ | ||
| A | ||
| B | ||
| C | ||
|
||
/** second group */ | ||
| D | ||
| E | ||
| F |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,8 @@ type open_flag = | |
| O_DSYNC | ||
| O_SYNC | ||
| O_RSYNC | ||
|
||
| O_SHARE_DELETE | ||
|
||
| O_CLOEXEC | ||
|
||
| O_KEEPEXEC | ||
|
||
let vv = 3 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ let eq = (loc, x, y) => { | |
|
||
type shape = | ||
| Circle(int) | ||
|
||
| Rectangle(int, int) | ||
|
||
let myShape = Circle(10) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this PR, no newlines in between variant constructors. This makes the implementation simpler since I don't need to hack around node's location.
Personally, I prefer the formatting this way too. What do you think? @cknitt @zth @nojaf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine for me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I meant the new formatting of doc comments before variants is great.
Regarding the newlines, it would be nice if this was still possible:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you just put an empty comment line where you want the break?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shulhi, this is better! I wasn't a fan of adjusting the ranges in the parser to satisfy the format. It felt wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will reformat it to
I can still investigate this if we want to preserve the previous behavior. I actually like it without the newline.
The challenge with preserving the previous behavior has to do with how we treat comments and doc comments (comment table and attribute). If we compare the location for the comment for the above example,
first group
is attached to line 3, while it would be at line 2 for doc comment. We would have to adjust the ranges to make it print the same way for both - which felt like a hack.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that sounds quite hacky indeed.
I guess I can live with no newlines in that case. 🙂