Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
177 commits
Select commit Hold shift + click to select a range
cbf971e
initial lsp
aspeddro Dec 1, 2024
acbfc57
Merge branch 'master' into lsp
aspeddro Dec 30, 2024
ce6dd17
Merge branch 'master' into lsp
aspeddro Mar 17, 2025
56d6afe
Merge branch 'master' into lsp
aspeddro Jun 20, 2025
434c8fe
Merge branch 'master' into lsp
aspeddro Apr 28, 2026
9767c9f
update
aspeddro Apr 29, 2026
b1b4b04
add state
aspeddro Apr 30, 2026
d09d328
Extract server I/O into Server module and simplify handlers
aspeddro May 12, 2026
80e8218
Add parse_implementation_from_source and refactor LSP server
aspeddro May 12, 2026
efc77b3
Merge branch 'master' into lsp
aspeddro May 13, 2026
ad0b764
Split LSP into bin/src layout and add hover integration test
aspeddro May 14, 2026
5a36dd1
Refactor analysis to decouple I/O from core logic
aspeddro May 16, 2026
9276f9e
Delegate hover logic to `Analysis.Commands.hover`
aspeddro May 16, 2026
1c9f4b4
Rename `tokenModifiersString` to `tokenModifiers` with correct type
aspeddro May 16, 2026
f81dcdb
Merge branch 'master' into lsp
aspeddro May 22, 2026
56563c2
Update dune-project
aspeddro May 22, 2026
7d0a6e0
Merge branch 'master' into lsp
aspeddro May 30, 2026
f0e8468
Merge branch 'master' into lsp
aspeddro May 31, 2026
104bb77
Refactor LSP test infrastructure
aspeddro May 31, 2026
555bb76
ci: add linux-headers
aspeddro May 31, 2026
e8e3dc0
ci: add linux-headers-generic
aspeddro May 31, 2026
c0bdf8b
ci: linux-libc-dev
aspeddro May 31, 2026
4e26483
ci: add build-essential
aspeddro May 31, 2026
dafb3d9
ci: add build-essential and linux-libc-dev
aspeddro May 31, 2026
682137e
ci: update cache version to v5
aspeddro May 31, 2026
ee3f8ad
ci: make Linux headers visible to musl-gcc
aspeddro Jun 1, 2026
d26a86a
Merge branch 'master' into lsp
aspeddro Jun 1, 2026
91f82e4
ci: support arm and disable test for build for ocaml 5.0
aspeddro Jun 1, 2026
921ee2c
makefile: add test-lsp
aspeddro Jun 2, 2026
2d19cb8
Merge branch 'master' into lsp
aspeddro Jun 3, 2026
b556990
Add LSP compiler diagnostics and file watching
aspeddro Jun 5, 2026
6c1c18d
Comment to add more compiler log test
aspeddro Jun 6, 2026
337066d
ci: add lsp test step
aspeddro Jun 6, 2026
9b86e9d
fix opam install ppx_expect
aspeddro Jun 6, 2026
b6566fd
ci: run test inside opam `opam exec --`
aspeddro Jun 6, 2026
350aaa7
lsp: disable hover supports_markdown_links for now
aspeddro Jun 6, 2026
0461d57
Move Eio_main setup to LSP executable
aspeddro Jun 6, 2026
7ac8f90
ci: skip lsp tests on Windows
aspeddro Jun 6, 2026
3e1cde6
Expand LSP request handling and diagnostics
aspeddro Jun 7, 2026
126f691
Enforce LSP server lifecycle
aspeddro Jun 7, 2026
2bcd8dc
analysis refactor: remove global state `Shared_types.state`
aspeddro Jun 7, 2026
5127e6a
lsp: use analysis state
aspeddro Jun 7, 2026
3f6d138
Revert "analysis refactor: remove global state `Shared_types.state`"
aspeddro Jun 8, 2026
7a1f9db
Merge branch 'master' into lsp
aspeddro Jun 8, 2026
f74e2c9
analysis: add state_to_yojson
aspeddro Jun 8, 2026
688f5cd
lsp: refactor load_full
aspeddro Jun 8, 2026
2616cc1
add minimal param to State.to_yojson
aspeddro Jun 9, 2026
989b85d
Makefile: skip test on Windows and update ci
aspeddro Jun 9, 2026
1ea5304
refactor: add `discover_subpackages_and_populate`
aspeddro Jun 10, 2026
c9f7f16
Merge branch 'master' into lsp
aspeddro Jun 10, 2026
911cf85
fix type error from latest master merge
aspeddro Jun 10, 2026
967d34e
Improve LSP workspace initialization and package resolution
aspeddro Jun 10, 2026
0853d3c
Implement code_actions.ml
aspeddro Jun 13, 2026
12d2e75
lsp format: use `rescript format` command
aspeddro Jun 13, 2026
a4635e3
Add code actions from compiler log
aspeddro Jun 13, 2026
dc2d30f
Add LSP configuration handling
aspeddro Jun 14, 2026
d9308a1
Circular dependency diagnostics: expand end character
aspeddro Jun 14, 2026
5759740
Add LSP compiler config parsing
aspeddro Jun 14, 2026
a31d367
add code actions and custom requests
aspeddro Jun 14, 2026
fe72544
fix dune tests
aspeddro Jun 14, 2026
71829e3
code action: check for window/showDocuent support
aspeddro Jun 15, 2026
42f097a
Add LSP file navigation commands
aspeddro Jun 16, 2026
aa66d0e
chore: renames and minor fixes
aspeddro Jun 16, 2026
a6645f6
add todo comments and minor fixes
aspeddro Jun 16, 2026
fe3e496
add lsp.md
aspeddro Jun 16, 2026
dddcf27
Update lsp.md
aspeddro Jun 16, 2026
7d693f8
Merge branch 'master' into lsp
aspeddro Jun 17, 2026
a0a9226
Omit empty document symbol children
aspeddro Jun 17, 2026
f0c9b00
Fix lsp document symbol
aspeddro Jun 17, 2026
e547876
Update lsp.md
aspeddro Jun 17, 2026
7bda550
Add server notification `rescript/compilationFinished`
aspeddro Jun 17, 2026
43869d9
compiler_log: add warning number
aspeddro Jun 17, 2026
d9dba17
add warning number in diagnostic message
aspeddro Jun 18, 2026
6078f60
Add more test to compiler log parser
aspeddro Jun 18, 2026
691c2fb
Add cli
aspeddro Jun 18, 2026
5ec4d65
fix Neovim bug document symbol
aspeddro Jun 19, 2026
2872ed5
minimal refactor on rescript_language_server.ml
aspeddro Jun 19, 2026
f059445
support `workspace/codeLens/refresh`
aspeddro Jun 19, 2026
fa21eec
Resolve runtime packages from workspace node_modules
aspeddro Jun 19, 2026
434d5b8
build system: remove `RESCRIPT_RUNTIME` env var
aspeddro Jun 19, 2026
0036ae7
Make Configuration unstrict
aspeddro Jun 19, 2026
763f61d
add more log message for invalid settings
aspeddro Jun 19, 2026
714af2c
dump server state: add configuration and order elements
aspeddro Jun 19, 2026
9dc1bfc
Server request settings from item `rescript.settings`
aspeddro Jun 19, 2026
1518254
move Exit to end
aspeddro Jun 19, 2026
5138750
Support TextDocumentDiagnostic and improve TextDocumentDidOpen
aspeddro Jun 19, 2026
113df9f
Keep diagnostic sources separate
aspeddro Jun 19, 2026
2889b5a
Use sourcedirs for initial compiler diagnostics
aspeddro Jun 19, 2026
632dcec
remove double newline from message diagnostic
aspeddro Jun 19, 2026
223c421
update analysis tests
aspeddro Jun 19, 2026
def48a0
refactor compiler log parser
aspeddro Jun 20, 2026
9ff490c
cli, print to stderr
aspeddro Jun 20, 2026
d633159
refactor compiler log to use option for range
aspeddro Jun 20, 2026
78c3e21
Update compiler log tests snapshots
aspeddro Jun 20, 2026
1e95aab
Update compiler_config.ml
aspeddro Jun 20, 2026
5808d26
Remove comment from code_actions.ml
aspeddro Jun 20, 2026
e340e40
Avoid duplicate syntax diagnostics on document changes
aspeddro Jun 20, 2026
08b6557
minor fixes: add todo comment and fix typos in messages
aspeddro Jun 20, 2026
c14de44
workspace/configuration section must use `rescript`
aspeddro Jun 20, 2026
ee9331e
Improve todo comments
aspeddro Jun 20, 2026
96505e1
Update lsp.md
aspeddro Jun 20, 2026
3247c2d
Update lsp.md
aspeddro Jun 20, 2026
3cb3190
Refactor cmt_viewer.dump for serve-side
aspeddro Jun 20, 2026
66200a1
Refactor execute commands. Move logic to module execute_commands.ml
aspeddro Jun 21, 2026
5a696e4
Move format logic to module Formatter.ml
aspeddro Jun 21, 2026
0efba12
Refactor code, better error messages
aspeddro Jun 21, 2026
207a05f
Analysis cmt dump return a string instead a option
aspeddro Jun 21, 2026
4c1d668
Update lsp.md
aspeddro Jun 21, 2026
adeef92
minor fixes
aspeddro Jun 21, 2026
eaca209
minor refactor
aspeddro Jun 21, 2026
d2b939a
Merge branch 'master' into lsp
aspeddro Jun 22, 2026
62aadc8
fix typo: Unknow -> Unknown
aspeddro Jun 30, 2026
3d32ad6
code actions: use %todo
aspeddro Jun 30, 2026
e7e4edd
Update lsp.md
aspeddro Jun 30, 2026
7ecb29e
Update lsp.md
aspeddro Jun 30, 2026
dcbb246
lsp.md: fix typos
aspeddro Jun 30, 2026
9e18966
Add rescript_language_server.mli
aspeddro Jul 1, 2026
5e44b5a
update formatter and lsp.md
aspeddro Jul 12, 2026
b1128cd
Resolve some TODOs
aspeddro Jul 16, 2026
ab13d92
Restore get_runtime_dir in build_system.ml
aspeddro Jul 17, 2026
2124bc0
Resolve todo resolve dep resolution using analysis
aspeddro Jul 17, 2026
0880539
Remove signature help setting. Enable by default
aspeddro Jul 17, 2026
b1d3224
Replace command `rescript-vscode.go_to_location` with native URls
aspeddro Jul 17, 2026
c2b3660
Update lsp.md
aspeddro Jul 17, 2026
eac2a24
Merge branch 'master' into lsp
aspeddro Jul 17, 2026
7413dc4
Restore step ci `Make Linux headers visible to musl-gcc`
aspeddro Jul 17, 2026
0b6206e
Update action.yml
aspeddro Jul 17, 2026
983c968
Restore version in action.yml
aspeddro Jul 17, 2026
6b53a89
Fix uring install on ci
aspeddro Jul 17, 2026
592a731
Update lsp.md and add notes.md
aspeddro Jul 17, 2026
e9a47cc
Integrate lsp command into Rewatch
aspeddro Jul 17, 2026
6d3d8a5
Make binary statically linked
aspeddro Jul 17, 2026
5e320a4
Fix stale and flickering LSP diagnostics
aspeddro Jul 25, 2026
f2caebc
add lsp in COMPILER_SOURCES
aspeddro Jul 25, 2026
51be468
fix duplicated diagnostic
aspeddro Jul 25, 2026
977c321
Update test.ml
aspeddro Jul 25, 2026
14fcdfd
Fix formatter
aspeddro Jul 25, 2026
4f1261e
Refactor document store to use incremental text change
aspeddro Jul 26, 2026
0a6bc45
Fix neovim bug in test dev
aspeddro Jul 26, 2026
24e0e34
Update lsp.md
aspeddro Jul 26, 2026
0f17da8
Add Document.extension_of_kind
aspeddro Jul 31, 2026
74bdab7
test: enable tests on windows using Unix.open_process_args
aspeddro Jul 31, 2026
11f17cb
implement test e2e
aspeddro Aug 2, 2026
59b49ce
Merge branch 'master' into lsp
aspeddro Oct 23, 2026
17d694e
update yarn.lock
aspeddro Oct 23, 2026
ba2141e
remove lsp from rust rewatch
aspeddro Oct 23, 2026
7153a6e
update makefile lsp tests
aspeddro Oct 23, 2026
e612509
add hover test
aspeddro Oct 23, 2026
a9e7508
Add more lsp tests
aspeddro Oct 24, 2026
cc126b8
Add full tests
aspeddro Oct 24, 2026
3e2a095
Move lsp entrypoint to rewatch-ocaml
aspeddro Oct 24, 2026
d0d935c
Fix module shadow
aspeddro Oct 24, 2026
97485ad
Remove `packages/@rescript/darwin-x64`
aspeddro Oct 24, 2026
25c8ea8
Remove rescript_language_server_exe binary from bin.js files
aspeddro Oct 24, 2026
7041f86
Fix `dune runtest`
aspeddro Oct 24, 2026
ba7b4c2
Merge branch 'master' into lsp
aspeddro Oct 25, 2026
b4367d4
Restore lsp tests on CI
aspeddro Oct 25, 2026
7ae1e3d
Restore test-rewatch-rust rule in makefile
aspeddro Oct 25, 2026
a0ea8d0
Merge branch 'master' into lsp
aspeddro Oct 26, 2026
defa136
write file for dump cmt and server state
aspeddro Oct 26, 2026
ed86dbb
Update lsp.md and notes.md
aspeddro Oct 26, 2026
ecd62e7
Merge branch 'master' into lsp
aspeddro Oct 26, 2026
f010956
Update hover_jsx.ml
aspeddro Oct 26, 2026
ef543ff
Merge branch 'master' into lsp
aspeddro Oct 31, 2026
5be287b
Fix Analysis.Create_interface.command
aspeddro Oct 31, 2026
b499a88
Disable workspaceFolders
aspeddro Oct 31, 2026
a6edb10
Remove comment interFileDependencies
aspeddro Oct 31, 2026
b7147d1
Recover the LSP analysis context after a workspace build
aspeddro Oct 31, 2026
fec7da9
Update tests
aspeddro Oct 31, 2026
f2e3a7a
Remove uri.mli, package.json entry and
aspeddro Oct 31, 2026
2152e00
Add `position_encoding` option in state
aspeddro Oct 31, 2026
93bec6c
Fixed helpers.ml: the source extension is removed before appending the
aspeddro Oct 31, 2026
406f62c
Resolve compiled JavaScript and interface artifacts using the requested
aspeddro Oct 31, 2026
e440b15
Fixed: a nonempty workspaceFolders list now selects its first folder
aspeddro Oct 31, 2026
2611be3
Add position_encoding in `State.to_yojson`
aspeddro Oct 31, 2026
427f2db
Close formatter pipes and reap the child process when formatting fails,
aspeddro Oct 31, 2026
6c444d4
Add CHANGELOG fragment
aspeddro Oct 31, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 60 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,13 @@ jobs:
exe-suffix: ".exe"
dune-profile: release

