Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
693422c
initial lsp
aspeddro Dec 1, 2024
34bcd22
Merge branch 'master' into lsp
aspeddro Dec 30, 2024
7f209ef
Merge branch 'master' into lsp
aspeddro Mar 17, 2025
e203450
Merge branch 'master' into lsp
aspeddro Jun 20, 2025
e1273d6
Merge branch 'master' into lsp
aspeddro Apr 28, 2026
129af21
update
aspeddro Apr 29, 2026
6b65a25
add state
aspeddro Apr 30, 2026
e2989d0
Extract server I/O into Server module and simplify handlers
aspeddro May 12, 2026
a99abc6
Add parse_implementation_from_source and refactor LSP server
aspeddro May 12, 2026
2529f30
Merge branch 'master' into lsp
aspeddro May 13, 2026
365836c
Split LSP into bin/src layout and add hover integration test
aspeddro May 14, 2026
1692629
Refactor analysis to decouple I/O from core logic
aspeddro May 16, 2026
743126f
Delegate hover logic to `Analysis.Commands.hover`
aspeddro May 16, 2026
0e522be
Rename `tokenModifiersString` to `tokenModifiers` with correct type
aspeddro May 16, 2026
9da83c8
Merge branch 'master' into lsp
aspeddro May 22, 2026
9df9079
Update dune-project
aspeddro May 22, 2026
1b65e21
Merge branch 'master' into lsp
aspeddro May 30, 2026
768a040
Merge branch 'master' into lsp
aspeddro May 31, 2026
29cd3d7
Refactor LSP test infrastructure
aspeddro May 31, 2026
a20da0d
ci: add linux-headers
aspeddro May 31, 2026
5a57bbc
ci: add linux-headers-generic
aspeddro May 31, 2026
9442c4b
ci: linux-libc-dev
aspeddro May 31, 2026
64dffd8
ci: add build-essential
aspeddro May 31, 2026
e0f6296
ci: add build-essential and linux-libc-dev
aspeddro May 31, 2026
8cebaf2
ci: update cache version to v5
aspeddro May 31, 2026
85138b1
ci: make Linux headers visible to musl-gcc
aspeddro Jun 1, 2026
ee6de86
Merge branch 'master' into lsp
aspeddro Jun 1, 2026
66b69fe
ci: support arm and disable test for build for ocaml 5.0
aspeddro Jun 1, 2026
c50f613
makefile: add test-lsp
aspeddro Jun 2, 2026
fd83f06
Merge branch 'master' into lsp
aspeddro Jun 3, 2026
890fd16
Add LSP compiler diagnostics and file watching
aspeddro Jun 5, 2026
39639c6
Comment to add more compiler log test
aspeddro Jun 6, 2026
5e002cb
ci: add lsp test step
aspeddro Jun 6, 2026
5781622
fix opam install ppx_expect
aspeddro Jun 6, 2026
728c4bf
ci: run test inside opam `opam exec --`
aspeddro Jun 6, 2026
33edc85
lsp: disable hover supports_markdown_links for now
aspeddro Jun 6, 2026
75a6123
Move Eio_main setup to LSP executable
aspeddro Jun 6, 2026
126f67a
ci: skip lsp tests on Windows
aspeddro Jun 6, 2026
5d14a57
Expand LSP request handling and diagnostics
aspeddro Jun 7, 2026
015a2d2
Enforce LSP server lifecycle
aspeddro Jun 7, 2026
bbcb7b9
analysis refactor: remove global state `Shared_types.state`
aspeddro Jun 7, 2026
b63a60f
lsp: use analysis state
aspeddro Jun 7, 2026
88190b9
Revert "analysis refactor: remove global state `Shared_types.state`"
aspeddro Jun 8, 2026
4632fab
Merge branch 'master' into lsp
aspeddro Jun 8, 2026
3be179c
analysis: add state_to_yojson
aspeddro Jun 8, 2026
9bc661c
lsp: refactor load_full
aspeddro Jun 8, 2026
8ec52ae
add minimal param to State.to_yojson
aspeddro Jun 9, 2026
22a5eeb
Makefile: skip test on Windows and update ci
aspeddro Jun 9, 2026
16e4fb2
refactor: add `discover_subpackages_and_populate`
aspeddro Jun 10, 2026
2a1bf04
Merge branch 'master' into lsp
aspeddro Jun 10, 2026
67a741f
fix type error from latest master merge
aspeddro Jun 10, 2026
d9ca156
Improve LSP workspace initialization and package resolution
aspeddro Jun 10, 2026
ac07b29
Implement code_actions.ml
aspeddro Jun 13, 2026
ba293ab
lsp format: use `rescript format` command
aspeddro Jun 13, 2026
87e280d
Add code actions from compiler log
aspeddro Jun 13, 2026
9f6c805
Add LSP configuration handling
aspeddro Jun 14, 2026
b4e797c
Circular dependency diagnostics: expand end character
aspeddro Jun 14, 2026
1566ae2
Add LSP compiler config parsing
aspeddro Jun 14, 2026
fc76cba
add code actions and custom requests
aspeddro Jun 14, 2026
2fae316
fix dune tests
aspeddro Jun 14, 2026
0107015
code action: check for window/showDocuent support
aspeddro Jun 15, 2026
85942cd
Add LSP file navigation commands
aspeddro Jun 16, 2026
2bcd312
chore: renames and minor fixes
aspeddro Jun 16, 2026
879995d
add todo comments and minor fixes
aspeddro Jun 16, 2026
e246eef
add lsp.md
aspeddro Jun 16, 2026
b9d2730
Update lsp.md
aspeddro Jun 16, 2026
138172b
Merge branch 'master' into lsp
aspeddro Jun 17, 2026
55d0431
Omit empty document symbol children
aspeddro Jun 17, 2026
4194057
Fix lsp document symbol
aspeddro Jun 17, 2026
cc7ed4f
Update lsp.md
aspeddro Jun 17, 2026
de08232
Add server notification `rescript/compilationFinished`
aspeddro Jun 17, 2026
1152368
compiler_log: add warning number
aspeddro Jun 17, 2026
d2afded
add warning number in diagnostic message
aspeddro Jun 18, 2026
d3cfd95
Add more test to compiler log parser
aspeddro Jun 18, 2026
11ac541
Add cli
aspeddro Jun 18, 2026
1ccc66e
fix Neovim bug document symbol
aspeddro Jun 19, 2026
94d0d87
minimal refactor on rescript_language_server.ml
aspeddro Jun 19, 2026
2943e98
support `workspace/codeLens/refresh`
aspeddro Jun 19, 2026
0c4e43a
Resolve runtime packages from workspace node_modules
aspeddro Jun 19, 2026
47bae3b
build system: remove `RESCRIPT_RUNTIME` env var
aspeddro Jun 19, 2026
5133b39
Make Configuration unstrict
aspeddro Jun 19, 2026
a41e580
add more log message for invalid settings
aspeddro Jun 19, 2026
9a1bbb8
dump server state: add configuration and order elements
aspeddro Jun 19, 2026
08d0f48
Server request settings from item `rescript.settings`
aspeddro Jun 19, 2026
e0dcc88
move Exit to end
aspeddro Jun 19, 2026
d8e0e67
Support TextDocumentDiagnostic and improve TextDocumentDidOpen
aspeddro Jun 19, 2026
7c7c209
Keep diagnostic sources separate
aspeddro Jun 19, 2026
5813157
Use sourcedirs for initial compiler diagnostics
aspeddro Jun 19, 2026
393a6c3
remove double newline from message diagnostic
aspeddro Jun 19, 2026
dd758b8
update analysis tests
aspeddro Jun 19, 2026
81b6f1d
refactor compiler log parser
aspeddro Jun 20, 2026
d18955c
cli, print to stderr
aspeddro Jun 20, 2026
abf9743
refactor compiler log to use option for range
aspeddro Jun 20, 2026
e3eab6e
Update compiler log tests snapshots
aspeddro Jun 20, 2026
0eef9a4
Update compiler_config.ml
aspeddro Jun 20, 2026
07cfb97
Remove comment from code_actions.ml
aspeddro Jun 20, 2026
3737687
Avoid duplicate syntax diagnostics on document changes
aspeddro Jun 20, 2026
1fd9414
minor fixes: add todo comment and fix typos in messages
aspeddro Jun 20, 2026
acb52a5
workspace/configuration section must use `rescript`
aspeddro Jun 20, 2026
2f10c7f
Improve todo comments
aspeddro Jun 20, 2026
f8c0d4a
Update lsp.md
aspeddro Jun 20, 2026
42fe2ae
Update lsp.md
aspeddro Jun 20, 2026
be81434
Refactor cmt_viewer.dump for serve-side
aspeddro Jun 20, 2026
c80ae00
Refactor execute commands. Move logic to module execute_commands.ml
aspeddro Jun 21, 2026
6ddcce5
Move format logic to module Formatter.ml
aspeddro Jun 21, 2026
2d411c9
Refactor code, better error messages
aspeddro Jun 21, 2026
0f16ff5
Analysis cmt dump return a string instead a option
aspeddro Jun 21, 2026
a5f8c82
Update lsp.md
aspeddro Jun 21, 2026
b712f28
minor fixes
aspeddro Jun 21, 2026
136c02f
minor refactor
aspeddro Jun 21, 2026
a79ed75
Merge branch 'master' into lsp
aspeddro Jun 22, 2026
0e0b495
fix typo: Unknow -> Unknown
aspeddro Jun 30, 2026
a13340d
code actions: use %todo
aspeddro Jun 30, 2026
82dad0a
Update lsp.md
aspeddro Jun 30, 2026
d313206
Update lsp.md
aspeddro Jun 30, 2026
23337d4
lsp.md: fix typos
aspeddro Jun 30, 2026
539d1a6
Add rescript_language_server.mli
aspeddro Jul 1, 2026
649ab7c
update formatter and lsp.md
aspeddro Jul 12, 2026
3b4cfe3
Resolve some TODOs
aspeddro Jul 16, 2026
bd375c5
Restore get_runtime_dir in build_system.ml
aspeddro Jul 17, 2026
7079611
Resolve todo resolve dep resolution using analysis
aspeddro Jul 17, 2026
4959f72
Remove signature help setting. Enable by default
aspeddro Jul 17, 2026
9872578
Replace command `rescript-vscode.go_to_location` with native URls
aspeddro Jul 17, 2026
7b4cdfc
Update lsp.md
aspeddro Jul 17, 2026
ef60d77
Merge branch 'master' into lsp
aspeddro Jul 17, 2026
45e2308
Restore step ci `Make Linux headers visible to musl-gcc`
aspeddro Jul 17, 2026
e871beb
Update action.yml
aspeddro Jul 17, 2026
87b1b87
Restore version in action.yml
aspeddro Jul 17, 2026
041bf08
Fix uring install on ci
aspeddro Jul 17, 2026
5568145
Update lsp.md and add notes.md
aspeddro Jul 17, 2026
a0e32ab
Integrate lsp command into Rewatch
aspeddro Jul 17, 2026
9c999ee
Make binary statically linked
aspeddro Jul 17, 2026
bef996d
Fix stale and flickering LSP diagnostics
aspeddro Jul 25, 2026
5061f2f
add lsp in COMPILER_SOURCES
aspeddro Jul 25, 2026
1a57d99
fix duplicated diagnostic
aspeddro Jul 25, 2026
201b3e1
Update test.ml
aspeddro Jul 25, 2026
22b5f6b
Fix formatter
aspeddro Jul 25, 2026
6e6d0ec
Refactor document store to use incremental text change
aspeddro Jul 26, 2026
6cd1f91
Fix neovim bug in test dev
aspeddro Jul 26, 2026
ea637a1
Update lsp.md
aspeddro Jul 26, 2026
30b0921
Add Document.extension_of_kind
aspeddro Jul 31, 2026
4356d72
test: enable tests on windows using Unix.open_process_args
aspeddro Jul 31, 2026
c65e5d1
implement test e2e
aspeddro Aug 2, 2026
b3d96f9
Merge branch 'master' into lsp
aspeddro Oct 23, 2026
2863c1c
update yarn.lock
aspeddro Oct 23, 2026
0ee23ac
remove lsp from rust rewatch
aspeddro Oct 23, 2026
45e23a9
update makefile lsp tests
aspeddro Oct 23, 2026
4935477
add hover test
aspeddro Oct 23, 2026
646b885
Add more lsp tests
aspeddro Oct 24, 2026
a94e6d4
Add full tests
aspeddro Oct 24, 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
71 changes: 62 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 @@ -109,6 +107,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 @@ -212,6 +260,11 @@ jobs:
if: runner.os != 'Windows'
run: make -C tests/gentype_tests/typescript-react-example clean test

