Skip to content

Commit f477ca7

Browse files
Merge pull request #1134 from rescript-lang/agents-md
Create an AGENTS.md
2 parents c1b3031 + f3cf0a5 commit f477ca7

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

AGENTS.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to AI coding assistants when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is the official ReScript VSCode extension, providing language support for ReScript (.res/.resi files) in Visual Studio Code. The project uses a Language Server Protocol (LSP) architecture with a TypeScript client/server and native OCaml binaries for analysis.
8+
9+
## Architecture
10+
11+
### Key Components
12+
13+
- **client/**: VSCode extension client (`client/src/extension.ts`) - handles UI, commands, and language client initialization
14+
- **server/**: Language Server (`server/src/server.ts`, `server/src/cli.ts`) - implements LSP features, communicates with ReScript compiler
15+
- **analysis/**: Native OCaml binary for code analysis, hover, autocomplete, and other language features. This is for older ReScript versions only (ReScript 11 and below). New features are usually only implemented in the rescript compiler monorepo.
16+
- **tools/**: ReScript tools binary for additional functionality like interface file generation. This is also for older ReScript versions only (ReScript 11 and below). New features are usually only implemented in the rescript compiler monorepo.
17+
- **grammars/**: TextMate grammar files for syntax highlighting
18+
- **snippets.json**: Code snippets for common ReScript patterns
19+
20+
### Build System
21+
22+
The project uses:
23+
24+
- **dune**: For building OCaml components (analysis & tools)
25+
- **esbuild**: For bundling TypeScript client/server
26+
- **npm**: For JavaScript/TypeScript dependencies
27+
- **TypeScript**: For type checking the client/server code
28+
29+
## Development Commands
30+
31+
### Initial Setup
32+
33+
```bash
34+
npm install # Install all dependencies including client/server
35+
opam switch 5.2.0 # Install OCaml switch (if not already done)
36+
opam install . --deps-only # Install OCaml dependencies
37+
```
38+
39+
### Building
40+
41+
```bash
42+
make build # Build OCaml binaries and copy to root
43+
npm run compile # Compile TypeScript (client & server)
44+
npm run bundle # Bundle for production (esbuild)
45+
npm run vscode:prepublish # Clean and bundle (used for publishing)
46+
```
47+
48+
### Development
49+
50+
```bash
51+
npm run watch # Watch TypeScript compilation
52+
make -C analysis test # Run analysis tests
53+
make -C tools/tests test # Run tools tests
54+
make test # Run all tests
55+
```
56+
57+
### Code Quality
58+
59+
```bash
60+
make format # Format OCaml (dune) and JS/TS (prettier)
61+
make checkformat # Check formatting without modifying
62+
make clean # Clean build artifacts
63+
```
64+
65+
### Running the Extension in Development
66+
67+
1. Open the project in VSCode
68+
2. Press F5 to launch a new VSCode window (Extension Development Host)
69+
3. Open a ReScript project to test the extension
70+
71+
## Key Files
72+
73+
### Configuration
74+
75+
- `package.json`: Extension manifest, commands, settings, and scripts
76+
- `rescript.configuration.json`: Editor configuration for ReScript files
77+
- `client/src/extension.ts`: Extension entry point and client initialization
78+
- `server/src/server.ts`: Language server implementation
79+
- `server/src/cli.ts`: CLI entry point for the language server
80+
81+
### OCaml Components
82+
83+
- `analysis/`: Code analysis binary (hover, autocomplete, etc.)
84+
- `tools/`: ReScript tools binary (interface generation, etc.)
85+
86+
### Language Features
87+
88+
- **LSP Features**: hover, goto definition, find references, rename, autocomplete
89+
- **Code Analysis**: dead code detection, exception analysis (via reanalyze)
90+
- **Build Integration**: compile diagnostics, status indicators
91+
- **Commands**: interface creation, file switching, compiled JS opening
92+
93+
## Testing
94+
95+
The project has several test suites:
96+
97+
- `analysis/tests/`: Tests for the analysis binary
98+
- `tools/tests/`: Tests for ReScript tools
99+
- `analysis/tests-incremental-typechecking/`: Incremental typechecking tests
100+
- `analysis/tests-generic-jsx-transform/`: JSX transformation tests
101+
102+
## Project Structure Notes
103+
104+
- The extension supports both `.res` (implementation) and `.resi` (interface) files
105+
- Uses VSCode Language Client protocol for communication between client and server
106+
- Native binaries are cross-platform (darwin, linux, win32) and included in the extension. The rescript-editor-analysis is invoked by the LSP Server in a one-shot mode. Dumping JSON to stdout and the LSP picks that up.
107+
- Supports workspace configurations and monorepo structures
108+
- Incremental type checking can be enabled for better performance on large projects
109+
- As mentioned above the native OCaml binaries here are only here for backwards-compatibility with ReScript versions 11 or below. Since ReScript 12 both `analysis` and `tools` are part of the [ReScript compiler monorepo](https://github.com/rescript-lang/rescript), thus refrain from changing them too much (bugfixes that need to be ported are ok).

CLAUDE.md

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

0 commit comments

Comments
 (0)