# Disable for now. eio and eio_main require ocaml >= 5.2.0
# Verify that the compiler still builds with the oldest OCaml version we support.
# Steps comparing OCaml and Rust rewatch are skipped on this job; the
# first linux-x64 job runs them. OCaml 5.0 does not build with GCC 15
# (C23 by default), so this job stays on Ubuntu 24.04.
- os: ubuntu-24.04
ocaml_compiler: ocaml-variants.5.0.0+options,ocaml-option-static
node-target: linux-x64
rust-target: x86_64-unknown-linux-musl
dune-profile: static
# - os: ubuntu-24.04
# ocaml_compiler: ocaml-variants.5.0.0+options,ocaml-option-static
# node-target: linux-x64
# rust-target: x86_64-unknown-linux-musl
# dune-profile: static

runs-on: ${{matrix.os}}

Expand Down Expand Up @@ -110,6 +108,56 @@ jobs:
exe-suffix: ${{ matrix.exe-suffix }}
run-quality-checks: "true"

# The static OCaml switch uses musl-gcc. linux-libc-dev installs Linux
# headers under /usr/include, but musl-gcc searches the musl include dir.
# Link the Linux headers into musl's include path so packages with C stubs
# such as uring can include <linux/...> headers.
- name: Make Linux headers visible to musl-gcc
if: runner.os == 'Linux'
run: |
set -eux