# The Makefile skip some tests on Windows because OCaml Eio process operations is not supported on Windows yet
# Eio.Stdenv.process_mgr raise a error, see https://github.com/ocaml-multicore/eio/blob/37d6e67f7e25b43e4a66574ed98838c79f1a21b4/lib_eio_windows/eio_windows.ml#L36
- name: Run LSP tests
run: opam exec -- make test-lsp

# On Windows, after running setup-ocaml (if it wasn't cached yet or the cache couldn't be restored),
# Cygwin bash is used instead of Git Bash for Windows, breaking the rewatch tests.
# So we need to adjust the path to bring back Git Bash for Windows.
Expand Down Expand Up @@ -525,7 +578,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
8 changes: 4 additions & 4 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 @@ -188,10 +188,10 @@ test-gentype: lib
test-rewatch: lib
./rewatch/tests/suite.sh $(RESCRIPT_EXE)

test-rewatch-rust: lib rewatch
./rewatch/tests/suite.sh $(RESCRIPT_RUST_EXE)
test-lsp: lib
@dune runtest tests/lsp_tests

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

# Playground

Expand Down
2 changes: 1 addition & 1 deletion analysis/src/code_actions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

let make ~title ~kind ~uri ~new_text ~range =
let text_document =
Lsp.Types.OptionalVersionedTextDocumentIdentifier.create
Lsp.Types.OptionalVersionedTextDocumentIdentifier.create ~version:0
~uri:(Uri.from_string uri) ()
in
let edit =
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/diagnostics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let document_syntax ~source ~kind_file =
~end_:
(Lsp.Types.Position.create ~line:(endline - 1) ~character:endcol)
in
Lsp.Types.Diagnostic.create ~range
Lsp.Types.Diagnostic.create ~range ~source:"ReScript"
~message:(`String (Res_diagnostics.explain diagnostic))
~severity:Lsp.Types.DiagnosticSeverity.Error ())
in
Expand Down
8 changes: 2 additions & 6 deletions analysis/src/markdown.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ let divider = "\n---\n"

type link = {start_pos: Lsp.Types.Position.t; file: string; label: string}

let link_to_command_args link =
Printf.sprintf "[\"%s\",%i,%i]" link.file link.start_pos.line
link.start_pos.character

let make_goto_command link =
Printf.sprintf "[%s](command:rescript-vscode.go_to_location?%s)" link.label
(Uri.encode_uri_component (link_to_command_args link))
Printf.sprintf "[%s](%s#L%d,%d)" link.label link.file (link.start_pos.line + 1)
(link.start_pos.character + 1)

let go_to_definition_text ~env ~pos =
let start_line, start_col = Pos.of_lexing pos in
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);
]
34 changes: 0 additions & 34 deletions analysis/src/uri.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,3 @@ let to_top_level_loc (uri : Lsp.Uri.t) =
let to_string t =
if !strip_path then Filename.basename (Lsp.Uri.to_path t)
else Lsp.Uri.to_string t

(* Light weight, hopefully-enough-for-the-purpose fn to encode URI components.
Built to handle the reserved characters listed in
https://en.wikipedia.org/wiki/Percent-encoding. Note that this function is not
general purpose, rather it's currently only for URL encoding the argument list
passed to command links in markdown. *)
let encode_uri_component text =
let ln = String.length text in
let buf = Buffer.create ln in
let rec loop i =
if i < ln then (
(match text.[i] with
| '"' -> Buffer.add_string buf "%22"
| '\'' -> Buffer.add_string buf "%22"
| ':' -> Buffer.add_string buf "%3A"
| ';' -> Buffer.add_string buf "%3B"
| '/' -> Buffer.add_string buf "%2F"
| '\\' -> Buffer.add_string buf "%5C"
| ',' -> Buffer.add_string buf "%2C"
| '&' -> Buffer.add_string buf "%26"
| '[' -> Buffer.add_string buf "%5B"
| ']' -> Buffer.add_string buf "%5D"
| '#' -> Buffer.add_string buf "%23"
| '$' -> Buffer.add_string buf "%24"
| '+' -> Buffer.add_string buf "%2B"
| '=' -> Buffer.add_string buf "%3D"
| '?' -> Buffer.add_string buf "%3F"
| '@' -> Buffer.add_string buf "%40"
| '%' -> Buffer.add_string buf "%25"
| c -> Buffer.add_char buf c);
loop (i + 1))
in
loop 0;
Buffer.contents buf
9 changes: 9 additions & 0 deletions analysis/src/uri.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type t = Lsp.Uri.t

val from_path : string -> t
val from_string : string -> t
val is_interface : t -> bool
val strip_path : bool ref
val to_path : t -> string
val to_string : t -> string
val to_top_level_loc : t -> Location.t
1 change: 1 addition & 0 deletions changes/opam-ppx-expect.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Update ppx_expect to v0.17.3 to resolve test dependencies with ppxlib 0.38 and OCaml 5.5.
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
Loading
Loading