This file provides guidance to AI coding assistants when working with code in this repository.
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.
- client/: VSCode extension client (
client/src/extension.ts) - handles UI, commands, and language client initialization - server/: Language Server (
server/src/server.ts,server/src/cli.ts) - implements LSP features, communicates with ReScript compiler - 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.
- 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.
- grammars/: TextMate grammar files for syntax highlighting
- snippets.json: Code snippets for common ReScript patterns
The project uses:
- dune: For building OCaml components (analysis & tools)
- esbuild: For bundling TypeScript client/server
- npm: For JavaScript/TypeScript dependencies
- TypeScript: For type checking the client/server code
npm install # Install all dependencies including client/server
opam switch 5.2.0 # Install OCaml switch (if not already done)
opam install . --deps-only # Install OCaml dependenciesmake build # Build OCaml binaries and copy to root
npm run compile # Compile TypeScript (client & server)
npm run bundle # Bundle for production (esbuild)
npm run vscode:prepublish # Clean and bundle (used for publishing)npm run watch # Watch TypeScript compilation
make -C analysis test # Run analysis tests
make -C tools/tests test # Run tools tests
make test # Run all testsmake format # Format OCaml (dune) and JS/TS (prettier)
make checkformat # Check formatting without modifying
make clean # Clean build artifacts- Open the project in VSCode
- Press F5 to launch a new VSCode window (Extension Development Host)
- Open a ReScript project to test the extension
package.json: Extension manifest, commands, settings, and scriptsrescript.configuration.json: Editor configuration for ReScript filesclient/src/extension.ts: Extension entry point and client initializationserver/src/server.ts: Language server implementationserver/src/cli.ts: CLI entry point for the language server
analysis/: Code analysis binary (hover, autocomplete, etc.)tools/: ReScript tools binary (interface generation, etc.)
- LSP Features: hover, goto definition, find references, rename, autocomplete
- Code Analysis: dead code detection, exception analysis (via reanalyze)
- Build Integration: compile diagnostics, status indicators
- Commands: interface creation, file switching, compiled JS opening
The project has several test suites:
analysis/tests/: Tests for the analysis binarytools/tests/: Tests for ReScript toolsanalysis/tests-incremental-typechecking/: Incremental typechecking testsanalysis/tests-generic-jsx-transform/: JSX transformation tests
- The extension supports both
.res(implementation) and.resi(interface) files - Uses VSCode Language Client protocol for communication between client and server
- 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.
- Supports workspace configurations and monorepo structures
- Incremental type checking can be enabled for better performance on large projects
- As mentioned above the native OCaml binaries here are only here for backwards-compatibility with ReScript versions 11 or below. Since ReScript 12 both
analysisandtoolsare part of the ReScript compiler monorepo, thus refrain from changing them too much (bugfixes that need to be ported are ok).