# Get the GNU multiarch triplet for the current machine.
# Examples:
# x86_64-linux-gnu
# aarch64-linux-gnu
GNU_MULTIARCH="$(gcc -print-multiarch)"

# Convert the GNU triplet into the musl include directory name.
# Examples:
# x86_64-linux-gnu -> x86_64-linux-musl
# aarch64-linux-gnu -> aarch64-linux-musl
MUSL_MULTIARCH="${GNU_MULTIARCH%-gnu}-musl"

# musl-gcc searches this include directory.
MUSL_INCLUDE="/usr/include/${MUSL_MULTIARCH}"

# Linux arch-specific asm headers are installed here by linux-libc-dev.
GNU_ASM="/usr/include/${GNU_MULTIARCH}/asm"

# Ensure the musl include directory exists.
sudo mkdir -p "$MUSL_INCLUDE"

# Remove old paths first.
# This avoids silently keeping broken/stale symlinks from previous runs.
sudo rm -rf "$MUSL_INCLUDE/linux"
sudo rm -rf "$MUSL_INCLUDE/asm"
sudo rm -rf "$MUSL_INCLUDE/asm-generic"

# Expose Linux UAPI headers to musl-gcc.
# This fixes packages that include headers like <linux/swab.h>.
sudo ln -s /usr/include/linux "$MUSL_INCLUDE/linux"

# Expose architecture-specific asm headers to musl-gcc.
sudo ln -s "$GNU_ASM" "$MUSL_INCLUDE/asm"

# Expose generic asm headers used by many Linux headers.
sudo ln -s /usr/include/asm-generic "$MUSL_INCLUDE/asm-generic"

# Smoke test: fail early if musl-gcc still cannot find Linux headers.
echo '#include <linux/swab.h>' > /tmp/test.c
musl-gcc -c /tmp/test.c -o /tmp/test.o

- name: Setup OCaml ${{ matrix.ocaml_compiler }}
id: setup_ocaml
uses: ./.github/actions/setup-ocaml
Expand Down Expand Up @@ -235,6 +283,9 @@ jobs:
run: make -C tests/gentype_tests/typescript-react-example clean test
shell: bash

- name: Run LSP tests
run: opam exec -- make test-lsp

- name: Run OCaml rewatch parity tests
if: ${{ !contains(matrix.ocaml_compiler, '5.0.0') }}
timeout-minutes: 20
Expand Down Expand Up @@ -512,7 +563,7 @@ jobs:
uses: actions/checkout@v7
- name: Run make in dev container
uses: devcontainers/ci@v0.3
with:
with:
push: never
runCmd: make

Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ clean-rewatch:

# Compiler

COMPILER_SOURCE_DIRS := compiler tests analysis tools rewatch-ocaml
COMPILER_SOURCE_DIRS := compiler tests analysis tools rewatch-ocaml lsp
COMPILER_SOURCES = $(shell find $(COMPILER_SOURCE_DIRS) -type f \( -name '*.ml' -o -name '*.mli' -o -name '*.c' -o -name '*.h' -o -name '*.dune' -o -name dune -o -name dune-project \))
COMPILER_BIN_NAMES := bsc rescript-editor-analysis rescript-tools rescript
COMPILER_EXES := $(addsuffix .exe,$(addprefix $(BIN_DIR)/,$(COMPILER_BIN_NAMES)))
Expand Down Expand Up @@ -191,7 +191,10 @@ test-rewatch: lib
test-rewatch-rust: lib rewatch
./rewatch/tests/suite.sh $(RESCRIPT_RUST_EXE)

test-all: test test-gentype test-analysis test-tools test-rewatch
test-lsp: lib
@dune runtest tests/lsp_tests

test-all: test test-gentype test-analysis test-tools test-rewatch test-lsp

# Playground

Expand Down
63 changes: 48 additions & 15 deletions analysis/src/module_resolution.ml
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
let ( /+ ) = Filename.concat

let rec resolve_node_module_path ~start_path name =
if name = "@rescript/runtime" then
(* Hack: we need a reliable way to resolve modules in monorepos. *)
Some (Runtime_package.get_path ())
let package_path name =
let scope = Filename.dirname name in
let name = Filename.basename name in
match scope.[0] with
| '@' -> scope /+ name
| _ -> name

let resolve_deno_pnpm ~start_path name =
let create_path folder =
start_path /+ "node_modules" /+ folder /+ "node_modules"
/+ package_path name
in
let deno = create_path ".deno" in
let pnpm = create_path ".pnpm" in
match (Files.if_exists deno, Files.if_exists pnpm) with
| Some deno, None -> Some deno
| None, Some pnpm -> Some pnpm
| Some deno, Some pnpm ->
failwith
(Printf.sprintf
"Failed to resolve path for %s. Conflict: two directories found. one \
for Deno (%s) and one for pnpm (%s)."
name deno pnpm)
| _ -> None

let rec resolve_from_node_modules ~start_path name =
let path = start_path /+ "node_modules" /+ package_path name in
if Files.exists path then Some path
else
let scope = Filename.dirname name in
let name = Filename.basename name in
let name =
match scope.[0] with
| '@' -> scope /+ name
| _ -> name
in
let path = start_path /+ "node_modules" /+ name in
if Files.exists path then Some path
else if Filename.dirname start_path = start_path then None
else resolve_node_module_path ~start_path:(Filename.dirname start_path) name
match resolve_deno_pnpm ~start_path name with
| Some p -> Some p
| None ->
if Filename.dirname start_path = start_path then None
else
resolve_from_node_modules ~start_path:(Filename.dirname start_path) name

let resolve_node_module_path ?(fallback_to_runtime_package = true) ~start_path
name =
match resolve_from_node_modules ~start_path name with
| Some path -> Some path
| None
when fallback_to_runtime_package
&& name = Runtime_package.name
&& Files.exists (Runtime_package.get_path ()) ->
(* Compiler-local fallback for development builds where the runtime package
is not installed in the target workspace. Real project installs must win
so LSP definition locations point at the workspace's node_modules. *)
Some (Runtime_package.get_path ())
| None -> None
105 changes: 105 additions & 0 deletions analysis/src/shared_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -979,3 +979,108 @@ let extract_exp_apply_args ~args =
| [] -> List.rev acc
in
args |> process_args ~acc:[]

let state_to_yojson (state : state) =
let option_to_yojson f = function
| None -> `Null
| Some value -> f value
in

let string_set_to_yojson set =
`List (set |> File_set.elements |> List.map (fun value -> `String value))
in

let path_to_yojson path = `List (List.map (fun item -> `String item) path) in

let paths_to_yojson = function
| Impl {cmt; res} ->
`Assoc
[("kind", `String "Impl"); ("cmt", `String cmt); ("res", `String res)]
| Namespace {cmt} ->
`Assoc [("kind", `String "Namespace"); ("cmt", `String cmt)]
| IntfAndImpl {cmti; resi; cmt; res} ->
`Assoc
[
("kind", `String "IntfAndImpl");
("cmti", `String cmti);
("resi", `String resi);
("cmt", `String cmt);
("res", `String res);
]
in

let paths_for_module_to_yojson paths_for_module =
paths_for_module |> Hashtbl.to_seq
|> Seq.map (fun (file, paths) -> (file, paths_to_yojson paths))
|> List.of_seq
|> fun fields -> `Assoc fields
in

let autocomplete_to_yojson autocomplete =
autocomplete |> Misc.String_map.bindings
|> List.map (fun (name, files) ->
(name, `List (List.map (fun file -> `String file) files)))
|> fun fields -> `Assoc fields
in

let package_to_yojson (package : package) =
let major, minor = package.rescript_version in
`Assoc
[
( "generic_jsx_module",
option_to_yojson
(fun value -> `String value)
package.generic_jsx_module );
("suffix", `String package.suffix);
("root_path", `String package.root_path);
("project_files", string_set_to_yojson package.project_files);
( "dependencies",
`List (package.dependencies |> List.map (fun x -> `String x)) );
("dependencies_files", string_set_to_yojson package.dependencies_files);
("paths_for_module", paths_for_module_to_yojson package.paths_for_module);
( "namespace",
option_to_yojson (fun value -> `String value) package.namespace );
("opens", `List (List.map path_to_yojson package.opens));
( "rescript_version",
`Assoc [("major", `Int major); ("minor", `Int minor)] );
("autocomplete", autocomplete_to_yojson package.autocomplete);
]
in

let file_to_yojson (file : File.t) =
`Assoc
[
("uri", `String (file.uri |> Lsp.Uri.to_string));
("module_name", `String file.module_name);
("stamps_count", `Int (List.length (Stamps.get_entries file.stamps)));
("structure_name", `String file.structure.name);
( "structure_docstring",
`List (List.map (fun value -> `String value) file.structure.docstring)
);
("structure_items_count", `Int (List.length file.structure.items));
]
in

let cmt_cache =
state.cmt_cache |> Hashtbl.to_seq
|> Seq.map (fun (file_path, file) -> (file_path, file_to_yojson file))
|> List.of_seq
in

let root_for_uri =
state.root_for_uri |> Hashtbl.to_seq |> List.of_seq
|> List.map (fun (uri, str) -> [(Lsp.Uri.to_string uri, `String str)])
|> List.flatten
in

let packages_by_root =
state.packages_by_root |> Hashtbl.to_seq |> List.of_seq
|> List.map (fun (root, package) -> (root, package_to_yojson package))
in

`Assoc
[
("cmt_cache", `Assoc cmt_cache);
("root_for_uri", `Assoc root_for_uri);
("packages_by_root", `Assoc packages_by_root);
]
3 changes: 3 additions & 0 deletions changes/language-server.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Add an experimental ReScript language server bundled with the compiler, available
through `rescript lsp --stdio`. It reuses compiler analysis for hover,
completion, navigation, rename, diagnostics, formatting, and code actions.
2 changes: 1 addition & 1 deletion dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(dirs compiler tests analysis tools rewatch-ocaml)
(dirs compiler tests analysis tools rewatch-ocaml lsp)

; All warnings are enabled, except:
; - 4 (fragile-match): wildcard cases are used deliberately.
Expand Down
18 changes: 18 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,21 @@
(yojson
(= 3.0.0))
(odoc :with-doc)))

(package
(name rescript-language-server)
(synopsis "ReScript LSP")
(depends
(ocaml
(>= 5.0.0))
(lsp
(>= 1.22.0))
(eio
(>= 1.3))
(eio_main
(>= 1.3))
analysis
dune
ppx_deriving_yojson
(ppx_expect
(and :with-test (= v0.17.3)))))
Loading
Loading