From 28020ee1801fb7a0f7d1bb0a5fcbee0624ae2edb Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 23 Nov 2026 10:16:29 -0300 Subject: [PATCH 01/13] Add the OCaml ReScript language server Ship the language server with the compiler so editor analysis uses the matching compiler metadata instead of a separately versioned executable. Consolidate the initial implementation, tests, documentation, and build integration while retaining the upstream master history. Command added (language-server entrypoint): Before (text): rescript: build, watch, clean, format, compiler-args After (text): rescript: build, watch, clean, format, compiler-args, lsp --stdio The lsp subcommand runs the OCaml server over stdio using Eio. Connect LSP requests to the in-tree analysis library. Track editor syntax and compiler diagnostics separately, refresh analysis after builds, and provide configuration, navigation, interface creation, and debug commands. Add cross-platform stdio expect tests, editor setup documentation, CI integration, and third-party license notices for the linked dependencies. Signed-off-by: Pedro Castro --- .../setup-linux-dependencies/action.yml | 51 + .github/workflows/ci.yml | 5 +- Makefile | 7 +- analysis/src/module_resolution.ml | 61 +- analysis/src/shared_types.ml | 100 ++ changes/language-server.feature.md | 3 + dune | 2 +- dune-project | 18 + licenses/README.md | 4 + licenses/components.json | 234 ++- licenses/ocaml/liburing.txt | 20 + lsp/README.md | 338 ++++ lsp/src/code_actions.ml | 523 ++++++ lsp/src/compiler_config.ml | 428 +++++ lsp/src/compiler_log.ml | 1514 +++++++++++++++++ lsp/src/configuration.ml | 52 + lsp/src/constants.ml | 9 + lsp/src/custom_requests.ml | 114 ++ lsp/src/diagnostics.ml | 396 +++++ lsp/src/document.ml | 104 ++ lsp/src/document_store.ml | 51 + lsp/src/dune | 16 + lsp/src/execute_commands.ml | 138 ++ lsp/src/formatter.ml | 123 ++ lsp/src/fs.ml | 25 + lsp/src/helpers.ml | 221 +++ lsp/src/rescript_language_server.ml | 790 +++++++++ lsp/src/rescript_language_server.mli | 5 + lsp/src/server.ml | 286 ++++ lsp/src/source_dirs.ml | 80 + lsp/src/state.ml | 142 ++ .../darwin-arm64/THIRD_PARTY_LICENSES | 1215 ++++++++++++- .../linux-arm64/THIRD_PARTY_LICENSES | 1342 ++++++++++++++- .../@rescript/linux-x64/THIRD_PARTY_LICENSES | 1342 ++++++++++++++- .../@rescript/win32-x64/THIRD_PARTY_LICENSES | 1112 +++++++++++- rescript-language-server.opam | 33 + rewatch-ocaml/README.md | 2 +- rewatch-ocaml/cli.ml | 16 +- rewatch-ocaml/cli.mli | 1 + rewatch-ocaml/dune | 2 +- rewatch-ocaml/rescript_ocaml.ml | 11 + scripts/generateThirdPartyLicenses.js | 5 +- tests/build_tests/cli_help/input.js | 22 + tests/dune | 2 +- tests/lsp_tests/README.md | 70 + tests/lsp_tests/code_action.ml | 302 ++++ tests/lsp_tests/code_lens.ml | 111 ++ tests/lsp_tests/completion.ml | 218 +++ tests/lsp_tests/completion_generic_jsx.ml | 166 ++ tests/lsp_tests/completion_jsx.ml | 36 + tests/lsp_tests/completion_resolve.ml | 61 + tests/lsp_tests/completion_typed_arrays.ml | 350 ++++ tests/lsp_tests/create_interface.ml | 118 ++ tests/lsp_tests/definition.ml | 199 +++ tests/lsp_tests/diagnostics.ml | 373 ++++ tests/lsp_tests/document_changes.ml | 41 + tests/lsp_tests/document_symbol.ml | 103 ++ tests/lsp_tests/document_syntax.ml | 104 ++ tests/lsp_tests/dune | 10 + tests/lsp_tests/execute_commands.ml | 131 ++ tests/lsp_tests/formatting.ml | 71 + tests/lsp_tests/hover.ml | 815 +++++++++ tests/lsp_tests/hover_jsx.ml | 288 ++++ tests/lsp_tests/inlay_hint.ml | 170 ++ tests/lsp_tests/output_configuration.ml | 108 ++ tests/lsp_tests/prepare_rename.ml | 41 + tests/lsp_tests/project_recovery.ml | 108 ++ tests/lsp_tests/record_rest.ml | 144 ++ tests/lsp_tests/references.ml | 261 +++ tests/lsp_tests/rename.ml | 259 +++ tests/lsp_tests/semantic_tokens.ml | 104 ++ tests/lsp_tests/signature_help.ml | 305 ++++ tests/lsp_tests/test.ml | 441 +++++ tests/lsp_tests/type_definition.ml | 93 + tests/rewatch_ounit_tests/cli_tests.ml | 18 + 75 files changed, 16555 insertions(+), 29 deletions(-) create mode 100644 changes/language-server.feature.md create mode 100644 licenses/ocaml/liburing.txt create mode 100644 lsp/README.md create mode 100644 lsp/src/code_actions.ml create mode 100644 lsp/src/compiler_config.ml create mode 100644 lsp/src/compiler_log.ml create mode 100644 lsp/src/configuration.ml create mode 100644 lsp/src/constants.ml create mode 100644 lsp/src/custom_requests.ml create mode 100644 lsp/src/diagnostics.ml create mode 100644 lsp/src/document.ml create mode 100644 lsp/src/document_store.ml create mode 100644 lsp/src/dune create mode 100644 lsp/src/execute_commands.ml create mode 100644 lsp/src/formatter.ml create mode 100644 lsp/src/fs.ml create mode 100644 lsp/src/helpers.ml create mode 100644 lsp/src/rescript_language_server.ml create mode 100644 lsp/src/rescript_language_server.mli create mode 100644 lsp/src/server.ml create mode 100644 lsp/src/source_dirs.ml create mode 100644 lsp/src/state.ml create mode 100644 rescript-language-server.opam create mode 100644 tests/lsp_tests/README.md create mode 100644 tests/lsp_tests/code_action.ml create mode 100644 tests/lsp_tests/code_lens.ml create mode 100644 tests/lsp_tests/completion.ml create mode 100644 tests/lsp_tests/completion_generic_jsx.ml create mode 100644 tests/lsp_tests/completion_jsx.ml create mode 100644 tests/lsp_tests/completion_resolve.ml create mode 100644 tests/lsp_tests/completion_typed_arrays.ml create mode 100644 tests/lsp_tests/create_interface.ml create mode 100644 tests/lsp_tests/definition.ml create mode 100644 tests/lsp_tests/diagnostics.ml create mode 100644 tests/lsp_tests/document_changes.ml create mode 100644 tests/lsp_tests/document_symbol.ml create mode 100644 tests/lsp_tests/document_syntax.ml create mode 100644 tests/lsp_tests/dune create mode 100644 tests/lsp_tests/execute_commands.ml create mode 100644 tests/lsp_tests/formatting.ml create mode 100644 tests/lsp_tests/hover.ml create mode 100644 tests/lsp_tests/hover_jsx.ml create mode 100644 tests/lsp_tests/inlay_hint.ml create mode 100644 tests/lsp_tests/output_configuration.ml create mode 100644 tests/lsp_tests/prepare_rename.ml create mode 100644 tests/lsp_tests/project_recovery.ml create mode 100644 tests/lsp_tests/record_rest.ml create mode 100644 tests/lsp_tests/references.ml create mode 100644 tests/lsp_tests/rename.ml create mode 100644 tests/lsp_tests/semantic_tokens.ml create mode 100644 tests/lsp_tests/signature_help.ml create mode 100644 tests/lsp_tests/test.ml create mode 100644 tests/lsp_tests/type_definition.ml diff --git a/.github/actions/setup-linux-dependencies/action.yml b/.github/actions/setup-linux-dependencies/action.yml index 7f2325223d1..0d461102fa7 100644 --- a/.github/actions/setup-linux-dependencies/action.yml +++ b/.github/actions/setup-linux-dependencies/action.yml @@ -18,3 +18,54 @@ runs: sudo DEBIAN_FRONTEND=noninteractive apt-get install --yes -qq \ --no-install-recommends --no-upgrade \ bubblewrap musl-tools rsync cmake + + # 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 headers. + - name: Make Linux headers visible to musl-gcc + if: runner.os == 'Linux' + shell: bash + 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 . + 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 ' > /tmp/test.c + musl-gcc -c /tmp/test.c -o /tmp/test.o diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4eb0b335e7..7b8a6d5edbe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: # tests repeat the linux-x64 job's. 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 + ocaml_compiler: ocaml-variants.5.3.0+options,ocaml-option-static node-target: linux-x64 dune-profile: static skip_rewatch_integration_tests: true @@ -267,6 +267,9 @@ jobs: opam exec -- ./_build/default/tests/rewatch_ounit_tests/rewatch_ounit_tests_main.exe -runner sequential shell: bash + - name: Run LSP tests + run: opam exec -- make test-lsp + # The canonical suite works in rewatch/testrepo and the focused one in # directories of its own, so they run side by side; each takes one to # three and a half minutes. The canonical suite fails when another diff --git a/Makefile b/Makefile index 06e7822511e..10f9498f2a8 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ $(YARN_INSTALL_STAMP): $(YARN_INSTALL_SOURCES) # Compiler -COMPILER_SOURCE_DIRS := compiler syntax tests analysis tools rewatch-ocaml +COMPILER_SOURCE_DIRS := compiler syntax 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))) @@ -159,7 +159,10 @@ test-gentype: lib test-rewatch: lib ./rewatch/tests/suite.sh $(RESCRIPT_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 diff --git a/analysis/src/module_resolution.ml b/analysis/src/module_resolution.ml index 459ae3f69f9..b91612733d9 100644 --- a/analysis/src/module_resolution.ml +++ b/analysis/src/module_resolution.ml @@ -1,18 +1,49 @@ 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 ~start_path name = + match resolve_from_node_modules ~start_path name with + | Some path -> Some path + | None + when 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 diff --git a/analysis/src/shared_types.ml b/analysis/src/shared_types.ml index 4378978a54b..b0a777ffe5e 100644 --- a/analysis/src/shared_types.ml +++ b/analysis/src/shared_types.ml @@ -946,3 +946,103 @@ 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) = + `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_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)); + ("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); + ] diff --git a/changes/language-server.feature.md b/changes/language-server.feature.md new file mode 100644 index 00000000000..3ed1fee3425 --- /dev/null +++ b/changes/language-server.feature.md @@ -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. diff --git a/dune b/dune index aff1465ae28..46b2cc2b46a 100644 --- a/dune +++ b/dune @@ -1,4 +1,4 @@ -(dirs compiler syntax tests analysis tools rewatch-ocaml) +(dirs compiler syntax tests analysis tools rewatch-ocaml lsp) ; All warnings are enabled, except: ; - 4 (fragile-match): wildcard cases are used deliberately. diff --git a/dune-project b/dune-project index a96fe358c5e..16863e8cd2e 100644 --- a/dune-project +++ b/dune-project @@ -120,3 +120,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))))) diff --git a/licenses/README.md b/licenses/README.md index 00e727afd86..707d4eccb85 100644 --- a/licenses/README.md +++ b/licenses/README.md @@ -12,6 +12,10 @@ The files are generated from `components.json` by Its version and license text come from the current opam switch. The script asks dune which opam packages the shipped executables link, and fails when one is missing from the inventory or listed without being linked. + A metadata-only compatibility package can set `licenseOpam` to the package + providing its implementation and license text (for example, `seq.base` uses + the OCaml standard library's license). Additional bundled-source notices + are included through `licenseFiles`. - Every other entry is vendored or adapted source, or a platform toolchain, with its license text in this directory or in the vendored source directory. Entries with a `platforms` field are included only there: Linux diff --git a/licenses/components.json b/licenses/components.json index 6e354de2b5f..ddf8f3116e0 100644 --- a/licenses/components.json +++ b/licenses/components.json @@ -69,7 +69,7 @@ "opam": "lsp", "source": "https://github.com/ocaml/ocaml-lsp", "license": "ISC", - "scope": "rescript-editor-analysis and rescript-tools" + "scope": "rescript, rescript-editor-analysis and rescript-tools" }, { "name": "Jsonrpc", @@ -99,6 +99,238 @@ "license": "ISC", "scope": "rescript-tools" }, + { + "name": "Eio", + "opam": "eio", + "source": "https://github.com/ocaml-multicore/eio", + "license": "ISC", + "scope": "language-server I/O in rescript" + }, + { + "name": "Eio main", + "opam": "eio_main", + "source": "https://github.com/ocaml-multicore/eio", + "license": "ISC", + "scope": "language-server event loop in rescript" + }, + { + "name": "Eio POSIX backend", + "opam": "eio_posix", + "source": "https://github.com/ocaml-multicore/eio", + "license": "ISC", + "scope": "POSIX language-server backend in rescript", + "platforms": ["darwin", "linux"] + }, + { + "name": "Eio Linux backend", + "opam": "eio_linux", + "source": "https://github.com/ocaml-multicore/eio", + "license": "ISC", + "scope": "Linux language-server backend in rescript", + "platforms": ["linux"] + }, + { + "name": "OCaml uring", + "opam": "uring", + "source": "https://github.com/ocaml-multicore/ocaml-uring", + "license": "ISC AND MIT", + "scope": "io_uring support for Eio in rescript", + "platforms": ["linux"], + "notes": "Includes vendored liburing, distributed under its MIT license.", + "licenseFiles": ["licenses/ocaml/liburing.txt"] + }, + { + "name": "Iomux", + "opam": "iomux", + "source": "https://github.com/ocaml-multicore/ocaml-iomux", + "license": "ISC", + "scope": "runtime dependency of Eio POSIX", + "platforms": ["darwin", "linux"] + }, + { + "name": "Fmt", + "opam": "fmt", + "source": "https://erratique.ch/software/fmt", + "license": "ISC", + "scope": "runtime dependency of Eio" + }, + { + "name": "Mtime", + "opam": "mtime", + "source": "https://erratique.ch/software/mtime", + "license": "ISC", + "scope": "runtime dependency of Eio" + }, + { + "name": "domain-local-await", + "opam": "domain-local-await", + "source": "https://github.com/ocaml-multicore/domain-local-await", + "license": "ISC", + "scope": "runtime dependency of Eio" + }, + { + "name": "thread-table", + "opam": "thread-table", + "source": "https://github.com/ocaml-multicore/thread-table", + "license": "ISC", + "scope": "runtime dependency of domain-local-await" + }, + { + "name": "Optint", + "opam": "optint", + "source": "https://github.com/mirage/optint", + "license": "ISC", + "scope": "runtime dependency of Eio" + }, + { + "name": "Psq", + "opam": "psq", + "source": "https://github.com/pqwy/psq", + "license": "ISC", + "scope": "runtime dependency of Eio" + }, + { + "name": "Seq compatibility package", + "opam": "seq", + "source": "https://github.com/ocaml/ocaml", + "license": "LGPL-2.1-only WITH OCaml-LGPL-linking-exception", + "scope": "standard-library iterator types used by Eio", + "licenseOpam": "ocaml", + "notes": "Metadata-only compatibility package. Seq is provided by the OCaml standard library; its license text comes from the ocaml package." + }, + { + "name": "Bigstringaf", + "opam": "bigstringaf", + "source": "https://github.com/inhabitedtype/bigstringaf", + "license": "BSD-3-Clause", + "scope": "runtime dependency of Eio" + }, + { + "name": "lwt-dllist", + "opam": "lwt-dllist", + "source": "https://github.com/mirage/lwt-dllist", + "license": "MIT", + "scope": "runtime dependency of Eio" + }, + { + "name": "OCaml Cstruct", + "opam": "cstruct", + "source": "https://github.com/mirage/ocaml-cstruct", + "license": "ISC", + "scope": "runtime dependency of Eio" + }, + { + "name": "Hmap", + "opam": "hmap", + "source": "https://erratique.ch/software/hmap", + "license": "ISC", + "scope": "runtime dependency of Eio" + }, + { + "name": "ppx_expect runtime", + "opam": "ppx_expect", + "source": "https://github.com/janestreet/ppx_expect", + "license": "MIT", + "scope": "runtime dependency of the language-server library in rescript" + }, + { + "name": "Ppxlib", + "opam": "ppxlib", + "source": "https://github.com/ocaml-ppx/ppxlib", + "license": "MIT", + "scope": "runtime dependency of ppx_expect" + }, + { + "name": "Stdio", + "opam": "stdio", + "source": "https://github.com/janestreet/stdio", + "license": "MIT", + "scope": "runtime dependency of the language-server PPX runtimes" + }, + { + "name": "Base", + "opam": "base", + "source": "https://github.com/janestreet/base", + "license": "MIT", + "scope": "runtime dependency of the language-server PPX runtimes" + }, + { + "name": "ocaml_intrinsics_kernel", + "opam": "ocaml_intrinsics_kernel", + "source": "https://github.com/janestreet/ocaml_intrinsics_kernel", + "license": "MIT", + "scope": "runtime dependency of Base" + }, + { + "name": "Sexplib0", + "opam": "sexplib0", + "source": "https://github.com/janestreet/sexplib0", + "license": "MIT", + "scope": "runtime dependency of Base and the language-server PPX runtimes" + }, + { + "name": "ppx_here runtime", + "opam": "ppx_here", + "source": "https://github.com/janestreet/ppx_here", + "license": "MIT", + "scope": "runtime dependency of ppx_expect" + }, + { + "name": "ppx_inline_test runtime", + "opam": "ppx_inline_test", + "source": "https://github.com/janestreet/ppx_inline_test", + "license": "MIT", + "scope": "runtime dependency of ppx_expect" + }, + { + "name": "time_now", + "opam": "time_now", + "source": "https://github.com/janestreet/time_now", + "license": "MIT", + "scope": "runtime dependency of ppx_inline_test" + }, + { + "name": "ppx_hash runtime", + "opam": "ppx_hash", + "source": "https://github.com/janestreet/ppx_hash", + "license": "MIT", + "scope": "runtime dependency of Base" + }, + { + "name": "ppx_enumerate runtime", + "opam": "ppx_enumerate", + "source": "https://github.com/janestreet/ppx_enumerate", + "license": "MIT", + "scope": "runtime dependency of Base" + }, + { + "name": "ppx_compare runtime", + "opam": "ppx_compare", + "source": "https://github.com/janestreet/ppx_compare", + "license": "MIT", + "scope": "runtime dependency of Base" + }, + { + "name": "ppx_sexp_conv runtime", + "opam": "ppx_sexp_conv", + "source": "https://github.com/janestreet/ppx_sexp_conv", + "license": "MIT", + "scope": "runtime dependency of Base" + }, + { + "name": "jane-street-headers", + "opam": "jane-street-headers", + "source": "https://github.com/janestreet/jane-street-headers", + "license": "MIT", + "scope": "C support for Jane Street runtime libraries" + }, + { + "name": "ppx_deriving_yojson runtime", + "opam": "ppx_deriving_yojson", + "source": "https://github.com/ocaml-ppx/ppx_deriving_yojson", + "license": "MIT", + "scope": "JSON codecs in the language-server library in rescript" + }, { "name": "Cmdliner", "opam": "cmdliner", diff --git a/licenses/ocaml/liburing.txt b/licenses/ocaml/liburing.txt new file mode 100644 index 00000000000..d559f33a880 --- /dev/null +++ b/licenses/ocaml/liburing.txt @@ -0,0 +1,20 @@ +Copyright 2020 Jens Axboe + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lsp/README.md b/lsp/README.md new file mode 100644 index 00000000000..c8d98ad22bb --- /dev/null +++ b/lsp/README.md @@ -0,0 +1,338 @@ +# ReScript language server + +This directory contains the OCaml language server for ReScript. It calls the +in-tree [analysis library](../analysis/README.md) directly for editor features +and runs inside the OCaml `rescript` CLI. There is no separate +`rescript-language-server` executable. + +The implementation is experimental. This guide covers the implementation, +design rationale, editor setup, feature status, and diagnostic ownership. +Planned work and historical behavior are distinguished from current behavior. + +## Why OCaml + +Editor features already live in the OCaml analysis library and depend on +compiler types: typed trees, locations, package metadata, and diagnostics. +Calling those APIs directly avoids subprocess orchestration and JSON +serialization through `rescript-editor-analysis`. Changes to the compiler, +analysis, and server can be developed together in the same language and tested +with Dune and expect tests. + +### Why ship with the compiler + +The `.cmt` and `.cmti` artifacts contain marshalled `Typedtree`, `Types`, and +`Env` values. These are not a stable cross-version protocol. Changing their +OCaml representations can make older artifacts unsafe to read. For example, +[issue #8475](https://github.com/rescript-lang/rescript/issues/8475) describes +crashes from incompatible typedtree data; record-rest changes exposed the same +class of problem. + +The project's ReScript dependency supplies the compiler, analysis, and server +from one release. Editors use one project-local entrypoint instead of selecting +a separately versioned server, and compiler/LSP changes can ship atomically. + +Bundling does not eliminate stale artifacts. Changes to marshalled types still +require appropriate CMT magic-number changes, and projects must be rebuilt with +the matching compiler. A server supporting multiple compiler versions would +need version-specific decoders or a stable, explicitly versioned analysis +format. Graceful reporting of incompatible artifacts remains an important +error-handling boundary. + +## Running the server + +Configure the editor to launch the project's ReScript installation: + +```sh +node_modules/.bin/rescript lsp --stdio +``` + +`--stdio` is required. `rescript lsp` without it fails with usage help; the +subcommand does not accept `--quiet` or `--verbose`. Only stdio transport is +implemented, not Node IPC or sockets. Standard output carries protocol messages. + +Run a build or build watcher separately to produce and refresh typed metadata: + +```sh +node_modules/.bin/rescript build +# Or keep a watcher running: +node_modules/.bin/rescript watch +``` + +The server does not start or manage builds. Unsaved buffers receive syntax +diagnostics, but type-based features depend on compiled artifacts from a build. +Incremental LSP document synchronization means applying text edits to the +in-memory buffer; it does not mean incremental typechecking of that buffer. + +Use the workspace's build root when configuring the editor, rather than an +arbitrary nested source package. The client must handle dynamic registration of +`workspace/didChangeWatchedFiles` to report compiler-log changes. + +## Architecture + +```text +Editor client + <-> JSON-RPC over stdio +rescript lsp --stdio (rewatch-ocaml/rescript_ocaml.ml) + -> Eio_main.run supplies filesystem and stdio capabilities + -> Server handles transport and protocol lifecycle + -> Rescript_language_server dispatches requests and notifications + -> Analysis reads compiler metadata and computes editor results + +External build -> lib/rescript artifacts and compiler logs +Editor file watcher -> workspace/didChangeWatchedFiles -> context/diagnostics refresh +``` + +The server links the analysis code rather than spawning +`rescript-editor-analysis` for requests. Analysis consumes `.cmt` and `.cmti` +files containing marshalled compiler-internal data, not a stable cross-version +schema. Shipping the server with the compiler keeps their representations +aligned, but does not make stale artifacts compatible: rebuild a project after +updating its compiler. + +The server library lives in `lsp/src` and has an opam package named +`rescript-language-server`. It depends on the OCaml `lsp` library, Eio, +`ppx_deriving_yojson`, and the in-tree analysis library; tests use `ppx_expect`. + +### Code map + +| Module | Responsibility | +| --- | --- | +| [CLI entrypoint](../rewatch-ocaml/rescript_ocaml.ml) | Starts the server inside the `rescript` executable using Eio. | +| [server.ml](src/server.ml) | JSON-RPC framing, serialized input dispatch, initialization/shutdown lifecycle, and tracking responses to server requests. | +| [rescript_language_server.ml](src/rescript_language_server.ml) | Advertised capabilities, request handlers, document events, package discovery, and configuration/diagnostic refresh. | +| [state.ml](src/state.ml) | Per-session documents, settings, filesystem capability, initialization parameters, encoding, analysis state, and package configuration. | +| [document.ml](src/document.ml), [document_store.ml](src/document_store.ml) | Versioned in-memory `.res`/`.resi` documents and incremental text edits using `Lsp.Text_document`. | +| [helpers.ml](src/helpers.ml), [compiler_config.ml](src/compiler_config.ml) | Package selection, typed-artifact loading, and compiled JavaScript/interface path resolution. | +| [compiler_log.ml](src/compiler_log.ml), [source_dirs.ml](src/source_dirs.ml) | Compiler-log parsing, build-completion detection, and `.sourcedirs.json` build-root extraction. | +| [diagnostics.ml](src/diagnostics.ml) | Separate diagnostic sources, snapshot updates, URI/range conversion, and publication. | +| [code_actions.ml](src/code_actions.ml), [custom_requests.ml](src/custom_requests.ml), [execute_commands.ml](src/execute_commands.ml) | Analysis actions, interface creation, compiled-file navigation, and debugging commands. | +| [configuration.ml](src/configuration.ml) | Settings decoding and defaults. | +| [formatter.ml](src/formatter.ml) | Runs the project's `rescript format` command on the buffer and computes text edits; its process helper uses Unix on Windows and Eio on Linux/macOS. | +| [fs.ml](src/fs.ml) | Filesystem helpers over the Eio filesystem capability. | + +### Project discovery and recovery + +Initialization discovers the workspace package and dependencies and builds the +analysis lookup tables and compiler configuration map. Generated metadata under +`lib/rescript` is needed for most type-based requests. + +The server dynamically registers compiler-log watchers. When a `.compiler.log` +is created or changed, it rediscovers the project into fresh analysis tables. +Successful discovery replaces the context while preserving open buffers, +settings, encoding, and diagnostics. If discovery still fails, the old context +remains usable. This lets a session opened before the first build recover +without restarting the server. + +For diagnostic refresh, the server reads the compiler logs identified by +`lib/rescript/.sourcedirs.json`, not just the log mentioned in the watcher +event. This keeps diagnostics across discovered build roots in sync. + +## Diagnostics + +Diagnostics have three owners with different lifetimes: + +| Source | Lifetime | +| --- | --- | +| `compiler` | Saved build errors and warnings, including diagnostics for closed files. | +| `compiler_syntax` | Compiler syntax errors for closed documents only. | +| `syntax` | Syntax errors computed from open in-memory buffers. | + +On open/change, the server parses the current buffer for syntax errors. On +close, it clears that buffer's syntax diagnostics but retains build diagnostics; +a saved syntax error can then come from the compiler log instead. + +Only completed compiler logs form a new snapshot. A log still being written +must not clear the last completed results. Even a completed, syntax-only log +does not replace previous non-syntax diagnostics: parsing may have stopped the +compiler before it could check the rest of the workspace. A subsequent snapshot +with non-syntax diagnostics replaces them; a completed empty snapshot clears +them. Type diagnostics may therefore remain stale while syntax errors prevent +a complete check. + +For clients supporting pull diagnostics, open documents use +`textDocument/diagnostic`, while closed documents receive pushed compiler +diagnostics. Clients without pull support receive pushed diagnostics for both. +Avoid publishing the same diagnostic through both channels: clients can retain +them separately and display duplicates. Supported clients are asked to refresh +pull diagnostics after compiler-log updates. + +### Diagnostic scenarios and design history + +Three editor scenarios motivated the ownership model: + +1. Only A is open, while B and C have compiler type errors caused by an edit to + A. Saving a syntax error in A previously replaced the compiler snapshot with + that syntax error and incorrectly cleared B/C. The server now preserves + their non-syntax diagnostics until a later usable snapshot replaces them. +2. Closing A while B and C still have type errors must not clear those errors, + even if every document is closed. They belong to the workspace build, not + to the lifetime of an editor buffer. +3. Closing a buffer with an unsaved syntax error should clear that in-memory + diagnostic. If the syntax error was saved and reported by the compiler, it + should instead remain visible through compiler syntax diagnostics. + +The original proposal separated editor syntax and compiler diagnostics into +two maps. The current implementation further separates compiler syntax so +open documents can use their buffers without losing saved syntax errors for +closed files. Completed-log checks prevent save-time flicker, and separate +push/pull ownership prevents duplicate display. + +```text +didChange: + update syntax diagnostics from the current buffer + retain compiler diagnostics + +compiler log changed: + incomplete log -> keep the last completed snapshot + completed syntax-only log -> refresh closed-file syntax; retain type errors + completed non-syntax/empty log -> replace/clear compiler diagnostics + +didClose: + clear buffer syntax diagnostics + retain build diagnostics and allow compiler syntax for the closed document +``` + +## Features and settings + +Implemented requests include hover, completion and completion resolution, +signature help, definitions and type definitions, references, prepare rename +and rename, document symbols, code actions, code lenses, inlay hints, full +semantic tokens, document formatting, and document diagnostics. + +Custom requests provide compiled JavaScript navigation, interface creation, and +implementation/interface switching. Execute commands also expose navigation +and state/CMT dumps. Dumps are written to temporary files and opened with +`window/showDocument`, not returned as JSON content for the client to display. +File-opening commands require client support for that request. + +Settings are fetched through `workspace/configuration` using the `rescript` +section after `workspace/didChangeConfiguration`. `initializationOptions` is +not a settings source. The following JSON shows the defaults for that section: + +```json +{ + "hover": { "supportMarkdownLinks": false }, + "codeLens": false, + "inlayHints": { "enable": false, "maxLength": 25 } +} +``` + +Set `inlayHints.maxLength` to `null` for unlimited length. Signature help is +enabled independently of these settings. Client configuration layouts may +require middleware to return the `rescript` section in this shape. Markdown +links in hover are optional because editor support varies. + +### Protocol coverage + +The following groups summarize the implemented protocol surface. They do not +imply complete feature parity or exhaustive test coverage. + +| Area | Implemented requests and notifications | +| --- | --- | +| Lifecycle | `initialize`, `initialized`, `shutdown`, `exit` | +| Documents | `textDocument/didOpen`, `textDocument/didChange` (incremental edits), `textDocument/didClose` | +| Inspection | `textDocument/hover`, `textDocument/signatureHelp`, `textDocument/documentSymbol` | +| Completion | `textDocument/completion`, `completionItem/resolve` | +| Navigation | `textDocument/definition`, `textDocument/typeDefinition`, `textDocument/references` | +| Editing | `textDocument/prepareRename`, `textDocument/rename`, `textDocument/codeAction`, `textDocument/formatting` | +| Annotations | `textDocument/codeLens`, `workspace/codeLens/refresh`, `textDocument/inlayHint`, `textDocument/semanticTokens/full` | +| Diagnostics | `textDocument/publishDiagnostics`, `textDocument/diagnostic`, `workspace/diagnostic/refresh` when supported | +| Workspace | `workspace/didChangeWatchedFiles`, `client/registerCapability`, `workspace/didChangeConfiguration`, `workspace/configuration`, `workspace/executeCommand` | + +Code actions combine analysis refactorings, diagnostic quick fixes, and +compiled-JavaScript/interface navigation. Circular-dependency errors have no +precise source location, so the server uses a document-wide range when it has +the open buffer and a fallback range otherwise. Warning messages include their +warning number. Monorepo compiler-log discovery uses `cmt_scan` build roots in +`.sourcedirs.json`, metadata introduced in ReScript 12.1. + +### Custom requests and commands + +| Name | Behavior | +| --- | --- | +| `textDocument/openCompiled` | Resolves the compiled JavaScript file for a source document. | +| `textDocument/createInterface` | Creates an interface from compiled metadata; fails if it already exists. | +| `textDocument/switchImplementationInterface` | Resolves the corresponding implementation/interface. | +| `rescript/openCompiled` | Execute-command navigation to compiled JavaScript. | +| `rescript/createInterface` | Execute-command interface creation and opening. | +| `rescript/switchImplementationInterface` | Execute-command navigation between implementation and interface. | +| `rescript/dumpServerState` | Writes a temporary `.json` dump of session state and opens it. | +| `rescript/dumpCmt` | Writes a temporary `.txt` dump of typed metadata and opens it. | + +State dumps include document versions/lengths, diagnostics, configuration, +initialization parameters, analysis state, and compiler configuration. The +file-opening command flow is: + +```text +CodeAction.command -> workspace/executeCommand -> window/showDocument +``` + +Clients without `window/showDocument` support cannot use this opening flow. +The server also sends `rescript/compilationFinished` on watched-file updates +for compatibility with the existing VS Code analysis integration. This is a +watcher-triggered notification, not server-managed build progress. + +### Current limitations + +- No server-managed builds or unsaved-buffer incremental typechecking. +- One workspace context per session; workspace-folder changes are not handled. +- No semantic-token deltas, range formatting, or workspace-symbol search. +- Document synchronization negotiates UTF-8 or UTF-16, with UTF-16 as the LSP + default. Analysis locations and some range helpers still use byte offsets; + conversion is not complete for non-ASCII text under UTF-16. Negotiating an + encoding does not by itself make all analysis positions use it. +- Configuration-file changes are not independently watched. Restart the server + if a configuration change is not picked up through a later build-log event. + +Other unimplemented requests include `textDocument/declaration`, +`textDocument/implementation`, `textDocument/documentHighlight`, +`codeAction/resolve`, `codeLens/resolve`, `inlayHint/resolve`, +`textDocument/semanticTokens/range`, `textDocument/onTypeFormatting`, +`textDocument/foldingRange`, `textDocument/selectionRange`, +`textDocument/documentLink`, `documentLink/resolve`, +`textDocument/documentColor`, and `textDocument/linkedEditingRange`. +`textDocument/didSave` does not trigger work; compiler-log notifications drive +build refresh. Node IPC and sockets are not supported. + +Unimplemented custom features include `rescript/startBuild`, +`rescript/compilationStatus`, `rescript/dumpParseTree`, and +`rescript/dumpTypedTree`. Build integration would need decisions about watcher +ownership, shutdown, cancellation, and progress reporting. Direct compiler +integration and unsaved-buffer typechecking remain future work; the existing +analysis artifact lookup is not a complete implementation of either feature. + +## Development and tests + +From the repository root, build the toolchain/runtime and run the E2E suite: + +```sh +opam exec -- make test-lsp +``` + +After those artifacts are built, run only the E2E tests or the server's inline +tests: + +```sh +opam exec -- dune runtest tests/lsp_tests +opam exec -- dune runtest lsp +``` + +The E2E tests are OCaml `ppx_expect` snapshots. Their shared client launches the +actual CLI over stdio using Unix process APIs for Windows/Linux/macOS support. +Tests create temporary projects, build them, edit buffers, send requests and +notifications, and normalize workspace paths in snapshots. Coverage includes +editor features, diagnostic ownership, build recovery, formatting, and command +capability handling. The server also has inline tests for its local helpers. + +`Test.setup_project` writes `rescript.json` and documents and can run a build; +`Test.with_project` provides temporary workspace setup and cleanup. Tests use +explicit zero-based cursor positions, not analysis-suite cursor markers. +The harness supplies `RESCRIPT_RUNTIME` because it bypasses the npm launcher. +Cases cover JSX, multi-document requests, unsaved buffers, configuration, +client capabilities, stale warnings, duplicate publication, and save-time +flicker. Representative cases come from `tests/analysis_tests`, which remains +an independent suite with additional coverage. + +See [tests/lsp_tests/README.md](../tests/lsp_tests/README.md) for fixture helpers, +snapshot review/promotion commands, and known limitations captured by tests. + diff --git a/lsp/src/code_actions.ml b/lsp/src/code_actions.ml new file mode 100644 index 00000000000..cd5d4c76417 --- /dev/null +++ b/lsp/src/code_actions.ml @@ -0,0 +1,523 @@ +open Lsp +open Lsp.Types + +module From_diagnostics : sig + val get : doc:Document.t -> diagnostics:Diagnostic.t list -> CodeAction.t list +end = struct + let diagnostic_message (diagnostic : Diagnostic.t) = + match diagnostic.message with + | `String message -> message + | `MarkupContent {value} -> value + + let ansi_escape_regex = Str.regexp "\027\\[[0-9;]*m" + let whitespace_regex = Str.regexp "[ \t\r\n]+" + + let strip_ansi str = Str.global_replace ansi_escape_regex "" str + + let empty_range position = Range.create ~start:position ~end_:position + + let replace_text range new_text = [TextEdit.create ~range ~newText:new_text] + + let spaces length = String.make (max 0 length) ' ' + + let quick_fix ~uri ~diagnostic ~title ~edits = + let edit = WorkspaceEdit.create ~changes:[(uri, edits)] () in + Some + (CodeAction.create ~title ~edit ~diagnostics:[diagnostic] + ~kind:CodeActionKind.QuickFix ~isPreferred:true ()) + + let insert_before_ending_char (range : Range.t) new_text = + let position = + Position.create ~line:range.end_.line + ~character:(max 0 (range.end_.character - 1)) + in + [TextEdit.create ~range:(empty_range position) ~newText:new_text] + + let wrap_range_in_text (range : Range.t) before after = + [ + TextEdit.create ~range:(empty_range range.start) ~newText:before; + TextEdit.create ~range:(empty_range range.end_) ~newText:after; + ] + + let split_fields fields = + fields |> String.trim |> Str.split (Str.regexp "[ \t\r\n]+") + + let drop_prefix ~prefix line = + let line = String.trim line in + if String.starts_with ~prefix line then + let prefix_length = String.length prefix in + Some (String.sub line prefix_length (String.length line - prefix_length)) + else None + + let before_first_dot line = + match String.index_opt line '.' with + | Some index -> String.sub line 0 index + | None -> line + + let before_defined_as typ = + match Str.search_forward (Str.regexp_string "(defined as") typ 0 with + | index -> String.sub typ 0 index + | exception Not_found -> typ + + let extract_typename lines = + lines |> String.concat " " |> strip_ansi |> before_defined_as |> String.trim + |> Str.global_replace whitespace_regex "" + + let line_starts_with ~prefix line = + line |> strip_ansi |> String.trim |> String.starts_with ~prefix + + let did_you_mean ~uri ~diagnostic = + let did_you_mean_prefix = "Hint: Did you mean" in + let did_you_mean_regex = Str.regexp "Did you mean \\([A-Za-z0-9_]+\\)" in + + let suggestion_from_line line = + match Str.search_forward did_you_mean_regex line 0 with + | _ -> Some (Str.matched_group 1 line) + | exception Not_found -> None + in + + let find_did_you_mean_line message = + message |> String.split_on_char '\n' + |> List.find_opt (fun line -> + String.starts_with ~prefix:did_you_mean_prefix (String.trim line)) + in + + let message = diagnostic_message diagnostic in + + match find_did_you_mean_line message with + | None -> None + | Some line -> ( + match suggestion_from_line line with + | None -> None + | Some suggestion -> + let edit = + WorkspaceEdit.create + ~changes: + [ + ( uri, + [TextEdit.create ~range:diagnostic.range ~newText:suggestion] + ); + ] + () + in + Some + (CodeAction.create + ~title:(Printf.sprintf "Replace with '%s'" suggestion) + ~edit ~diagnostics:[diagnostic] ~kind:CodeActionKind.QuickFix + ~isPreferred:true ())) + + let wrap_in_some ~uri ~diagnostic = + let pattern_prefix = "This pattern matches values of type" in + let pattern_type_regex = + Str.regexp "This pattern matches values of type \\(.*\\)$" + in + let expected_type_prefix = + "but a pattern was expected which matches values of type" + in + let expected_type_regex = + Str.regexp + "but a pattern was expected which matches values of type\\(.*\\)$" + in + let option_type_regex = Str.regexp_string "option<" in + let is_option_type typ = + match Str.search_forward option_type_regex typ 0 with + | _ -> true + | exception Not_found -> false + in + let type_from_pattern_line line = + match Str.search_forward pattern_type_regex line 0 with + | _ -> Some (String.trim (Str.matched_group 1 line)) + | exception Not_found -> None + in + let type_from_expected_line line = + match Str.search_forward expected_type_regex line 0 with + | _ -> Some (String.trim (Str.matched_group 1 line)) + | exception Not_found -> None + in + let rec expected_type lines = + match lines with + | [] -> None + | line :: next_lines -> + if String.starts_with ~prefix:expected_type_prefix (String.trim line) + then + match type_from_expected_line line with + | Some typ when typ <> "" -> Some typ + | _ -> ( + match next_lines with + | next_line :: _ -> Some (String.trim next_line) + | [] -> None) + else expected_type next_lines + in + let message = diagnostic_message diagnostic in + let lines = String.split_on_char '\n' message in + let rec loop lines = + match lines with + | [] -> None + | line :: rest -> + if String.starts_with ~prefix:pattern_prefix (String.trim line) then + match type_from_pattern_line line with + | Some actual_type when not (is_option_type actual_type) -> ( + match expected_type rest with + | Some expected_type when is_option_type expected_type -> + let edit = + WorkspaceEdit.create + ~changes: + [(uri, wrap_range_in_text diagnostic.range "Some(" ")")] + () + in + Some + (CodeAction.create ~title:"Wrap in option Some" ~edit + ~diagnostics:[diagnostic] ~kind:CodeActionKind.QuickFix + ~isPreferred:true ()) + | _ -> None) + | _ -> None + else loop rest + in + loop lines + + let simple_conversion ~uri ~(diagnostic : Diagnostic.t) = + let prefix = "You can convert " in + let conversion_regex = + Str.regexp + "You can convert \\([A-Za-z0-9_]+\\) to \\([A-Za-z0-9_]+\\) with \ + \\([A-Za-z0-9_.]+\\)\\.$" + in + let code_action_from_line line = + let line = line |> strip_ansi |> String.trim in + if String.starts_with ~prefix line then + match Str.search_forward conversion_regex line 0 with + | _ -> + let from_type = Str.matched_group 1 line in + let to_type = Str.matched_group 2 line in + let fn = Str.matched_group 3 line in + quick_fix ~uri ~diagnostic + ~title: + (Printf.sprintf "Convert %s to %s with %s" from_type to_type fn) + ~edits:(wrap_range_in_text diagnostic.range (fn ^ "(") ")") + | exception Not_found -> None + else None + in + let rec loop lines = + match lines with + | [] -> None + | line :: rest -> ( + match code_action_from_line line with + | Some _ as code_action -> code_action + | None -> loop rest) + in + diagnostic |> diagnostic_message |> String.split_on_char '\n' |> loop + + let apply_uncurried ~uri ~(diagnostic : Diagnostic.t) = + let prefix = + "This is an uncurried ReScript function. It must be applied with a dot." + in + let make_code_action () = + let position = + Position.create ~line:diagnostic.range.end_.line + ~character:(diagnostic.range.end_.character + 1) + in + quick_fix ~uri ~diagnostic ~title:"Apply uncurried function call with dot" + ~edits:[TextEdit.create ~range:(empty_range position) ~newText:". "] + in + let rec loop lines = + match lines with + | [] -> None + | line :: rest -> + if line_starts_with ~prefix line then make_code_action () else loop rest + in + diagnostic |> diagnostic_message |> String.split_on_char '\n' |> loop + + let simple_add_missing_cases ~uri ~(diagnostic : Diagnostic.t) ~source = + let prefix = "You forgot to handle a possible case here, for example:" in + let make_code_action hint = + match + Analysis.Codemod.transform_opt ~source + ~pos:(diagnostic.range.start.line, diagnostic.range.start.character) + ~debug:false ~typ:Analysis.Codemod.AddMissingCases ~hint + with + | None -> None + | Some new_switch_code -> + quick_fix ~uri ~diagnostic ~title:"Insert missing cases" + ~edits:(replace_text diagnostic.range new_switch_code) + in + let rec loop lines = + match lines with + | [] -> None + | line :: rest -> + if line_starts_with ~prefix line then + let hint = rest |> String.concat "" |> String.trim in + if hint = "" then None else make_code_action hint + else loop rest + in + diagnostic |> diagnostic_message |> String.split_on_char '\n' |> loop + + let simple_type_mismatches ~uri ~(diagnostic : Diagnostic.t) = + let this_has_type_prefix = "This has type:" in + let somewhere_wanted_prefix = "Somewhere wanted:" in + let default_value = function + | "string" -> "\"-\"" + | "bool" -> "false" + | "int" -> "-1" + | "float" -> "-1." + | _ -> "assert false" + in + let rec collect_until_somewhere_wanted acc lines = + match lines with + | [] -> None + | line :: rest -> ( + match drop_prefix ~prefix:somewhere_wanted_prefix line with + | Some wanted -> Some (List.rev acc, wanted, rest) + | None -> collect_until_somewhere_wanted (line :: acc) rest) + in + let rec collect_until_blank acc lines = + match lines with + | [] -> List.rev acc + | line :: rest -> + if line |> strip_ansi |> String.trim = "" then List.rev acc + else collect_until_blank (line :: acc) rest + in + let code_action_from_types ~actual_type ~wanted_type = + if actual_type = Printf.sprintf "option<%s>" wanted_type then + quick_fix ~uri ~diagnostic ~title:"Unwrap optional value" + ~edits: + (wrap_range_in_text diagnostic.range "switch " + (Printf.sprintf " { | None => %s | Some(v) => v }" + (default_value wanted_type))) + else if Printf.sprintf "option<%s>" actual_type = wanted_type then + quick_fix ~uri ~diagnostic ~title:"Wrap value in Some" + ~edits:(wrap_range_in_text diagnostic.range "Some(" ")") + else None + in + let rec loop lines = + match lines with + | [] -> None + | line :: rest -> ( + match drop_prefix ~prefix:this_has_type_prefix line with + | None -> loop rest + | Some actual -> ( + match collect_until_somewhere_wanted [actual] rest with + | None -> None + | Some (actual_lines, wanted, rest) -> + let wanted_lines = wanted :: collect_until_blank [] rest in + let actual_type = extract_typename actual_lines in + let wanted_type = extract_typename wanted_lines in + code_action_from_types ~actual_type ~wanted_type)) + in + diagnostic |> diagnostic_message |> String.split_on_char '\n' |> loop + + let handle_undefined_record_fields ~uri ~(diagnostic : Diagnostic.t) + ~record_field_names ~todo_value = + match record_field_names with + | [] -> None + | _ -> + let range = diagnostic.range in + let multiline_record_definition_body = + range.start.line <> range.end_.line + in + let new_text = + if multiline_record_definition_body then + let padding_content_record_field = + spaces (range.end_.character + 1) + in + let padding_content_end_brace = spaces (range.end_.character - 1) in + let fields = + record_field_names + |> List.mapi (fun index field_name -> + let padding = + if index = 0 then " " else padding_content_record_field + in + Printf.sprintf "%s%s: %s,\n" padding field_name todo_value) + |> String.concat "" + in + fields ^ padding_content_end_brace + else + let prefix = + if range.end_.character - range.start.character > 2 then ", " + else "" + in + let fields = + record_field_names + |> List.map (fun field_name -> + Printf.sprintf "%s: %s" field_name todo_value) + |> String.concat ", " + in + prefix ^ fields + in + let edit = + WorkspaceEdit.create + ~changes:[(uri, insert_before_ending_char range new_text)] + () + in + Some + (CodeAction.create ~title:"Add missing record fields" ~edit + ~diagnostics:[diagnostic] ~kind:CodeActionKind.QuickFix + ~isPreferred:true ()) + + let add_undefined_record_fields_v10 ~uri ~diagnostic = + let prefix = "Some record fields are undefined:" in + let message = diagnostic_message diagnostic in + let lines = String.split_on_char '\n' message in + let rec loop lines = + match lines with + | [] -> None + | line :: rest -> ( + match drop_prefix ~prefix line with + | None -> loop rest + | Some fields -> + let record_field_names = + split_fields fields @ (rest |> List.concat_map split_fields) + in + handle_undefined_record_fields ~uri ~diagnostic ~record_field_names + ~todo_value:"%todo") + in + loop lines + + let add_undefined_record_fields_v11 ~uri ~diagnostic = + let prefix = "Some required record fields are missing:" in + let message = diagnostic_message diagnostic in + let lines = String.split_on_char '\n' message in + let rec collect_until_dot acc lines = + match lines with + | [] -> List.rev acc + | line :: rest -> + let fields = line |> before_first_dot |> split_fields in + let acc = List.rev_append fields acc in + if String.contains line '.' then List.rev acc + else collect_until_dot acc rest + in + let rec loop lines = + match lines with + | [] -> None + | line :: rest -> ( + match drop_prefix ~prefix line with + | None -> loop rest + | Some fields -> + let record_field_names = + split_fields (before_first_dot fields) + @ if String.contains line '.' then [] else collect_until_dot [] rest + in + handle_undefined_record_fields ~uri ~diagnostic ~record_field_names + ~todo_value:"%todo") + in + loop lines + + let extractor ~doc ~diagnostic = + let code_actions = ref [] in + + let append code_action = + match code_action with + | Some code_action -> code_actions := code_action :: !code_actions + | None -> () + in + let uri = Document.uri doc in + + did_you_mean ~uri ~diagnostic |> append; + wrap_in_some ~uri ~diagnostic |> append; + simple_conversion ~uri ~diagnostic |> append; + apply_uncurried ~uri ~diagnostic |> append; + simple_add_missing_cases ~uri ~diagnostic ~source:(Document.text doc) + |> append; + simple_type_mismatches ~uri ~diagnostic |> append; + add_undefined_record_fields_v10 ~uri ~diagnostic |> append; + add_undefined_record_fields_v11 ~uri ~diagnostic |> append; + + !code_actions + + let get ~doc ~diagnostics = + diagnostics + |> List.map (fun diagnostic -> extractor ~doc ~diagnostic) + |> List.flatten +end + +module Open_compiled_file = struct + let make ~doc ~state = + let uri = Document.uri doc in + let compiled_uri = + Helpers.get_compiled_file ~uri + ~compiler_config:(State.compiler_config state) + ~fs:state.fs + in + match compiled_uri with + | Some uri -> + let title = "Open compiled file" in + [ + CodeAction.create + ~command: + (Command.create + ~arguments:[`String (Uri.to_string uri)] + ~command:Execute_commands.Open_compiled.name ~title ()) + ~title (); + ] + | None -> [] +end + +module Create_interface_file = struct + let make ~doc ~(state : State.t) = + let uri = Document.uri doc in + + let should_create = + match Document.kind doc with + | Res -> not (Fs.exists ~fs:state.fs ~follow:false (Uri.to_path uri)) + | _ -> false + in + + let cmi_file = + Helpers.get_cmi_file ~uri ~fs:state.fs + ~compiler_config:(State.compiler_config state) + in + + match (should_create, cmi_file) with + | true, Some cmi_file -> + let title = "Create interface file" in + [ + CodeAction.create + ~command: + (Command.create + ~arguments: + [ + `String (Uri.to_string uri); + `String (Uri.of_path cmi_file |> Uri.to_string); + ] + ~command:Execute_commands.Create_interface.name ~title ()) + ~title (); + ] + | _ -> [] +end + +module Switch_implementation_interface_file = struct + let make ~doc ~(state : State.t) = + match Document.kind doc with + | Res -> + let uri = Document.uri doc in + let target = Uri.to_path uri ^ "i" in + if Fs.exists ~follow:false ~fs:state.fs target then + let title = "Switch to interface file" in + [ + CodeAction.create + ~command: + (Command.create + ~arguments:[`String (Uri.of_path target |> Uri.to_string)] + ~command:Execute_commands.Switch_implementation_interface.name + ~title ()) + ~title (); + ] + else [] + | Resi -> + let uri = Document.uri doc in + let target = (Uri.to_path uri |> Filename.remove_extension) ^ ".res" in + if Fs.exists ~follow:false ~fs:state.fs target then + let title = "Switch to implementation file" in + [ + CodeAction.create + ~command: + (Command.create + ~arguments:[`String (Uri.of_path target |> Uri.to_string)] + ~command:Execute_commands.Switch_implementation_interface.name + ~title ()) + ~title (); + ] + else [] + (* TODO: Offer "create implementation file" when a .resi has no matching + .res file, instead of only showing the switch action for existing files. *) + | _ -> [] +end diff --git a/lsp/src/compiler_config.ml b/lsp/src/compiler_config.ml new file mode 100644 index 00000000000..ece1b623c6f --- /dev/null +++ b/lsp/src/compiler_config.ml @@ -0,0 +1,428 @@ +module Parse = struct + type namespace = Namespace_bool of bool | Namespace_string of string + + let namespace_to_yojson = function + | Namespace_bool value -> `Bool value + | Namespace_string value -> `String value + + let namespace_of_yojson = function + | `Bool value -> Ok (Namespace_bool value) + | `String value -> Ok (Namespace_string value) + | json -> + Error + ("Expected namespace to be a boolean or string, got " + ^ Yojson.Safe.to_string json) + + type module_format = Commonjs | Es6 | Es6_global | Esmodule + + let module_format_to_yojson = function + | Commonjs -> `String "commonjs" + | Es6 -> `String "es6" + | Es6_global -> `String "es6-global" + | Esmodule -> `String "esmodule" + + let module_format_of_yojson = function + | `String "commonjs" -> Ok Commonjs + | `String "es6" -> Ok Es6 + | `String "es6-global" -> Ok Es6_global + | `String "esmodule" -> Ok Esmodule + | _ -> Error "Compiler_config.module_format" + + type module_format_object = { + in_source: bool option; [@key "in-source"] [@default None] + module_: module_format; [@key "module"] + suffix: string option; [@default None] + } + [@@deriving yojson {strict = false}] + + type package_spec = + | Module_format of module_format + | Module_format_object of module_format_object + + let package_spec_to_yojson = function + | Module_format module_format -> module_format_to_yojson module_format + | Module_format_object module_format_object -> + module_format_object_to_yojson module_format_object + + let package_spec_of_yojson json = + match module_format_of_yojson json with + | Ok module_format -> Ok (Module_format module_format) + | Error _ -> ( + match module_format_object_of_yojson json with + | Ok module_format_object -> + Ok (Module_format_object module_format_object) + | Error message -> Error message) + + type package_specs = package_spec list + + let package_specs_to_yojson package_specs = + `List (List.map package_spec_to_yojson package_specs) + + let package_specs_of_yojson json = + let rec collect = function + | [] -> Ok [] + | json :: rest -> ( + match package_spec_of_yojson json with + | Ok package_spec -> ( + match collect rest with + | Ok package_specs -> Ok (package_spec :: package_specs) + | Error _ as error -> error) + | Error _ as error -> error) + in + + match json with + | `List package_specs -> collect package_specs + | json -> ( + match package_spec_of_yojson json with + | Ok package_spec -> Ok [package_spec] + | Error _ as error -> error) + + type dependencie_object = { + name: string; + features: string list option; [@default None] + } + [@@deriving yojson {strict = false}] + + type dependencies = String of string | Object of dependencie_object + + let dependencies_to_yojson = function + | String name -> `String name + | Object dependency -> dependencie_object_to_yojson dependency + + let dependencies_of_yojson = function + | `String name -> Ok (String name) + | `Assoc _ as json -> ( + match dependencie_object_of_yojson json with + | Ok dependency -> Ok (Object dependency) + | Error message -> Error message) + | _ -> Error "Expected a dependency name or object" + + type t = { + name: string; + namespace: namespace option; [@default None] + package_specs: package_specs option; [@key "package-specs"] [@default None] + suffix: string option; [@default None] + dependencies: dependencies list option; [@default None] + dev_dependencies: dependencies list option; + [@key "dev-dependencies"] [@default None] + (* Old fields, deprecated *) + bs_dependencies: dependencies list option; + [@key "bs-dependencies"] [@default None] + bs_dev_dependencies: dependencies list option; + [@key "bs-dev-dependencies"] [@default None] + } + [@@deriving yojson {strict = false}] + + let%expect_test "namespace codecs accept the compiler's JSON forms" = + List.iter + (fun json -> + match namespace_of_yojson json with + | Ok namespace -> + namespace_to_yojson namespace + |> Yojson.Safe.to_string |> print_endline + | Error message -> print_endline message) + [`Bool true; `Bool false; `String "App"; `Int 1]; + [%expect + {| + true + false + "App" + Expected namespace to be a boolean or string, got 1 + |}] + + let%expect_test "package specs codecs accept single values and lists" = + List.iter + (fun text -> + match package_specs_of_yojson (Yojson.Safe.from_string text) with + | Ok specs -> + package_specs_to_yojson specs + |> Yojson.Safe.to_string |> print_endline + | Error message -> print_endline message) + [ + {|"commonjs"|}; + {|["es6","es6-global","esmodule"]|}; + {|{"module":"esmodule","in-source":true,"suffix":".mjs"}|}; + {|[]|}; + {|["commonjs",42]|}; + ]; + [%expect + {| + ["commonjs"] + ["es6","es6-global","esmodule"] + [{"in-source":true,"module":"esmodule","suffix":".mjs"}] + [] + Compiler_config.Parse.module_format_object + |}] + + let%expect_test "parse build schema" = + let prin_config config = + match config with + | Error message -> print_endline ("Error: " ^ message) + | Ok config -> ( + Printf.printf "name=%s\n" config.name; + (match config.namespace with + | Some (Namespace_string namespace) -> + Printf.printf "namespace=%s\n" namespace + | Some (Namespace_bool namespace) -> + Printf.printf "namespace=%b\n" namespace + | None -> print_endline "namespace=None"); + (match config.dependencies with + | None -> print_endline "dependencies=None" + | Some deps -> + let deps_names = + deps + |> List.map (fun dep -> + match dep with + | String name -> name + | Object {name} -> name) + |> String.concat ", " + in + Printf.printf "dependencies=Some(%s)\n" deps_names); + (match config.package_specs with + | Some specs -> + let r = + specs + |> List.map (fun spec -> + package_spec_to_yojson spec |> Yojson.Safe.pretty_to_string) + |> String.concat ", " + in + Printf.sprintf "package_specs=Some(%s)" r |> print_endline + | None -> print_endline "package_specs=None"); + match config.suffix with + | Some suffix -> Printf.sprintf "suffix=%s" suffix |> print_endline + | None -> print_endline "suffix=None") + in + + let json = + Yojson.Safe.from_string + {|{ + "name": "app", + "namespace": "App", + "dependencies": [], + "package-specs": [ + "esmodule", + { + "in-source": true, + "module": "commonjs", + "suffix": ".cjs" + } + ], + "suffix": ".js" + }|} + in + prin_config (of_yojson json); + [%expect + {| + name=app + namespace=App + dependencies=Some() + package_specs=Some("esmodule", { "in-source": true, "module": "commonjs", "suffix": ".cjs" }) + suffix=.js + |}]; + + let json_2 = + Yojson.Safe.from_string + {|{ + "name": "@rescript-lang/guide", + "namespace": false, + "dependencies": [ + "@rescript-lang/playground", + "@rescript-lang/shared", + "@rescript/react", + "@rescript/webapi" + ], + "compiler-flags": ["-open WebAPI.Global"], + "sources": [ + { + "dir": "__tests__", + "subdirs": true, + "type": "dev" + }, + { + "dir": "app", + "subdirs": true + } + ], + "warnings": { + "error": "+8" + } + }|} + in + prin_config (of_yojson json_2); + [%expect + {| + name=@rescript-lang/guide + namespace=false + dependencies=Some(@rescript-lang/playground, @rescript-lang/shared, @rescript/react, @rescript/webapi) + package_specs=None + suffix=None + |}]; + + let json_3 = + Yojson.Safe.from_string + {|{ + "name": "rescript-lang.org-monorepo", + "dependencies": [ + "@rescript-lang/shared", + "@rescript-lang/playground", + "@rescript-lang/guide", + "@rescript-lang/docs" + ], + "sources": [], + "jsx": { + "preserve": true, + "version": 4 + }, + "package-specs": { + "module": "esmodule", + "in-source": true + }, + "suffix": ".jsx" + } +|} + in + prin_config (of_yojson json_3); + [%expect + {| + name=rescript-lang.org-monorepo + namespace=None + dependencies=Some(@rescript-lang/shared, @rescript-lang/playground, @rescript-lang/guide, @rescript-lang/docs) + package_specs=Some({ "in-source": true, "module": "esmodule" }) + suffix=.jsx + |}]; + + let json_4 = + Yojson.Safe.from_string + {| +{ + "name": "app", + "dependencies": [ + "@plain/dep", + { "name": "@example/lib", "features": ["native"] } + ] +} +|} + in + prin_config (of_yojson json_4); + [%expect + {| + name=app + namespace=None + dependencies=Some(@plain/dep, @example/lib) + package_specs=None + suffix=None + |}] + + let%expect_test "dependency JSON round trips preserve features" = + let print json = + match dependencies_of_yojson (Yojson.Safe.from_string json) with + | Ok dependency -> + dependencies_to_yojson dependency + |> Yojson.Safe.pretty_to_string |> print_endline + | Error message -> Printf.printf "Error: %s\n" message + in + print {|"@plain/dep"|}; + print {|{"name":"@example/lib","features":["native"]}|}; + print {|{"name":"@example/lib"}|}; + print {|42|}; + print {|{"features":["native"]}|}; + print {|{"name":"@example/lib","features":true}|}; + [%expect + {| + "@plain/dep" + { "name": "@example/lib", "features": [ "native" ] } + { "name": "@example/lib" } + Error: Expected a dependency name or object + Error: Compiler_config.Parse.dependencie_object.name + Error: Compiler_config.Parse.dependencie_object.features + |}] +end + +module Uri_map = Map.Make (Lsp.Uri) + +type t = Parse.t Uri_map.t + +let parse ~root ~fs = + let ( /+ ) = Filename.concat in + + let config_file = + let rescript_json = root /+ Constants.rescript_json in + let bsconfig_json = root /+ Constants.bsconfig_json in + if Fs.exists ~follow:false ~fs rescript_json then rescript_json + else bsconfig_json + in + + match Fs.load ~fs config_file with + | Some content -> ( + match Yojson.Safe.from_string content with + | json -> ( + match Parse.of_yojson json with + | Ok s -> Ok s + | Error msg -> + Error + (Printf.sprintf "Failed to parse compiler config %s. %s" config_file + msg)) + | exception exc -> + Error + (Printf.sprintf "Failed to parse rescript configuration file at %s. %s" + root (Printexc.to_string exc))) + | None -> Error ("Failed to read rescript configuration file at " ^ root) + +type output_config = {suffix: string; folder: string; in_source: bool} +let get_output_config (config : Parse.t) = + let default_suffix = ".js" in + let default_in_source = false in + let folder_name = function + | Parse.Commonjs -> "js" + | Es6_global -> "es6_global" + | Es6 | Esmodule -> "es6" + in + match config.package_specs with + | Some pkg_spec -> ( + match pkg_spec with + | [] -> + { + suffix = config.suffix |> Option.value ~default:default_suffix; + folder = folder_name Parse.Commonjs; + in_source = default_in_source; + } + | Module_format module_ :: _ -> + { + suffix = config.suffix |> Option.value ~default:default_suffix; + folder = folder_name module_; + in_source = default_in_source; + } + | Module_format_object {module_; suffix; in_source} :: _ -> + let suffix = + match (suffix, config.suffix) with + | Some s, _ -> s + | None, Some s -> s + | _ -> default_suffix + in + { + suffix; + folder = folder_name module_; + in_source = in_source |> Option.value ~default:default_in_source; + }) + | None -> + { + suffix = config.suffix |> Option.value ~default:default_suffix; + folder = folder_name Parse.Commonjs; + in_source = default_in_source; + } + +let get_all_dependecies_names (config : Parse.t) = + let names deps = + match deps with + | None -> [] + | Some deps -> + deps + |> List.map (fun dep -> + match dep with + | Parse.String name -> name + | Object {name} -> name) + in + (config.dependencies |> names) + @ (config.dev_dependencies |> names) + @ (config.bs_dependencies |> names) + @ (config.bs_dev_dependencies |> names) diff --git a/lsp/src/compiler_log.ml b/lsp/src/compiler_log.ml new file mode 100644 index 00000000000..dedad285030 --- /dev/null +++ b/lsp/src/compiler_log.ml @@ -0,0 +1,1514 @@ +module Parse : sig + type path = Relative_path of string | Full_path of string + + type kind = + | Syntax_error + | Warning of {number: int; configured_as_error: bool} + | Common_error (* type error, value can't be found *) + | Circular_dependency + | Unknown + + type diagnostic_entry = { + kind: kind; + path: path; + message: string; + range: Lsp.Types.Range.t option; + } + + val is_complete : string -> bool + val parse_log_content : string -> diagnostic_entry list +end = struct + type position = {line: int; col: int} + + type parsed_range = {start_pos: position; end_pos: position} + + type path = Relative_path of string | Full_path of string + + type kind = + | Syntax_error + | Warning of {number: int; configured_as_error: bool} + | Common_error + | Circular_dependency + | Unknown + + type diagnostic_entry = { + kind: kind; + path: path; + message: string; + range: Lsp.Types.Range.t option; + } + + type location_format = Path_location | File_location + + let split_lines s = s |> String.split_on_char '\n' |> Array.of_list + + let is_blank s = String.trim s = "" + + let starts_with prefix s = + let prefix_len = String.length prefix in + String.length s >= prefix_len && String.sub s 0 prefix_len = prefix + + let ends_with suffix s = + let suffix_len = String.length suffix in + let len = String.length s in + len >= suffix_len && String.sub s (len - suffix_len) suffix_len = suffix + + let is_rescript_source_path s = + (not (String.contains s ' ')) + && List.exists + (fun suffix -> ends_with suffix s) + [".res"; ".resi"; ".re"; ".rei"] + + let filepath_of_path path = + if Filename.is_relative path then Relative_path path else Full_path path + + let parse_path_location line = + (* Supported formats: + + /path/file.res:3:9 + start = 3:9 + end = 3:9 + + /path/file.res:3:5-8 + start = 3:5 + end = 3:8 + + /path/file.res:1:8-2:3 + start = 1:8 + end = 2:3 + + /path/file.res + no range + *) + let line = String.trim line in + + let point_re = Str.regexp "^\\(.+\\):\\([0-9]+\\):\\([0-9]+\\)$" in + let same_line_range_re = + Str.regexp "^\\(.+\\):\\([0-9]+\\):\\([0-9]+\\)-\\([0-9]+\\)$" + in + let cross_line_range_re = + Str.regexp + "^\\(.+\\):\\([0-9]+\\):\\([0-9]+\\)-\\([0-9]+\\):\\([0-9]+\\)$" + in + let make_location filepath start_line start_col end_line end_col = + Some + ( filepath_of_path (Str.matched_group filepath line), + Some + { + start_pos = + { + line = Str.matched_group start_line line |> int_of_string; + col = Str.matched_group start_col line |> int_of_string; + }; + end_pos = + { + line = Str.matched_group end_line line |> int_of_string; + col = Str.matched_group end_col line |> int_of_string; + }; + } ) + in + + try + if Str.string_match cross_line_range_re line 0 then + make_location 1 2 3 4 5 + else if Str.string_match same_line_range_re line 0 then + make_location 1 2 3 2 4 + else if Str.string_match point_re line 0 then make_location 1 2 3 2 3 + else if is_rescript_source_path line then + Some (filepath_of_path line, None) + else None + with Not_found | Failure _ -> + if is_rescript_source_path line then Some (filepath_of_path line, None) + else None + + let parse_file_location line = + (* Supported formats: + + File "/path/file.res", line 3, characters 5-8: + start = 3:5 + end = 3:8 + + File "/path/file.res", lines 11-13, characters 6-7: + start = 11:6 + end = 13:7 + *) + let line = String.trim line in + + let single_line_re = + Str.regexp + "^File \"\\([^\"]+\\)\", line \\([0-9]+\\), characters \ + \\([0-9]+\\)-\\([0-9]+\\):$" + in + let multi_line_re = + Str.regexp + "^File \"\\([^\"]+\\)\", lines \\([0-9]+\\)-\\([0-9]+\\), characters \ + \\([0-9]+\\)-\\([0-9]+\\):$" + in + + if Str.string_match single_line_re line 0 then + let filepath = Str.matched_group 1 line in + let line_number = Str.matched_group 2 line |> int_of_string in + let start_col = Str.matched_group 3 line |> int_of_string in + let end_col = Str.matched_group 4 line |> int_of_string in + Some + ( filepath_of_path filepath, + Some + { + start_pos = {line = line_number; col = start_col}; + end_pos = {line = line_number; col = end_col}; + } ) + else if Str.string_match multi_line_re line 0 then + let filepath = Str.matched_group 1 line in + let start_line = Str.matched_group 2 line |> int_of_string in + let end_line = Str.matched_group 3 line |> int_of_string in + let start_col = Str.matched_group 4 line |> int_of_string in + let end_col = Str.matched_group 5 line |> int_of_string in + Some + ( filepath_of_path filepath, + Some + { + start_pos = {line = start_line; col = start_col}; + end_pos = {line = end_line; col = end_col}; + } ) + else None + + let parse_location line = + match parse_path_location line with + | Some location -> Some (Path_location, location) + | None -> ( + match parse_file_location line with + | Some location -> Some (File_location, location) + | None -> None) + + let is_location_line line = + match parse_location line with + | Some _ -> true + | None -> false + + let is_source_code_line line = + (* Matches lines like: + 1 │ let a = 1 + 2 │ let b = "hi" + 11 | ......Todos { + 46 ┆ module Input = { + + Unnumbered OCaml gutter continuation lines are handled by + [message_from_lines] only after a numbered source line has started an + excerpt. A diagnostic message can itself start with [|], for example + missing pattern-match cases. + *) + let rescript_re = Str.regexp "^[ \t]*[0-9]+[ \t]*│" in + let rescript_rei_re = Str.regexp "^[ \t]*[0-9]+[ \t]*┆" in + let ocaml_re = Str.regexp "^[ \t]*[0-9]+[ \t]*|" in + Str.string_match rescript_re line 0 + || Str.string_match rescript_rei_re line 0 + || Str.string_match ocaml_re line 0 + + let is_source_continuation_line line = + Str.string_match (Str.regexp "^[ \t]*|") line 0 + + let is_source_excerpt_line line = + is_source_code_line line || is_source_continuation_line line + + let trim_empty_edges lines = + let rec drop_start = function + | [] -> [] + | x :: xs when is_blank x -> drop_start xs + | xs -> xs + in + + let rec drop_end xs = + match List.rev xs with + | [] -> [] + | x :: rest when is_blank x -> drop_end (List.rev rest) + | _ -> xs + in + + lines |> drop_start |> drop_end + + let find_title_index lines loc_index = + let rec loop i = + if i < 0 then None + else + let line = lines.(i) in + let trimmed = String.trim line in + + if is_blank line || starts_with "#Start" trimmed then loop (i - 1) + else Some i + in + loop (loc_index - 1) + + let warning_from_line line = + let line = String.trim line in + let warning_number_re = Str.regexp "^Warning number[ \t]+\\([0-9]+\\)" in + let warning_re = Str.regexp "^Warning[ \t]+\\([0-9]+\\)" in + let configured_as_error = + try + ignore + (Str.search_forward + (Str.regexp_string "(configured as error)") + line 0); + true + with Not_found -> false + in + if Str.string_match warning_number_re line 0 then + Some (Str.matched_group 1 line |> int_of_string, configured_as_error) + else if Str.string_match warning_re line 0 then + Some (Str.matched_group 1 line |> int_of_string, configured_as_error) + else None + + let is_diagnostic_message_start line = + let content = String.trim line in + String.starts_with ~prefix:"Warning " content + || String.starts_with ~prefix:"Error" content + + let kind_from_title title = + match title with + | "Syntax error!" -> Syntax_error + | "We've found a bug for you!" -> Common_error + | other -> ( + match warning_from_line other with + | Some (number, configured_as_error) -> + Warning {number; configured_as_error} + | None -> Unknown) + + let kind_from_message lines = + let rec loop = function + | [] -> Unknown + | line :: rest -> + let content = String.trim line in + if is_blank content || is_source_excerpt_line content then loop rest + else if String.starts_with ~prefix:"Warning " content then + match warning_from_line content with + | Some (number, configured_as_error) -> + Warning {number; configured_as_error} + | None -> Unknown + else if String.starts_with ~prefix:"Error" content then Unknown + else loop rest + in + loop lines + + let message_from_lines lines = + let rec filter_source_lines in_source_excerpt acc = function + | [] -> List.rev acc + | line :: rest -> + let trimmed = String.trim line in + if + is_location_line line + || starts_with "#Done" trimmed + || starts_with "#Start" trimmed + then filter_source_lines false acc rest + else if is_source_code_line line then filter_source_lines true acc rest + else if in_source_excerpt then + if is_diagnostic_message_start line then + filter_source_lines false (line :: acc) rest + else if is_blank line then + filter_source_lines false (line :: acc) rest + else filter_source_lines true acc rest + else filter_source_lines false (line :: acc) rest + in + lines + |> filter_source_lines false [] + |> trim_empty_edges |> List.map String.trim |> String.concat "\n" + + let unique_preserve_order items = + let rec loop seen acc = function + | [] -> List.rev acc + | item :: rest -> + if List.mem item seen then loop seen acc rest + else loop (item :: seen) (item :: acc) rest + in + loop [] [] items + + let collect_matches re group line = + let rec loop start acc = + try + ignore (Str.search_forward re line start); + let matched = Str.matched_group group line in + loop (Str.match_end ()) (matched :: acc) + with Not_found -> List.rev acc + in + loop 0 [] + + let source_path_from_artifact_path path = + if ends_with ".cmj" path then + String.sub path 0 (String.length path - 4) ^ ".res" + else path + + let parse_dependency_cycle_paths message_lines = + let paren_source_path_re = + Str.regexp "(\\([^()]+\\.\\(res\\|resi\\|re\\|rei\\)\\))" + in + let artifact_path_re = Str.regexp "\\([^ ]+\\.cmj\\)" in + let source_paths = + message_lines |> List.concat_map (collect_matches paren_source_path_re 1) + in + match source_paths with + | _ :: _ -> unique_preserve_order source_paths + | [] -> + message_lines + |> List.concat_map (collect_matches artifact_path_re 1) + |> List.map source_path_from_artifact_path + |> unique_preserve_order + + let parse_dependency_cycle_entries lines len = + let rec collect_until_done i acc = + if i >= len then (List.rev acc, i) + else + let trimmed = String.trim lines.(i) in + if starts_with "#Done" trimmed then (List.rev acc, i) + else collect_until_done (i + 1) (lines.(i) :: acc) + in + let rec loop i acc = + if i >= len then List.rev acc + else + let trimmed = String.trim lines.(i) in + if starts_with "Can't continue... Found a circular dependency" trimmed + then + let message_lines, next_i = collect_until_done i [] in + let message = + message_lines |> trim_empty_edges |> List.map String.trim + |> String.concat "\n" + in + let paths = parse_dependency_cycle_paths message_lines in + let entries = + paths + |> List.map (fun filepath -> + { + path = filepath_of_path filepath; + kind = Circular_dependency; + message; + range = None; + }) + in + loop (next_i + 1) (List.rev_append entries acc) + else if starts_with "FAILED: dependency cycle:" trimmed then + let message = trimmed in + let paths = parse_dependency_cycle_paths [trimmed] in + let entries = + paths + |> List.map (fun filepath -> + { + path = filepath_of_path filepath; + kind = Circular_dependency; + message; + range = None; + }) + in + loop (i + 1) (List.rev_append entries acc) + else loop (i + 1) acc + in + loop 0 [] + + let replace_double_newline message = + Str.global_replace (Str.regexp "\n\n") "\n" message + + let range_of_parsed_range = function + | None -> None + | Some range -> + (* Compiler log locations are 1-based, while LSP locations are 0-based. + End columns are already exclusive in compiler output, so only line + numbers and start columns are shifted. *) + let minus_one v = max 0 (v - 1) in + Some + (Lsp.Types.Range.create + ~start: + (Lsp.Types.Position.create + ~line:(range.start_pos.line |> minus_one) + ~character:(range.start_pos.col |> minus_one)) + ~end_: + (Lsp.Types.Position.create + ~line:(range.end_pos.line |> minus_one) + ~character:range.end_pos.col)) + + let is_complete content = + content |> String.split_on_char '\n' |> List.rev + |> List.find_opt (fun line -> not (is_blank line)) + |> function + | Some line -> starts_with "#Done" (String.trim line) + | None -> false + + let parse_log_content (content : string) = + let lines = split_lines content in + let len = Array.length lines in + + let diagnostics = + let rec loop i acc = + if i >= len then List.rev acc + else + match parse_location lines.(i) with + | Some (location_format, location) -> + let title_index = + match location_format with + | Path_location -> find_title_index lines i + | File_location -> None + in + loop (i + 1) ((i, title_index, location_format, location) :: acc) + | None -> loop (i + 1) acc + in + loop 0 [] + in + + let rec build entries = + match entries with + | [] -> [] + | (loc_index, title_index, location_format, (path, range)) :: rest -> + let next_boundary = + match rest with + | (next_loc_index, next_title_index, next_location_format, _) :: _ + -> ( + match next_location_format with + | File_location -> next_loc_index + | Path_location -> ( + match next_title_index with + | Some i -> i + | None -> next_loc_index)) + | [] -> len + in + + let message_start = + match title_index with + | Some i -> i + 1 + | None -> loc_index + 1 + in + + let raw_message_lines = + let rec collect i acc = + if i >= next_boundary then List.rev acc + else collect (i + 1) (lines.(i) :: acc) + in + collect message_start [] + in + + let kind = + match location_format with + | File_location -> kind_from_message raw_message_lines + | Path_location -> ( + match title_index with + | Some i -> kind_from_title (String.trim lines.(i)) + | None -> kind_from_message raw_message_lines) + in + + let message = + raw_message_lines |> message_from_lines |> replace_double_newline + in + + {kind; path; message; range = range_of_parsed_range range} :: build rest + in + + let dependency_cycle_diagnostics = + parse_dependency_cycle_entries lines len + in + + build diagnostics @ dependency_cycle_diagnostics +end + +let%expect_test "parse log" = + let diagnostic_of_entry (entry : Parse.diagnostic_entry) = + let range = + match entry.range with + | None -> `String "None" + | Some range -> Lsp.Types.Range.yojson_of_t range + in + Yojson.Safe.pretty_to_string + (`Assoc [("message", `String entry.message); ("range", range)]) + in + let print_logs logs = + logs + |> List.iter (fun (entry : Parse.diagnostic_entry) -> + let path = + match entry.path with + | Parse.Relative_path p -> Printf.sprintf "Relative_path(%s)" p + | Full_path p -> Printf.sprintf "Full_path(%s)" p + in + print_endline + ((match entry.kind with + | Syntax_error -> "Syntax_error" + | Warning {number; configured_as_error} -> + if configured_as_error then + Printf.sprintf "Warning %d (configured as error)" number + else Printf.sprintf "Warning %d" number + | Unknown -> "Unknown" + | Circular_dependency -> "Circular_dependency" + | Common_error -> "Common_error") + ^ " - " ^ path); + diagnostic_of_entry entry |> print_endline; + print_newline ()) + in + let example_log_1 = + {| + #Start(1600519680823) + + Syntax error! + /Users/chenglou/github/reason-react/src/test.res:1:8-2:3 + + 1 │ let a = + 2 │ let b = + 3 │ + + This let-binding misses an expression + + + Warning number 8 + /Users/chenglou/github/reason-react/src/test.res:3:5-8 + + 1 │ let a = j`šŸ˜€` + 2 │ let b = `šŸ˜€` + 3 │ let None = None + 4 │ let bla: int = " + 5 │ hi + + You forgot to handle a possible case here, for example: + Some _ + + + We've found a bug for you! + /Users/chenglou/github/reason-react/src/test.res:3:9 + + 1 │ let a = 1 + 2 │ let b = "hi" + 3 │ let a = b + 1 + + This has type: string + Somewhere wanted: int + + #Done(1600519680836) + |} + in + + Parse.parse_log_content example_log_1 |> print_logs; + [%expect + {| + Syntax_error - Full_path(/Users/chenglou/github/reason-react/src/test.res) + { + "message": "This let-binding misses an expression", + "range": { + "end": { "character": 3, "line": 1 }, + "start": { "character": 7, "line": 0 } + } + } + + Warning 8 - Full_path(/Users/chenglou/github/reason-react/src/test.res) + { + "message": "You forgot to handle a possible case here, for example:\nSome _", + "range": { + "end": { "character": 8, "line": 2 }, + "start": { "character": 4, "line": 2 } + } + } + + Common_error - Full_path(/Users/chenglou/github/reason-react/src/test.res) + { + "message": "This has type: string\nSomewhere wanted: int", + "range": { + "end": { "character": 9, "line": 2 }, + "start": { "character": 8, "line": 2 } + } + } + |}]; + + let example_log_2 = {|#Start(1780532423603) + #Done(1780532423840)|} in + + Parse.parse_log_content example_log_2 |> print_logs; + [%expect {| |}]; + + (* https://github.com/rescript-lang/rescript-vscode/issues/386#issuecomment-1221093517 *) + let example_log_3 = + {| + #Start(1660943070627) + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/fragmentsUsage/Fragments.res", lines 11-13, characters 6-7: + 11 | ......Todos { + | ...TodoItem + | } + 13 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/clientUsage/PromiseChaining.res", lines 17-21, characters 6-7: + 17 | ......os: allTodos { + | id + | text + | completed + | } + 21 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/clientUsage/ClientBasics.res", lines 18-22, characters 6-7: + 18 | ......os: allTodos { + | id + | text + | completed + | } + 22 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/docs/Docs.res", lines 7-11, characters 6-7: + 7 | ......os: allTodos { + | id + | text + | completed + | } + 11 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/fragmentsUsage/Query_Fragments.res", lines 6-9, characters 6-7: + 6 | ......os: allTodos { + | # This references the TodoItem fragment definition module above! + | ...TodoItem + | } + 9 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Mutation.res", lines 18-22, characters 6-7: + 18 | ......os: allTodos { + | id + | completed + | text + | } + 22 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_Lazy.res", lines 3-7, characters 6-7: + 3 | ......os: allTodos { + | id + | text + | completed + | } + 7 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_OverlySimple.res", lines 3-7, characters 4-5: + 3 | ....os: allTodos { + | id + | text + | completed + | } + 7 | . + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_SubscribeToMore.res", lines 5-9, characters 6-7: + 5 | ......os: allTodos { + | id + | completed + | text + | } + 9 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_Typical.res", lines 4-8, characters 6-7: + 4 | ......os: allTodos { + | id + | text + | completed + | } + 8 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + #Done(1660943070848) + |} + in + + Parse.parse_log_content example_log_3 |> print_logs; + [%expect + {| + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/fragmentsUsage/Fragments.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 12 }, + "start": { "character": 5, "line": 10 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/clientUsage/PromiseChaining.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 20 }, + "start": { "character": 5, "line": 16 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/clientUsage/ClientBasics.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 21 }, + "start": { "character": 5, "line": 17 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/docs/Docs.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 10 }, + "start": { "character": 5, "line": 6 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/fragmentsUsage/Query_Fragments.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 8 }, + "start": { "character": 5, "line": 5 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Mutation.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 21 }, + "start": { "character": 5, "line": 17 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_Lazy.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 6 }, + "start": { "character": 5, "line": 2 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_OverlySimple.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 5, "line": 6 }, + "start": { "character": 3, "line": 2 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_SubscribeToMore.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 8 }, + "start": { "character": 5, "line": 4 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_Typical.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 7 }, + "start": { "character": 5, "line": 3 } + } + } + |}]; + + (* https://github.com/rescript-lang/rescript-vscode/issues/86#issuecomment-786186698 *) + let example_log_4 = + {|#Start(1614285167013) + + Warning number 33 + /home/misha/projects/productionmason/web/auth/src/ErrorHandlingMiddleware.res:1:1-15 + + 1 │ open CommonBase + 2 │ + 3 │ external jsExnToExpressError: Js.Exn.t => Express.Error.t = "%identity" + + unused open CommonBase. + + + Warning number 27 + /home/misha/projects/productionmason/web/auth/src/config/Config.res:10:22-27 + + 8 │ external stringifyAnyWithSpace: ('a, @bs.as(json`null`) _, int) => str + ing = "stringify" + 9 │ + 10 │ let validateConfig = config => { + 11 │ let googleApplicationCredentialsPath = + 12 │ NodeJs.Process.env(NodeJs.Process.process)->Js.Dict.get("GOOGLE_AP + PLICATION_CREDENTIALS") + + unused variable config. + + + Warning number 34 + /home/misha/projects/productionmason/web/auth/src/express-handler/ExpressHandler.re:48:5-26 + + 46 ┆ module Input = { + 47 ┆ [@decco] + 48 ┆ type t = Request.input; + 49 ┆ }; + 50 ┆ + + unused type t. + + + Warning number 32 + /home/misha/projects/productionmason/web/auth/src/express-handler/ExpressHandler.re + + unused value t_encode. + + + We've found a bug for you! + /home/misha/projects/productionmason/web/auth/tests/Auth_Test.res:224:45 + + 222 ┆ ->AsyncResult.mapOk(x => { + 223 ┆ expect(x.data.users->Array.length)->toBeGreaterThan(0) + 224 ┆ expect(x.data.users->Array.getExn(0).last_name)->toBe(Some("Glenliv + et")) + 225 ┆ Ok() + 226 ┆ }) + + This has type: int + Somewhere wanted: array<'a> + + #Done(1614285167075)|} + in + + Parse.parse_log_content example_log_4 |> print_logs; + [%expect + {| + Warning 33 - Full_path(/home/misha/projects/productionmason/web/auth/src/ErrorHandlingMiddleware.res) + { + "message": "unused open CommonBase.", + "range": { + "end": { "character": 15, "line": 0 }, + "start": { "character": 0, "line": 0 } + } + } + + Warning 27 - Full_path(/home/misha/projects/productionmason/web/auth/src/config/Config.res) + { + "message": "unused variable config.", + "range": { + "end": { "character": 27, "line": 9 }, + "start": { "character": 21, "line": 9 } + } + } + + Warning 34 - Full_path(/home/misha/projects/productionmason/web/auth/src/express-handler/ExpressHandler.re) + { + "message": "unused type t.", + "range": { + "end": { "character": 26, "line": 47 }, + "start": { "character": 4, "line": 47 } + } + } + + Warning 32 - Full_path(/home/misha/projects/productionmason/web/auth/src/express-handler/ExpressHandler.re) + { "message": "unused value t_encode.", "range": "None" } + + Common_error - Full_path(/home/misha/projects/productionmason/web/auth/tests/Auth_Test.res) + { + "message": "This has type: int\nSomewhere wanted: array<'a>", + "range": { + "end": { "character": 45, "line": 223 }, + "start": { "character": 44, "line": 223 } + } + } + |}]; + + let example_log_5 = + {|#Start(1780595107359) + + Can't continue... Found a circular dependency in your code: + Demo (src/Demo.res) + → Other (src/Other.res) + → Demo (src/Demo.res) + Possible solutions: + - Extract shared code into a new module both depend on. + #Done(1780595107364) + |} + in + + Parse.parse_log_content example_log_5 |> print_logs; + [%expect + {| + Circular_dependency - Relative_path(src/Demo.res) + { + "message": "Can't continue... Found a circular dependency in your code:\nDemo (src/Demo.res)\n→ Other (src/Other.res)\n→ Demo (src/Demo.res)\nPossible solutions:\n- Extract shared code into a new module both depend on.", + "range": "None" + } + + Circular_dependency - Relative_path(src/Other.res) + { + "message": "Can't continue... Found a circular dependency in your code:\nDemo (src/Demo.res)\n→ Other (src/Other.res)\n→ Demo (src/Demo.res)\nPossible solutions:\n- Extract shared code into a new module both depend on.", + "range": "None" + } + |}]; + + let example_log_6 = + {|#Start(1780595245481) + FAILED: dependency cycle: src/Demo.cmj -> src/Other.cmj -> src/Demo.cmj. + #Done(1780595245488)|} + in + + Parse.parse_log_content example_log_6 |> print_logs; + [%expect + {| + Circular_dependency - Relative_path(src/Demo.res) + { + "message": "FAILED: dependency cycle: src/Demo.cmj -> src/Other.cmj -> src/Demo.cmj.", + "range": "None" + } + + Circular_dependency - Relative_path(src/Other.res) + { + "message": "FAILED: dependency cycle: src/Demo.cmj -> src/Other.cmj -> src/Demo.cmj.", + "range": "None" + } + |}]; + + let example_log_7 = + {|#Start(1780595410580) + + We've found a bug for you! + /tmp/my-rescript-app/src/Demo.res:1:9-15 + + 1 │ let a = Other.a + 2 │ + + The value a can't be found in Other + + FAILED: cannot make progress due to previous errors. + #Done(1780595410597)|} + in + + Parse.parse_log_content example_log_7 |> print_logs; + [%expect + {| + Common_error - Full_path(/tmp/my-rescript-app/src/Demo.res) + { + "message": "The value a can't be found in Other\nFAILED: cannot make progress due to previous errors.", + "range": { + "end": { "character": 15, "line": 0 }, + "start": { "character": 8, "line": 0 } + } + } + |}]; + + let example_log_8 = + {|#Start(1780603624843) + Error in lsp-test: + + Syntax error! + /home/pedro/Desktop/projects/lsp-test/src/ArrayUtils.res:1:41-2:0 + + 1 │ let empty = arr => Array.length(arr) === + 2 │ + + Did you forget to write an expression here? + + #Done(1780603624849)|} + in + Parse.parse_log_content example_log_8 |> print_logs; + [%expect + {| + Syntax_error - Full_path(/home/pedro/Desktop/projects/lsp-test/src/ArrayUtils.res) + { + "message": "Did you forget to write an expression here?", + "range": { + "end": { "character": 0, "line": 1 }, + "start": { "character": 40, "line": 0 } + } + } + |}]; + + let example_log_9 = + {|#Start(1780630901455) + + We've found a bug for you! + /home/pedro/Desktop/projects/lsp-test/src/ArrayUtils.res:1:41-43 + + 1 │ let empty = arr => Array.length(arr) == "2"; + 2 │ + + This has type: string + But it's being compared to something of type: int + + You can only compare things of the same type. + + You can convert string to int with Int.fromString. + + #Done(1780630901468)|} + in + + Parse.parse_log_content example_log_9 |> print_logs; + [%expect + {| + Common_error - Full_path(/home/pedro/Desktop/projects/lsp-test/src/ArrayUtils.res) + { + "message": "This has type: string\nBut it's being compared to something of type: int\nYou can only compare things of the same type.\nYou can convert string to int with Int.fromString.", + "range": { + "end": { "character": 43, "line": 0 }, + "start": { "character": 40, "line": 0 } + } + } + |}]; + + let example_log_10 = + {|#Start(1781383030890) + + Warning number 8 (configured as error) + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:6:3-9:3 + + 4 │ + 5 │ let f = (a: t) => { + 6 │ switch a { + 7 │ | A => () + 8 │ | B => () + 9 │ } + 10 │ } + 11 │ + + You forgot to handle a possible case here, for example: + | C + + + Warning number 37 + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:3:1-18 + + 1 │ open ReactRouter.Routes + 2 │ + 3 │ type t = A | B | C + 4 │ + 5 │ let f = (a: t) => { + + constructor A is never used to build values. + (However, this constructor appears in patterns.) + + + Warning number 37 + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:3:1-18 + + 1 │ open ReactRouter.Routes + 2 │ + 3 │ type t = A | B | C + 4 │ + 5 │ let f = (a: t) => { + + constructor B is never used to build values. + (However, this constructor appears in patterns.) + + + Warning number 37 + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:3:1-18 + + 1 │ open ReactRouter.Routes + 2 │ + 3 │ type t = A | B | C + 4 │ + 5 │ let f = (a: t) => { + + unused constructor C. + + + Warning number 32 + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:5:5 + + 3 │ type t = A | B | C + 4 │ + 5 │ let f = (a: t) => { + 6 │ switch a { + 7 │ | A => () + + unused value f. + + #Done(1781383030936)|} + in + Parse.parse_log_content example_log_10 |> print_logs; + [%expect + {| + Warning 8 (configured as error) - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) + { + "message": "You forgot to handle a possible case here, for example:\n| C", + "range": { + "end": { "character": 3, "line": 8 }, + "start": { "character": 2, "line": 5 } + } + } + + Warning 37 - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) + { + "message": "constructor A is never used to build values.\n(However, this constructor appears in patterns.)", + "range": { + "end": { "character": 18, "line": 2 }, + "start": { "character": 0, "line": 2 } + } + } + + Warning 37 - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) + { + "message": "constructor B is never used to build values.\n(However, this constructor appears in patterns.)", + "range": { + "end": { "character": 18, "line": 2 }, + "start": { "character": 0, "line": 2 } + } + } + + Warning 37 - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) + { + "message": "unused constructor C.", + "range": { + "end": { "character": 18, "line": 2 }, + "start": { "character": 0, "line": 2 } + } + } + + Warning 32 - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) + { + "message": "unused value f.", + "range": { + "end": { "character": 5, "line": 4 }, + "start": { "character": 4, "line": 4 } + } + } + |}]; + + let example_log_10 = + {|#Start(1780630901455) + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/access_record_field_on_option.res:12:15 + + 10 │ } + 11 │ + 12 │ let f = X.x.c.d + 13 │ + + You're trying to access the record field d, but the value you're trying to access it on is an option. + You need to unwrap the option first before accessing the record field. + + Possible solutions: + - Use Option.map to transform the option: xx->Option.map(field => field.d) + - Or use Option.getOr with a default: xx->Option.getOr(defaultRecord).d + + #Done(1781383030936)|} + in + + Parse.parse_log_content example_log_10 |> print_logs; + [%expect + {| + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/access_record_field_on_option.res) + { + "message": "You're trying to access the record field d, but the value you're trying to access it on is an option.\nYou need to unwrap the option first before accessing the record field.\nPossible solutions:\n- Use Option.map to transform the option: xx->Option.map(field => field.d)\n- Or use Option.getOr with a default: xx->Option.getOr(defaultRecord).d", + "range": { + "end": { "character": 15, "line": 11 }, + "start": { "character": 14, "line": 11 } + } + } + |}]; + + let example_log_11 = + {|#Start(1780630901455) + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/arity_mismatch.res:2:21-27 + + 1 │ let makeVar = (~f, ()) => 34 + 2 │ let makeVariables = makeVar(~f=f => f) + 3 │ + + This function call is incorrect. + The function has type: + (~f: 'a => 'a, unit) => int + + - The function takes 1 unlabelled argument, but is called with none + + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/array_item_type_mismatch.res:1:16-22 + + 1 │ let x = [1, 2, "hello"] + 2 │ + + This array item has type: string + But this array is expected to have items of type: int + + Arrays can only contain items of the same type. + + Possible solutions: + - Convert all values in the array to the same type. + - Use a tuple, if your array is of fixed length. Tuples can mix types freely, and compiles to a JavaScript array. Example of a tuple: `let myTuple = (10, "hello", 15.5, true) + + You can convert string to int with Int.fromString. + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:4:5-7:1 + + 2 │ type t = .. + 3 │ type t += E(int) + 4 │ } = { + 5 │ type t = .. + 6 │ type t += E(string) + 7 │ } + 8 │ + + Signature mismatch: + Modules do not match: + { + type t = .. + type t += E(string) + } + is not included in + { + type t = .. + type t += E(int) + } + Extension declarations do not match: + type t += E(string) + is not included in + type t += E(int) + tests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:3:13-18: + Expected declaration + tests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:6:13-21: + Actual declaration + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/functor_apply_arg_mismatch.res:13:22-29 + + 11 │ } + 12 │ + 13 │ module Result = Make(Concrete) + 14 │ let _ = Result.bar + 15 │ + + Signature mismatch: + Modules do not match: { + let unrelated: string + } is not included in HasFoo + The value `foo' is required but not provided + tests/build_tests/super_errors/fixtures/functor_apply_arg_mismatch.res:2:3-14: + Expected declaration + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/include_missing_field.res:4:5-6:1 + + 2 │ let x: int + 3 │ let y: string + 4 │ } = { + 5 │ let x = 1 + 6 │ } + 7 │ + + Signature mismatch: + Modules do not match: + { + let x: int + } + is not included in + { + let x: int + let y: string + } + The value `y' is required but not provided + tests/build_tests/super_errors/fixtures/include_missing_field.res:3:3-15: + Expected declaration + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:5:5-9:1 + + 3 │ let x: int + 4 │ } + 5 │ } = { + 6 │ module type T = { + 7 │ let x: string + 8 │ } + 9 │ } + 10 │ + + Signature mismatch: + Modules do not match: + { + module type T = { + let x: string + } + } + is not included in + { + module type T = { + let x: int + } + } + Module type declarations do not match: + module type T = { + let x: string + } + does not match + module type T = { + let x: int + } + At position module type T = + Modules do not match: + { + let x: string + } + is not included in + { + let x: int + } + At position module type T = + Values do not match: let x: string is not included in let x: int + tests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:3:5-14: + Expected declaration + tests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:7:5-17: + Actual declaration + + #Done(1781383030936)|} + in + + Parse.parse_log_content example_log_11 |> print_logs; + [%expect + {| + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/arity_mismatch.res) + { + "message": "This function call is incorrect.\nThe function has type:\n(~f: 'a => 'a, unit) => int\n- The function takes 1 unlabelled argument, but is called with none", + "range": { + "end": { "character": 27, "line": 1 }, + "start": { "character": 20, "line": 1 } + } + } + + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/array_item_type_mismatch.res) + { + "message": "This array item has type: string\nBut this array is expected to have items of type: int\nArrays can only contain items of the same type.\nPossible solutions:\n- Convert all values in the array to the same type.\n- Use a tuple, if your array is of fixed length. Tuples can mix types freely, and compiles to a JavaScript array. Example of a tuple: `let myTuple = (10, \"hello\", 15.5, true)\nYou can convert string to int with Int.fromString.", + "range": { + "end": { "character": 22, "line": 0 }, + "start": { "character": 15, "line": 0 } + } + } + + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res) + { + "message": "Signature mismatch:\nModules do not match:\n{\ntype t = ..\ntype t += E(string)\n}\nis not included in\n{\ntype t = ..\ntype t += E(int)\n}\nExtension declarations do not match:\ntype t += E(string)\nis not included in\ntype t += E(int)\ntests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:3:13-18:\nExpected declaration\ntests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:6:13-21:\nActual declaration", + "range": { + "end": { "character": 1, "line": 6 }, + "start": { "character": 4, "line": 3 } + } + } + + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/functor_apply_arg_mismatch.res) + { + "message": "Signature mismatch:\nModules do not match: {\nlet unrelated: string\n} is not included in HasFoo\nThe value `foo' is required but not provided\ntests/build_tests/super_errors/fixtures/functor_apply_arg_mismatch.res:2:3-14:\nExpected declaration", + "range": { + "end": { "character": 29, "line": 12 }, + "start": { "character": 21, "line": 12 } + } + } + + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/include_missing_field.res) + { + "message": "Signature mismatch:\nModules do not match:\n{\nlet x: int\n}\nis not included in\n{\nlet x: int\nlet y: string\n}\nThe value `y' is required but not provided\ntests/build_tests/super_errors/fixtures/include_missing_field.res:3:3-15:\nExpected declaration", + "range": { + "end": { "character": 1, "line": 5 }, + "start": { "character": 4, "line": 3 } + } + } + + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res) + { + "message": "Signature mismatch:\nModules do not match:\n{\nmodule type T = {\nlet x: string\n}\n}\nis not included in\n{\nmodule type T = {\nlet x: int\n}\n}\nModule type declarations do not match:\nmodule type T = {\nlet x: string\n}\ndoes not match\nmodule type T = {\nlet x: int\n}\nAt position module type T = \nModules do not match:\n{\nlet x: string\n}\nis not included in\n{\nlet x: int\n}\nAt position module type T = \nValues do not match: let x: string is not included in let x: int\ntests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:3:5-14:\nExpected declaration\ntests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:7:5-17:\nActual declaration", + "range": { + "end": { "character": 1, "line": 8 }, + "start": { "character": 4, "line": 4 } + } + } + |}]; + + let example_log_12 = + {|#Start(1781743112207) + Error in build_warn_as_error: + + Warning number 110 (configured as error) + /home/pedro/Desktop/projects/rescript-compiler/tests/build_tests/build_warn_as_error/src/Demo.res:1:17-21 + + 1 │ let todo = _ => %todo + 2 │ + + Todo found. + + This code is not implemented yet and will crash at runtime. Make sure you implement this before running the code. + + #Done(1781743112217)|} + in + + Parse.parse_log_content example_log_12 |> print_logs; + [%expect + {| + Warning 110 (configured as error) - Full_path(/home/pedro/Desktop/projects/rescript-compiler/tests/build_tests/build_warn_as_error/src/Demo.res) + { + "message": "Todo found.\nThis code is not implemented yet and will crash at runtime. Make sure you implement this before running the code.", + "range": { + "end": { "character": 21, "line": 0 }, + "start": { "character": 16, "line": 0 } + } + } + |}]; + + let example_log_13 = + {|#Start(1781744629915) + + We've found a bug for you! + /home/pedro/Desktop/projects/rescript-compiler/tests/build_tests/gpr_978/src/gpr_978_module.res + + M is exported twice + + #Done(1781744629934)|} + in + + Parse.parse_log_content example_log_13 |> print_logs; + [%expect + {| + Common_error - Full_path(/home/pedro/Desktop/projects/rescript-compiler/tests/build_tests/gpr_978/src/gpr_978_module.res) + { "message": "M is exported twice", "range": "None" } + |}]; + + let example_log_14 = + {|#Start(1781910915195) + + We've found a bug for you! + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/scripts/LogAlgoliaEnvStatus.res:13:37-85 + + 11 ┆ switch Node.Process.argv[1] { + 12 ┆ | Some(entrypoint) => + 13 ┆ Node.URL.fileURLToPath(url) === Node.Path.resolve(Node.Process.cwd(), + ┆ entrypoint) + 14 ┆ | None => false + 15 ┆ } + + This has type: string + But it's being compared to something of type: int + + You can only compare things of the same type. + + You can convert string to int with Int.fromString. + + + We've found a bug for you! + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/scripts/gendocs.res:23:3-24:21 + + 21 │ let args = Process.argv->Array.slice(~start=2) + 22 │ let dirname = + 23 │ url + 24 │ ->URL.fileURLToPath + 25 │ ->Path.dirname + 26 │ + + This has type: int + But this function argument is expecting: string + + You can convert int to string with Int.toString. + + #Done(1781910915345)|} + in + + Parse.parse_log_content example_log_14 |> print_logs; + [%expect + {| + Common_error - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/scripts/LogAlgoliaEnvStatus.res) + { + "message": "This has type: string\nBut it's being compared to something of type: int\nYou can only compare things of the same type.\nYou can convert string to int with Int.fromString.", + "range": { + "end": { "character": 85, "line": 12 }, + "start": { "character": 36, "line": 12 } + } + } + + Common_error - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/scripts/gendocs.res) + { + "message": "This has type: int\nBut this function argument is expecting: string\nYou can convert int to string with Int.toString.", + "range": { + "end": { "character": 21, "line": 23 }, + "start": { "character": 2, "line": 22 } + } + } + |}] diff --git a/lsp/src/configuration.ml b/lsp/src/configuration.ml new file mode 100644 index 00000000000..fa39cadfcd7 --- /dev/null +++ b/lsp/src/configuration.ml @@ -0,0 +1,52 @@ +type hover = { + support_markdown_links: bool; [@key "supportMarkdownLinks"] [@default false] +} +[@@deriving yojson {strict = false}] + +type inlay_hints = { + enable: bool; [@default false] + max_length: int option; [@key "maxLength"] [@default Some 25] +} +[@@deriving yojson {strict = false}] + +type t = { + hover: hover; [@default {support_markdown_links = false}] + code_lens: bool; [@key "codeLens"] [@default false] + inlay_hints: inlay_hints; + [@key "inlayHints"] [@default {enable = false; max_length = Some 25}] +} +[@@deriving yojson {strict = false}] + +let default = + { + hover = {support_markdown_links = false}; + code_lens = false; + inlay_hints = {enable = false; max_length = Some 25}; + } + +let%expect_test "parse config" = + let parse_and_print_config json = + match of_yojson (Yojson.Safe.from_string json) with + | Ok c -> c |> to_yojson |> Yojson.Safe.pretty_to_string |> print_endline + | Error _ -> print_endline "Error" + in + + let example_config_json_1 = + {| + { + "askToStartBuild": false, + "inlayHints": { "enable": true, "maxLength": 25 }, + "codeLens": true, + "signatureHelp": { "enabled": true, "forConstructorPayloads": true }, + "incrementalTypechecking": { "enable": true, "acrossFiles": false }, + "cache": { "projectConfig": { "enable": true } }, + "binaryPath": null, + "platformPath": null, + "runtimePath": null, + "compileStatus": { "enable": true }, + "logLevel": "info" + } + |} + in + parse_and_print_config example_config_json_1; + [%expect {| { "codeLens": true, "inlayHints": { "enable": true } } |}] diff --git a/lsp/src/constants.ml b/lsp/src/constants.ml new file mode 100644 index 00000000000..6bb91f2d617 --- /dev/null +++ b/lsp/src/constants.ml @@ -0,0 +1,9 @@ +let ( /+ ) = Filename.concat + +let build_output_folder = "lib" +let compiler_dir_partial_path = build_output_folder /+ "rescript" +let compiler_log = ".compiler.log" +let sources_dirs = ".sourcedirs.json" +let rescript_json = "rescript.json" +let bsconfig_json = "bsconfig.json" +let compiler_log_partial_path = compiler_dir_partial_path /+ compiler_log diff --git a/lsp/src/custom_requests.ml b/lsp/src/custom_requests.ml new file mode 100644 index 00000000000..d92501166d2 --- /dev/null +++ b/lsp/src/custom_requests.ml @@ -0,0 +1,114 @@ +open Lsp +open Lsp.Types + +let make_error ?(code = Jsonrpc.Response.Error.Code.InternalError) message = + Jsonrpc.Response.Error.make ~message ~code () + +module Open_compiled_file = struct + let meth = "textDocument/openCompiled" + + (* Custom request to open compiled file + + Request params: TextDocumentIdentifier + Return: TextDocumentIdentifier | ResponseError + *) + let on_request ~(params : Jsonrpc.Structured.t option) ~(state : State.t) = + let make ~(uri : Uri.t) ~(state : State.t) = + let compiled_uri = + Helpers.get_compiled_file ~uri + ~compiler_config:(State.compiler_config state) + ~fs:state.fs + in + match compiled_uri with + | Some uri -> Ok uri + | None -> Error ("Failed to get compiled file for " ^ Uri.to_path uri) + in + match params with + | Some json -> ( + let doc = + json |> Jsonrpc.Structured.yojson_of_t + |> TextDocumentIdentifier.t_of_yojson + in + match make ~uri:doc.uri ~state with + | Ok uri -> + Ok + (TextDocumentIdentifier.create ~uri + |> TextDocumentIdentifier.yojson_of_t) + | Error message -> Error (make_error message)) + | _ -> + Error + (make_error ?code:(Some InvalidParams) + (Printf.sprintf + "Invalid params for request %s, expected a TextDocumentIdentifier" + meth)) +end + +module Create_interface_file = struct + let meth = "textDocument/createInterface" + + let make ~uri ~cmi_uri ~(state : State.t) = + match Document.kind_of_uri uri with + | Res -> ( + match + Analysis.Create_interface.command ~path:(Uri.to_path uri) + ~source:(Document_store.get ~uri state.store |> Document.text) + ~cmi_file:(cmi_uri |> Uri.to_path) + with + | Ok content -> + let resi_file = Uri.to_path uri ^ "i" in + let () = + Fs.save ~append:false ~create:(`Or_truncate 0o644) ~fs:state.fs + resi_file content + in + Ok (Uri.of_path resi_file) + | Error e -> Error e) + | _ -> + Error + (Printf.sprintf + "Invalid file to create interface for %s. Expected a .res file" + (Uri.to_string uri)) + + (* Custom request to create a interface file. + + Request params: TextDocumentIdentifier + Return: TextDocumentIdentifier | ResponseError + *) + let on_request ~(params : Jsonrpc.Structured.t option) ~(state : State.t) = + match params with + | Some json -> + let doc = + json |> Jsonrpc.Structured.yojson_of_t + |> TextDocumentIdentifier.t_of_yojson + in + let uri = doc.uri in + let cmi_file = + Helpers.get_cmi_file ~uri ~fs:state.fs + ~compiler_config:(State.compiler_config state) + in + let result = + match cmi_file with + | Some cmi_file -> + let response = + match make ~uri ~cmi_uri:(Uri.of_path cmi_file) ~state with + | Ok uri -> + Ok + (TextDocumentIdentifier.create ~uri + |> TextDocumentIdentifier.yojson_of_t) + | Error message -> Error (make_error message) + in + response + | None -> + Error + (make_error + (Printf.sprintf + "Failed to find cmi file for %s to create interface file" + (Uri.to_string uri))) + in + result + | _ -> + Error + (make_error ?code:(Some InvalidParams) + (Printf.sprintf + "Invalid params for request %s, expected a TextDocumentIdentifier" + meth)) +end diff --git a/lsp/src/diagnostics.ml b/lsp/src/diagnostics.ml new file mode 100644 index 00000000000..5a6b6f34527 --- /dev/null +++ b/lsp/src/diagnostics.ml @@ -0,0 +1,396 @@ +open Lsp +open Lsp.Types + +module Uri_map = Map.Make (Uri) + +type diagnostics = Diagnostic.t list Uri_map.t + +(* Diagnostics come from sources with different lifetimes: + - compiler diagnostics are workspace/build state; + - compiler syntax diagnostics are only trusted after a document is closed; + - syntax diagnostics for open documents must follow the unsaved editor buffer. + Keep them separate so one source can be refreshed or cleared without + accidentally dropping diagnostics owned by another source. *) +type t = { + (* Non-syntax build diagnostics parsed from .compiler.log, such as type + errors, warnings, and dependency cycles. *) + compiler: diagnostics; + (* Syntax diagnostics parsed from .compiler.log. These are only published for + closed documents because open documents use the editor buffer below. *) + compiler_syntax: diagnostics; + (* Syntax diagnostics produced from currently open in-memory documents. *) + syntax: diagnostics; + send: PublishDiagnosticsParams.t -> unit; +} + +let empty () = Uri_map.empty + +let make ~diagnostics ~send = + {compiler = diagnostics; compiler_syntax = empty (); syntax = empty (); send} + +let merge_diagnostics left right = + Uri_map.merge + (fun _ left right -> + match (left, right) with + | None, None -> None + | Some diagnostics, None | None, Some diagnostics -> Some diagnostics + | Some left, Some right -> Some (left @ right)) + left right + +let get_all t : diagnostics = + let compiler = merge_diagnostics t.compiler t.compiler_syntax in + merge_diagnostics t.syntax compiler + +let diagnostics ?(include_syntax = true) t = + if include_syntax then get_all t + else merge_diagnostics t.compiler t.compiler_syntax + +let replace_snapshot ~old ~latest = + Uri_map.merge + (fun _ existing incoming -> + match (existing, incoming) with + | None, None -> None + | Some _, None -> Some [] + | None, Some diagnostics | Some _, Some diagnostics -> Some diagnostics) + old latest + +let update_compiler ~(new_diagnostics : diagnostics) t = + {t with compiler = replace_snapshot ~old:t.compiler ~latest:new_diagnostics} + +let update_compiler_syntax ~(new_diagnostics : diagnostics) t = + { + t with + compiler_syntax = + replace_snapshot ~old:t.compiler_syntax ~latest:new_diagnostics; + } + +let update_syntax ~uri ~(new_diagnostics : Diagnostic.t list) t = + {t with syntax = Uri_map.add uri new_diagnostics t.syntax} + +let clear_syntax ~uri t = update_syntax ~uri ~new_diagnostics:[] t + +let%expect_test "get_all merges diagnostics from every source" = + let uri = Uri.of_path "/workspace/A.res" in + let range = + Range.create + ~start:(Position.create ~line:0 ~character:0) + ~end_:(Position.create ~line:0 ~character:1) + in + let diagnostic message = + Diagnostic.create ~range ~message:(`String message) () + in + let t = + { + compiler = Uri_map.singleton uri [diagnostic "compiler"]; + compiler_syntax = Uri_map.singleton uri [diagnostic "compiler syntax"]; + syntax = Uri_map.singleton uri [diagnostic "syntax"]; + send = (fun _ -> ()); + } + in + get_all t |> Uri_map.find uri + |> List.iter (fun (diagnostic : Diagnostic.t) -> + match diagnostic.message with + | `String message -> print_endline message + | `MarkupContent {value} -> print_endline value); + [%expect {| + syntax + compiler + compiler syntax |}] + +let send ?(include_syntax = true) ?(force_publish_uris = []) + ?(should_publish = fun _ -> true) t = + let diagnostics = diagnostics ~include_syntax t in + Uri_map.iter + (fun uri diagnostics -> + if should_publish uri then + t.send (PublishDiagnosticsParams.create ~uri ~diagnostics ())) + diagnostics; + force_publish_uris + |> List.iter (fun uri -> + (* A URI excluded from this push may still have diagnostics retained + from an earlier push. Publish an empty list when ownership changes + so the client does not combine that stale result with pull data. *) + if (not (should_publish uri)) || not (Uri_map.mem uri diagnostics) then + t.send (PublishDiagnosticsParams.create ~uri ~diagnostics:[] ())) + +let%expect_test "send can reserve an open document for pull diagnostics" = + let open_uri = Uri.of_path "/workspace/Open.res" in + let closed_uri = Uri.of_path "/workspace/Closed.res" in + let range = + Range.create + ~start:(Position.create ~line:0 ~character:0) + ~end_:(Position.create ~line:0 ~character:1) + in + let diagnostic message = + Diagnostic.create ~range ~message:(`String message) () + in + let print ({uri; diagnostics; _} : PublishDiagnosticsParams.t) = + Printf.printf "%s: %d\n" + (Filename.basename (Uri.to_path uri)) + (List.length diagnostics) + in + let t = + { + compiler = + Uri_map.empty + |> Uri_map.add open_uri [diagnostic "open compiler"] + |> Uri_map.add closed_uri [diagnostic "closed compiler"]; + compiler_syntax = Uri_map.empty; + syntax = Uri_map.singleton open_uri [diagnostic "open syntax"]; + send = print; + } + in + send ~include_syntax:false ~force_publish_uris:[open_uri] + ~should_publish:(fun uri -> Uri.compare uri open_uri <> 0) + t; + [%expect {| + Closed.res: 1 + Open.res: 0 |}] + +(* Convert parsed compiler-log entries into LSP diagnostics grouped by document + URI. Compiler logs may report paths either relative to the workspace root or + as absolute paths, so this function normalizes each entry into a DocumentUri + before publishing. + + Open-document syntax diagnostics come from the current editor buffer. Compiler + syntax diagnostics are only useful for closed documents, where the compiler + log is the freshest source we have. *) +let to_lsp_format ~include_syntax ~include_non_syntax + (workspace_root : DocumentUri.t) (doc_store : Document_store.t) diagnostics + = + let workspace_root_path = workspace_root |> DocumentUri.to_path in + + let range_of_entry uri = function + | Some range -> range + | None -> ( + match Document_store.get_opt ~uri doc_store with + | None -> + let shortest_possible_code = "let a=1" in + Document.range_of_text shortest_possible_code + | Some doc -> Document.range_of_text (Document.text doc)) + in + + let diagnostic_of_entry uri (entry : Compiler_log.Parse.diagnostic_entry) = + let message, severity = + match entry.kind with + | Warning {number; configured_as_error} -> + let default = "Warning " ^ string_of_int number in + if configured_as_error then + ( default ^ " (configured as error) - " ^ entry.message, + DiagnosticSeverity.Error ) + else (default ^ " - " ^ entry.message, DiagnosticSeverity.Warning) + | Unknown -> ("Unknown error - " ^ entry.message, DiagnosticSeverity.Error) + | _ -> (entry.message, DiagnosticSeverity.Error) + in + Diagnostic.create ~severity ~source:"ReScript" + ~range:(range_of_entry uri entry.range) + ~message:(`String message) () + in + + let diagnostics_sanitized = + diagnostics + |> List.filter_map (fun (entry : Compiler_log.Parse.diagnostic_entry) -> + let uri = + match entry.path with + | Compiler_log.Parse.Relative_path p -> + Uri.of_path (Filename.concat workspace_root_path p) + | Full_path p -> Uri.of_path p + in + + match entry.kind with + | Syntax_error -> + if + include_syntax + && Option.is_none (Document_store.get_opt ~uri doc_store) + then Some (uri, diagnostic_of_entry uri entry) + else None + | Circular_dependency -> + if not include_non_syntax then None + else Some (uri, diagnostic_of_entry uri entry) + | Warning _ | Common_error | Unknown -> + if not include_non_syntax then None + else Some (uri, diagnostic_of_entry uri entry)) + in + + diagnostics_sanitized + |> List.fold_left + (fun acc (uri, diagnostic) -> + Uri_map.update uri + (function + | None -> Some [diagnostic] + | Some diagnostics -> Some (diagnostic :: diagnostics)) + acc) + Uri_map.empty + +let has_non_syntax_diagnostics diagnostics = + diagnostics + |> List.exists + (fun (diagnostic_entry : Compiler_log.Parse.diagnostic_entry) -> + match diagnostic_entry.kind with + | Syntax_error -> false + | Warning _ | Circular_dependency | Common_error | Unknown -> true) + +let update_from_compiler_log ~workspace_root ~doc_store compiler_log t = + let compiler_syntax = + compiler_log + |> to_lsp_format ~include_syntax:true ~include_non_syntax:false + workspace_root doc_store + in + let t = update_compiler_syntax ~new_diagnostics:compiler_syntax t in + (* A syntax-only compiler log is an incomplete build snapshot: the compiler + stopped before type checking the rest of the workspace. Keep the previous + non-syntax compiler diagnostics until the next complete build snapshot or + successful empty log arrives. *) + if compiler_log = [] || has_non_syntax_diagnostics compiler_log then + let compiler = + compiler_log + |> to_lsp_format ~include_syntax:false ~include_non_syntax:true + workspace_root doc_store + in + update_compiler ~new_diagnostics:compiler t + else t + +let diagnostics_from_completed_logs contents = + if List.for_all Compiler_log.Parse.is_complete contents then + contents + |> List.map Compiler_log.Parse.parse_log_content + |> List.flatten |> Option.some + else None + +let collect_diagnostics_from_log_using_source_dirs workspace_root fs = + let ( /+ ) = Filename.concat in + let workspace_root_path = workspace_root |> Uri.to_path in + let path = + workspace_root_path /+ Constants.compiler_dir_partial_path + /+ Constants.sources_dirs + in + (* .sourcedirs.json is the source of truth for compiler-log locations. It is + written by the build system and includes every build root that can emit a + .compiler.log. Fall back to the root log only when that metadata is missing + or empty, so opening a document can still publish the last known diagnostics + from older or partial builds. *) + let build_roots = + Source_dirs.get_build_roots_from_file ~fs path |> Option.value ~default:[] + in + build_roots + |> List.filter_map (fun build_root -> + let compiler_log_path = + workspace_root_path /+ build_root /+ Constants.compiler_log + in + Fs.load ~fs compiler_log_path) + |> diagnostics_from_completed_logs + +let%expect_test "only completed compiler logs form a diagnostics snapshot" = + let print = function + | None -> print_endline "incomplete" + | Some diagnostics -> + Printf.printf "complete: %d diagnostics\n" (List.length diagnostics) + in + diagnostics_from_completed_logs ["#Start(1)\n"] |> print; + [%expect {| incomplete |}]; + + diagnostics_from_completed_logs ["#Start(1)\n#Done(2)\n"] |> print; + [%expect {| complete: 0 diagnostics |}]; + + diagnostics_from_completed_logs ["#Start(1)\n#Done(2)\n"; "#Start(3)\n"] + |> print; + [%expect {| incomplete |}] + +let%expect_test "compiler syntax diagnostics don't clear type diagnostics" = + let workspace_root = Uri.of_path "/workspace" in + let uri_a = Uri.of_path "/workspace/A.res" in + let uri_b = Uri.of_path "/workspace/B.res" in + let uri_c = Uri.of_path "/workspace/C.res" in + let range = + Range.create + ~start:(Position.create ~line:0 ~character:0) + ~end_:(Position.create ~line:0 ~character:1) + in + let diagnostic message = + Diagnostic.create ~range ~message:(`String message) () + in + let entry uri kind message = + let open Compiler_log.Parse in + {kind; path = Full_path (Uri.to_path uri); message; range = Some range} + in + let print t = + diagnostics t + |> Uri_map.iter (fun uri diagnostics -> + let messages = + diagnostics + |> List.map (fun (diagnostic : Diagnostic.t) -> + match diagnostic.message with + | `String message -> message + | `MarkupContent {value} -> value) + in + Printf.printf "%s: %s\n" + (Filename.basename (Uri.to_path uri)) + (match messages with + | [] -> "" + | messages -> String.concat ", " messages)) + in + let doc_store = Document_store.make () in + let t = make ~diagnostics:(empty ()) ~send:(fun _ -> ()) in + let t = + update_from_compiler_log ~workspace_root ~doc_store + [entry uri_b Common_error "type B"; entry uri_c Common_error "type C"] + t + in + print t; + [%expect {| + B.res: type B + C.res: type C |}]; + + let doc = + Document.make + (DidOpenTextDocumentParams.create + ~textDocument: + (TextDocumentItem.create ~languageId:(LanguageKind.Other "rescript") + ~uri:uri_a ~text:"let x =" ~version:1)) + ~position_encoding:`UTF16 + in + ignore (Document_store.add doc_store ~doc); + let t = update_syntax ~uri:uri_a ~new_diagnostics:[diagnostic "syntax A"] t in + let t = + update_from_compiler_log ~workspace_root ~doc_store + [entry uri_a Syntax_error "compiler syntax A"] + t + in + print t; + [%expect {| + A.res: syntax A + B.res: type B + C.res: type C |}]; + + ignore (Document_store.remove doc_store ~uri:uri_a); + let t = clear_syntax ~uri:uri_a t in + let t = + update_from_compiler_log ~workspace_root ~doc_store + [entry uri_a Syntax_error "compiler syntax A"] + t + in + print t; + [%expect + {| + A.res: compiler syntax A + B.res: type B + C.res: type C |}]; + + let t = + update_from_compiler_log ~workspace_root ~doc_store + [entry uri_b Common_error "type B fixed later"] + t + in + print t; + [%expect + {| + A.res: + B.res: type B fixed later + C.res: |}]; + + let t = update_from_compiler_log ~workspace_root ~doc_store [] t in + print t; + [%expect {| + A.res: + B.res: + C.res: |}] diff --git a/lsp/src/document.ml b/lsp/src/document.ml new file mode 100644 index 00000000000..24b875e30b6 --- /dev/null +++ b/lsp/src/document.ml @@ -0,0 +1,104 @@ +open Lsp +open Lsp.Types + +type t = Text_document.t + +type kind = Analysis.Files.classified_file + +let kind_of_uri uri = + let p = Uri.to_path uri in + match p |> Filename.extension with + | ".res" -> Analysis.Files.Res + | ".resi" -> Analysis.Files.Resi + | other -> + Jsonrpc.Response.Error.raise + (Jsonrpc.Response.Error.make ~code:InvalidRequest + ~message:("unsupported file extension for " ^ p) + ~data:(`Assoc [("extension", `String other)]) + ()) + +let kind doc = doc |> Text_document.documentUri |> kind_of_uri + +let extension_of_kind (kind : kind) = + match kind with + | Res -> "res" + | Resi -> "resi" + | Other -> assert false + +let make (doc : DidOpenTextDocumentParams.t) ~position_encoding = + let t_doc = Text_document.make ~position_encoding doc in + t_doc + +let text t = Text_document.text t + +let uri t = Text_document.documentUri t + +let update_text ~version t changes = + match Text_document.apply_content_changes ~version t changes with + | exception Text_document.Invalid_utf _ -> + (* TODO: add log *) + t + | tdoc -> tdoc + +let range_of_text (text : string) : Range.t = + let text_length = String.length text in + let rec end_position offset line character = + if offset = text_length then Position.create ~line ~character + else + match String.get text offset with + | '\n' -> end_position (offset + 1) (line + 1) 0 + | _ -> end_position (offset + 1) line (character + 1) + in + Range.create + ~start:(Position.create ~line:0 ~character:0) + ~end_:(end_position 0 0 0) + +let%expect_test "range_of_text" = + let print text = + let range = range_of_text text in + Yojson.Safe.pretty_to_string + (`Assoc + [ + ("start", range.start |> Position.yojson_of_t); + ("end", range.end_ |> Position.yojson_of_t); + ]) + |> print_endline + in + print ""; + print "let a = 1"; + print "let a = 1\nlet b = 2"; + print "let a = 1\n"; + print "\xC3\xA9"; + print "ab"; + print "ab\ncd"; + [%expect + {| + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 0, "line": 0 } + } + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 9, "line": 0 } + } + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 9, "line": 1 } + } + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 0, "line": 1 } + } + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 2, "line": 0 } + } + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 2, "line": 0 } + } + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 2, "line": 1 } + } + |}] diff --git a/lsp/src/document_store.ml b/lsp/src/document_store.ml new file mode 100644 index 00000000000..53ee5054234 --- /dev/null +++ b/lsp/src/document_store.ml @@ -0,0 +1,51 @@ +open Lsp + +type t = {documents: (Uri.t, Document.t) Hashtbl.t} + +let make () = {documents = Hashtbl.create 50} + +let raise ~message = + Jsonrpc.Response.Error.raise + (Jsonrpc.Response.Error.make ~code:InvalidRequest ~message ()) + +let add t ~doc = + let uri = Document.uri doc in + (match Hashtbl.mem t.documents uri with + | false -> Hashtbl.add t.documents uri doc + | true -> + raise + ~message: + (Printf.sprintf "Document store already has %s to open" + (Uri.to_string uri))); + t + +let update t ~doc = + let uri = Document.uri doc in + (match Hashtbl.find_opt t.documents uri with + | None -> + raise + ~message: + (Printf.sprintf "Document store not found %s to update" + (Uri.to_string uri)) + | Some _ -> Hashtbl.replace t.documents uri doc); + t + +let remove t ~uri = + (match Hashtbl.mem t.documents uri with + | true -> Hashtbl.remove t.documents uri + | false -> + raise + ~message: + (Printf.sprintf "Document store not found %s to remove" + (Uri.to_string uri))); + t + +let get_opt t ~uri = Hashtbl.find_opt t.documents uri + +let get t ~uri = + match get_opt t ~uri with + | Some doc -> doc + | None -> + raise + ~message: + (Printf.sprintf "Document store not found %s to get" (Uri.to_string uri)) diff --git a/lsp/src/dune b/lsp/src/dune new file mode 100644 index 00000000000..3ec232bdb2d --- /dev/null +++ b/lsp/src/dune @@ -0,0 +1,16 @@ +(library + (name rescript_language_server) + (libraries + lsp + eio + eio_main + eio.unix + unix + analysis + str + ppx_deriving_yojson.runtime) + (inline_tests) + (preprocess + (pps ppx_deriving_yojson ppx_expect)) + (flags + (:standard -w +a-4-9-30-40-41-42-44-48-70))) diff --git a/lsp/src/execute_commands.ml b/lsp/src/execute_commands.ml new file mode 100644 index 00000000000..a734b509b70 --- /dev/null +++ b/lsp/src/execute_commands.ml @@ -0,0 +1,138 @@ +open Lsp +open Lsp.Types + +let request_show_document ~uri ~takeFocus (server : State.t Server.t) = + let state = Server.state server in + let client_support_window_show_document = + match (State.params state).capabilities.window with + | Some {showDocument = Some {support}} -> support = true + | _ -> false + in + if client_support_window_show_document then ( + Server.request + (Server_request.ShowDocumentRequest + (ShowDocumentParams.create ~takeFocus ~uri ())) + server; + Ok None) + else + let message = + match (State.params state).clientInfo with + | Some {name; version} -> + Printf.sprintf + "The client %s (version %s) dont support window/showDocument request" + name + (Option.value version ~default:"unknown") + | None -> "The client dont support window/showDocument request" + in + Error (Printf.sprintf "Failed to open %s. %s" (Uri.to_path uri) message) + +module Open_compiled = struct + let name = "rescript/openCompiled" + let execute ~(arguments : Yojson.Safe.t list option) + (server : State.t Server.t) = + match arguments with + | Some [`String uri] -> + request_show_document ~uri:(Uri.of_string uri) ~takeFocus:true server + | _ -> + Error + (Printf.sprintf + "Invalid arguments for workspace/executeCommand %s. Expected a list \ + of string: [uri]" + name) +end + +module Create_interface = struct + let name = "rescript/createInterface" + let execute ~(arguments : Yojson.Safe.t list option) + (server : State.t Server.t) = + match arguments with + | Some [`String uri; `String cmi_uri] -> ( + match + Custom_requests.Create_interface_file.make ~uri:(Uri.of_string uri) + ~cmi_uri:(Uri.of_string cmi_uri) ~state:(Server.state server) + with + | Ok uri -> request_show_document ~uri ~takeFocus:true server + | Error message -> + Error + (Printf.sprintf "Failed to create interface file for %s and %s: %s" + uri cmi_uri message)) + | _ -> + Error + (Printf.sprintf + "Invalid arguments for workspace/executeCommand %s. Expected a list \ + of string: [uri, cmi_uri]" + name) +end + +module Switch_implementation_interface = struct + let name = "rescript/switchImplementationInterface" + let execute ~(arguments : Yojson.Safe.t list option) + (server : State.t Server.t) = + match arguments with + | Some [`String uri] -> + request_show_document ~uri:(Uri.of_string uri) ~takeFocus:true server + | _ -> + Error + (Printf.sprintf + "Invalid arguments for workspace/executeCommand %s. Expected a list \ + of string: [uri]" + name) +end + +let write_tmp_file ~prefix ~suffix ~content (server : State.t Server.t) = + let fs = (Server.state server).fs in + let random = Random.State.make_self_init () in + let name = + Printf.sprintf "%s%08x%08x%s" prefix (Random.State.bits random) + (Random.State.bits random) suffix + in + let path = Filename.concat (Filename.get_temp_dir_name ()) name in + try + Fs.save ~append:false ~create:(`Or_truncate 0o644) ~fs path content; + Ok (Uri.of_path path) + with _ as exn -> + Error ("Failed to write temporary dump: " ^ Printexc.to_string exn) + +module Dump_server_state = struct + let name = "rescript/dumpServerState" + let execute ~arguments:(_ : Yojson.Safe.t list option) + (server : State.t Server.t) = + let content = + State.to_yojson (Server.state server) |> Yojson.Safe.pretty_to_string + in + match + write_tmp_file ~prefix:"rescript-server-state-" ~suffix:".json" ~content + server + with + | Ok uri -> request_show_document ~uri ~takeFocus:true server + | Error _ as err -> err +end + +module Dump_cmt = struct + let name = "rescript/dumpCmt" + let execute ~(arguments : Yojson.Safe.t list option) + (server : State.t Server.t) = + match arguments with + | Some [`String uri] -> ( + let analysis_state = server |> Server.state |> State.analysis_state in + match Helpers.load_full (Uri.of_string uri) analysis_state with + | Some full -> ( + let content = Analysis.Cmt_viewer.dump ~full in + match + write_tmp_file ~prefix:"rescript-cmt-" ~suffix:".txt" ~content server + with + | Ok uri -> request_show_document ~uri ~takeFocus:true server + | Error _ as err -> err) + | None -> + Error + (Printf.sprintf + "Failed to dump cmt for %s, we are unable to read the metadata of \ + cmt file" + uri)) + | _ -> + Error + (Printf.sprintf + "Invalid arguments for workspace/executeCommand %s. Expected a list \ + of string: [uri]" + name) +end diff --git a/lsp/src/formatter.ml b/lsp/src/formatter.ml new file mode 100644 index 00000000000..ffc27513bd5 --- /dev/null +++ b/lsp/src/formatter.ml @@ -0,0 +1,123 @@ +module Process = struct + type result = {status: Unix.process_status; stdout: string} + + let rec waitpid pid = + match Unix.waitpid [] pid with + | _, status -> status + | exception Unix.Unix_error (Unix.EINTR, _, _) -> waitpid pid + + let with_temp_file f = + let path, channel = + Filename.open_temp_file ~mode:[Open_binary] "rescript-lsp-process-" ".tmp" + in + Fun.protect + ~finally:(fun () -> + close_out_noerr channel; + try Sys.remove path with Sys_error _ -> ()) + (fun () -> f path channel) + + let run_unix ~stdin program args = + (* Windows cannot select() on anonymous pipes. Files avoid pipe-buffer + deadlocks even if a child writes both streams before reading its stdin. *) + with_temp_file (fun input_path input -> + output_string input stdin; + flush input; + with_temp_file (fun output_path output -> + with_temp_file (fun _ error -> + In_channel.with_open_bin input_path (fun input -> + let pid = + Unix.create_process program + (Array.of_list (program :: args)) + (Unix.descr_of_in_channel input) + (Unix.descr_of_out_channel output) + (Unix.descr_of_out_channel error) + in + let reaped = ref false in + Fun.protect + ~finally:(fun () -> + if not !reaped then ( + (try Unix.kill pid Sys.sigkill + with Unix.Unix_error (Unix.ESRCH, _, _) -> ()); + ignore (waitpid pid))) + (fun () -> + let status = waitpid pid in + reaped := true; + let stdout = + In_channel.with_open_bin output_path + In_channel.input_all + in + {status; stdout}))))) + + let run_eio ~stdin program args = + (* The worker needs its own effect handler: Eio operations cannot run in a + plain systhread using the calling fiber's scheduler. *) + Eio_main.run (fun env -> + let stdout = Buffer.create 4096 in + let status = + Eio.Switch.run (fun sw -> + let manager = Eio.Stdenv.process_mgr env in + let input, writer = Eio.Process.pipe ~sw manager in + let process = + Eio.Process.spawn ~sw manager ~executable:program ~stdin:input + ~stdout:(Eio.Flow.buffer_sink stdout) + ~stderr:Eio.Flow.null (program :: args) + in + Eio.Flow.close input; + Eio.Fiber.fork ~sw (fun () -> + Fun.protect + ~finally:(fun () -> Eio.Flow.close writer) + (fun () -> + try Eio.Flow.copy (Eio.Flow.string_source stdin) writer + with Eio.Io (Eio.Net.E (Connection_reset _), _) -> + (* A child may exit or close stdin without consuming all + input. Its exit status and diagnostics still matter. *) + ())); + match Eio.Process.await process with + | `Exited code -> Unix.WEXITED code + | `Signaled signal -> Unix.WSIGNALED signal) + in + (* Switch completion also waits for the output copying fibers. *) + {status; stdout = Buffer.contents stdout}) + + let run ~stdin program args = + Eio_unix.run_in_systhread ~label:"lsp process" (fun () -> + if Sys.win32 then run_unix ~stdin program args + else run_eio ~stdin program args) +end + +open Lsp + +let run ~uri ~(state : State.t) = + let doc = Document_store.get ~uri state.store in + let source = Document.text doc in + let kind_file = Document.kind doc in + + let executable = + let executable_name = "rescript" in + let root_path = State.workspace_root state |> Uri.to_path in + let ( /+ ) = Filename.concat in + root_path /+ "node_modules" /+ ".bin" /+ executable_name + in + + match Fs.exists ~follow:true ~fs:state.fs executable with + | false -> + Error + (Printf.sprintf "Unable to find rescript binary at %s" + (Filename.dirname executable)) + | true -> ( + let extension_name = Document.extension_of_kind kind_file in + try + let result = + Process.run ~stdin:source executable + ["format"; "--stdin"; "." ^ extension_name] + in + match result.status with + | Unix.WEXITED 0 -> Ok (Diff.edit ~from:source ~to_:result.stdout) + | _ -> + Error + (Printf.sprintf "Failed to format %s" + (uri |> Uri.to_path |> Filename.basename)) + with exn -> + Error + (Printf.sprintf "Unexpected result to format %s. %s" (Uri.to_path uri) + (Printexc.to_string exn))) diff --git a/lsp/src/fs.ml b/lsp/src/fs.ml new file mode 100644 index 00000000000..db37e0b09fb --- /dev/null +++ b/lsp/src/fs.ml @@ -0,0 +1,25 @@ +type fs = Eio.Fs.dir_ty Eio.Path.t + +let append = Eio.Path.( / ) + +let to_eio_path ~(fs : fs) (path : string) = append fs path + +let protect f = + match f () with + | value -> Some value + | exception _ -> None + +let load ~fs path = protect (fun () -> Eio.Path.load (to_eio_path ~fs path)) + +let save ~append ~create ~fs path content = + Eio.Path.save ~append ~create (to_eio_path ~fs path) content + +let kind ~follow ~fs path = + match protect (fun () -> Eio.Path.kind ~follow (to_eio_path ~fs path)) with + | Some `Not_found | None -> None + | Some kind -> Some kind + +let exists ~follow ~fs path = + match kind ~follow ~fs path with + | Some _ -> true + | None -> false diff --git a/lsp/src/helpers.ml b/lsp/src/helpers.ml new file mode 100644 index 00000000000..1aa5a7f16cc --- /dev/null +++ b/lsp/src/helpers.ml @@ -0,0 +1,221 @@ +open Lsp +open Lsp.Types + +let root_uri_of_initialize_params (params : InitializeParams.t) = + match (params.workspaceFolders, params.rootUri, params.rootPath) with + | _, Some root_uri, _ -> root_uri + | Some (Some (workspace_folder :: _)), _, _ -> workspace_folder.uri + | _, _, Some (Some root_path) -> root_path |> Uri.of_path + | _ -> Sys.getcwd () |> Uri.of_path + +(* Return the most specific root from [entries] that contains [path]. + + Matching is done on path boundaries, so [/repo/packages/app] matches + [/repo/packages/app/src/A.res], but it does not match + [/repo/packages/application/src/A.res]. + + If multiple roots match, the longest root wins. This matters in monorepos + where a file can be under both the workspace root and a nested package root. + + Examples: + - [best_root_match ~path:"/repo/packages/app/src/A.res" + ["/repo"; "/repo/packages/app"]] + returns [Some "/repo/packages/app"]. + - [best_root_match ~path:"/repo/packages/application/src/A.res" + ["/repo/packages/app"]] + returns [None]. *) +let best_root_match ~path entries = + let path_matches_root ~path ~root = + let is_sep = function + | '/' | '\\' -> true + | _ -> false + in + let root_len = String.length root in + let path_len = String.length path in + root_len > 0 + && (path = root + || path_len > root_len + && String.starts_with ~prefix:root path + && (is_sep root.[root_len - 1] || is_sep path.[root_len])) + in + entries + |> List.fold_left + (fun best root -> + if path_matches_root ~path ~root then + match best with + | None -> Some root + | Some best_root -> + if String.length root > String.length best_root then Some root + else best + else best) + None + +let relative_to ~root path = + let root = if String.ends_with ~suffix:"/" root then root else root ^ "/" in + + if String.starts_with ~prefix:root path then + let root_len = String.length root in + String.sub path root_len (String.length path - root_len) + else path + +let to_camel_case (text : string) : string = + let len = String.length text in + let buffer = Buffer.create len in + + let is_separator = function + | ' ' | '\t' | '\n' | '\r' | '-' -> true + | _ -> false + in + + let rec loop i capitalize_next = + if i >= len then Buffer.contents buffer + else + let c = text.[i] in + + if is_separator c then loop (i + 1) true + else if capitalize_next then ( + Buffer.add_char buffer (Char.uppercase_ascii c); + loop (i + 1) false) + else ( + Buffer.add_char buffer c; + loop (i + 1) false) + in + + loop 0 true + +let get_cmi_file ~(uri : Uri.t) ~(compiler_config : Compiler_config.t) + ~(fs : Fs.fs) = + let path = Uri.to_path uri in + let config_roots = + compiler_config |> Compiler_config.Uri_map.to_seq + |> Seq.map (fun (uri, config) -> (uri |> Uri.to_path, config)) + |> List.of_seq |> List.map fst + in + + let config = + match config_roots |> best_root_match ~path with + | Some root -> + Compiler_config.Uri_map.find_opt (Uri.of_path root) compiler_config + | None -> None + in + match config with + | Some config -> + let namespace = + match config.namespace with + | Some (Namespace_bool true) -> config.name |> to_camel_case + | Some (Namespace_string name) -> name |> to_camel_case + | _ -> "" + in + let suffix_to_append = + if String.length namespace > 0 then "-" ^ namespace else "" + in + let resi_file = + match best_root_match ~path config_roots with + | Some package_root_path -> + let cmi_file = + let open Filename in + let ( /+ ) = concat in + let relative_path = relative_to ~root:package_root_path path in + let cmi = + let stem = basename relative_path |> remove_extension in + stem ^ suffix_to_append ^ ".cmi" + in + (* Build artifacts are flat, regardless of the source directory. *) + package_root_path /+ Constants.compiler_dir_partial_path /+ cmi + in + let result = + match Fs.exists ~follow:false ~fs cmi_file with + | true -> Some cmi_file + | false -> None + in + result + | None -> None + in + resi_file + | None -> None + +let get_compiled_file ~(uri : Uri.t) ~(compiler_config : Compiler_config.t) + ~(fs : Fs.fs) = + let path = Uri.to_path uri in + let config_roots = + compiler_config |> Compiler_config.Uri_map.to_seq + |> Seq.map (fun (uri, config) -> (uri |> Uri.to_path, config)) + |> List.of_seq |> List.map fst + in + + let config = + match config_roots |> best_root_match ~path with + | Some root -> + Compiler_config.Uri_map.find_opt (Uri.of_path root) compiler_config + | None -> None + in + match config with + | Some config -> + let {Compiler_config.suffix; folder; in_source} = + Compiler_config.get_output_config config + in + + let js_file_path = + let file_path = + let open Filename in + let ( /+ ) = concat in + if in_source then + let filename = basename path in + let js_file = remove_extension filename ^ suffix in + Some (dirname path /+ js_file) + else + match best_root_match ~path config_roots with + | Some package_root_path -> + (* + Some example with sources + package_root_path: /workspace/rescript-lang.org/apps/guide + path: /workspace/rescript-lang.org/apps/guide/app/GuideHome.res + compiled js: /workspace/rescript-lang.org/apps/guide/lib/es6/app/GuideHome.jsx + *) + (* app/GuideHome.res *) + let relative_path = relative_to ~root:package_root_path path in + let sources_dir = dirname relative_path in + let js_file = + let res_file = basename relative_path in + remove_extension res_file ^ suffix + in + Some + (package_root_path /+ Constants.build_output_folder /+ folder + /+ sources_dir /+ js_file) + | None -> None + in + match file_path with + | Some file_path when Fs.exists ~fs ~follow:false file_path -> + Some (file_path |> Uri.of_path) + | _ -> None + in + + js_file_path + | None -> None + +let load_full uri (analysis_state : Analysis.Shared_types.state) = + let package_for_path ~path = + let roots = + analysis_state.packages_by_root |> Hashtbl.to_seq_keys |> List.of_seq + in + match best_root_match ~path roots with + | Some root -> Hashtbl.find_opt analysis_state.packages_by_root root + | None -> None + in + + let path = uri |> Uri.to_path in + match package_for_path ~path with + | Some package -> ( + let module_name = + Analysis.Build_system.namespaced_name package.namespace + (Analysis.Find_files.get_name path) + in + match Analysis.Cmt.full_for_incremental_cmt ~package ~module_name ~uri with + | Some cmt_info -> Some cmt_info + | None -> ( + match Hashtbl.find_opt package.paths_for_module module_name with + | Some paths -> + let cmt = Analysis.Shared_types.get_cmt_path ~uri paths in + Analysis.Cmt.full_for_cmt ~module_name ~package ~uri cmt + | None -> None)) + | None -> None diff --git a/lsp/src/rescript_language_server.ml b/lsp/src/rescript_language_server.ml new file mode 100644 index 00000000000..ad452b4f937 --- /dev/null +++ b/lsp/src/rescript_language_server.ml @@ -0,0 +1,790 @@ +open Lsp +open Lsp.Types + +let initialization (client_capabilities : ClientCapabilities.t) = + let textDocumentSync = + `TextDocumentSyncOptions + (TextDocumentSyncOptions.create ~openClose:true + ~change:TextDocumentSyncKind.Incremental ~willSave:false + ~save:(`SaveOptions (SaveOptions.create ~includeText:false ())) + ~willSaveWaitUntil:false ()) + in + let completionProvider = + CompletionOptions.create + ~triggerCharacters:["."; ">"; "@"; "~"; "\""; "="; "("] + ~resolveProvider:true () + in + let codeLensProvider = CodeLensOptions.create ~resolveProvider:false () in + let signatureHelpProvider = + SignatureHelpOptions.create ~triggerCharacters:["("] + ~retriggerCharacters:["="; ","] () + in + let inlayHintProvider = + `InlayHintOptions (InlayHintOptions.create ~resolveProvider:false ()) + in + let renameProvider = + `RenameOptions (RenameOptions.create ~prepareProvider:true ()) + in + (* NOTE: For now, we do not support this. *) + let workspace = + let workspaceFolders = + WorkspaceFoldersServerCapabilities.create ~supported:false + ~changeNotifications:(`Bool false) () + in + WorkspaceOptions.create ~workspaceFolders () + in + let semanticTokensProvider = + let legend = + SemanticTokensLegend.create ~tokenModifiers:[] + ~tokenTypes: + [ + "operator"; + "variable"; + "type"; + (* emit jsx-tag < and > in
as modifier *) + "modifier"; + "namespace"; + "enumMember"; + "property"; + (* emit jsxlowercase, div in
as interface *) + "interface"; + ] + in + let full = + `SemanticTokensFullDelta (SemanticTokensFullDelta.create ~delta:false ()) + in + `SemanticTokensOptions (SemanticTokensOptions.create ~legend ~full ()) + in + let codeActionProvider = + `CodeActionOptions (CodeActionOptions.create ~resolveProvider:false ()) + in + let executeCommandProvider = + ExecuteCommandOptions.create + ~commands: + [ + Execute_commands.Open_compiled.name; + Execute_commands.Switch_implementation_interface.name; + Execute_commands.Dump_server_state.name; + Execute_commands.Dump_cmt.name; + ] + () + in + let diagnosticProvider = + `DiagnosticOptions + (DiagnosticOptions.create ~workspaceDiagnostics:false + ~identifier:"rescript" ~interFileDependencies:false ()) + in + let positionEncoding = + match Capabilities.position_encodings client_capabilities with + | None -> None + | Some options -> + List.find_map + (fun encondig -> + if Capabilities.supported options ~tag:encondig ~equal:Stdlib.( = ) + then Some encondig + else None) + [PositionEncodingKind.UTF16; UTF8] + in + let capabilities = + ServerCapabilities.create ~textDocumentSync ~completionProvider + ~codeLensProvider ~hoverProvider:(`Bool true) ~signatureHelpProvider + ~renameProvider ~workspace ~semanticTokensProvider ~inlayHintProvider + ~definitionProvider:(`Bool true) ~typeDefinitionProvider:(`Bool true) + ~codeActionProvider ~documentSymbolProvider:(`Bool true) + ~referencesProvider:(`Bool true) ~documentFormattingProvider:(`Bool true) + ~executeCommandProvider ~diagnosticProvider ?positionEncoding () + in + let serverInfo = ServerInfo.create ~name:"rescript-language-server" () in + InitializeResult.create ~capabilities ~serverInfo () + +let get_updated_diagnostics_from_log (state : State.t) diagnostics = + let workspace_root = State.workspace_root state in + match + Diagnostics.collect_diagnostics_from_log_using_source_dirs workspace_root + state.fs + with + | None -> None + | Some compiler_log -> + Some + (Diagnostics.update_from_compiler_log ~workspace_root + ~doc_store:state.store compiler_log diagnostics) + +let get_latest_completed_diagnostics state diagnostics = + get_updated_diagnostics_from_log state diagnostics + |> Option.value ~default:diagnostics + +let uses_pull_diagnostics (state : State.t) = + match (State.params state).capabilities.textDocument with + | Some {diagnostic = Some _} -> true + | _ -> false + +(* Clients keep push diagnostics (textDocument/publishDiagnostics) and pull + diagnostics (textDocument/diagnostic) as separate results. Sending the same + compiler diagnostic through both mechanisms therefore displays it twice. + For clients that support pull diagnostics, open documents are owned by pull + and only closed documents receive pushed compiler diagnostics. Clients + without pull support continue to receive the complete pushed snapshot. *) +let publish_diagnostics ?(force_publish_uris = []) (state : State.t) diagnostics + = + if uses_pull_diagnostics state then + Diagnostics.send ~include_syntax:false ~force_publish_uris + ~should_publish:(fun uri -> + Option.is_none (Document_store.get_opt state.store ~uri)) + diagnostics + else Diagnostics.send diagnostics + +(* This intentionally mutates [analysis_state] in place. The analysis layer keeps + package discovery tables as mutable hash tables so later requests can resolve + files and modules without rebuilding package metadata. That makes this + function unsafe in the usual functional sense: callers must provide a fresh + per-server analysis state or accept that repeated calls append/overwrite + package roots as a side effect. *) +let discover_subpackages_and_populate ~notify_errors ~workspace_root + ~(analysis_state : Analysis.Shared_types.state) ~(server : State.t Server.t) + = + let root_path = workspace_root |> Uri.to_path in + let root_package = + match Analysis.Packages.new_bs_package ~root_path with + | Some p -> Some p + | None -> + let message = + Printf.sprintf + "Failed to initialize the context for the project at %s. Try \ + building the project. The server will retry when a compiler log \ + changes." + root_path + in + if notify_errors then + Server.show_message_notification ~kind:MessageType.Error message server; + None + in + + let resolve_node_modules_paths = + match + Compiler_config.parse ~root:root_path ~fs:(Server.state server).fs + with + | Ok config -> + let deps_paths, deps_errors = + Compiler_config.get_all_dependecies_names config + |> List.partition_map (fun dep_name -> + match + Analysis.Module_resolution.resolve_node_module_path + ~start_path:(workspace_root |> Uri.to_path) + dep_name + with + | Some value -> Either.Left value + | None -> Either.Right dep_name + | exception Failure err -> Either.Right err) + in + + if notify_errors && List.length deps_errors > 0 then + Server.show_message_notification ~kind:MessageType.Error + (Printf.sprintf "Failed to resolve node modules dependencies: %s" + (String.concat ", " deps_errors)) + server; + + Some deps_paths + | Error message -> + Server.show_message_notification ~kind:MessageType.Error message server; + None + in + + (match root_package with + | Some root_package -> + Hashtbl.add analysis_state.root_for_uri workspace_root + root_package.root_path; + Hashtbl.add analysis_state.packages_by_root root_package.root_path + root_package + | None -> ()); + + (match resolve_node_modules_paths with + | Some node_modules_paths -> + node_modules_paths + |> List.iter (fun node_module_path -> + let uri = Uri.of_path node_module_path in + match + Analysis.Packages.new_bs_package ~root_path:node_module_path + with + | Some package -> + Hashtbl.add analysis_state.root_for_uri uri package.root_path; + Hashtbl.add analysis_state.packages_by_root package.root_path + package + | None -> ()); + () + | None -> ()) + |> ignore + +let discover_project_context ~notify_errors ~workspace_root + (server : State.t Server.t) = + let analysis_state = Analysis.Shared_types.create_state () in + discover_subpackages_and_populate ~notify_errors ~workspace_root + ~analysis_state ~server; + + let compiler_config = + analysis_state.packages_by_root |> Hashtbl.to_seq + |> Seq.filter_map (fun (root_path, _) -> + match + Compiler_config.parse ~root:root_path ~fs:(Server.state server).fs + with + | Ok config -> Some (Uri.of_path root_path, config) + | Error _ -> + (* NOTE: Surface malformed package configs to the client. We ignore + them for now so initialization can continue with any remaining + valid packages. *) + None) + |> Compiler_config.Uri_map.of_seq + in + (analysis_state, compiler_config) + +let on_initialize (params : InitializeParams.t) (server : State.t Server.t) = + let state = Server.state server in + let diagnostics = + Diagnostics.make ~diagnostics:(Diagnostics.empty ()) + ~send:(fun publish_diagnostics_params -> + Server.notification + (Server_notification.PublishDiagnostics publish_diagnostics_params) + server) + in + let workspace_root = Helpers.root_uri_of_initialize_params params in + let analysis_state, compiler_config = + discover_project_context ~notify_errors:true ~workspace_root server + in + + let initialization_info = initialization params.capabilities in + + let position_encoding = + match initialization_info.capabilities.positionEncoding with + | None | Some UTF16 -> `UTF16 + | Some UTF8 -> `UTF8 + | Some UTF32 | Some (Other _) -> assert false + in + + let state = + State.initialize state ~params ~diagnostics ~analysis_state ~compiler_config + ~position_encoding + in + (initialization_info, state) + +let on_request (Client_request.E request) (server : State.t Server.t) = + let load_full uri (state : State.t) = + match state.status with + | Initialized _ -> Helpers.load_full uri (State.analysis_state state) + | Uninitialized -> None + in + + let ok value = Ok (Client_request.yojson_of_result request value) in + + let error ?(code = Jsonrpc.Response.Error.Code.InternalError) message = + Error (Jsonrpc.Response.Error.make ~message ~code ()) + in + + let state = Server.state server in + + match request with + | Client_request.Initialize params -> + let initialization_info, state = on_initialize params server in + (ok initialization_info, state) + | TextDocumentHover {position; textDocument = {uri}} -> + let doc = Document_store.get ~uri state.store in + let source = doc |> Document.text in + let full = load_full uri state in + let resp = + Analysis.Commands.hover + ~state:(State.analysis_state state) + ~source ~kind_file:(Document.kind doc) + ~pos:(position.line, position.character) + ~debug:false + ~supports_markdown_links: + state.configuration.hover.support_markdown_links ~full + in + (ok resp, state) + | TextDocumentDiagnostic {textDocument = {uri}} -> + let diagnostics = State.diagnostics state |> Diagnostics.get_all in + let items = + Diagnostics.Uri_map.find_opt uri diagnostics |> Option.value ~default:[] + in + let resp = + `RelatedFullDocumentDiagnosticReport + (RelatedFullDocumentDiagnosticReport.create ~items ()) + in + (ok resp, state) + | TextDocumentCompletion {textDocument = {uri}; position} -> + let doc = Document_store.get ~uri state.store in + let source = doc |> Document.text in + let full = load_full uri state in + + let resp = + Analysis.Commands.completion + ~state:(State.analysis_state state) + ~debug:false ~source ~kind_file:(Document.kind doc) + ~pos:(position.line, position.character) + ~full + in + (ok (Some (`List resp)), state) + | CompletionItemResolve item -> + let resp = + match (item.documentation, item.data) with + (* + documentation === null && item.data != null + See https://github.com/rescript-lang/rescript-vscode/blob/2bc69d29ed92e19b14054952bafe9d4af7bd4c4b/server/src/server.ts#L958-L970 + *) + | None, Some (`Assoc fields) -> ( + let file_path = List.assoc_opt "filePath" fields in + let module_path = List.assoc_opt "modulePath" fields in + match (file_path, module_path) with + | Some (`String file_path), Some (`String module_path) -> + let full = load_full (Uri.of_path file_path) state in + let documentation = + Analysis.Commands.completion_resolve + ~state:(State.analysis_state state) + ~full ~module_path + in + Some {item with documentation} + | _ -> None) + | _ -> None + in + (ok (resp |> Option.value ~default:item), state) + | SignatureHelp {textDocument = {uri}; position} -> + let doc = Document_store.get ~uri state.store in + let source = doc |> Document.text in + let full = load_full uri state in + let resp = + match + Analysis.Commands.signature_help + ~state:(State.analysis_state state) + ~source ~kind_file:(Document.kind doc) + ~pos:(position.line, position.character) + ~full ~allow_for_constructor_payloads:true ~debug:false + with + | Some s -> s + | None -> SignatureHelp.create ~signatures:[] () + in + (ok (Some resp), state) + | TextDocumentDefinition {textDocument = {uri}; position} -> + let full = load_full uri state in + let resp = + match + Analysis.Commands.definition + ~state:(State.analysis_state state) + ~full + ~pos:(position.line, position.character) + ~debug:false + with + | Some loc -> Some (`Location [loc]) + | None -> None + in + (ok resp, state) + | TextDocumentTypeDefinition {textDocument = {uri}; position} -> + let full = load_full uri state in + let resp = + match + Analysis.Commands.type_definition + ~state:(State.analysis_state state) + ~full + ~pos:(position.line, position.character) + ~debug:false + with + | Some loc -> Some (`Location [loc]) + | None -> None + in + (ok resp, state) + | TextDocumentReferences {textDocument = {uri}; position} -> + let full = load_full uri state in + let resp = + Analysis.Commands.references + ~state:(State.analysis_state state) + ~full + ~pos:(position.line, position.character) + ~debug:false + in + (ok (Some resp), state) + | DocumentSymbol {textDocument = {uri}} -> + let doc = Document_store.get ~uri state.store in + let source = doc |> Document.text in + let resp = + Analysis.Document_symbol.get_symbols ~source + ~kind_file:(Document.kind doc) + in + (ok (Some (`DocumentSymbol resp)), state) + | CodeAction + {textDocument = {uri}; range = {start; end_}; context = {diagnostics}} -> + let full = load_full uri state in + let doc = Document_store.get ~uri state.store in + let source = doc |> Document.text in + let code_actions_from_compiler_log = + Code_actions.From_diagnostics.get ~doc ~diagnostics + in + let code_actions_from_analysis = + Analysis.Xform.extract_code_actions + ~state:(State.analysis_state state) + ~path:(Uri.to_path uri) + ~start_pos:(start.line, start.character) + ~end_pos:(end_.line, end_.character) + ~source ~kind_file:(Document.kind doc) ~full ~debug:false + in + let other_actions = + let client_support_window_show_document = + match (State.params state).capabilities.window with + | Some {showDocument = Some {support}} -> support = true + | _ -> false + in + + let open_compiled_file = + if client_support_window_show_document then + Code_actions.Open_compiled_file.make ~doc ~state + else [] + in + let create_interface_file = + Code_actions.Create_interface_file.make ~doc ~state + in + let switch_implementation_interface_file = + if client_support_window_show_document then + Code_actions.Switch_implementation_interface_file.make ~doc ~state + else [] + in + + open_compiled_file @ create_interface_file + @ switch_implementation_interface_file + in + let resp = + code_actions_from_compiler_log @ code_actions_from_analysis + @ other_actions + |> List.map (fun ca -> `CodeAction ca) + in + (ok (Some resp), state) + | TextDocumentCodeLens {textDocument = {uri}} -> + if state.configuration.code_lens then + let doc = Document_store.get ~uri state.store in + let source = doc |> Document.text in + let full = load_full uri state in + let resp = + Analysis.Hint.code_lens ~source ~kind_file:(Document.kind doc) ~full + ~debug:false + in + (ok (Some (resp |> Option.value ~default:[])), state) + else (ok (Some []), state) + | InlayHint {textDocument = {uri}; range = {start; end_}} -> + if state.configuration.inlay_hints.enable then + let doc = Document_store.get ~uri state.store in + let source = doc |> Document.text in + let full = load_full uri state in + let resp = + Analysis.Hint.inlay + ~state:(State.analysis_state state) + ~source ~kind_file:(Document.kind doc) ~full + ~pos:(start.line, end_.line) + ~max_length:state.configuration.inlay_hints.max_length ~debug:false + in + (ok resp, state) + else (ok None, state) + | SemanticTokensFull {textDocument = {uri}} -> + let doc = Document_store.get ~uri state.store in + let source = doc |> Document.text in + let resp = + Analysis.Semantic_tokens.semantic_tokens ~source + ~kind_file:(Document.kind doc) + in + (ok (Some resp), state) + | TextDocumentRename {textDocument = {uri}; position; newName} -> + let full = load_full uri state in + let resp = + match + Analysis.Commands.rename + ~state:(State.analysis_state state) + ~full + ~pos:(position.line, position.character) + ~new_name:newName ~debug:false + with + | Some we -> we + | None -> WorkspaceEdit.create () + in + (ok (Some resp), state) + | TextDocumentPrepareRename {textDocument = {uri}; position} -> + let full = load_full uri state in + let resp = + match + Analysis.Commands.prepare_rename ~full + ~pos:(position.line, position.character) + ~debug:false + with + | Some {range} -> Some (`Range range) + | None -> None + in + (ok resp, state) + | TextDocumentFormatting {textDocument = {uri}} -> ( + match Formatter.run ~uri ~state with + | Ok text_edit -> (ok (Some text_edit), state) + | Error message -> + Server.show_message_notification ~kind:MessageType.Error message server; + (error message, state)) + | ExecuteCommand {command; arguments} -> ( + let open Execute_commands in + match + List.assoc_opt command + [ + (Open_compiled.name, Open_compiled.execute); + (Create_interface.name, Create_interface.execute); + ( Switch_implementation_interface.name, + Switch_implementation_interface.execute ); + (Dump_server_state.name, Dump_server_state.execute); + (Dump_cmt.name, Dump_cmt.execute); + ] + with + | Some execute -> ( + match execute ~arguments server with + | Ok None -> (ok `Null, state) + | Ok (Some response) -> (ok response, state) + | Error message -> (error message, state)) + | None -> + ( error + (Printf.sprintf + "Unknown command %s for workspace/executeCommand request" command), + state )) + | Shutdown -> (ok (), state) + | DebugTextDocumentGet _ | DebugEcho _ | WorkspaceSymbol _ + | CodeActionResolve _ | TextDocumentColor _ | TextDocumentColorPresentation _ + | TextDocumentCodeLensResolve _ | TextDocumentHighlight _ + | TextDocumentFoldingRange _ | TextDocumentLinkResolve _ | TextDocumentLink _ + | WillSaveWaitUntilTextDocument _ | TextDocumentRangeFormatting _ + | TextDocumentOnTypeFormatting _ | SelectionRange _ + | TextDocumentImplementation _ | SemanticTokensDelta _ | TextDocumentMoniker _ + | TextDocumentPrepareCallHierarchy _ | CallHierarchyIncomingCalls _ + | CallHierarchyOutgoingCalls _ | SemanticTokensRange _ | LinkedEditingRange _ + | WillCreateFiles _ | WillRenameFiles _ | WillDeleteFiles _ + | InlayHintResolve _ | TextDocumentInlineCompletion _ + | TextDocumentInlineValue _ | WorkspaceSymbolResolve _ | WorkspaceDiagnostic _ + | TextDocumentRangesFormatting _ | TextDocumentPrepareTypeHierarchy _ + | TypeHierarchySupertypes _ | TypeHierarchySubtypes _ + | TextDocumentDeclaration _ | WorkspaceTextDocumentContent _ -> + (error "Request not supported yet!", state) + | UnknownRequest {meth; params} -> ( + let open Custom_requests in + match + List.assoc_opt meth + [ + (Create_interface_file.meth, Create_interface_file.on_request); + (Open_compiled_file.meth, Open_compiled_file.on_request); + ] + with + | Some on_request -> (on_request ~params ~state, state) + | None -> + ( error ?code:(Some Jsonrpc.Response.Error.Code.InvalidRequest) + (Printf.sprintf "Unknown request %s" meth), + state )) + +let on_notification notification (server : State.t Server.t) = + let state = Server.state server in + + match notification with + | Client_notification.TextDocumentDidOpen did_open_params -> + let doc = + Document.make did_open_params + ~position_encoding:(State.position_encoding state) + in + let store = Document_store.add ~doc state.store in + + let diagnostics = + State.diagnostics state + |> get_latest_completed_diagnostics state + |> Diagnostics.update_syntax ~uri:(Document.uri doc) + ~new_diagnostics: + (Analysis.Diagnostics.document_syntax ~source:(Document.text doc) + ~kind_file:(Document.kind doc)) + in + let state = {state with store} in + diagnostics + |> publish_diagnostics ~force_publish_uris:[Document.uri doc] state; + state |> State.update_diagnostics diagnostics + | TextDocumentDidChange {contentChanges; textDocument = {uri; version}} -> + let previous_doc = Document_store.get ~uri state.store in + let new_doc = Document.update_text ~version previous_doc contentChanges in + + let store = Document_store.update ~doc:new_doc state.store in + + let diagnostics = + State.diagnostics state + |> get_latest_completed_diagnostics state + |> Diagnostics.update_syntax ~uri + ~new_diagnostics: + (Analysis.Diagnostics.document_syntax + ~source:(Document.text new_doc) + ~kind_file:(Document.kind new_doc)) + in + + let state = {state with store} in + diagnostics |> publish_diagnostics ~force_publish_uris:[uri] state; + state |> State.update_diagnostics diagnostics + | TextDocumentDidClose {textDocument = {uri; _}} -> + let store = Document_store.remove ~uri state.store in + let state = {state with store} in + let diagnostics = + State.diagnostics state + |> Diagnostics.clear_syntax ~uri + |> get_latest_completed_diagnostics state + in + diagnostics |> publish_diagnostics state; + state |> State.update_diagnostics diagnostics + | Initialized _ -> + (* Register dynamic file watchers for compiler log files. + ReScript writes one .compiler.log per build root. In monorepos, + .sourcedirs.json contains the build_root entries for each subpackage, + so use it to watch every generated compiler log and refresh diagnostics + when any of them changes. *) + let watchers = + [WatchKind.Create; Change; Delete] + |> List.map (fun kind -> + FileSystemWatcher.create + ~kind + (* NOTE: Clients dont send notification `workspace/didChangeWatchedFiles` + when pattern is a relative path `lib/rescript/.compiler.log` of full path + `{workspace_root}/lib/rescript/.compiler.log`. The glob should start with `**` + *) + ~globPattern: + (`Pattern ("**/" ^ Constants.compiler_log_partial_path)) + ()) + in + + let registerOptions = + DidChangeWatchedFilesRegistrationOptions.create ~watchers + |> DidChangeWatchedFilesRegistrationOptions.yojson_of_t + in + let registration = + Registration.create ~id:"rescript_file_watchers" + ~method_:"workspace/didChangeWatchedFiles" ~registerOptions () + in + let params = RegistrationParams.create ~registrations:[registration] in + Server.request (Server_request.ClientRegisterCapability params) server; + + state + | DidChangeWatchedFiles {changes} -> ( + let state = + if + List.exists + (fun (event : FileEvent.t) -> + Filename.basename (Uri.to_path event.uri) = Constants.compiler_log + && (event.type_ = FileChangeType.Created + || event.type_ = FileChangeType.Changed)) + changes + then + let workspace_root = State.workspace_root state in + let analysis_state, compiler_config = + discover_project_context ~notify_errors:false ~workspace_root server + in + (* A workspace opened before its first build has no package metadata. + Rediscover into fresh tables so failed lookups and old CMT caches + cannot survive the build. Keep the previous context if metadata is + still unavailable, and preserve buffers, settings and diagnostics. *) + if + Hashtbl.mem analysis_state.packages_by_root + (Uri.to_path workspace_root) + then + State.initialize state ~params:(State.params state) + ~diagnostics:(State.diagnostics state) ~analysis_state + ~compiler_config + ~position_encoding:(State.position_encoding state) + else state + else state + in + (* Do not limit diagnostics to the path reported by + DidChangeWatchedFilesParams. In monorepos, a build in one subpackage + can change diagnostics that should be shown for files in another + subpackage. Re-read every compiler log listed in .sourcedirs.json so + stale errors are cleared and cross-package diagnostics stay in sync. *) + Server.notification + (Server_notification.UnknownNotification + (Jsonrpc.Notification.create ~method_:"rescript/compilationFinished" ())) + server; + match State.diagnostics state |> get_updated_diagnostics_from_log state with + | None -> state + | Some diagnostics -> + diagnostics |> publish_diagnostics state; + + (match (State.params state).capabilities.workspace with + | Some {diagnostics = Some {refreshSupport = Some true}} + when uses_pull_diagnostics state -> + Server.request Server_request.WorkspaceDiagnosticRefresh server + | _ -> ()); + + (match (State.params state).capabilities.workspace with + | Some {codeLens = Some {refreshSupport = Some true}} -> + Server.request Server_request.CodeLensRefresh server + | _ -> ()); + + state |> State.update_diagnostics diagnostics) + | ChangeConfiguration _ -> + (* workspace/didChangeConfiguration only signals that settings may have + changed. The LSP configuration model is pull-based, so the server should + ignore this notification payload and fetch the scoped settings it needs + with workspace/configuration. + + See https://github.com/microsoft/language-server-protocol/issues/567#issuecomment-448538082 + *) + Server.request + (Server_request.WorkspaceConfiguration + (ConfigurationParams.create + (* NOTE: The client decides how to map that section to its own configuration store. + Behavior I observed using `rescript.settings`: + - Neovim send `null` + - Zed send `null` + - VSCode sends the correct data layout + The best approach was to increase the scope to `rescript` and write a small middleware in VSCode extension. + *) + ~items:[ConfigurationItem.create ~section:"rescript" ()])) + server; + state + | Exit -> state + | ChangeWorkspaceFolders _ | CancelRequest _ | DidSaveTextDocument _ + | DidCreateFiles _ | DidDeleteFiles _ | DidRenameFiles _ + | WillSaveTextDocument _ | WorkDoneProgressCancel _ | WorkDoneProgress _ + | Progress _ | NotebookDocumentDidOpen _ | NotebookDocumentDidChange _ + | NotebookDocumentDidSave _ | NotebookDocumentDidClose _ | SetTrace _ -> + state + | UnknownNotification {method_} -> + Server.log_message_notification ~kind:MessageType.Error + ("Unknown notication " ^ method_) + server; + state + +(* TODO: Revisit this *) +let on_response + (Server.Response_result (request, result) : Server.response_result) + (server : State.t Server.t) = + let request_error_message = function + | Server.Response_error error -> error.message + | Server.Decode_error exn -> Printexc.to_string exn + in + + let state = Server.state server in + + match (request, result) with + | Server_request.WorkspaceConfiguration _, result -> ( + match result with + | Ok [settings] -> ( + match Configuration.of_yojson settings with + | Ok configuration -> {state with configuration} + | Error _ -> + Server.log_message_notification ~kind:MessageType.Error + ("Failed to parse rescript settings: " + ^ Yojson.Safe.pretty_to_string settings) + server; + state) + | Ok _ -> + Server.log_message_notification ~kind:MessageType.Error + "Invalid rescript settings. The server not received a list with one \ + element" + server; + state + | Error err -> + Server.log_message_notification ~kind:MessageType.Error + ("Error on response of workspace/configuration request: " + ^ request_error_message err) + server; + state) + | _ -> state + +let listen ~input ~output ~fs = + let state = + State.make ~store:(Document_store.make ()) + ~configuration:Configuration.default ~fs + in + Server.listen ~input ~output ~on_request ~on_notification ~on_response ~state diff --git a/lsp/src/rescript_language_server.mli b/lsp/src/rescript_language_server.mli new file mode 100644 index 00000000000..bb8b50ba84d --- /dev/null +++ b/lsp/src/rescript_language_server.mli @@ -0,0 +1,5 @@ +val listen : + input:[> Eio__Flow.source_ty] Eio.Resource.t -> + output:[> Eio__Flow.sink_ty] Eio.Resource.t -> + fs:Eio.Fs.dir_ty Eio.Path.t -> + unit diff --git a/lsp/src/server.ml b/lsp/src/server.ml new file mode 100644 index 00000000000..0b80615d874 --- /dev/null +++ b/lsp/src/server.ml @@ -0,0 +1,286 @@ +module Io : sig + type 'a t + + val return : 'a -> 'a t + val raise : exn -> 'a t + val await : 'a t -> 'a + val async : (sw:Eio.Switch.t -> ('a, exn) result) -> 'a t + + module O : sig + (* Consumed by the external Lsp.Io.Make functor, outside Reanalyze's scan. *) + val ( let+ ) : 'a t -> ('a -> 'b) -> 'b t [@@live] + val ( let* ) : 'a t -> ('a -> 'b t) -> 'b t [@@live] + end +end = struct + type 'a t = sw:Eio.Switch.t -> ('a, exn) result Eio.Promise.t + + let await t = Eio.Switch.run @@ fun sw -> Eio.Promise.await_exn (t ~sw) + let return value ~sw:_ = Eio.Promise.create_resolved (Ok value) + let error desc ~sw:_ = Eio.Promise.create_resolved (Error desc) + + let async f ~sw = + let promise, resolver = Eio.Promise.create () in + ( Eio.Fiber.fork ~sw @@ fun () -> + try + let result = f ~sw in + Eio.Promise.resolve resolver result + with exn -> Eio.Promise.resolve resolver @@ Error exn ); + promise + + let bind t f = + async @@ fun ~sw -> + match Eio.Promise.await (t ~sw) with + | Ok value -> Eio.Promise.await @@ f value ~sw + | Error desc -> Error desc + + let raise = error + + module O = struct + let ( let+ ) x f = bind x @@ fun value -> return @@ f value + let ( let* ) = bind + end +end + +module Chan : sig + type input + type output + + val of_source : [> Eio__Flow.source_ty] Eio.Resource.t -> input + val with_sink : [> Eio__Flow.sink_ty] Eio.Resource.t -> (output -> 'a) -> 'a + + val read_line : input -> string option Io.t + val read_exactly : input -> int -> string option Io.t + val write : output -> string list -> unit Io.t +end = struct + type input = {mutex: Eio.Mutex.t; buf: Eio.Buf_read.t} + type output = {mutex: Eio.Mutex.t; buf: Eio.Buf_write.t} + + let initial_size = 1024 + let max_size = 1024 * 1024 + + let of_source source : input = + let mutex = Eio.Mutex.create () in + let buf = Eio.Buf_read.of_flow ~initial_size ~max_size source in + {mutex; buf} + + let with_sink sink f = + let mutex = Eio.Mutex.create () in + Eio.Buf_write.with_flow ~initial_size sink @@ fun buf -> f {mutex; buf} + + let read_line (input : input) = + Io.async @@ fun ~sw:_ -> + Eio.Mutex.use_rw ~protect:true input.mutex @@ fun () -> + if Eio.Buf_read.eof_seen input.buf then Ok None + else + match Eio.Buf_read.line input.buf with + | line -> Ok (Some line) + | exception End_of_file -> Ok None + + let read_exactly (input : input) size = + Io.async @@ fun ~sw:_ -> + Eio.Mutex.use_rw ~protect:true input.mutex @@ fun () -> + if Eio.Buf_read.eof_seen input.buf then Ok None + else + match Eio.Buf_read.take size input.buf with + | data -> Ok (Some data) + | exception End_of_file -> Ok None + + let write (output : output) (str : string list) = + Io.async @@ fun ~sw:_ -> + Eio.Mutex.use_rw ~protect:true output.mutex @@ fun () -> + Ok (List.iter (Eio.Buf_write.string output.buf) str) +end + +module Lsp_Io = Lsp.Io.Make (Io) (Chan) + +let notification_of_jsonrpc notification = + match Lsp.Client_notification.of_jsonrpc notification with + | Ok notification -> notification + | Error error -> raise (Lsp.Io.Error error) + +module Request_id = struct + type t = Jsonrpc.Id.t + + let equal = Jsonrpc.Id.equal + let hash = Jsonrpc.Id.hash +end + +module Request_id_table = Hashtbl.Make (Request_id) + +type request_error = + | Response_error of Jsonrpc.Response.Error.t + | Decode_error of exn + +type response_result = + | Response_result : + 'a Lsp.Server_request.t * ('a, request_error) result + -> response_result + +type pending_request = Pending : 'a Lsp.Server_request.t -> pending_request + +type request_context = { + mutable next_id: int; + pending: pending_request Request_id_table.t; +} + +type 'a t = {channel: Chan.output; state: 'a; request_context: request_context} + +let state t = t.state + +let respond server response = + Io.await @@ Lsp_Io.write server.channel @@ Response response + +let notification notification server = + let notification = Lsp.Server_notification.to_jsonrpc notification in + Io.await @@ Lsp_Io.write server.channel @@ Notification notification + +let request request server = + let id = `Int server.request_context.next_id in + server.request_context.next_id <- server.request_context.next_id + 1; + Request_id_table.add server.request_context.pending id (Pending request); + let request = Lsp.Server_request.to_jsonrpc_request request ~id in + try Io.await @@ Lsp_Io.write server.channel @@ Request request + with exn -> + Request_id_table.remove server.request_context.pending id; + raise exn + +let handle_response (response : Jsonrpc.Response.t) server = + match + Request_id_table.find_opt server.request_context.pending response.id + with + | None -> None + | Some (Pending request) -> ( + Request_id_table.remove server.request_context.pending response.id; + match response.result with + | Ok json -> + let result = + match Lsp.Server_request.response_of_json request json with + | response -> Ok response + | exception exn -> Error (Decode_error exn) + in + Some (Response_result (request, result)) + | Error err -> + let result = Error (Response_error err) in + Some (Response_result (request, result))) + +let log_message_notification ~kind message server = + notification + (Lsp.Server_notification.LogMessage + (Lsp.Types.LogMessageParams.create ~type_:kind ~message)) + server + +let show_message_notification ~kind message server = + notification + (Lsp.Server_notification.ShowMessage + (Lsp.Types.ShowMessageParams.create ~type_:kind ~message)) + server + +type lifecycle = Awaiting_initialize | Running | Shutdown_requested + +let error_response ~id ~code ~message = + let err = Jsonrpc.Response.Error.make ~code ~message () in + Jsonrpc.Response.{id; result = Error err} + +let is_initialize_request (request : Jsonrpc.Request.t) = + request.method_ = "initialize" + +let is_shutdown_request (request : Jsonrpc.Request.t) = + request.method_ = "shutdown" + +let is_exit_notification (notification : Jsonrpc.Notification.t) = + notification.method_ = "exit" + +let exit_from_lifecycle lifecycle = + let exit_code = + match lifecycle with + | Shutdown_requested -> 0 + | _ -> 1 + in + exit exit_code + +let rec input_loop ~input ~state with_ = + match Io.await @@ Lsp_Io.read input with + | Some packet -> + let state = with_ state packet in + input_loop ~input ~state with_ + | exception _ -> failwith "Server.input_loop" + | None -> () + +let listen ~input ~output ~on_request ~on_notification ~on_response ~state = + let lifecycle = ref Awaiting_initialize in + let handle_request server request = + match !lifecycle with + | Awaiting_initialize when not (is_initialize_request request) -> + respond server + (error_response ~id:request.id + ~code:Jsonrpc.Response.Error.Code.ServerNotInitialized + ~message:"Server has not received an initialize request"); + server.state + | Running when is_initialize_request request -> + respond server + (error_response ~id:request.id + ~code:Jsonrpc.Response.Error.Code.InvalidRequest + ~message:"Server has already been initialized"); + server.state + | Shutdown_requested -> + respond server + (error_response ~id:request.id + ~code:Jsonrpc.Response.Error.Code.InvalidRequest + ~message:"Server has already received a shutdown request"); + server.state + | Awaiting_initialize | Running -> + let response, state = + match Lsp.Client_request.of_jsonrpc request with + | Error message -> + let code = Jsonrpc.Response.Error.Code.InvalidParams in + let err = Jsonrpc.Response.Error.make ~code ~message () in + (Jsonrpc.Response.{id = request.id; result = Error err}, state) + | Ok packed -> + let result, state = on_request packed server in + (Jsonrpc.Response.{id = request.id; result}, state) + in + respond server response; + (match response.result with + | Ok _ when is_initialize_request request -> lifecycle := Running + | Ok _ when is_shutdown_request request -> lifecycle := Shutdown_requested + | Ok _ | Error _ -> ()); + state + in + let handle_notification server notification = + if is_exit_notification notification then exit_from_lifecycle !lifecycle + else + match !lifecycle with + | Awaiting_initialize | Shutdown_requested -> server.state + | Running -> on_notification (notification_of_jsonrpc notification) server + in + let input = Chan.of_source input in + Chan.with_sink output (fun channel -> + let request_context = + {next_id = 1; pending = Request_id_table.create 16} + in + input_loop ~input ~state (fun state packet -> + let server = {channel; state; request_context} in + match packet with + | Notification notification -> handle_notification server notification + | Request request -> handle_request server request + | Batch_call calls -> + List.fold_left + (fun state call -> + let server = {channel; state; request_context} in + match call with + | `Request request -> handle_request server request + | `Notification notification -> + handle_notification server notification) + state calls + | Response response -> ( + match handle_response response server with + | Some response -> on_response response server + | None -> state) + | Batch_response responses -> + List.fold_left + (fun state response -> + let server = {channel; state; request_context} in + match handle_response response server with + | Some response -> on_response response server + | None -> state) + state responses)) diff --git a/lsp/src/source_dirs.ml b/lsp/src/source_dirs.ml new file mode 100644 index 00000000000..227ff9470c5 --- /dev/null +++ b/lsp/src/source_dirs.ml @@ -0,0 +1,80 @@ +type cmt_scan_item = {build_root: string} [@@deriving yojson {strict = false}] + +type source_dirs = {cmt_scan: cmt_scan_item list} +[@@deriving yojson {strict = false}] + +let get_build_roots_from_json json = + match source_dirs_of_yojson json with + | Ok {cmt_scan} -> Some (List.map (fun {build_root} -> build_root) cmt_scan) + | Error _ -> None + +let get_build_roots_from_file ~fs path = + match Fs.load ~fs path with + | Some content -> ( + match Yojson.Safe.from_string content with + | json -> get_build_roots_from_json json + | exception _ -> None) + | None -> None + +let%expect_test "get_build_roots" = + let print_build_roots result = + match result with + | None -> () + | Some l -> List.iter print_endline l + in + let json_1 = + Yojson.Safe.from_string + {| +{ + "cmt_scan": [ + { + "build_root": "path/to/lib/bs" + } + ] +} + |} + in + + json_1 |> get_build_roots_from_json |> print_build_roots; + [%expect {| path/to/lib/bs |}]; + + let json_2 = + Yojson.Safe.from_string + {| +{ +"cmt_scan": [ + { + "build_root": "path/to/lib/bs" + }, + { + "build_root": "path2/to/lib/bs" + } +] +} + |} + in + + json_2 |> get_build_roots_from_json |> print_build_roots; + [%expect {| + path/to/lib/bs + path2/to/lib/bs + |}]; + + let json_3 = + Yojson.Safe.from_string + {| +{ +"cmt_scan": [ +{ + "build_root": [] +}, +{ + "build_root": {} +} +] +} +|} + in + + json_3 |> get_build_roots_from_json |> print_build_roots; + [%expect {| |}] diff --git a/lsp/src/state.ml b/lsp/src/state.ml new file mode 100644 index 00000000000..f16e363c22c --- /dev/null +++ b/lsp/src/state.ml @@ -0,0 +1,142 @@ +open Lsp.Types + +type status = + | Uninitialized + | Initialized of { + params: InitializeParams.t; + diagnostics: Diagnostics.t; + analysis_state: Analysis.Shared_types.state; + compiler_config: Compiler_config.t; + position_encoding: [`UTF16 | `UTF8]; + } + +type t = { + status: status; + store: Document_store.t; + configuration: Configuration.t; + fs: Eio.Fs.dir_ty Eio.Path.t; +} + +let make ~store ~configuration ~fs = + {status = Uninitialized; store; configuration; fs} + +let initialize t ~params ~diagnostics ~analysis_state ~compiler_config + ~position_encoding = + { + t with + status = + Initialized + { + params; + diagnostics; + analysis_state; + compiler_config; + position_encoding; + }; + } + +let diagnostics t = + match t.status with + | Uninitialized -> assert false + | Initialized init -> init.diagnostics + +let params t = + match t.status with + | Uninitialized -> assert false + | Initialized init -> init.params + +let position_encoding t = + match t.status with + | Uninitialized -> assert false + | Initialized init -> init.position_encoding + +(* TODO: Consider storing initialized state in a separate record so updates do + not need to reconstruct the full Initialized payload by hand. *) +let update_diagnostics diagnostics t = + match t.status with + | Uninitialized -> assert false + | Initialized {params; analysis_state; compiler_config; position_encoding} -> + { + t with + status = + Initialized + { + params; + analysis_state; + diagnostics; + compiler_config; + position_encoding; + }; + } + +let analysis_state t = + match t.status with + | Uninitialized -> assert false + | Initialized {analysis_state} -> analysis_state + +let compiler_config t = + match t.status with + | Uninitialized -> assert false + | Initialized {compiler_config} -> compiler_config + +let workspace_root t = + match t.status with + | Uninitialized -> assert false + | Initialized init -> Helpers.root_uri_of_initialize_params init.params + +let to_yojson (t : t) : Yojson.Safe.t = + let document_store_to_yojson (store : Document_store.t) = + store.documents |> Hashtbl.to_seq + |> Seq.map (fun (uri, doc) -> + ( Lsp.Uri.to_string uri, + `Assoc + [ + ("version", `Int (Lsp.Text_document.version doc)); + ( "text_length", + `Int (doc |> Lsp.Text_document.text |> String.length) ); + ] )) + |> List.of_seq + |> fun fields -> `Assoc fields + in + + let diagnostics_to_yojson (diagnostics : Diagnostics.t) = + diagnostics |> Diagnostics.get_all |> Diagnostics.Uri_map.to_seq + |> Seq.map (fun (uri, diagnostics) -> + ( Lsp.Uri.to_string uri, + `List (List.map Diagnostic.yojson_of_t diagnostics) )) + |> List.of_seq + |> fun fields -> `Assoc fields + in + + let compiler_config_to_yojson (compiler_config : Compiler_config.t) = + compiler_config |> Compiler_config.Uri_map.to_seq + |> Seq.map (fun (uri, config) -> + (Lsp.Uri.to_string uri, Compiler_config.Parse.to_yojson config)) + |> List.of_seq + |> fun fields -> `Assoc fields + in + + let status_to_yojson = function + | Uninitialized -> `Assoc [("kind", `String "Uninitialized")] + | Initialized {params; diagnostics; compiler_config; position_encoding} -> + `Assoc + [ + ("kind", `String "Initialized"); + ("diagnostics", diagnostics_to_yojson diagnostics); + ("compiler_config", compiler_config_to_yojson compiler_config); + ( "position_encoding", + match position_encoding with + | `UTF16 -> `String "utf-16" + | `UTF8 -> `String "utf-8" ); + ("params", InitializeParams.yojson_of_t params); + ] + in + + `Assoc + [ + ("status", status_to_yojson t.status); + ("store", document_store_to_yojson t.store); + ("configuration", Configuration.to_yojson t.configuration); + ( "analysis_state", + Analysis.Shared_types.state_to_yojson (analysis_state t) ); + ] diff --git a/packages/@rescript/darwin-arm64/THIRD_PARTY_LICENSES b/packages/@rescript/darwin-arm64/THIRD_PARTY_LICENSES index 8da216572d4..639dc857052 100644 --- a/packages/@rescript/darwin-arm64/THIRD_PARTY_LICENSES +++ b/packages/@rescript/darwin-arm64/THIRD_PARTY_LICENSES @@ -964,7 +964,7 @@ LSP Version: 1.28.1 Source: https://github.com/ocaml/ocaml-lsp License: ISC -Included in: rescript-editor-analysis and rescript-tools +Included in: rescript, rescript-editor-analysis and rescript-tools ISC License @@ -1088,6 +1088,1219 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ------------------------------------------------------------------------------- +EIO +=== +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: language-server I/O in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +EIO MAIN +======== +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: language-server event loop in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +EIO POSIX BACKEND +================= +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: POSIX language-server backend in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +IOMUX +===== +Version: 0.4 +Source: https://github.com/ocaml-multicore/ocaml-iomux +License: ISC +Included in: runtime dependency of Eio POSIX + +Copyright (c) 2023 Christiano Haesbaert + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +FMT +=== +Version: 0.11.0 +Source: https://erratique.ch/software/fmt +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2016 The fmt programmers + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +MTIME +===== +Version: 2.2.0 +Source: https://erratique.ch/software/mtime +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2015 The mtime programmers + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +DOMAIN-LOCAL-AWAIT +================== +Version: 1.0.1 +Source: https://github.com/ocaml-multicore/domain-local-await +License: ISC +Included in: runtime dependency of Eio + +Copyright Ā© 2023 Vesa Karvonen + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +------------------------------------------------------------------------------- + +THREAD-TABLE +============ +Version: 1.0.0 +Source: https://github.com/ocaml-multicore/thread-table +License: ISC +Included in: runtime dependency of domain-local-await + +Copyright Ā© 2023 Vesa Karvonen + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +------------------------------------------------------------------------------- + +OPTINT +====== +Version: 0.3.0 +Source: https://github.com/mirage/optint +License: ISC +Included in: runtime dependency of Eio + +The MIT License (MIT) + +Copyright (c) 2018 Romain Calascibetta + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- + +PSQ +=== +Version: 0.2.1 +Source: https://github.com/pqwy/psq +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2016 David Kaloper MerÅ”injak + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +SEQ COMPATIBILITY PACKAGE +========================= +Version: base +Source: https://github.com/ocaml/ocaml +License: LGPL-2.1-only WITH OCaml-LGPL-linking-exception +Included in: standard-library iterator types used by Eio +Notes: Metadata-only compatibility package. Seq is provided by the OCaml standard library; its license text comes from the ocaml package. + +In the following, "the OCaml Core System" refers to all files marked +"Copyright INRIA" in this distribution. + +The OCaml Core System is distributed under the terms of the +GNU Lesser General Public License (LGPL) version 2.1 (included below). + +As a special exception to the GNU Lesser General Public License, you +may link, statically or dynamically, a "work that uses the OCaml Core +System" with a publicly distributed version of the OCaml Core System +to produce an executable file containing portions of the OCaml Core +System, and distribute that executable file under terms of your +choice, without any of the additional requirements listed in clause 6 +of the GNU Lesser General Public License. By "a publicly distributed +version of the OCaml Core System", we mean either the unmodified OCaml +Core System as distributed by INRIA, or a modified version of the +OCaml Core System that is distributed under the conditions defined in +clause 2 of the GNU Lesser General Public License. This exception +does not however invalidate any other reasons why the executable file +might be covered by the GNU Lesser General Public License. + +---------------------------------------------------------------------- + +GNU LESSER GENERAL PUBLIC LICENSE + +Version 2.1, February 1999 + +Copyright (C) 1991, 1999 Free Software Foundation, Inc. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + +Preamble + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. + +This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. + +When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. + +To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. + +For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. + +We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. + +To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. + +Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. + +Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. + +When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. + +We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. + +For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. + +In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. + +Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. + +The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". + +A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. + +The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. + c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. + d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. + + (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. + +Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. + +This option is useful when you wish to copy part of the code of the Library into a program that is not a library. + +4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. + +5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. + +However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. + +When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. + +If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. + +6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: + + a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) + b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. + c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. + d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. + e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + +It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. + +7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. + b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. + +10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. + +11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Libraries + +If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). + +To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + +one line to give the library's name and an idea of what it does. +Copyright (C) year name of author + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in +the library `Frob' (a library for tweaking knobs) written +by James Random Hacker. + +signature of Ty Coon, 1 April 1990 +Ty Coon, President of Vice + +That's all there is to it! + +-------------------------------------------------- + +------------------------------------------------------------------------------- + +BIGSTRINGAF +=========== +Version: 0.10.0 +Source: https://github.com/inhabitedtype/bigstringaf +License: BSD-3-Clause +Included in: runtime dependency of Eio + +Copyright (c) 2018, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +LWT-DLLIST +========== +Version: 1.1.0 +Source: https://github.com/mirage/lwt-dllist +License: MIT +Included in: runtime dependency of Eio + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +OCAML CSTRUCT +============= +Version: 6.3.0 +Source: https://github.com/mirage/ocaml-cstruct +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2012 Anil Madhavapeddy +Copyright (c) 2012 Pierre Chambart +Copyright (c) Christiano F. Haesbaert +Copyright (c) Citrix Inc +Copyright (c) David Sheets +Copyright (c) Drup +Copyright (c) Hannes Mehnert +Copyright (c) Jeremy Yallop +Copyright (c) Mindy Preston +Copyright (c) Nicolas Ojeda Bar +Copyright (c) Richard Mortier +Copyright (c) Rudi Grinberg +Copyright (c) Thomas Gazagnaire +Copyright (c) Thomas Leonard +Copyright (c) Vincent Bernardoff +Copyright (c) pqwy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +HMAP +==== +Version: 0.8.1 +Source: https://erratique.ch/software/hmap +License: ISC +Included in: runtime dependency of Eio + + Copyright (c) 2016 Daniel C. Bünzli + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_EXPECT RUNTIME +================== +Version: v0.17.3 +Source: https://github.com/janestreet/ppx_expect +License: MIT +Included in: runtime dependency of the language-server library in rescript + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPXLIB +====== +Version: 0.39.0 +Source: https://github.com/ocaml-ppx/ppxlib +License: MIT +Included in: runtime dependency of ppx_expect + +The MIT License + +Copyright (c) 2018 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +STDIO +===== +Version: v0.17.0 +Source: https://github.com/janestreet/stdio +License: MIT +Included in: runtime dependency of the language-server PPX runtimes + +The MIT License + +Copyright (c) 2016--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +BASE +==== +Version: v0.17.3 +Source: https://github.com/janestreet/base +License: MIT +Included in: runtime dependency of the language-server PPX runtimes + +The MIT License + +Copyright (c) 2016--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +OCAML_INTRINSICS_KERNEL +======================= +Version: v0.17.3 +Source: https://github.com/janestreet/ocaml_intrinsics_kernel +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2020--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +SEXPLIB0 +======== +Version: v0.17.0 +Source: https://github.com/janestreet/sexplib0 +License: MIT +Included in: runtime dependency of Base and the language-server PPX runtimes + +The MIT License + +Copyright (c) 2005--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_HERE RUNTIME +================ +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_here +License: MIT +Included in: runtime dependency of ppx_expect + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_INLINE_TEST RUNTIME +======================= +Version: v0.17.1 +Source: https://github.com/janestreet/ppx_inline_test +License: MIT +Included in: runtime dependency of ppx_expect + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +TIME_NOW +======== +Version: v0.17.0 +Source: https://github.com/janestreet/time_now +License: MIT +Included in: runtime dependency of ppx_inline_test + +The MIT License + +Copyright (c) 2019--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_HASH RUNTIME +================ +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_hash +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_ENUMERATE RUNTIME +===================== +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_enumerate +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_COMPARE RUNTIME +=================== +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_compare +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_SEXP_CONV RUNTIME +===================== +Version: v0.17.1 +Source: https://github.com/janestreet/ppx_sexp_conv +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +JANE-STREET-HEADERS +=================== +Version: v0.17.0 +Source: https://github.com/janestreet/jane-street-headers +License: MIT +Included in: C support for Jane Street runtime libraries + +The MIT License + +Copyright (c) 2016--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_DERIVING_YOJSON RUNTIME +=========================== +Version: 3.10.0 +Source: https://github.com/ocaml-ppx/ppx_deriving_yojson +License: MIT +Included in: JSON codecs in the language-server library in rescript + +Copyright (c) 2014-2018 whitequark + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +------------------------------------------------------------------------------- + CMDLINER ======== Version: 2.1.1 diff --git a/packages/@rescript/linux-arm64/THIRD_PARTY_LICENSES b/packages/@rescript/linux-arm64/THIRD_PARTY_LICENSES index b0adace61a0..41fea420227 100644 --- a/packages/@rescript/linux-arm64/THIRD_PARTY_LICENSES +++ b/packages/@rescript/linux-arm64/THIRD_PARTY_LICENSES @@ -964,7 +964,7 @@ LSP Version: 1.28.1 Source: https://github.com/ocaml/ocaml-lsp License: ISC -Included in: rescript-editor-analysis and rescript-tools +Included in: rescript, rescript-editor-analysis and rescript-tools ISC License @@ -1088,6 +1088,1346 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ------------------------------------------------------------------------------- +EIO +=== +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: language-server I/O in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +EIO MAIN +======== +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: language-server event loop in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +EIO POSIX BACKEND +================= +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: POSIX language-server backend in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +EIO LINUX BACKEND +================= +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: Linux language-server backend in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +OCAML URING +=========== +Version: 2.15.1 +Source: https://github.com/ocaml-multicore/ocaml-uring +License: ISC AND MIT +Included in: io_uring support for Eio in rescript +Notes: Includes vendored liburing, distributed under its MIT license. + +/* + * Copyright (C) 2020-2021 Anil Madhavapeddy + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +Copyright 2020 Jens Axboe + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- + +IOMUX +===== +Version: 0.4 +Source: https://github.com/ocaml-multicore/ocaml-iomux +License: ISC +Included in: runtime dependency of Eio POSIX + +Copyright (c) 2023 Christiano Haesbaert + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +FMT +=== +Version: 0.11.0 +Source: https://erratique.ch/software/fmt +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2016 The fmt programmers + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +MTIME +===== +Version: 2.2.0 +Source: https://erratique.ch/software/mtime +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2015 The mtime programmers + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +DOMAIN-LOCAL-AWAIT +================== +Version: 1.0.1 +Source: https://github.com/ocaml-multicore/domain-local-await +License: ISC +Included in: runtime dependency of Eio + +Copyright Ā© 2023 Vesa Karvonen + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +------------------------------------------------------------------------------- + +THREAD-TABLE +============ +Version: 1.0.0 +Source: https://github.com/ocaml-multicore/thread-table +License: ISC +Included in: runtime dependency of domain-local-await + +Copyright Ā© 2023 Vesa Karvonen + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +------------------------------------------------------------------------------- + +OPTINT +====== +Version: 0.3.0 +Source: https://github.com/mirage/optint +License: ISC +Included in: runtime dependency of Eio + +The MIT License (MIT) + +Copyright (c) 2018 Romain Calascibetta + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- + +PSQ +=== +Version: 0.2.1 +Source: https://github.com/pqwy/psq +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2016 David Kaloper MerÅ”injak + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +SEQ COMPATIBILITY PACKAGE +========================= +Version: base +Source: https://github.com/ocaml/ocaml +License: LGPL-2.1-only WITH OCaml-LGPL-linking-exception +Included in: standard-library iterator types used by Eio +Notes: Metadata-only compatibility package. Seq is provided by the OCaml standard library; its license text comes from the ocaml package. + +In the following, "the OCaml Core System" refers to all files marked +"Copyright INRIA" in this distribution. + +The OCaml Core System is distributed under the terms of the +GNU Lesser General Public License (LGPL) version 2.1 (included below). + +As a special exception to the GNU Lesser General Public License, you +may link, statically or dynamically, a "work that uses the OCaml Core +System" with a publicly distributed version of the OCaml Core System +to produce an executable file containing portions of the OCaml Core +System, and distribute that executable file under terms of your +choice, without any of the additional requirements listed in clause 6 +of the GNU Lesser General Public License. By "a publicly distributed +version of the OCaml Core System", we mean either the unmodified OCaml +Core System as distributed by INRIA, or a modified version of the +OCaml Core System that is distributed under the conditions defined in +clause 2 of the GNU Lesser General Public License. This exception +does not however invalidate any other reasons why the executable file +might be covered by the GNU Lesser General Public License. + +---------------------------------------------------------------------- + +GNU LESSER GENERAL PUBLIC LICENSE + +Version 2.1, February 1999 + +Copyright (C) 1991, 1999 Free Software Foundation, Inc. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + +Preamble + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. + +This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. + +When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. + +To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. + +For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. + +We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. + +To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. + +Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. + +Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. + +When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. + +We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. + +For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. + +In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. + +Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. + +The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". + +A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. + +The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. + c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. + d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. + + (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. + +Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. + +This option is useful when you wish to copy part of the code of the Library into a program that is not a library. + +4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. + +5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. + +However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. + +When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. + +If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. + +6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: + + a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) + b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. + c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. + d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. + e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + +It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. + +7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. + b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. + +10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. + +11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Libraries + +If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). + +To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + +one line to give the library's name and an idea of what it does. +Copyright (C) year name of author + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in +the library `Frob' (a library for tweaking knobs) written +by James Random Hacker. + +signature of Ty Coon, 1 April 1990 +Ty Coon, President of Vice + +That's all there is to it! + +-------------------------------------------------- + +------------------------------------------------------------------------------- + +BIGSTRINGAF +=========== +Version: 0.10.0 +Source: https://github.com/inhabitedtype/bigstringaf +License: BSD-3-Clause +Included in: runtime dependency of Eio + +Copyright (c) 2018, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +LWT-DLLIST +========== +Version: 1.1.0 +Source: https://github.com/mirage/lwt-dllist +License: MIT +Included in: runtime dependency of Eio + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +OCAML CSTRUCT +============= +Version: 6.3.0 +Source: https://github.com/mirage/ocaml-cstruct +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2012 Anil Madhavapeddy +Copyright (c) 2012 Pierre Chambart +Copyright (c) Christiano F. Haesbaert +Copyright (c) Citrix Inc +Copyright (c) David Sheets +Copyright (c) Drup +Copyright (c) Hannes Mehnert +Copyright (c) Jeremy Yallop +Copyright (c) Mindy Preston +Copyright (c) Nicolas Ojeda Bar +Copyright (c) Richard Mortier +Copyright (c) Rudi Grinberg +Copyright (c) Thomas Gazagnaire +Copyright (c) Thomas Leonard +Copyright (c) Vincent Bernardoff +Copyright (c) pqwy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +HMAP +==== +Version: 0.8.1 +Source: https://erratique.ch/software/hmap +License: ISC +Included in: runtime dependency of Eio + + Copyright (c) 2016 Daniel C. Bünzli + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_EXPECT RUNTIME +================== +Version: v0.17.3 +Source: https://github.com/janestreet/ppx_expect +License: MIT +Included in: runtime dependency of the language-server library in rescript + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPXLIB +====== +Version: 0.39.0 +Source: https://github.com/ocaml-ppx/ppxlib +License: MIT +Included in: runtime dependency of ppx_expect + +The MIT License + +Copyright (c) 2018 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +STDIO +===== +Version: v0.17.0 +Source: https://github.com/janestreet/stdio +License: MIT +Included in: runtime dependency of the language-server PPX runtimes + +The MIT License + +Copyright (c) 2016--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +BASE +==== +Version: v0.17.3 +Source: https://github.com/janestreet/base +License: MIT +Included in: runtime dependency of the language-server PPX runtimes + +The MIT License + +Copyright (c) 2016--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +OCAML_INTRINSICS_KERNEL +======================= +Version: v0.17.3 +Source: https://github.com/janestreet/ocaml_intrinsics_kernel +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2020--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +SEXPLIB0 +======== +Version: v0.17.0 +Source: https://github.com/janestreet/sexplib0 +License: MIT +Included in: runtime dependency of Base and the language-server PPX runtimes + +The MIT License + +Copyright (c) 2005--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_HERE RUNTIME +================ +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_here +License: MIT +Included in: runtime dependency of ppx_expect + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_INLINE_TEST RUNTIME +======================= +Version: v0.17.1 +Source: https://github.com/janestreet/ppx_inline_test +License: MIT +Included in: runtime dependency of ppx_expect + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +TIME_NOW +======== +Version: v0.17.0 +Source: https://github.com/janestreet/time_now +License: MIT +Included in: runtime dependency of ppx_inline_test + +The MIT License + +Copyright (c) 2019--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_HASH RUNTIME +================ +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_hash +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_ENUMERATE RUNTIME +===================== +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_enumerate +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_COMPARE RUNTIME +=================== +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_compare +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_SEXP_CONV RUNTIME +===================== +Version: v0.17.1 +Source: https://github.com/janestreet/ppx_sexp_conv +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +JANE-STREET-HEADERS +=================== +Version: v0.17.0 +Source: https://github.com/janestreet/jane-street-headers +License: MIT +Included in: C support for Jane Street runtime libraries + +The MIT License + +Copyright (c) 2016--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_DERIVING_YOJSON RUNTIME +=========================== +Version: 3.10.0 +Source: https://github.com/ocaml-ppx/ppx_deriving_yojson +License: MIT +Included in: JSON codecs in the language-server library in rescript + +Copyright (c) 2014-2018 whitequark + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +------------------------------------------------------------------------------- + CMDLINER ======== Version: 2.1.1 diff --git a/packages/@rescript/linux-x64/THIRD_PARTY_LICENSES b/packages/@rescript/linux-x64/THIRD_PARTY_LICENSES index 08b0c9a3e2a..b0f1d6c5785 100644 --- a/packages/@rescript/linux-x64/THIRD_PARTY_LICENSES +++ b/packages/@rescript/linux-x64/THIRD_PARTY_LICENSES @@ -964,7 +964,7 @@ LSP Version: 1.28.1 Source: https://github.com/ocaml/ocaml-lsp License: ISC -Included in: rescript-editor-analysis and rescript-tools +Included in: rescript, rescript-editor-analysis and rescript-tools ISC License @@ -1088,6 +1088,1346 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ------------------------------------------------------------------------------- +EIO +=== +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: language-server I/O in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +EIO MAIN +======== +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: language-server event loop in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +EIO POSIX BACKEND +================= +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: POSIX language-server backend in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +EIO LINUX BACKEND +================= +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: Linux language-server backend in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +OCAML URING +=========== +Version: 2.15.1 +Source: https://github.com/ocaml-multicore/ocaml-uring +License: ISC AND MIT +Included in: io_uring support for Eio in rescript +Notes: Includes vendored liburing, distributed under its MIT license. + +/* + * Copyright (C) 2020-2021 Anil Madhavapeddy + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +Copyright 2020 Jens Axboe + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- + +IOMUX +===== +Version: 0.4 +Source: https://github.com/ocaml-multicore/ocaml-iomux +License: ISC +Included in: runtime dependency of Eio POSIX + +Copyright (c) 2023 Christiano Haesbaert + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +FMT +=== +Version: 0.11.0 +Source: https://erratique.ch/software/fmt +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2016 The fmt programmers + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +MTIME +===== +Version: 2.2.0 +Source: https://erratique.ch/software/mtime +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2015 The mtime programmers + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +DOMAIN-LOCAL-AWAIT +================== +Version: 1.0.1 +Source: https://github.com/ocaml-multicore/domain-local-await +License: ISC +Included in: runtime dependency of Eio + +Copyright Ā© 2023 Vesa Karvonen + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +------------------------------------------------------------------------------- + +THREAD-TABLE +============ +Version: 1.0.0 +Source: https://github.com/ocaml-multicore/thread-table +License: ISC +Included in: runtime dependency of domain-local-await + +Copyright Ā© 2023 Vesa Karvonen + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +------------------------------------------------------------------------------- + +OPTINT +====== +Version: 0.3.0 +Source: https://github.com/mirage/optint +License: ISC +Included in: runtime dependency of Eio + +The MIT License (MIT) + +Copyright (c) 2018 Romain Calascibetta + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- + +PSQ +=== +Version: 0.2.1 +Source: https://github.com/pqwy/psq +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2016 David Kaloper MerÅ”injak + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +SEQ COMPATIBILITY PACKAGE +========================= +Version: base +Source: https://github.com/ocaml/ocaml +License: LGPL-2.1-only WITH OCaml-LGPL-linking-exception +Included in: standard-library iterator types used by Eio +Notes: Metadata-only compatibility package. Seq is provided by the OCaml standard library; its license text comes from the ocaml package. + +In the following, "the OCaml Core System" refers to all files marked +"Copyright INRIA" in this distribution. + +The OCaml Core System is distributed under the terms of the +GNU Lesser General Public License (LGPL) version 2.1 (included below). + +As a special exception to the GNU Lesser General Public License, you +may link, statically or dynamically, a "work that uses the OCaml Core +System" with a publicly distributed version of the OCaml Core System +to produce an executable file containing portions of the OCaml Core +System, and distribute that executable file under terms of your +choice, without any of the additional requirements listed in clause 6 +of the GNU Lesser General Public License. By "a publicly distributed +version of the OCaml Core System", we mean either the unmodified OCaml +Core System as distributed by INRIA, or a modified version of the +OCaml Core System that is distributed under the conditions defined in +clause 2 of the GNU Lesser General Public License. This exception +does not however invalidate any other reasons why the executable file +might be covered by the GNU Lesser General Public License. + +---------------------------------------------------------------------- + +GNU LESSER GENERAL PUBLIC LICENSE + +Version 2.1, February 1999 + +Copyright (C) 1991, 1999 Free Software Foundation, Inc. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + +Preamble + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. + +This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. + +When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. + +To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. + +For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. + +We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. + +To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. + +Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. + +Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. + +When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. + +We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. + +For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. + +In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. + +Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. + +The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". + +A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. + +The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. + c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. + d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. + + (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. + +Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. + +This option is useful when you wish to copy part of the code of the Library into a program that is not a library. + +4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. + +5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. + +However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. + +When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. + +If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. + +6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: + + a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) + b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. + c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. + d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. + e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + +It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. + +7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. + b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. + +10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. + +11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Libraries + +If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). + +To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + +one line to give the library's name and an idea of what it does. +Copyright (C) year name of author + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in +the library `Frob' (a library for tweaking knobs) written +by James Random Hacker. + +signature of Ty Coon, 1 April 1990 +Ty Coon, President of Vice + +That's all there is to it! + +-------------------------------------------------- + +------------------------------------------------------------------------------- + +BIGSTRINGAF +=========== +Version: 0.10.0 +Source: https://github.com/inhabitedtype/bigstringaf +License: BSD-3-Clause +Included in: runtime dependency of Eio + +Copyright (c) 2018, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +LWT-DLLIST +========== +Version: 1.1.0 +Source: https://github.com/mirage/lwt-dllist +License: MIT +Included in: runtime dependency of Eio + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +OCAML CSTRUCT +============= +Version: 6.3.0 +Source: https://github.com/mirage/ocaml-cstruct +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2012 Anil Madhavapeddy +Copyright (c) 2012 Pierre Chambart +Copyright (c) Christiano F. Haesbaert +Copyright (c) Citrix Inc +Copyright (c) David Sheets +Copyright (c) Drup +Copyright (c) Hannes Mehnert +Copyright (c) Jeremy Yallop +Copyright (c) Mindy Preston +Copyright (c) Nicolas Ojeda Bar +Copyright (c) Richard Mortier +Copyright (c) Rudi Grinberg +Copyright (c) Thomas Gazagnaire +Copyright (c) Thomas Leonard +Copyright (c) Vincent Bernardoff +Copyright (c) pqwy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +HMAP +==== +Version: 0.8.1 +Source: https://erratique.ch/software/hmap +License: ISC +Included in: runtime dependency of Eio + + Copyright (c) 2016 Daniel C. Bünzli + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_EXPECT RUNTIME +================== +Version: v0.17.3 +Source: https://github.com/janestreet/ppx_expect +License: MIT +Included in: runtime dependency of the language-server library in rescript + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPXLIB +====== +Version: 0.39.0 +Source: https://github.com/ocaml-ppx/ppxlib +License: MIT +Included in: runtime dependency of ppx_expect + +The MIT License + +Copyright (c) 2018 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +STDIO +===== +Version: v0.17.0 +Source: https://github.com/janestreet/stdio +License: MIT +Included in: runtime dependency of the language-server PPX runtimes + +The MIT License + +Copyright (c) 2016--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +BASE +==== +Version: v0.17.3 +Source: https://github.com/janestreet/base +License: MIT +Included in: runtime dependency of the language-server PPX runtimes + +The MIT License + +Copyright (c) 2016--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +OCAML_INTRINSICS_KERNEL +======================= +Version: v0.17.3 +Source: https://github.com/janestreet/ocaml_intrinsics_kernel +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2020--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +SEXPLIB0 +======== +Version: v0.17.0 +Source: https://github.com/janestreet/sexplib0 +License: MIT +Included in: runtime dependency of Base and the language-server PPX runtimes + +The MIT License + +Copyright (c) 2005--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_HERE RUNTIME +================ +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_here +License: MIT +Included in: runtime dependency of ppx_expect + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_INLINE_TEST RUNTIME +======================= +Version: v0.17.1 +Source: https://github.com/janestreet/ppx_inline_test +License: MIT +Included in: runtime dependency of ppx_expect + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +TIME_NOW +======== +Version: v0.17.0 +Source: https://github.com/janestreet/time_now +License: MIT +Included in: runtime dependency of ppx_inline_test + +The MIT License + +Copyright (c) 2019--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_HASH RUNTIME +================ +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_hash +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_ENUMERATE RUNTIME +===================== +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_enumerate +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_COMPARE RUNTIME +=================== +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_compare +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_SEXP_CONV RUNTIME +===================== +Version: v0.17.1 +Source: https://github.com/janestreet/ppx_sexp_conv +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +JANE-STREET-HEADERS +=================== +Version: v0.17.0 +Source: https://github.com/janestreet/jane-street-headers +License: MIT +Included in: C support for Jane Street runtime libraries + +The MIT License + +Copyright (c) 2016--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_DERIVING_YOJSON RUNTIME +=========================== +Version: 3.10.0 +Source: https://github.com/ocaml-ppx/ppx_deriving_yojson +License: MIT +Included in: JSON codecs in the language-server library in rescript + +Copyright (c) 2014-2018 whitequark + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +------------------------------------------------------------------------------- + CMDLINER ======== Version: 2.1.1 diff --git a/packages/@rescript/win32-x64/THIRD_PARTY_LICENSES b/packages/@rescript/win32-x64/THIRD_PARTY_LICENSES index 78565901469..7391a21acf6 100644 --- a/packages/@rescript/win32-x64/THIRD_PARTY_LICENSES +++ b/packages/@rescript/win32-x64/THIRD_PARTY_LICENSES @@ -964,7 +964,7 @@ LSP Version: 1.28.1 Source: https://github.com/ocaml/ocaml-lsp License: ISC -Included in: rescript-editor-analysis and rescript-tools +Included in: rescript, rescript-editor-analysis and rescript-tools ISC License @@ -1088,6 +1088,1116 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ------------------------------------------------------------------------------- +EIO +=== +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: language-server I/O in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +EIO MAIN +======== +Version: 1.6 +Source: https://github.com/ocaml-multicore/eio +License: ISC +Included in: language-server event loop in rescript + +Copyright (C) 2021 Anil Madhavapeddy +Copyright (C) 2022 Thomas Leonard + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This project includes some IPv6 code by Hugo Heuzard from ocaml-ipaddr, +which has the following license: + +ISC License + +Copyright (c) 2013-2015 David Sheets +Copyright (c) 2010-2011, 2014 Anil Madhavapeddy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +The `Eio.Buf_write` module is based on Faraday by Inhabited Type LLC, +which has the following license (BSD-3-clause): + +Copyright (c) 2016, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +FMT +=== +Version: 0.11.0 +Source: https://erratique.ch/software/fmt +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2016 The fmt programmers + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +MTIME +===== +Version: 2.2.0 +Source: https://erratique.ch/software/mtime +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2015 The mtime programmers + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +DOMAIN-LOCAL-AWAIT +================== +Version: 1.0.1 +Source: https://github.com/ocaml-multicore/domain-local-await +License: ISC +Included in: runtime dependency of Eio + +Copyright Ā© 2023 Vesa Karvonen + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +------------------------------------------------------------------------------- + +THREAD-TABLE +============ +Version: 1.0.0 +Source: https://github.com/ocaml-multicore/thread-table +License: ISC +Included in: runtime dependency of domain-local-await + +Copyright Ā© 2023 Vesa Karvonen + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +------------------------------------------------------------------------------- + +OPTINT +====== +Version: 0.3.0 +Source: https://github.com/mirage/optint +License: ISC +Included in: runtime dependency of Eio + +The MIT License (MIT) + +Copyright (c) 2018 Romain Calascibetta + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- + +PSQ +=== +Version: 0.2.1 +Source: https://github.com/pqwy/psq +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2016 David Kaloper MerÅ”injak + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +SEQ COMPATIBILITY PACKAGE +========================= +Version: base +Source: https://github.com/ocaml/ocaml +License: LGPL-2.1-only WITH OCaml-LGPL-linking-exception +Included in: standard-library iterator types used by Eio +Notes: Metadata-only compatibility package. Seq is provided by the OCaml standard library; its license text comes from the ocaml package. + +In the following, "the OCaml Core System" refers to all files marked +"Copyright INRIA" in this distribution. + +The OCaml Core System is distributed under the terms of the +GNU Lesser General Public License (LGPL) version 2.1 (included below). + +As a special exception to the GNU Lesser General Public License, you +may link, statically or dynamically, a "work that uses the OCaml Core +System" with a publicly distributed version of the OCaml Core System +to produce an executable file containing portions of the OCaml Core +System, and distribute that executable file under terms of your +choice, without any of the additional requirements listed in clause 6 +of the GNU Lesser General Public License. By "a publicly distributed +version of the OCaml Core System", we mean either the unmodified OCaml +Core System as distributed by INRIA, or a modified version of the +OCaml Core System that is distributed under the conditions defined in +clause 2 of the GNU Lesser General Public License. This exception +does not however invalidate any other reasons why the executable file +might be covered by the GNU Lesser General Public License. + +---------------------------------------------------------------------- + +GNU LESSER GENERAL PUBLIC LICENSE + +Version 2.1, February 1999 + +Copyright (C) 1991, 1999 Free Software Foundation, Inc. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + +Preamble + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. + +This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. + +When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. + +To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. + +For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. + +We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. + +To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. + +Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. + +Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. + +When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. + +We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. + +For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. + +In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. + +Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. + +The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". + +A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. + +The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. + c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. + d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. + + (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. + +Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. + +This option is useful when you wish to copy part of the code of the Library into a program that is not a library. + +4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. + +5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. + +However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. + +When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. + +If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. + +6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: + + a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) + b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. + c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. + d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. + e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + +It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. + +7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. + b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. + +10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. + +11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Libraries + +If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). + +To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + +one line to give the library's name and an idea of what it does. +Copyright (C) year name of author + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in +the library `Frob' (a library for tweaking knobs) written +by James Random Hacker. + +signature of Ty Coon, 1 April 1990 +Ty Coon, President of Vice + +That's all there is to it! + +-------------------------------------------------- + +------------------------------------------------------------------------------- + +BIGSTRINGAF +=========== +Version: 0.10.0 +Source: https://github.com/inhabitedtype/bigstringaf +License: BSD-3-Clause +Included in: runtime dependency of Eio + +Copyright (c) 2018, Inhabited Type LLC + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- + +LWT-DLLIST +========== +Version: 1.1.0 +Source: https://github.com/mirage/lwt-dllist +License: MIT +Included in: runtime dependency of Eio + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +OCAML CSTRUCT +============= +Version: 6.3.0 +Source: https://github.com/mirage/ocaml-cstruct +License: ISC +Included in: runtime dependency of Eio + +Copyright (c) 2012 Anil Madhavapeddy +Copyright (c) 2012 Pierre Chambart +Copyright (c) Christiano F. Haesbaert +Copyright (c) Citrix Inc +Copyright (c) David Sheets +Copyright (c) Drup +Copyright (c) Hannes Mehnert +Copyright (c) Jeremy Yallop +Copyright (c) Mindy Preston +Copyright (c) Nicolas Ojeda Bar +Copyright (c) Richard Mortier +Copyright (c) Rudi Grinberg +Copyright (c) Thomas Gazagnaire +Copyright (c) Thomas Leonard +Copyright (c) Vincent Bernardoff +Copyright (c) pqwy + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +HMAP +==== +Version: 0.8.1 +Source: https://erratique.ch/software/hmap +License: ISC +Included in: runtime dependency of Eio + + Copyright (c) 2016 Daniel C. Bünzli + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_EXPECT RUNTIME +================== +Version: v0.17.3 +Source: https://github.com/janestreet/ppx_expect +License: MIT +Included in: runtime dependency of the language-server library in rescript + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPXLIB +====== +Version: 0.39.0 +Source: https://github.com/ocaml-ppx/ppxlib +License: MIT +Included in: runtime dependency of ppx_expect + +The MIT License + +Copyright (c) 2018 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +STDIO +===== +Version: v0.17.0 +Source: https://github.com/janestreet/stdio +License: MIT +Included in: runtime dependency of the language-server PPX runtimes + +The MIT License + +Copyright (c) 2016--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +BASE +==== +Version: v0.17.3 +Source: https://github.com/janestreet/base +License: MIT +Included in: runtime dependency of the language-server PPX runtimes + +The MIT License + +Copyright (c) 2016--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +OCAML_INTRINSICS_KERNEL +======================= +Version: v0.17.3 +Source: https://github.com/janestreet/ocaml_intrinsics_kernel +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2020--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +SEXPLIB0 +======== +Version: v0.17.0 +Source: https://github.com/janestreet/sexplib0 +License: MIT +Included in: runtime dependency of Base and the language-server PPX runtimes + +The MIT License + +Copyright (c) 2005--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_HERE RUNTIME +================ +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_here +License: MIT +Included in: runtime dependency of ppx_expect + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_INLINE_TEST RUNTIME +======================= +Version: v0.17.1 +Source: https://github.com/janestreet/ppx_inline_test +License: MIT +Included in: runtime dependency of ppx_expect + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +TIME_NOW +======== +Version: v0.17.0 +Source: https://github.com/janestreet/time_now +License: MIT +Included in: runtime dependency of ppx_inline_test + +The MIT License + +Copyright (c) 2019--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_HASH RUNTIME +================ +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_hash +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_ENUMERATE RUNTIME +===================== +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_enumerate +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_COMPARE RUNTIME +=================== +Version: v0.17.0 +Source: https://github.com/janestreet/ppx_compare +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_SEXP_CONV RUNTIME +===================== +Version: v0.17.1 +Source: https://github.com/janestreet/ppx_sexp_conv +License: MIT +Included in: runtime dependency of Base + +The MIT License + +Copyright (c) 2015--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +JANE-STREET-HEADERS +=================== +Version: v0.17.0 +Source: https://github.com/janestreet/jane-street-headers +License: MIT +Included in: C support for Jane Street runtime libraries + +The MIT License + +Copyright (c) 2016--2024 Jane Street Group, LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------- + +PPX_DERIVING_YOJSON RUNTIME +=========================== +Version: 3.10.0 +Source: https://github.com/ocaml-ppx/ppx_deriving_yojson +License: MIT +Included in: JSON codecs in the language-server library in rescript + +Copyright (c) 2014-2018 whitequark + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +------------------------------------------------------------------------------- + CMDLINER ======== Version: 2.1.1 diff --git a/rescript-language-server.opam b/rescript-language-server.opam new file mode 100644 index 00000000000..e10bf88261e --- /dev/null +++ b/rescript-language-server.opam @@ -0,0 +1,33 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "ReScript LSP" +maintainer: ["Hongbo Zhang " "Cristiano Calcagno"] +authors: ["Hongbo Zhang "] +license: "LGPL-3.0-or-later" +homepage: "https://github.com/rescript-lang/rescript-compiler" +bug-reports: "https://github.com/rescript-lang/rescript-compiler/issues" +depends: [ + "ocaml" {>= "5.0.0"} + "lsp" {>= "1.22.0"} + "eio" {>= "1.3"} + "eio_main" {>= "1.3"} + "analysis" + "dune" {>= "3.17"} + "ppx_deriving_yojson" + "ppx_expect" {with-test & = "v0.17.3"} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] diff --git a/rewatch-ocaml/README.md b/rewatch-ocaml/README.md index b474bb19ef8..08da7cba96b 100644 --- a/rewatch-ocaml/README.md +++ b/rewatch-ocaml/README.md @@ -1,7 +1,7 @@ # Rewatch This directory contains ReScript's build system and CLI (`rescript build`, -`watch`, `clean`, `format`, and `compiler-args`). It ships as `rescript` in the +`watch`, `clean`, `format`, `compiler-args` and `lsp`). It ships as `rescript` in the `@rescript/` packages and is tested with the integration suite in [`../rewatch/tests`](../rewatch/tests). diff --git a/rewatch-ocaml/cli.ml b/rewatch-ocaml/cli.ml index e5cbe56183d..442911e523b 100644 --- a/rewatch-ocaml/cli.ml +++ b/rewatch-ocaml/cli.ml @@ -4,6 +4,7 @@ type command = | Watch of build_options | Format of format_input | Compiler_args of {verbosity: int; path: string} + | Lsp and build_options = { verbosity: int; @@ -217,6 +218,14 @@ let compiler_args_term = let+ verbosity = verbosity and+ path in Compiler_args {verbosity; path} +let lsp_term = + Arg.( + required + & vflag None + [ + (Some Lsp, info ["stdio"] ~doc:"Use standard input/output (required)."); + ]) + let exits = [ Cmd.Exit.info 0 ~doc:"on success."; @@ -270,6 +279,11 @@ let root = (command_info "help" "Print this message or command help.") help_term in + let lsp = + Cmd.make + (command_info "lsp" "Start the ReScript language server over stdio.") + lsp_term + in let info = let man = [ @@ -287,7 +301,7 @@ let root = ~version:("rescript " ^ Rewatch_version.version) ~doc:"Fast, Simple, Fully Typed JavaScript from the Future" ~man in - let commands = [build; watch; clean; format; compiler_args; help] in + let commands = [build; watch; clean; format; compiler_args; lsp; help] in (* Options before a command name make Cmdliner read the name as the folder of the default build, so [rescript -v watch] would build a folder named watch. *) diff --git a/rewatch-ocaml/cli.mli b/rewatch-ocaml/cli.mli index ceb134500d5..50920871927 100644 --- a/rewatch-ocaml/cli.mli +++ b/rewatch-ocaml/cli.mli @@ -4,6 +4,7 @@ type command = | Watch of build_options | Format of format_input | Compiler_args of {verbosity: int; path: string} + | Lsp and build_options = { verbosity: int; diff --git a/rewatch-ocaml/dune b/rewatch-ocaml/dune index 4bd9afcc4c3..4e7d0b8fe26 100644 --- a/rewatch-ocaml/dune +++ b/rewatch-ocaml/dune @@ -98,4 +98,4 @@ (modules rescript_ocaml) (flags (:standard -open Rewatch_ocaml_lib)) - (libraries rewatch_ocaml_lib)) + (libraries rewatch_ocaml_lib rescript_language_server eio_main)) diff --git a/rewatch-ocaml/rescript_ocaml.ml b/rewatch-ocaml/rescript_ocaml.ml index 46877354582..13278a1a130 100644 --- a/rewatch-ocaml/rescript_ocaml.ml +++ b/rewatch-ocaml/rescript_ocaml.ml @@ -56,11 +56,22 @@ let run_command ~poll = function Format.run_files ~poll ~verbosity ~check paths | Cli.Compiler_args {verbosity; path} -> print_endline (Compiler_args_command.run ~verbosity path) + | Cli.Lsp -> + Eio_main.run (fun env -> + let fs = Eio.Stdenv.fs env in + let input = Eio.Stdenv.stdin env in + let output = Eio.Stdenv.stdout env in + Rescript_language_server.listen ~input ~output ~fs) | Cli.Clean {verbosity; folder; prod} -> Clean.run ~poll ~verbosity ~folder ~prod let run = function | Cli.Watch _ as command -> run_command ~poll:(fun () -> ()) command + | Cli.Lsp as command -> + (* The Eio server does not poll the build's termination callback. Keep the + standalone server's signal behavior instead of swallowing termination + signals in the build-only handlers. *) + run_command ~poll:(fun () -> ()) command | command -> with_termination_handlers (fun ~poll -> run_command ~poll command) diff --git a/scripts/generateThirdPartyLicenses.js b/scripts/generateThirdPartyLicenses.js index 4ef6769094d..e54aee4e2ba 100644 --- a/scripts/generateThirdPartyLicenses.js +++ b/scripts/generateThirdPartyLicenses.js @@ -41,6 +41,7 @@ const shippedExecutables = new Map([ * @typedef {{ * name: string, * opam?: string, + * licenseOpam?: string, * version?: string, * libuvVersionFrom?: string, * source: string, @@ -269,7 +270,9 @@ function renderComponent(component) { component.notes === undefined ? undefined : `Notes: ${component.notes}`, ].filter(line => line !== undefined); const licenseTexts = [ - ...(component.opam === undefined ? [] : opamLicenseTexts(component.opam)), + ...(component.opam === undefined + ? [] + : opamLicenseTexts(component.licenseOpam ?? component.opam)), ...(component.licenseFiles ?? []).map(file => fs.readFileSync(path.join(projectDir, file), "utf8"), ), diff --git a/tests/build_tests/cli_help/input.js b/tests/build_tests/cli_help/input.js index ded42fa80b6..b9628ffd78d 100755 --- a/tests/build_tests/cli_help/input.js +++ b/tests/build_tests/cli_help/input.js @@ -39,6 +39,9 @@ const cliHelp = " help [OPTION]… [COMMAND]\n" + " Print this message or command help.\n" + "\n" + + " lsp --stdio [OPTION]…\n" + + " Start the ReScript language server over stdio.\n" + + "\n" + " watch [OPTION]… [FOLDER]\n" + " Build, then start a watcher.\n" + "\n" + @@ -338,6 +341,25 @@ async function test(params, expected) { assert.equal(out.status, expected.status); } +// Missing transport is a usage error, not a running server or a help success. +await test(["lsp"], { + stdout: "", + stderr: + "Usage: rescript lsp [--help] --stdio [OPTION]…\n" + + "rescript: required option --stdio is missing\n", + status: 2, +}); + +for (const flag of ["--quiet", "--verbose"]) { + await test(["lsp", "--stdio", flag], { + stdout: "", + stderr: + "Usage: rescript lsp [--help] --stdio [OPTION]…\n" + + `rescript: unknown option ${flag}\n`, + status: 2, + }); +} + // Shows build help with --help arg await test(["build", "--help"], { stdout: buildHelp, diff --git a/tests/dune b/tests/dune index dca9405bcc3..22b63ed819c 100644 --- a/tests/dune +++ b/tests/dune @@ -1 +1 @@ -(dirs ounit_tests rewatch_ounit_tests syntax_tests) +(dirs ounit_tests rewatch_ounit_tests syntax_tests lsp_tests) diff --git a/tests/lsp_tests/README.md b/tests/lsp_tests/README.md new file mode 100644 index 00000000000..1964c255482 --- /dev/null +++ b/tests/lsp_tests/README.md @@ -0,0 +1,70 @@ +# LSP Snapshot Tests + +These OCaml `ppx_expect` tests run the language server over stdio. They adapt +representative cases from `tests/analysis_tests`; the original analysis suite +remains in place and has additional coverage. + +Each feature has its own module, with one named `let%expect_test` per scenario. +Source snippets contain no cursor markers. Positions are explicit, zero-based +LSP positions, recalculated after removing marker lines and uncommenting code. + +| Analysis marker | Test module | LSP request | +| --- | --- | --- | +| `def` | `definition.ml` | `textDocument/definition` | +| `com` | `completion.ml`, `completion_jsx.ml`, `completion_generic_jsx.ml`, `completion_typed_arrays.ml` | `textDocument/completion` | +| `cre` | `completion_resolve.ml` | `completionItem/resolve` | +| `doc` | `document_symbol.ml` | `textDocument/documentSymbol` | +| `sem`, `hig` | `semantic_tokens.ml` | `textDocument/semanticTokens/full` | +| `hov` | `hover.ml`, `hover_jsx.ml` | `textDocument/hover` | +| `she` | `signature_help.ml` | `textDocument/signatureHelp` | +| `int` | `create_interface.ml` | `textDocument/createInterface` (custom) | +| `ref` | `references.ml` | `textDocument/references` | +| `pre` | `prepare_rename.ml` | `textDocument/prepareRename` | +| `ren` | `rename.ml` | `textDocument/rename` | +| `typ` | `type_definition.ml` | `textDocument/typeDefinition` | +| `xfm` | `code_action.ml` | `textDocument/codeAction` | +| `hin` | `inlay_hint.ml` | `textDocument/inlayHint` | +| `dia` | `document_syntax.ml` | `textDocument/diagnostic` | +| `cle` | `code_lens.ml` | `textDocument/codeLens` | + +`Test.with_project` creates an isolated temporary project, optionally builds it, +opens `Test.res`, and cleans up after the server exits. Additional `.res` and +`.resi` files can be supplied through `~files`. Use `Test.change_document` to +exercise unsaved buffers without changing the compiled source, and +`Test.configure` to answer the server's configuration request. + +Use `~jsx:true` to build with a temporary copy of the local React bindings. +Use `~rescript_json` to override the project configuration for namespaces or +custom JSX runtimes. `record_rest.ml` covers definitions, completion, inlay +hints, and semantic tokens for typed record-rest patterns. Completion coverage +also includes Temporal shared result types and all eleven typed-array kinds; +namespaced references and existential hover have dedicated cases. +Use `~capabilities` to exercise push-only clients as well as the default client +with pull diagnostics. `diagnostics.ml` tests both actual recompilation and +explicit compiler-log phases delivered through `workspace/didChangeWatchedFiles`. +The client captures every diagnostic publication and uses a request round trip +as a barrier, so these tests do not rely on sleeps or an external file watcher. + +`Test.snapshot` serializes typed LSP responses, replacing the temporary root +with `/workspace` while preserving relative paths, ranges and response order. +The interface tests also snapshot the generated file contents. + +Some snapshots characterize current limitations rather than desired behavior: +file rename destinations are double encoded; module rename omits JSX tag uses; +component references repeat the declaration range; and a missing constructor +argument produces no signature help. These cases have TODO comments in their +tests. Path normalization preserves the malformed URI shape instead of hiding it. + +Build the local toolchain and runtime with `opam exec -- make lib`, then run: + +```sh +opam exec -- dune runtest tests/lsp_tests +``` + +Review snapshot differences before accepting them for a specific module: + +```sh +opam exec -- dune promotion diff tests/lsp_tests/definition.ml +opam exec -- dune promote tests/lsp_tests/definition.ml +opam exec -- dune runtest tests/lsp_tests +``` diff --git a/tests/lsp_tests/code_action.ml b/tests/lsp_tests/code_action.ml new file mode 100644 index 00000000000..5e939c94042 --- /dev/null +++ b/tests/lsp_tests/code_action.ml @@ -0,0 +1,302 @@ +open Lsp +open Types + +let actions doc start end_ = + Client_request.CodeAction + (CodeActionParams.create ~textDocument:(Test.text_document doc) + ~range:(Test.range start end_) + ~context:(CodeActionContext.create ~diagnostics:[] ()) + ()) + +let%expect_test "expands a wildcard to the remaining variant cases" = + Test.with_project ~name:"code-action" + ~text: + {|type kind = First | Second | Third | Fourth(int) +let variant = First +let value = switch variant { +| First => "first" +| _ => "other" +} +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (actions doc (4, 3) (4, 3))); + [%expect + {| + [ + { + "edit": { + "documentChanges": [ + { + "edits": [ + { + "newText": "Second | Third | Fourth(_)", + "range": { + "end": { "character": 3, "line": 4 }, + "start": { "character": 2, "line": 4 } + } + } + ], + "textDocument": { + "uri": "file:///workspace/Test.res", + "version": 0 + } + } + ] + }, + "kind": "refactor.rewrite", + "title": "Expand catch-all" + } + ] + |}] + +let%expect_test "extracts a local module into its own file" = + Test.with_project ~name:"code-action" + ~text: + {|module ExtractableModule = { + /** Doc comment. */ + type t = int + let doStuff = a => a + 1 +} +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (actions doc (3, 5) (3, 5))); + [%expect + {| + [ + { + "edit": { + "documentChanges": [ + { + "kind": "create", + "options": { "ignoreIfExists": true, "overwrite": false }, + "uri": "file:///workspace/ExtractableModule.res" + }, + { + "edits": [ + { + "newText": "/** Doc comment. */\ntype t = int\n\nlet doStuff = a => a + 1\n", + "range": { + "end": { "character": 1, "line": 4 }, + "start": { "character": 0, "line": 0 } + } + } + ], + "textDocument": { + "uri": "file:///workspace/ExtractableModule.res", + "version": null + } + }, + { + "edits": [ + { + "newText": "", + "range": { + "end": { "character": 1, "line": 4 }, + "start": { "character": 0, "line": 0 } + } + } + ], + "textDocument": { + "uri": "file:///workspace/Test.res", + "version": null + } + } + ] + }, + "kind": "refactor.rewrite", + "title": "Extract local module \"ExtractableModule\" to file \"ExtractableModule.res\"" + } + ] + |}] + +let%expect_test "rewrites an if expression as a switch" = + Test.with_project ~name:"code-action" + ~text: + {|type kind = First | Second +let kind = First +let value = if kind == First { + "First" +} else { + "Not First" +} +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (actions doc (2, 18) (2, 18))); + [%expect + {| + [ + { + "edit": { + "documentChanges": [ + { + "edits": [ + { + "newText": "switch kind {\n | First => %todo\n | Second => %todo\n }", + "range": { + "end": { "character": 19, "line": 2 }, + "start": { "character": 15, "line": 2 } + } + } + ], + "textDocument": { + "uri": "file:///workspace/Test.res", + "version": 0 + } + } + ] + }, + "kind": "refactor.rewrite", + "title": "Exhaustive switch" + }, + { + "edit": { + "documentChanges": [ + { + "edits": [ + { + "newText": "switch kind {\n | First => \"First\"\n | _ => \"Not First\"\n }", + "range": { + "end": { "character": 1, "line": 6 }, + "start": { "character": 12, "line": 2 } + } + } + ], + "textDocument": { + "uri": "file:///workspace/Test.res", + "version": 0 + } + } + ] + }, + "kind": "refactor.rewrite", + "title": "Replace with switch" + } + ] + |}] + +let%expect_test "offers a type annotation for an inferred string binding" = + Test.with_project ~name:"code-action" ~text:{|let name = "hello" +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (actions doc (0, 5) (0, 5))); + [%expect + {| + [ + { + "edit": { + "documentChanges": [ + { + "edits": [ + { + "newText": ": string", + "range": { + "end": { "character": 8, "line": 0 }, + "start": { "character": 8, "line": 0 } + } + } + ], + "textDocument": { + "uri": "file:///workspace/Test.res", + "version": 0 + } + } + ] + }, + "kind": "refactor.rewrite", + "title": "Add type annotation" + }, + { + "edit": { + "documentChanges": [ + { + "edits": [ + { + "newText": "/**\n\n*/\nlet name = \"hello\"", + "range": { + "end": { "character": 18, "line": 0 }, + "start": { "character": 0, "line": 0 } + } + } + ], + "textDocument": { + "uri": "file:///workspace/Test.res", + "version": 0 + } + } + ] + }, + "kind": "refactor.rewrite", + "title": "Add Documentation template" + } + ] + |}] + +let%expect_test "offers braces around a function body" = + Test.with_project ~name:"code-action" + ~text:{|let name = "hello" +let noBraces = () => name +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (actions doc (1, 21) (1, 21))); + [%expect + {| + [ + { + "edit": { + "documentChanges": [ + { + "edits": [ + { + "newText": "let noBraces = () => {\n name\n}", + "range": { + "end": { "character": 25, "line": 1 }, + "start": { "character": 0, "line": 1 } + } + } + ], + "textDocument": { + "uri": "file:///workspace/Test.res", + "version": 0 + } + } + ] + }, + "kind": "refactor.rewrite", + "title": "Add braces to function" + } + ] + |}] + +let%expect_test "does not offer another annotation for an annotated binding" = + Test.with_project ~name:"code-action" ~text:{|let annotated: int = 34 +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (actions doc (0, 5) (0, 5))); + [%expect + {| + [ + { + "edit": { + "documentChanges": [ + { + "edits": [ + { + "newText": "/**\n\n*/\nlet annotated: int = 34", + "range": { + "end": { "character": 23, "line": 0 }, + "start": { "character": 0, "line": 0 } + } + } + ], + "textDocument": { + "uri": "file:///workspace/Test.res", + "version": 0 + } + } + ] + }, + "kind": "refactor.rewrite", + "title": "Add Documentation template" + } + ] + |}] diff --git a/tests/lsp_tests/code_lens.ml b/tests/lsp_tests/code_lens.ml new file mode 100644 index 00000000000..c40f8d8a3ee --- /dev/null +++ b/tests/lsp_tests/code_lens.ml @@ -0,0 +1,111 @@ +open Lsp +open Types + +let lenses doc = + Client_request.TextDocumentCodeLens + (CodeLensParams.create ~textDocument:(Test.text_document doc) ()) + +let%expect_test "omits generated React component bindings from code lenses" = + Test.with_project ~name:"code-lens-jsx" ~jsx:true + ~text:{|@react.component +let make = (~name) => React.string(name) +|} + (fun ~root ~doc client -> + Test.configure client (`Assoc [("codeLens", `Bool true)]); + Test.snapshot ~root client (lenses doc)); + [%expect {| [] |}] + +let%expect_test "shows a function type for a dictionary constructor" = + Test.with_project ~name:"code-lens" + ~text:{|let make = value => dict{"a": value} +|} (fun ~root ~doc client -> + Test.configure client (`Assoc [("codeLens", `Bool true)]); + Test.snapshot ~root client (lenses doc)); + [%expect + {| + [ + { + "command": { "command": "", "title": "'a => dict<'a>" }, + "range": { + "end": { "character": 8, "line": 0 }, + "start": { "character": 4, "line": 0 } + } + } + ] + |}] + +let%expect_test "shows a function type for an interpolated template" = + Test.with_project ~name:"code-lens" + ~text:{|let greeting = name => `hello ${name}` +|} (fun ~root ~doc client -> + Test.configure client (`Assoc [("codeLens", `Bool true)]); + Test.snapshot ~root client (lenses doc)); + [%expect + {| + [ + { + "command": { "command": "", "title": "string => string" }, + "range": { + "end": { "character": 12, "line": 0 }, + "start": { "character": 4, "line": 0 } + } + } + ] + |}] + +let%expect_test "does not return code lenses when disabled" = + Test.with_project ~name:"code-lens" ~text:{|let add = (x, y) => x + y +|} + (fun ~root ~doc client -> Test.snapshot ~root client (lenses doc)); + [%expect {| [] |}] + +let%expect_test "shows types for positional and labeled functions" = + Test.with_project ~name:"code-lens" + ~text: + {|let add = (x, y) => x + y +let foo = (~age, ~name) => name ++ Int.toString(age) +|} + (fun ~root ~doc client -> + Test.configure client (`Assoc [("codeLens", `Bool true)]); + Test.snapshot ~root client (lenses doc)); + [%expect + {| + [ + { + "command": { + "command": "", + "title": "(~age: int, ~name: string) => string" + }, + "range": { + "end": { "character": 7, "line": 1 }, + "start": { "character": 4, "line": 1 } + } + }, + { + "command": { "command": "", "title": "(int, int) => int" }, + "range": { + "end": { "character": 7, "line": 0 }, + "start": { "character": 4, "line": 0 } + } + } + ] + |}] + +let%expect_test "shows a type lens for a braced function" = + Test.with_project ~name:"code-lens" + ~text:{|let bracedAdd = {(x, y) => x + y} +|} (fun ~root ~doc client -> + Test.configure client (`Assoc [("codeLens", `Bool true)]); + Test.snapshot ~root client (lenses doc)); + [%expect + {| + [ + { + "command": { "command": "", "title": "(int, int) => int" }, + "range": { + "end": { "character": 13, "line": 0 }, + "start": { "character": 4, "line": 0 } + } + } + ] + |}] diff --git a/tests/lsp_tests/completion.ml b/tests/lsp_tests/completion.ml new file mode 100644 index 00000000000..828c1b326a5 --- /dev/null +++ b/tests/lsp_tests/completion.ml @@ -0,0 +1,218 @@ +open Lsp +open Types + +let completion doc pos = + Client_request.TextDocumentCompletion + (CompletionParams.create ~textDocument:(Test.text_document doc) + ~position:(Test.position pos) ()) + +let%expect_test "completes a Temporal conversion from its shared result type" = + let text = + {|let dateTime = Temporal.PlainDateTime.fromStringOrThrow("2024-02-29T09:30") +let date = dateTime->Temporal.PlainDateTime.toPlainDate +|} + in + Test.with_project ~name:"completion-temporal" ~text (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(text ^ {|date->toPlainY|}); + Test.snapshot ~root client (completion doc (2, 14))); + [%expect + {| + [ + { + "detail": "t => Temporal_Common.plainYearMonth", + "documentation": { + "kind": "markdown", + "value": "\n`toPlainYearMonth(date)` returns the year and month of `date`.\n\nSee [`Temporal.PlainDate.prototype.toPlainYearMonth`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate/toPlainYearMonth) on MDN.\n\n## Examples\n\n```rescript\nTemporal.PlainDate.fromStringOrThrow(\"2024-02-29\")\n->Temporal.PlainDate.toPlainYearMonth\n->Temporal.PlainYearMonth.toString == \"2024-02\"\n```\n" + }, + "kind": 12, + "label": "Temporal.PlainDate.toPlainYearMonth", + "tags": [] + } + ] + |}] + +let%expect_test "completes a string function after a pipe" = + let text = {|let value = "abc" +|} in + Test.with_project ~name:"completion" ~text (fun ~root ~doc client -> + Test.change_document client doc ~version:1 ~text:(text ^ {|value->toU|}); + Test.snapshot ~root client (completion doc (1, 10))); + [%expect + {| + [ + { + "detail": "string => string", + "documentation": { + "kind": "markdown", + "value": "\n`toUpperCase(str)` converts `str` to upper case using the locale-insensitive\ncase mappings in the Unicode Character Database. Notice that the conversion can\nexpand the number of letters in the result, for example the German ß\ncapitalizes to two Ses in a row.\nSee [`String.toUpperCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase) on MDN.\n\n## Examples\n\n```rescript\nString.toUpperCase(\"abc\") == \"ABC\"\nString.toUpperCase(`Straße`) == `STRASSE`\nString.toUpperCase(`πς`) == `ΠΣ`\n```\n" + }, + "kind": 12, + "label": "String.toUpperCase", + "tags": [] + } + ] + |}] + +let%expect_test "completes a named argument in a function call" = + let text = + {|module Lib = { + let foo = (~age, ~name) => name ++ Int.toString(age) +} +|} + in + Test.with_project ~name:"completion" ~text (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(text ^ {|let x = Lib.foo(~na|}); + Test.snapshot ~root client (completion doc (3, 19))); + [%expect + {| [ { "detail": "string", "kind": 4, "label": "name", "tags": [] } ] |}] + +let%expect_test "completes a constructor from the expected variant type" = + let text = {|type someVariant = One | Two | Three(int, string) +|} in + Test.with_project ~name:"completion" ~text (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(text ^ {|let x: someVariant = O|}); + Test.snapshot ~root client (completion doc (1, 22))); + [%expect + {| + [ + { + "detail": "One", + "documentation": { + "kind": "markdown", + "value": "```rescript\nOne\n```\n\n```rescript\ntype someVariant = One | Two | Three(int, string)\n```" + }, + "insertText": "One", + "insertTextFormat": 2, + "kind": 4, + "label": "One", + "sortText": "A One", + "tags": [] + }, + { "detail": "module Option", "kind": 9, "label": "Option", "tags": [] }, + { "detail": "module Ordering", "kind": 9, "label": "Ordering", "tags": [] }, + { "detail": "module Object", "kind": 9, "label": "Object", "tags": [] }, + { + "data": { "modulePath": "Obj", "filePath": "/workspace/Test.res" }, + "detail": "module Obj", + "kind": 9, + "label": "Obj", + "tags": [] + } + ] + |}] + +let%expect_test "completes a module member in a dictionary literal with spread" + = + let text = + {|module Colors = { + let red = "red" + let green = "green" +} +let base = dict{"a": Colors.red} +|} + in + Test.with_project ~name:"completion" ~text (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(text ^ {|let x = dict{...base, "b": Colors.g}|}); + Test.snapshot ~root client (completion doc (5, 33))); + [%expect + {| [ { "detail": "string", "kind": 12, "label": "green", "tags": [] } ] |}] + +let%expect_test "completes a record field in a destructuring pattern" = + let text = + {|type someRecord = {first: int, second: bool} +let f = {first: 123, second: true} +|} + in + Test.with_project ~name:"completion" ~text (fun ~root ~doc client -> + Test.change_document client doc ~version:1 ~text:(text ^ {|let {fi} = f|}); + Test.snapshot ~root client (completion doc (2, 7))); + [%expect + {| + [ + { + "detail": "int", + "documentation": { + "kind": "markdown", + "value": "```rescript\nfirst: int\n```\n\n```rescript\ntype someRecord = {first: int, second: bool}\n```" + }, + "kind": 5, + "label": "first", + "tags": [] + } + ] + |}] + +let%expect_test + "completes a documented deprecated module member in an unsaved buffer" = + let text = + {|module Dep: { + @res.doc("Some doc comment") @deprecated("Use customDouble instead") + let customDouble: int => int +} = { + let customDouble = foo => foo * 2 +} +|} + in + Test.with_project ~name:"completion" ~text (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(text ^ {|let cc = Dep.c|}); + Test.snapshot ~root client (completion doc (6, 14))); + [%expect + {| + [ + { + "deprecated": true, + "detail": "int => int", + "documentation": { + "kind": "markdown", + "value": "Deprecated: Use customDouble instead\n\nSome doc comment" + }, + "kind": 12, + "label": "customDouble", + "tags": [ 1 ] + } + ] + |}] + +let%expect_test "completes fields on a record receiver" = + let text = + {|type person = {name: string, age: int} +let person = {name: "Alice", age: 42} +|} + in + Test.with_project ~name:"completion" ~text (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(text ^ {|let name = person.na|}); + Test.snapshot ~root client (completion doc (2, 20))); + [%expect + {| + [ + { + "detail": "string", + "documentation": { + "kind": "markdown", + "value": "```rescript\nname: string\n```\n\n```rescript\ntype person = {name: string, age: int}\n```" + }, + "kind": 5, + "label": "name", + "tags": [] + } + ] + |}] + +let%expect_test "does not offer a module member with an unmatched prefix" = + let text = + {|module Lib = { + let next = (~number=0, ~year) => number + year +} +|} + in + Test.with_project ~name:"completion" ~text (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(text ^ {|let x = Lib.zzzz|}); + Test.snapshot ~root client (completion doc (3, 16))); + [%expect {| [] |}] diff --git a/tests/lsp_tests/completion_generic_jsx.ml b/tests/lsp_tests/completion_generic_jsx.ml new file mode 100644 index 00000000000..c7138fa79ba --- /dev/null +++ b/tests/lsp_tests/completion_generic_jsx.ml @@ -0,0 +1,166 @@ +let generic_jsx = + {|type element = Jsx.element +type component<'props> = Jsx.component<'props> +type componentLike<'props, 'return> = Jsx.componentLike<'props, 'return> +external component: componentLike<'props, element> => component<'props> = "%component_identity" +@module("preact") external jsx: (component<'props>, 'props) => element = "jsx" +@module("preact") external jsxKeyed: (component<'props>, 'props, ~key: string=?, @ignore unit) => element = "jsx" +@module("preact") external jsxs: (component<'props>, 'props) => element = "jsxs" +@module("preact") external jsxsKeyed: (component<'props>, 'props, ~key: string=?, @ignore unit) => element = "jsxs" +external array: array => element = "%identity" +@val external null: element = "null" +external string: string => element = "%identity" +module Elements = { + type props = {testing?: bool, test2?: string, children?: element} + @module("preact") external jsx: (string, props) => element = "jsx" + @module("preact") external jsxKeyed: (string, props, ~key: string=?, @ignore unit) => element = "jsx" + @module("preact") external jsxs: (string, props) => element = "jsxs" + @module("preact") external jsxsKeyed: (string, props, ~key: string=?, @ignore unit) => element = "jsxs" +} +|} + +let with_project ~text f = + Test.with_project ~name:"generic-jsx" ~text + ~rescript_json: + {|{"name":"generic-jsx","sources":{"dir":"."},"jsx":{"module":"GenericJsx"}}|} + ~files:[("GenericJsx.res", generic_jsx)] + f + +let%expect_test "completes intrinsic props from a custom JSX runtime" = + with_project ~text:{|let _ = GenericJsx.null +|} (fun ~root ~doc client -> + Test.change_document client doc ~version:1 ~text:{|let _ =
+ Test.change_document client doc ~version:1 + ~text:{|let _ =
{ + let someString = "" +|} + +let component = + component_prefix ^ {| GenericJsx.string(someProp ++ someString) + } +} +|} + +let%expect_test "offers a custom JSX string conversion in a component body" = + with_project ~text:component (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(component_prefix ^ {| someString->st + } +} +|}); + Test.snapshot ~root client (Completion.completion doc (4, 18))); + [%expect + {| + [ + { + "detail": "string", + "documentation": { + "kind": "markdown", + "value": "Turns `string` into a JSX element so it can be used inside of JSX." + }, + "insertTextFormat": 2, + "kind": 12, + "label": "GenericJsx.string", + "sortText": "A", + "tags": [] + }, + { + "detail": "(string, string) => bool", + "documentation": { + "kind": "markdown", + "value": "\n`startsWith(str, substr)` returns `true` if the `str` starts with `substr`,\n`false` otherwise.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWith(\"BuckleScript\", \"Buckle\") == true\nString.startsWith(\"BuckleScript\", \"\") == true\nString.startsWith(\"JavaScript\", \"Buckle\") == false\n```\n" + }, + "kind": 12, + "label": "String.startsWith", + "tags": [] + }, + { + "detail": "(string, string, int) => bool", + "documentation": { + "kind": "markdown", + "value": "\n`startsWithFrom(str, substr, n)` returns `true` if the `str` starts\nwith `substr` starting at position `n`, `false` otherwise. If `n` is negative,\nthe search starts at the beginning of `str`.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWithFrom(\"BuckleScript\", \"kle\", 3) == true\nString.startsWithFrom(\"BuckleScript\", \"\", 3) == true\nString.startsWithFrom(\"JavaScript\", \"Buckle\", 2) == false\n```\n" + }, + "kind": 12, + "label": "String.startsWithFrom", + "tags": [] + } + ] + |}] + +let%expect_test "offers a custom JSX string conversion with the runtime open" = + with_project ~text:component (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text: + (component_prefix + ^ {| open GenericJsx +
+ {someString->st} +
+ } +} +|} + ); + Test.snapshot ~root client (Completion.completion doc (6, 21))); + [%expect + {| + [ + { + "detail": "string", + "documentation": { + "kind": "markdown", + "value": "Turns `string` into a JSX element so it can be used inside of JSX." + }, + "insertTextFormat": 2, + "kind": 12, + "label": "string", + "sortText": "A", + "tags": [] + }, + { + "detail": "(string, string) => bool", + "documentation": { + "kind": "markdown", + "value": "\n`startsWith(str, substr)` returns `true` if the `str` starts with `substr`,\n`false` otherwise.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWith(\"BuckleScript\", \"Buckle\") == true\nString.startsWith(\"BuckleScript\", \"\") == true\nString.startsWith(\"JavaScript\", \"Buckle\") == false\n```\n" + }, + "kind": 12, + "label": "String.startsWith", + "tags": [] + }, + { + "detail": "(string, string, int) => bool", + "documentation": { + "kind": "markdown", + "value": "\n`startsWithFrom(str, substr, n)` returns `true` if the `str` starts\nwith `substr` starting at position `n`, `false` otherwise. If `n` is negative,\nthe search starts at the beginning of `str`.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWithFrom(\"BuckleScript\", \"kle\", 3) == true\nString.startsWithFrom(\"BuckleScript\", \"\", 3) == true\nString.startsWithFrom(\"JavaScript\", \"Buckle\", 2) == false\n```\n" + }, + "kind": 12, + "label": "String.startsWithFrom", + "tags": [] + } + ] + |}] diff --git a/tests/lsp_tests/completion_jsx.ml b/tests/lsp_tests/completion_jsx.ml new file mode 100644 index 00000000000..bbf8d29c1a7 --- /dev/null +++ b/tests/lsp_tests/completion_jsx.ml @@ -0,0 +1,36 @@ +module Completion_test = Completion + +let%expect_test "completes a nested JSX component prop" = + let text = + {|module O = { + module Comp = { + @react.component + let make = (~first="", ~zoo=3, ~second) => React.string(first ++ second ++ Int.toString(zoo)) + } +} +|} + in + Test.with_project ~name:"completion-jsx" ~jsx:true ~text + (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(text ^ {|let comp = ", "kind": 4, "label": "zoo", "tags": [] } ] |}] + +let%expect_test "completes a value in a JSX prop expression" = + let text = + {|module Comp = { + @react.component + let make = (~second) => React.string(second) +} +let zzz = "hello" +|} + in + Test.with_project ~name:"completion-jsx" ~jsx:true ~text + (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(text ^ {|let comp = + Test.change_document client doc ~version:1 ~text:{|let x = 1 +ModuleStu|}; + let items = + match Test.Client.request client (Completion.completion doc (1, 9)) with + | Some (`List items) -> items + | Some (`CompletionList list) -> list.items + | None -> failwith "Expected module completion" + in + let item = + List.find + (fun (item : CompletionItem.t) -> item.label = "ModuleStuff") + items + in + Test.snapshot ~root client (Client_request.CompletionItemResolve item)); + [%expect + {| + { + "data": { "modulePath": "ModuleStuff", "filePath": "/workspace/Test.res" }, + "detail": "module ModuleStuff", + "documentation": { + "kind": "markdown", + "value": " This is a top level module doc. " + }, + "kind": 9, + "label": "ModuleStuff", + "tags": [] + } + |}] + +let%expect_test "keeps an item without resolve metadata unchanged" = + Test.with_project ~name:"completion-resolve" ~text:{|let x = 1 +|} + (fun ~root ~doc:_ client -> + Test.snapshot ~root client + (Client_request.CompletionItemResolve + (CompletionItem.create ~label:"x" ()))); + [%expect {| { "label": "x" } |}] + +let%expect_test "preserves documentation already supplied on an item" = + Test.with_project ~name:"completion-resolve" ~text:{|let x = 1 +|} + (fun ~root ~doc:_ client -> + Test.snapshot ~root client + (Client_request.CompletionItemResolve + (CompletionItem.create ~label:"x" + ~documentation:(`String "Existing docs") ()))); + [%expect {| { "documentation": "Existing docs", "label": "x" } |}] diff --git a/tests/lsp_tests/completion_typed_arrays.ml b/tests/lsp_tests/completion_typed_arrays.ml new file mode 100644 index 00000000000..c2fcb2fa774 --- /dev/null +++ b/tests/lsp_tests/completion_typed_arrays.ml @@ -0,0 +1,350 @@ +let test_completion ~text ~receiver = + Test.with_project ~name:"typed-array-completion" ~text + (fun ~root ~doc client -> + (* Use one shared method prefix to check inferred receiver lookup and + element types without repeating every method's documentation. *) + let expression = receiver ^ ".findLastIndexWithIndex" in + Test.change_document client doc ~version:1 ~text:(text ^ expression); + Test.snapshot ~root client + (Completion.completion doc (1, String.length expression))) + +let%expect_test "completes methods on a BigInt64Array receiver" = + test_completion ~text:{|let value = BigInt64Array.fromLength(0) +|} + ~receiver:"value"; + [%expect + {| + [ + { + "additionalTextEdits": [ + { + "newText": "", + "range": { + "end": { "character": 6, "line": 1 }, + "start": { "character": 5, "line": 1 } + } + } + ], + "detail": "(t, (bigint, int) => bool) => int", + "documentation": { + "kind": "markdown", + "value": "\n `findLastIndexWithIndex(typedArray, predicate)` is the indexed variant of `findLastIndex`.\n " + }, + "insertText": "->BigInt64Array.findLastIndexWithIndex", + "kind": 12, + "label": "->BigInt64Array.findLastIndexWithIndex", + "sortText": "findLastIndexWithIndex", + "tags": [] + } + ] + |}] + +let%expect_test "completes methods on a BigUint64Array receiver" = + test_completion ~text:{|let value = BigUint64Array.fromLength(0) +|} + ~receiver:"value"; + [%expect + {| + [ + { + "additionalTextEdits": [ + { + "newText": "", + "range": { + "end": { "character": 6, "line": 1 }, + "start": { "character": 5, "line": 1 } + } + } + ], + "detail": "(t, (bigint, int) => bool) => int", + "documentation": { + "kind": "markdown", + "value": "\n `findLastIndexWithIndex(typedArray, predicate)` is the indexed variant of `findLastIndex`.\n " + }, + "insertText": "->BigUint64Array.findLastIndexWithIndex", + "kind": 12, + "label": "->BigUint64Array.findLastIndexWithIndex", + "sortText": "findLastIndexWithIndex", + "tags": [] + } + ] + |}] + +let%expect_test "completes methods on a Float32Array receiver" = + test_completion ~text:{|let value = Float32Array.fromLength(0) +|} + ~receiver:"value"; + [%expect + {| + [ + { + "additionalTextEdits": [ + { + "newText": "", + "range": { + "end": { "character": 6, "line": 1 }, + "start": { "character": 5, "line": 1 } + } + } + ], + "detail": "(t, (float, int) => bool) => int", + "documentation": { + "kind": "markdown", + "value": "\n `findLastIndexWithIndex(typedArray, predicate)` is the indexed variant of `findLastIndex`.\n " + }, + "insertText": "->Float32Array.findLastIndexWithIndex", + "kind": 12, + "label": "->Float32Array.findLastIndexWithIndex", + "sortText": "findLastIndexWithIndex", + "tags": [] + } + ] + |}] + +let%expect_test "completes methods on a Float64Array receiver" = + test_completion ~text:{|let value = Float64Array.fromLength(0) +|} + ~receiver:"value"; + [%expect + {| + [ + { + "additionalTextEdits": [ + { + "newText": "", + "range": { + "end": { "character": 6, "line": 1 }, + "start": { "character": 5, "line": 1 } + } + } + ], + "detail": "(t, (float, int) => bool) => int", + "documentation": { + "kind": "markdown", + "value": "\n `findLastIndexWithIndex(typedArray, predicate)` is the indexed variant of `findLastIndex`.\n " + }, + "insertText": "->Float64Array.findLastIndexWithIndex", + "kind": 12, + "label": "->Float64Array.findLastIndexWithIndex", + "sortText": "findLastIndexWithIndex", + "tags": [] + } + ] + |}] + +let%expect_test "completes methods on an Int16Array receiver" = + test_completion ~text:{|let value = Int16Array.fromLength(0) +|} + ~receiver:"value"; + [%expect + {| + [ + { + "additionalTextEdits": [ + { + "newText": "", + "range": { + "end": { "character": 6, "line": 1 }, + "start": { "character": 5, "line": 1 } + } + } + ], + "detail": "(t, (int, int) => bool) => int", + "documentation": { + "kind": "markdown", + "value": "\n `findLastIndexWithIndex(typedArray, predicate)` is the indexed variant of `findLastIndex`.\n " + }, + "insertText": "->Int16Array.findLastIndexWithIndex", + "kind": 12, + "label": "->Int16Array.findLastIndexWithIndex", + "sortText": "findLastIndexWithIndex", + "tags": [] + } + ] + |}] + +let%expect_test "completes methods on an Int32Array receiver" = + test_completion ~text:{|let value = Int32Array.fromLength(0) +|} + ~receiver:"value"; + [%expect + {| + [ + { + "additionalTextEdits": [ + { + "newText": "", + "range": { + "end": { "character": 6, "line": 1 }, + "start": { "character": 5, "line": 1 } + } + } + ], + "detail": "(t, (int, int) => bool) => int", + "documentation": { + "kind": "markdown", + "value": "\n `findLastIndexWithIndex(typedArray, predicate)` is the indexed variant of `findLastIndex`.\n " + }, + "insertText": "->Int32Array.findLastIndexWithIndex", + "kind": 12, + "label": "->Int32Array.findLastIndexWithIndex", + "sortText": "findLastIndexWithIndex", + "tags": [] + } + ] + |}] + +let%expect_test "completes methods on an Int8Array receiver" = + test_completion ~text:{|let value = Int8Array.fromLength(0) +|} + ~receiver:"value"; + [%expect + {| + [ + { + "additionalTextEdits": [ + { + "newText": "", + "range": { + "end": { "character": 6, "line": 1 }, + "start": { "character": 5, "line": 1 } + } + } + ], + "detail": "(t, (int, int) => bool) => int", + "documentation": { + "kind": "markdown", + "value": "\n `findLastIndexWithIndex(typedArray, predicate)` is the indexed variant of `findLastIndex`.\n " + }, + "insertText": "->Int8Array.findLastIndexWithIndex", + "kind": 12, + "label": "->Int8Array.findLastIndexWithIndex", + "sortText": "findLastIndexWithIndex", + "tags": [] + } + ] + |}] + +let%expect_test "completes methods on a Uint16Array receiver" = + test_completion ~text:{|let value = Uint16Array.fromLength(0) +|} + ~receiver:"value"; + [%expect + {| + [ + { + "additionalTextEdits": [ + { + "newText": "", + "range": { + "end": { "character": 6, "line": 1 }, + "start": { "character": 5, "line": 1 } + } + } + ], + "detail": "(t, (int, int) => bool) => int", + "documentation": { + "kind": "markdown", + "value": "\n `findLastIndexWithIndex(typedArray, predicate)` is the indexed variant of `findLastIndex`.\n " + }, + "insertText": "->Uint16Array.findLastIndexWithIndex", + "kind": 12, + "label": "->Uint16Array.findLastIndexWithIndex", + "sortText": "findLastIndexWithIndex", + "tags": [] + } + ] + |}] + +let%expect_test "completes methods on a Uint32Array receiver" = + test_completion ~text:{|let value = Uint32Array.fromLength(0) +|} + ~receiver:"value"; + [%expect + {| + [ + { + "additionalTextEdits": [ + { + "newText": "", + "range": { + "end": { "character": 6, "line": 1 }, + "start": { "character": 5, "line": 1 } + } + } + ], + "detail": "(t, (int, int) => bool) => int", + "documentation": { + "kind": "markdown", + "value": "\n `findLastIndexWithIndex(typedArray, predicate)` is the indexed variant of `findLastIndex`.\n " + }, + "insertText": "->Uint32Array.findLastIndexWithIndex", + "kind": 12, + "label": "->Uint32Array.findLastIndexWithIndex", + "sortText": "findLastIndexWithIndex", + "tags": [] + } + ] + |}] + +let%expect_test "completes methods on a Uint8Array receiver" = + test_completion ~text:{|let value = Uint8Array.fromLength(0) +|} + ~receiver:"value"; + [%expect + {| + [ + { + "additionalTextEdits": [ + { + "newText": "", + "range": { + "end": { "character": 6, "line": 1 }, + "start": { "character": 5, "line": 1 } + } + } + ], + "detail": "(t, (int, int) => bool) => int", + "documentation": { + "kind": "markdown", + "value": "\n `findLastIndexWithIndex(typedArray, predicate)` is the indexed variant of `findLastIndex`.\n " + }, + "insertText": "->Uint8Array.findLastIndexWithIndex", + "kind": 12, + "label": "->Uint8Array.findLastIndexWithIndex", + "sortText": "findLastIndexWithIndex", + "tags": [] + } + ] + |}] + +let%expect_test "completes methods on a Uint8ClampedArray receiver" = + test_completion ~text:{|let value = Uint8ClampedArray.fromLength(0) +|} + ~receiver:"value"; + [%expect + {| + [ + { + "additionalTextEdits": [ + { + "newText": "", + "range": { + "end": { "character": 6, "line": 1 }, + "start": { "character": 5, "line": 1 } + } + } + ], + "detail": "(t, (int, int) => bool) => int", + "documentation": { + "kind": "markdown", + "value": "\n `findLastIndexWithIndex(typedArray, predicate)` is the indexed variant of `findLastIndex`.\n " + }, + "insertText": "->Uint8ClampedArray.findLastIndexWithIndex", + "kind": 12, + "label": "->Uint8ClampedArray.findLastIndexWithIndex", + "sortText": "findLastIndexWithIndex", + "tags": [] + } + ] + |}] diff --git a/tests/lsp_tests/create_interface.ml b/tests/lsp_tests/create_interface.ml new file mode 100644 index 00000000000..e3f96c63add --- /dev/null +++ b/tests/lsp_tests/create_interface.ml @@ -0,0 +1,118 @@ +open Lsp +open Types + +let create_interface doc = + Client_request.UnknownRequest + { + meth = "textDocument/createInterface"; + params = + Some + (Jsonrpc.Structured.t_of_yojson + (TextDocumentIdentifier.yojson_of_t (Test.text_document doc))); + } + +let create_and_print ~root ~doc client = + let response = Test.Client.request client (create_interface doc) in + Test.print_json ~root response; + let interface = TextDocumentIdentifier.t_of_yojson response in + In_channel.with_open_bin (Uri.to_path interface.uri) In_channel.input_all + |> print_string + +let%expect_test "creates an interface for components with optional props" = + Test.with_project ~name:"create-interface-jsx" ~jsx:true + ~text: + {|@react.component +let make = (~name, ~count=3) => React.string(name ++ Int.toString(count)) +module Other = { + @react.component + let make = (~children) => children +} +|} + create_and_print; + [%expect + {| + { "uri": "file:///workspace/Test.resi" } + @react.component + let make: (~name: string, ~count: int=?) => React.element + module Other: { + @react.component + let make: (~children: React.element) => React.element + } + |}] + +let%expect_test "preserves functors and module type constraints" = + Test.with_project ~name:"create-interface" + ~text: + {|module type Input = { + type t + let value: t +} +module Make = (X: Input) => { + type t = X.t + let value = X.value +} +|} + create_and_print; + [%expect + {| + { "uri": "file:///workspace/Test.resi" } + module type Input = { + type t + let value: t + } + module Make: ( + X: Input, + ) => + { + type t = X.t + let value: X.t + } + |}] + +let%expect_test + "preserves polymorphic variants and external argument attributes" = + Test.with_project ~name:"create-interface" + ~text: + {|type red = [#Ruby | #Redwood | #Rust] +type blue = [#Sapphire | #Neon | #Navy] +type color = [red | blue | #Papayawhip] +external upperBound: ([< #d | #e | #f]) => unit = "myexternal" +external x: (@as("bar") ~foo: int) => unit = "myexternal" +|} + create_and_print; + [%expect + {| + { "uri": "file:///workspace/Test.resi" } + type red = [#Ruby | #Redwood | #Rust] + type blue = [#Sapphire | #Neon | #Navy] + type color = [red | blue | #Papayawhip] + external upperBound: ([< #d | #e | #f]) => unit = "myexternal" + external x: (@as("bar") ~foo: int) => unit = "myexternal" + |}] + +let%expect_test "creates an interface for records and labeled functions" = + Test.with_project ~name:"create-interface" + ~text:{|type r = {name: string, age: int} +let add = (~x, ~y) => x + y +|} + create_and_print; + [%expect + {| + { "uri": "file:///workspace/Test.resi" } + type r = {name: string, age: int} + let add: (~x: int, ~y: int) => int + |}] + +let%expect_test "preserves external declarations and inline constants" = + Test.with_project ~name:"create-interface" + ~text: + {|@module("path") external dirname: string => string = "dirname" +@inline let f1 = 10 +|} + create_and_print; + [%expect + {| + { "uri": "file:///workspace/Test.resi" } + @module("path") external dirname: string => string = "dirname" + @inline let f1: int + |}] diff --git a/tests/lsp_tests/definition.ml b/tests/lsp_tests/definition.ml new file mode 100644 index 00000000000..cc32e4efc7e --- /dev/null +++ b/tests/lsp_tests/definition.ml @@ -0,0 +1,199 @@ +open Lsp +open Types + +let definition doc pos = + Client_request.TextDocumentDefinition + (DefinitionParams.create ~textDocument:(Test.text_document doc) + ~position:(Test.position pos) ()) + +let%expect_test "follows a module alias to a value in another file" = + Test.with_project ~name:"definition" + ~text:{|module Alias = Other +let x = Alias.value +|} + ~files:[("Other.res", {|let value = 42 +|})] + (fun ~root ~doc client -> + Test.snapshot ~root client (definition doc (1, 16))); + [%expect + {| + [ + { + "range": { + "end": { "character": 9, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "uri": "file:///workspace/Other.res" + } + ] + |}] + +let%expect_test "finds a value bound by tuple destructuring" = + Test.with_project ~name:"definition" + ~text: + {|module A = { + let makeX = () => (1, 2) + let (xxx, yyy) = makeX() +} +let y = A.xxx +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (definition doc (4, 10))); + [%expect + {| + [ + { + "range": { + "end": { "character": 10, "line": 2 }, + "start": { "character": 7, "line": 2 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test "finds a value bound by record destructuring" = + Test.with_project ~name:"definition" + ~text: + {|module A = { + type t = {name: string, age: int} + let makeT = () => {name: "", age: 0} + let {name, age} = makeT() +} +let n1 = A.name +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (definition doc (5, 11))); + [%expect + {| + [ + { + "range": { + "end": { "character": 11, "line": 3 }, + "start": { "character": 7, "line": 3 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test "finds a React component from a JSX tag" = + Test.with_project ~name:"definition-jsx" ~jsx:true + ~text: + {|module Comp = { + @react.component + let make = (~name) => React.string(name) +} +let element = +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (definition doc (4, 16))); + [%expect + {| + [ + { + "range": { + "end": { "character": 10, "line": 2 }, + "start": { "character": 6, "line": 2 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test "finds a local value declaration" = + Test.with_project ~name:"definition" ~text:{|let xx = 10 +let y = xx +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (definition doc (1, 8))); + [%expect + {| + [ + { + "range": { + "end": { "character": 6, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test "finds a type inside a nested module" = + Test.with_project ~name:"definition" + ~text: + {|module Inner = { + type tInner = int +} +type typeInner = Inner.tInner +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (definition doc (3, 24))); + [%expect + {| + [ + { + "range": { + "end": { "character": 13, "line": 1 }, + "start": { "character": 7, "line": 1 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test "finds a value declaration in an open interface" = + Test.with_project ~name:"definition" ~text:{|let y = 4 +|} + ~files:[("Test.resi", {|let y: int +|})] + (fun ~root ~doc:_ client -> + let doc = + Test.make_document + ~uri:(Uri.of_path (Filename.concat root "Test.resi")) + ~text:{|let y: int +|} + in + Test.perform client (Test.open_document doc); + Test.snapshot ~root client (definition doc (0, 4))); + [%expect + {| + [ + { + "range": { + "end": { "character": 5, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "uri": "file:///workspace/Test.resi" + } + ] + |}] + +let%expect_test "finds an exported value in another file" = + Test.with_project ~name:"definition" ~text:{|let y = Other.x +|} + ~files:[("Other.res", {|let x = 12 +|})] + (fun ~root ~doc client -> + Test.snapshot ~root client (definition doc (0, 14))); + [%expect + {| + [ + { + "range": { + "end": { "character": 5, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "uri": "file:///workspace/Other.res" + } + ] + |}] + +let%expect_test "returns no definition in a comment" = + Test.with_project ~name:"definition" ~text:{|let x = 12 +// x +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (definition doc (1, 3))); + [%expect {| null |}] diff --git a/tests/lsp_tests/diagnostics.ml b/tests/lsp_tests/diagnostics.ml new file mode 100644 index 00000000000..1a77f86ba3f --- /dev/null +++ b/tests/lsp_tests/diagnostics.ml @@ -0,0 +1,373 @@ +module Syntax_test = Document_syntax + +open Lsp +open Types + +let ( /+ ) = Filename.concat +let push_capabilities = ClientCapabilities.create () + +let notify_log ~root client = + Test.Client.send_notification client + (Client_notification.DidChangeWatchedFiles + (DidChangeWatchedFilesParams.create + ~changes: + [ + FileEvent.create ~type_:FileChangeType.Changed + ~uri: + (Uri.of_path (root /+ "lib" /+ "rescript" /+ ".compiler.log")); + ])) + +(* Write each build phase explicitly so a partial compiler log is observable + deterministically, without racing a real compiler watcher. *) +let write_log ~root client content = + Test.write_file (root /+ "lib" /+ "rescript" /+ ".compiler.log") content; + notify_log ~root client + +let publications client = + Test.synchronize client; + Test.Client.take_notifications client + |> List.filter_map (fun (notification : Jsonrpc.Notification.t) -> + if notification.method_ = "textDocument/publishDiagnostics" then + Some (Option.get notification.params |> Jsonrpc.Structured.yojson_of_t) + else None) + +let print_publications ~root client = + publications client |> fun items -> Test.print_json ~root (`List items) + +let close_document client doc = + Test.Client.send_notification client + (Client_notification.TextDocumentDidClose + (DidCloseTextDocumentParams.create ~textDocument:(Test.text_document doc))) + +let save_document client (doc : TextDocumentItem.t) ~text = + Test.write_file (Uri.to_path doc.uri) text; + Test.Client.send_notification client + (Client_notification.DidSaveTextDocument + (DidSaveTextDocumentParams.create ~textDocument:(Test.text_document doc) + ())) + +let warning_log = + {|#Start(1) +Warning number 26 +Test.res:1:5-9 + +unused variable value. + +#Done(2) +|} + +let syntax_log = + {|#Start(3) +Syntax error! +Test.res:1:12-12 + +Did you forget to write an expression here? + +#Done(4) +|} + +let%expect_test + "removes a compiler warning after saving and rebuilding clean code" = + let clean = {|let value = () => 2 +|} in + let warning = {|let value = () => { + let unused = 1 + 2 +} +|} in + Test.with_project ~name:"diagnostics" ~text:clean (fun ~root ~doc client -> + Test.change_document client doc ~version:1 ~text:warning; + save_document client doc ~text:warning; + Test.run_rescript_build ~root; + notify_log ~root client; + Test.snapshot ~root client (Syntax_test.diagnostics doc); + Test.change_document client doc ~version:2 ~text:clean; + save_document client doc ~text:clean; + Test.run_rescript_build ~root; + notify_log ~root client; + Test.snapshot ~root client (Syntax_test.diagnostics doc)); + [%expect + {| + { + "kind": "full", + "items": [ + { + "message": "Warning 26 - unused variable unused.\nFix this by:\n- Deleting the variable if it's not used anymore.\n- Prepending the variable name with `_` (like `_unused`) to ignore that the variable is unused.\n- Using the variable somewhere.", + "range": { + "end": { "character": 12, "line": 1 }, + "start": { "character": 6, "line": 1 } + }, + "severity": 2, + "source": "ReScript" + } + ] + } + { "kind": "full", "items": [] } + |}] + +let%expect_test "does not clear pushed warnings during an incomplete build" = + Test.with_project ~name:"diagnostics" ~capabilities:push_capabilities + ~text:{|let value = 1 +|} (fun ~root ~doc client -> + ignore (publications client); + write_log ~root client warning_log; + print_endline "completed build:"; + print_publications ~root client; + write_log ~root client {|#Start(3) +|}; + print_endline "build started:"; + print_publications ~root client; + Test.change_document client doc ~version:1 ~text:doc.text; + save_document client doc ~text:doc.text; + print_endline "save during build:"; + print_publications ~root client; + write_log ~root client warning_log; + print_endline "next completed build:"; + print_publications ~root client); + [%expect + {| + completed build: + [ + { + "diagnostics": [ + { + "message": "Warning 26 - unused variable value.", + "range": { + "end": { "character": 9, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "severity": 2, + "source": "ReScript" + } + ], + "uri": "file:///workspace/Test.res" + } + ] + build started: + [] + save during build: + [ + { + "diagnostics": [ + { + "message": "Warning 26 - unused variable value.", + "range": { + "end": { "character": 9, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "severity": 2, + "source": "ReScript" + } + ], + "uri": "file:///workspace/Test.res" + } + ] + next completed build: + [ + { + "diagnostics": [ + { + "message": "Warning 26 - unused variable value.", + "range": { + "end": { "character": 9, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "severity": 2, + "source": "ReScript" + } + ], + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test + "moves compiler diagnostics between pull and push without duplication" = + Test.with_project ~name:"diagnostics" ~text:{|let value = 1 +|} + (fun ~root ~doc client -> + ignore (publications client); + write_log ~root client warning_log; + print_endline "open document pushes:"; + print_publications ~root client; + print_endline "open document pull:"; + Test.snapshot ~root client (Syntax_test.diagnostics doc); + close_document client doc; + print_endline "closed document pushes:"; + print_publications ~root client; + Test.perform client (Test.open_document doc); + print_endline "reopened document pushes:"; + print_publications ~root client; + print_endline "reopened document pull:"; + Test.snapshot ~root client (Syntax_test.diagnostics doc)); + [%expect + {| + open document pushes: + [] + open document pull: + { + "kind": "full", + "items": [ + { + "message": "Warning 26 - unused variable value.", + "range": { + "end": { "character": 9, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "severity": 2, + "source": "ReScript" + } + ] + } + closed document pushes: + [ + { + "diagnostics": [ + { + "message": "Warning 26 - unused variable value.", + "range": { + "end": { "character": 9, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "severity": 2, + "source": "ReScript" + } + ], + "uri": "file:///workspace/Test.res" + } + ] + reopened document pushes: + [ { "diagnostics": [], "uri": "file:///workspace/Test.res" } ] + reopened document pull: + { + "kind": "full", + "items": [ + { + "message": "Warning 26 - unused variable value.", + "range": { + "end": { "character": 9, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "severity": 2, + "source": "ReScript" + } + ] + } + |}] + +let%expect_test "clears unsaved syntax diagnostics when a document closes" = + Test.with_project ~name:"diagnostics" ~capabilities:push_capabilities + ~text:{|let value = 1 +|} (fun ~root ~doc client -> + ignore (publications client); + Test.change_document client doc ~version:1 ~text:{|let value = +|}; + print_endline "unsaved buffer:"; + print_publications ~root client; + close_document client doc; + print_endline "closed:"; + print_publications ~root client); + [%expect + {| + unsaved buffer: + [ + { + "diagnostics": [ + { + "message": "This let-binding misses an expression", + "range": { + "end": { "character": 0, "line": 1 }, + "start": { "character": 11, "line": 0 } + }, + "severity": 1, + "source": "ReScript" + } + ], + "uri": "file:///workspace/Test.res" + } + ] + closed: + [ { "diagnostics": [], "uri": "file:///workspace/Test.res" } ] + |}] + +let%expect_test + "keeps saved compiler syntax diagnostics after closing the buffer" = + Test.with_project ~name:"diagnostics" ~capabilities:push_capabilities + ~text:{|let value = 1 +|} (fun ~root ~doc client -> + ignore (publications client); + let text = {|let value = +|} in + Test.change_document client doc ~version:1 ~text; + save_document client doc ~text; + write_log ~root client syntax_log; + ignore (publications client); + close_document client doc; + print_publications ~root client); + [%expect + {| + [ + { + "diagnostics": [ + { + "message": "Did you forget to write an expression here?", + "range": { + "end": { "character": 12, "line": 0 }, + "start": { "character": 11, "line": 0 } + }, + "severity": 1, + "source": "ReScript" + } + ], + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test + "preserves other files type errors while the build has only syntax errors" = + Test.with_project ~name:"diagnostics" ~text:{|let value = 1 +|} + ~files:[("Other.res", {|let value = 1 +|})] + (fun ~root ~doc client -> + write_log ~root client + {|#Start(1) +We've found a bug for you! +Other.res:1:13-13 + +This has type: int +Somewhere wanted: string + +#Done(2) +|}; + Test.synchronize client; + Test.change_document client doc ~version:1 ~text:{|let value = +|}; + write_log ~root client syntax_log; + let other = + Test.make_document ~uri:(Uri.of_path (root /+ "Other.res")) ~text:{||} + in + Test.snapshot ~root client (Syntax_test.diagnostics other); + write_log ~root client {|#Start(5) +#Done(6) +|}; + Test.snapshot ~root client (Syntax_test.diagnostics other)); + [%expect + {| + { + "kind": "full", + "items": [ + { + "message": "This has type: int\nSomewhere wanted: string", + "range": { + "end": { "character": 13, "line": 0 }, + "start": { "character": 12, "line": 0 } + }, + "severity": 1, + "source": "ReScript" + } + ] + } + { "kind": "full", "items": [] } + |}] diff --git a/tests/lsp_tests/document_changes.ml b/tests/lsp_tests/document_changes.ml new file mode 100644 index 00000000000..bae0a23be30 --- /dev/null +++ b/tests/lsp_tests/document_changes.ml @@ -0,0 +1,41 @@ +open Lsp +open Types + +let%expect_test + "applies a partial text change before computing document symbols" = + Test.with_project ~name:"partial-text-change" ~run_build:false + ~text:{|let value = 1 +|} (fun ~root ~doc client -> + Test.Client.send_notification client + (Client_notification.TextDocumentDidChange + (DidChangeTextDocumentParams.create + ~textDocument: + (VersionedTextDocumentIdentifier.create ~uri:doc.uri ~version:1) + ~contentChanges: + [ + `TextDocumentContentChangePartial + (TextDocumentContentChangePartial.create + ~range:(Test.range (0, 4) (0, 9)) + ~text:"renamed" ()); + ])); + Test.snapshot ~root client + (Client_request.DocumentSymbol + (DocumentSymbolParams.create ~textDocument:(Test.text_document doc) + ()))); + [%expect + {| + [ + { + "kind": 16, + "name": "renamed", + "range": { + "end": { "character": 15, "line": 0 }, + "start": { "character": 0, "line": 0 } + }, + "selectionRange": { + "end": { "character": 15, "line": 0 }, + "start": { "character": 0, "line": 0 } + } + } + ] + |}] diff --git a/tests/lsp_tests/document_symbol.ml b/tests/lsp_tests/document_symbol.ml new file mode 100644 index 00000000000..79279de1019 --- /dev/null +++ b/tests/lsp_tests/document_symbol.ml @@ -0,0 +1,103 @@ +open Lsp +open Types + +let symbols doc = + Client_request.DocumentSymbol + (DocumentSymbolParams.create ~textDocument:(Test.text_document doc) ()) + +let%expect_test "lists nested module types and functions with their ranges" = + Test.with_project ~name:"document-symbol" ~run_build:false + ~text: + {|module ForAuto = { + type t = int + let abc = (x: t, _y: int) => x +} +let fa: ForAuto.t = 34 +|} + (fun ~root ~doc client -> Test.snapshot ~root client (symbols doc)); + [%expect + {| + [ + { + "kind": 16, + "name": "fa", + "range": { + "end": { "character": 22, "line": 4 }, + "start": { "character": 0, "line": 4 } + }, + "selectionRange": { + "end": { "character": 22, "line": 4 }, + "start": { "character": 0, "line": 4 } + } + }, + { + "children": [ + { + "kind": 12, + "name": "abc", + "range": { + "end": { "character": 32, "line": 2 }, + "start": { "character": 2, "line": 2 } + }, + "selectionRange": { + "end": { "character": 32, "line": 2 }, + "start": { "character": 2, "line": 2 } + } + }, + { + "kind": 26, + "name": "t", + "range": { + "end": { "character": 14, "line": 1 }, + "start": { "character": 2, "line": 1 } + }, + "selectionRange": { + "end": { "character": 14, "line": 1 }, + "start": { "character": 2, "line": 1 } + } + } + ], + "kind": 2, + "name": "ForAuto", + "range": { + "end": { "character": 1, "line": 3 }, + "start": { "character": 7, "line": 0 } + }, + "selectionRange": { + "end": { "character": 1, "line": 3 }, + "start": { "character": 7, "line": 0 } + } + } + ] + |}] + +let%expect_test "updates symbols from the unsaved document" = + Test.with_project ~name:"document-symbol" ~run_build:false + ~text:{|let zzz = 11 +|} (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:{|let bracedFunction = {x => x + 1} +|}; + Test.snapshot ~root client (symbols doc)); + [%expect + {| + [ + { + "kind": 12, + "name": "bracedFunction", + "range": { + "end": { "character": 33, "line": 0 }, + "start": { "character": 0, "line": 0 } + }, + "selectionRange": { + "end": { "character": 33, "line": 0 }, + "start": { "character": 0, "line": 0 } + } + } + ] + |}] + +let%expect_test "returns no symbols for an empty document" = + Test.with_project ~name:"document-symbol" ~run_build:false ~text:{||} + (fun ~root ~doc client -> Test.snapshot ~root client (symbols doc)); + [%expect {| [] |}] diff --git a/tests/lsp_tests/document_syntax.ml b/tests/lsp_tests/document_syntax.ml new file mode 100644 index 00000000000..97df7ce71f1 --- /dev/null +++ b/tests/lsp_tests/document_syntax.ml @@ -0,0 +1,104 @@ +open Lsp +open Types + +let diagnostics doc = + Client_request.TextDocumentDiagnostic + (DocumentDiagnosticParams.create ~textDocument:(Test.text_document doc) ()) + +let%expect_test "reports parser errors without requiring a successful build" = + Test.with_project ~name:"document-syntax" ~run_build:false + ~text:{|let = 1 + 1.0 +let add = =2 +lett a = 2 +|} (fun ~root ~doc client -> + Test.snapshot ~root client (diagnostics doc)); + [%expect + {| + { + "kind": "full", + "items": [ + { + "message": "Consecutive statements on a line must be separated by ';' or a newline", + "range": { + "end": { "character": 6, "line": 2 }, + "start": { "character": 4, "line": 2 } + }, + "severity": 1, + "source": "ReScript" + }, + { + "message": "This let-binding misses an expression", + "range": { + "end": { "character": 11, "line": 1 }, + "start": { "character": 9, "line": 1 } + }, + "severity": 1, + "source": "ReScript" + }, + { + "message": "I was expecting a name for this let-binding. Example: `let message = \"hello\"`", + "range": { + "end": { "character": 5, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "severity": 1, + "source": "ReScript" + } + ] + } + |}] + +let%expect_test "clears syntax diagnostics after correcting the unsaved buffer" + = + Test.with_project ~name:"document-syntax" ~run_build:false + ~text:{|let add = =2 +|} (fun ~root ~doc client -> + Test.snapshot ~root client (diagnostics doc); + Test.change_document client doc ~version:1 ~text:{|let add = 2 +|}; + Test.snapshot ~root client (diagnostics doc)); + [%expect + {| + { + "kind": "full", + "items": [ + { + "message": "This let-binding misses an expression", + "range": { + "end": { "character": 11, "line": 0 }, + "start": { "character": 9, "line": 0 } + }, + "severity": 1, + "source": "ReScript" + } + ] + } + { "kind": "full", "items": [] } + |}] + +let%expect_test "reports syntax errors introduced after opening valid code" = + Test.with_project ~name:"document-syntax" ~run_build:false + ~text:{|let add = 2 +|} (fun ~root ~doc client -> + Test.snapshot ~root client (diagnostics doc); + Test.change_document client doc ~version:1 ~text:{|let add = =2 +|}; + Test.snapshot ~root client (diagnostics doc)); + [%expect + {| + { "kind": "full", "items": [] } + { + "kind": "full", + "items": [ + { + "message": "This let-binding misses an expression", + "range": { + "end": { "character": 11, "line": 0 }, + "start": { "character": 9, "line": 0 } + }, + "severity": 1, + "source": "ReScript" + } + ] + } + |}] diff --git a/tests/lsp_tests/dune b/tests/lsp_tests/dune new file mode 100644 index 00000000000..c704af295ce --- /dev/null +++ b/tests/lsp_tests/dune @@ -0,0 +1,10 @@ +(library + (name rescript_lsp_tests) + (package rescript-language-server) + (libraries lsp jsonrpc yojson eio eio_main) + (inline_tests + (deps ../../rewatch-ocaml/rescript_ocaml.exe)) + (preprocess + (pps ppx_deriving_yojson ppx_expect)) + (flags + (-w "-9-32-33"))) diff --git a/tests/lsp_tests/execute_commands.ml b/tests/lsp_tests/execute_commands.ml new file mode 100644 index 00000000000..805c33e4fce --- /dev/null +++ b/tests/lsp_tests/execute_commands.ml @@ -0,0 +1,131 @@ +open Lsp +open Types + +let capabilities = + { + Test.client_capabilities with + window = + Some + (WindowClientCapabilities.create + ~showDocument:(ShowDocumentClientCapabilities.create ~support:true) + ()); + } + +let execute ?arguments command = + Client_request.ExecuteCommand + (ExecuteCommandParams.create ~command ?arguments ()) + +let read_dump client command inspect = + let id = Test.Client.send_request client command in + let request = Test.Client.read_request client "window/showDocument" in + let params = + Option.get request.params |> Jsonrpc.Structured.yojson_of_t + |> ShowDocumentParams.t_of_yojson + in + let path = Uri.to_path params.uri in + Fun.protect + ~finally:(fun () -> Sys.remove path) + (fun () -> + Printf.printf "temporary file: %b\n" + (Unix.realpath (Filename.dirname path) + = Unix.realpath (Filename.get_temp_dir_name ())); + Printf.printf "extension: %s\n" (Filename.extension path); + Printf.printf "takeFocus: %b\n" (params.takeFocus = Some true); + In_channel.with_open_bin path In_channel.input_all |> inspect; + Test.Client.send_packet client + (Jsonrpc.Packet.Response + (Jsonrpc.Response.ok request.id (`Assoc [("success", `Bool true)]))); + let response = Test.Client.read_response client id in + match response.result with + | Ok json -> Yojson.Safe.to_string json |> print_endline + | Error error -> failwith error.message); + path + +let%expect_test "opens server state as JSON in a unique temporary file" = + Test.with_project ~name:"dump-state" ~capabilities ~run_build:false + ~text:{|let value = 1|} (fun ~root:_ ~doc client -> + let inspect content = + let open Yojson.Safe.Util in + let state = Yojson.Safe.from_string content in + let document = + state |> member "store" |> member (Uri.to_string doc.uri) + in + Printf.printf "contains open document: %b\n" (document <> `Null) + in + let first = + read_dump client (execute "rescript/dumpServerState") inspect + in + let second = + read_dump client (execute "rescript/dumpServerState") inspect + in + Printf.printf "unique paths: %b\n" (first <> second)); + [%expect + {| + temporary file: true + extension: .json + takeFocus: true + contains open document: true + null + temporary file: true + extension: .json + takeFocus: true + contains open document: true + null + unique paths: true + |}] + +let%expect_test "opens CMT metadata as text in a temporary file" = + Test.with_project ~name:"dump-cmt" ~capabilities ~text:{|let value = 1|} + (fun ~root:_ ~doc client -> + read_dump client + (execute + ~arguments:[`String (Uri.to_string doc.uri)] + "rescript/dumpCmt") + (fun content -> + Printf.printf "contains CMT metadata: %b\n" + (String.starts_with ~prefix:"file module_name: Test\n" content)) + |> ignore); + [%expect + {| + temporary file: true + extension: .txt + takeFocus: true + contains CMT metadata: true + null + |}] + +let%expect_test "dump commands report missing showDocument support" = + Test.with_project ~name:"dump-unsupported" ~text:{|let value = 1|} + (fun ~root:_ ~doc client -> + List.iter + (fun command -> + let id = Test.Client.send_request client command in + match (Test.Client.read_response client id).result with + | Ok _ -> failwith "Expected unsupported client error" + | Error error -> + Printf.printf "showDocument error: %b\n" + (String.ends_with + ~suffix:"The client dont support window/showDocument request" + error.message)) + [ + execute "rescript/dumpServerState"; + execute + ~arguments:[`String (Uri.to_string doc.uri)] + "rescript/dumpCmt"; + ]); + [%expect {| + showDocument error: true + showDocument error: true + |}] + +let%expect_test "dumpCmt still rejects invalid arguments" = + Test.with_project ~name:"dump-invalid" ~capabilities ~run_build:false + ~text:{|let value = 1|} (fun ~root:_ ~doc:_ client -> + let id = Test.Client.send_request client (execute "rescript/dumpCmt") in + match (Test.Client.read_response client id).result with + | Ok _ -> failwith "Expected invalid arguments error" + | Error error -> print_endline error.message); + [%expect + {| + Invalid arguments for workspace/executeCommand rescript/dumpCmt. Expected a list of string: [uri] + |}] diff --git a/tests/lsp_tests/formatting.ml b/tests/lsp_tests/formatting.ml new file mode 100644 index 00000000000..fadf2d66840 --- /dev/null +++ b/tests/lsp_tests/formatting.ml @@ -0,0 +1,71 @@ +open Lsp +open Types + +let rejects_invalid_document ~extension ~text ~corrected = + Test.with_project ~name:"format-invalid" ~run_build:false ~text:{||} + (fun ~root ~doc:_ client -> + let executable = Filename.concat root "node_modules/.bin/rescript" in + let binary = + In_channel.with_open_bin Test.executable In_channel.input_all + in + Test.write_file executable binary; + Unix.chmod executable 0o755; + let doc = + Test.make_document ~text + ~uri:(Uri.of_path (Filename.concat root ("Invalid." ^ extension))) + in + Test.perform client (Test.open_document doc); + let request = + Client_request.TextDocumentFormatting + (DocumentFormattingParams.create + ~textDocument:(Test.text_document doc) + ~options: + (FormattingOptions.create ~tabSize:2 ~insertSpaces:true ()) + ()) + in + for _ = 1 to 3 do + let id = Test.Client.send_request client request in + match (Test.Client.read_response client id).result with + | Ok _ -> failwith "Expected a formatting error" + | Error error -> print_endline error.message + done; + Test.change_document client doc ~version:1 ~text:corrected; + Test.snapshot ~root client request) + +let%expect_test "rejects repeated formatting of an invalid implementation" = + rejects_invalid_document ~extension:"res" ~text:{|let value =|} + ~corrected:{|let value=1|}; + [%expect + {| + Failed to format Invalid.res + Failed to format Invalid.res + Failed to format Invalid.res + [ + { + "newText": "let value = 1\n", + "range": { + "end": { "character": 0, "line": 1 }, + "start": { "character": 0, "line": 0 } + } + } + ] + |}] + +let%expect_test "rejects repeated formatting of an invalid interface" = + rejects_invalid_document ~extension:"resi" ~text:{|let value:|} + ~corrected:{|let value:int|}; + [%expect + {| + Failed to format Invalid.resi + Failed to format Invalid.resi + Failed to format Invalid.resi + [ + { + "newText": "let value: int\n", + "range": { + "end": { "character": 0, "line": 1 }, + "start": { "character": 0, "line": 0 } + } + } + ] + |}] diff --git a/tests/lsp_tests/hover.ml b/tests/lsp_tests/hover.ml new file mode 100644 index 00000000000..8f522cf0825 --- /dev/null +++ b/tests/lsp_tests/hover.ml @@ -0,0 +1,815 @@ +open Lsp +open Lsp.Types + +let ( /+ ) = Filename.concat + +let print_hover_response resp = + match resp with + | Some hover -> + Hover.yojson_of_t hover |> Yojson.Safe.pretty_to_string |> print_endline + | None -> print_endline "" + +let hover ~uri ~position = + Test.Request + ( Client_request.TextDocumentHover + { + HoverParams.position; + textDocument = TextDocumentIdentifier.create ~uri; + workDoneToken = None; + }, + print_hover_response ) + +let rescript_json = + {| +{ + "name": "hover-test", + "sources": { + "dir": "." + }, + "package-specs": { + "module": "esmodule", + "in-source": false + }, + "suffix": ".res.js" +} +|} + +let test_hover ~text ~position = + let root = Filename.get_temp_dir_name () /+ "hover" in + let uri = Uri.of_path (root /+ "test.res") in + let doc = Test.make_document ~text ~uri in + Test.setup_project ~root ~rescript_json ~run_build:true ~documents:[doc]; + let line, character = position in + Test.with_client ~root (fun client -> + Test.perform_all client + [ + Test.open_document doc; + hover ~uri ~position:(Position.create ~line ~character); + ]) + |> ignore + +let%expect_test "shows the existential array type bound by a constructor" = + test_hover + ~text: + {|type rec any = Any(array<'a>, 'a => string): any +let showAll = (Any(xs, f)) => xs->Array.map(f) +|} + ~position:(1, 19); + [%expect + {| + { + "contents": { "kind": "markdown", "value": "```rescript\narray<$a>\n```" } + } + |}] + +let%expect_test "shows documentation for an exported value from another file" = + Test.with_project ~name:"hover" ~text:{|let x = Other.customDouble(2) +|} + ~files: + [ + ("Other.res", {|/** Doubles a value. */ +let customDouble = x => x * 2 +|}); + ] + (fun ~root ~doc client -> + Test.snapshot ~root client + (Client_request.TextDocumentHover + (HoverParams.create ~textDocument:(Test.text_document doc) + ~position:(Test.position (0, 18)) + ()))); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nint => int\n```\n---\n Doubles a value. " + } + } + |}] + +let%expect_test "shows the abstract type exposed by an interface" = + Test.with_project ~name:"hover" ~text:{|let x = Other.value +|} + ~files: + [ + ("Other.res", {|type t = int +let value = 1 +|}); + ("Other.resi", {|type t +let value: t +|}); + ] + (fun ~root ~doc client -> + Test.snapshot ~root client + (Client_request.TextDocumentHover + (HoverParams.create ~textDocument:(Test.text_document doc) + ~position:(Test.position (0, 15)) + ()))); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nOther.t\n```\n\n---\n```rescript\ntype Other.t\n```\n" + } + } + |}] + +let%expect_test "infers the type of an arithmetic binding" = + test_hover ~position:(0, 4) ~text:{|let abc = 22 + 34 +|}; + [%expect + {| { "contents": { "kind": "markdown", "value": "```rescript\nint\n```" } } |}] + +let%expect_test "shows a tuple type declaration" = + test_hover ~position:(0, 5) ~text:{|type t = (int, float) +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\ntype t = (int, float)\n```" + } + } + |}] + +let%expect_test "shows the signature of a module containing a type" = + test_hover ~position:(0, 7) ~text:{|module Id = { + type x = int +} +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nmodule Id: {\n type x = int\n}\n```" + } + } + |}] + +let documented_module = + {|@res.doc("This module is commented") +module Dep: { + @res.doc("Some doc comment") + let customDouble: int => int +} = { + let customDouble = foo => foo * 2 +} + +module D = Dep + +let cd = D.customDouble +|} + +let%expect_test "shows module documentation at an alias target" = + test_hover ~text:documented_module ~position:(8, 11); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "\nThis module is commented\n---\n\n```\n \n```\n```rescript\nmodule Dep: {\n let customDouble: int => int\n}\n```" + } + } + |}] + +let%expect_test "shows function documentation through a module alias" = + test_hover ~text:documented_module ~position:(10, 11); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nint => int\n```\n---\nSome doc comment" + } + } + |}] + +let%expect_test "shows the annotation and documentation of a function" = + test_hover ~position:(1, 4) + ~text: + {|@res.doc("Doc comment for functionWithTypeAnnotation") +let functionWithTypeAnnotation: unit => int = () => 1 +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nunit => int\n```\n---\nDoc comment for functionWithTypeAnnotation" + } + } + |}] + +let%expect_test "infers the type of an integer literal" = + test_hover ~position:(0, 10) ~text:{|let num = 34 +|}; + [%expect + {| { "contents": { "kind": "markdown", "value": "```rescript\nint\n```" } } |}] + +let logger_module = + {|module type Logger = { + let log: string => unit +} + +module JsLogger: Logger = { + let log = (msg: string) => Console.log(msg) + let _oneMore = 3 +} +|} + +let%expect_test "shows a module type signature" = + test_hover ~text:logger_module ~position:(0, 13); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nmodule type Logger = {\n let log: string => unit\n}\n```" + } + } + |}] + +let%expect_test "shows the constrained signature of a module" = + test_hover ~text:logger_module ~position:(4, 7); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nmodule type Logger = {\n let log: string => unit\n}\n```" + } + } + |}] + +let%expect_test "shows only the visible bindings of a module with shadowing" = + test_hover ~position:(0, 9) + ~text: + {|module IdDefinedTwice = { + let _x = 10 + let y = 20 + let _x = 10 +} +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nmodule IdDefinedTwice: {\n let y: int\n let _x: int\n}\n```" + } + } + |}] + +let module_aliases = + {|module A = { + let x = 13 +} + +module B = A + +module C = B +|} + +let%expect_test "resolves a module alias binding" = + test_hover ~text:module_aliases ~position:(4, 7); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nmodule A: {\n let x: int\n}\n```" + } + } + |}] + +let%expect_test "resolves a chain of module aliases" = + test_hover ~text:module_aliases ~position:(6, 7); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nmodule A: {\n let x: int\n}\n```" + } + } + |}] + +let%expect_test "infers a generic record field from a float operation" = + test_hover ~position:(2, 25) + ~text:{|type r<'a> = {i: 'a, f: float} + +let _get = r => r.f +. r.i +|}; + [%expect + {| { "contents": { "kind": "markdown", "value": "```rescript\nfloat\n```" } } |}] + +let%expect_test "infers the type of an aliased labeled parameter" = + test_hover ~position:(0, 21) ~text:{|let withAs = (~xx as yyy) => yyy + 1 +|}; + [%expect + {| { "contents": { "kind": "markdown", "value": "```rescript\nint\n```" } } |}] + +let polymorphic_variant_aliases = + {|module AA = { + type cond<'a> = [< #str(string)] as 'a + let fnnxx = (b: cond<_>) => true ? b : b +} + +let funAlias = AA.fnnxx + +let typeOk = funAlias + +let typeDuplicate = AA.fnnxx +|} + +let%expect_test + "preserves polymorphic variant constraints through a function alias" = + test_hover ~text:polymorphic_variant_aliases ~position:(7, 16); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nAA.cond<([< #str(string)] as 'a)> => AA.cond<'a>\n```\n\n---\n```rescript\ntype AA.cond<'a> = 'a\n constraint 'a = [< #str(string)]\n```\n" + } + } + |}] + +let%expect_test "shows polymorphic variant constraints on a qualified function" + = + test_hover ~text:polymorphic_variant_aliases ~position:(9, 25); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nAA.cond<([< #str(string)] as 'a)> => AA.cond<'a>\n```\n\n---\n```rescript\ntype AA.cond<'a> = 'a\n constraint 'a = [< #str(string)]\n```\n" + } + } + |}] + +let%expect_test "shows both unit parameters in a function type" = + test_hover ~position:(0, 4) ~text:{|let arity0b = ((), ()) => 3 +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\n(unit, unit) => int\n```" + } + } + |}] + +let%expect_test "shows the type of a function returning a function" = + test_hover ~position:(0, 5) + ~text:{|let arity0d = () => { + let f = () => 3 + f +} +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nunit => unit => int\n```" + } + } + |}] + +let%expect_test "includes a compact doc comment on a value" = + test_hover ~position:(1, 9) ~text:{|/**doc comment 1*/ +let docComment1 = 12 +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nint\n```\n---\ndoc comment 1" + } + } + |}] + +let%expect_test "preserves spaces in a value doc comment" = + test_hover ~position:(1, 6) + ~text:{|/** doc comment 2 */ +let docComment2 = 12 +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nint\n```\n---\n doc comment 2 " + } + } + |}] + +let record_substitution = + {|module TypeSubstitutionRecords = { + type foo<'a> = {content: 'a, zzz: string} + type bar = {age: int} + type foobar = foo + + let x1: foo = {content: {age: 42}, zzz: ""} + let x2: foobar = {content: {age: 42}, zzz: ""} +} +|} + +let%expect_test "expands the type argument of a generic record" = + test_hover ~text:record_substitution ~position:(5, 23); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nfoo\n```\n\n---\n```rescript\ntype foo<'a> = {content: 'a, zzz: string}\n```\n\n\n---\n```rescript\ntype bar = {age: int}\n```\n" + } + } + |}] + +let%expect_test "shows the alias of a specialized record" = + test_hover ~text:record_substitution ~position:(6, 22); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nfoobar\n```\n\n---\n```rescript\ntype foobar = foo\n```\n" + } + } + |}] + +let%expect_test "expands record types nested inside list and option" = + test_hover ~position:(3, 16) + ~text: + {|type r<'a> = {i: 'a, f: float} +type useR = {x: int, y: list>>} + +let testUseR = (v: useR) => v +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nuseR\n```\n\n---\n```rescript\ntype useR = {x: int, y: list>>}\n```\n\n\n---\n```rescript\ntype r<'a> = {i: 'a, f: float}\n```\n" + } + } + |}] + +let%expect_test "uses the documentation of a value rather than its initializer" + = + test_hover ~position:(8, 20) + ~text: + {|module NotShadowed = { + /** Stuff */ + let xx_ = 10 + + /** More Stuff */ + let xx = xx_ +} + +let _ = NotShadowed.xx +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nint\n```\n---\n More Stuff " + } + } + |}] + +let%expect_test "uses the documentation of the latest shadowing binding" = + test_hover ~position:(8, 17) + ~text: + {|module Shadowed = { + /** Stuff */ + let xx = 10 + + /** More Stuff */ + let xx = xx +} + +let _ = Shadowed.xx +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nint\n```\n---\n More Stuff " + } + } + |}] + +let%expect_test "shows documentation for a record field access" = + test_hover ~position:(9, 19) + ~text: + {|type recordWithDocstringField = { + /** Mighty fine field here. */ + someField: bool, +} + +let x: recordWithDocstringField = { + someField: true, +} + +let someField = x.someField +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nbool\n```\n---\n Mighty fine field here. " + } + } + |}] + +let%expect_test "shows a variant constructor with its documentation" = + test_hover ~position:(2, 20) + ~text: + {|type variant = | /** Cool variant! */ CoolVariant | /** Other cool variant */ OtherCoolVariant + +let coolVariant = CoolVariant +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nvariant\nCoolVariant\n```\n---\n Cool variant! \n\n---\n```rescript\ntype variant = CoolVariant | OtherCoolVariant\n```\n" + } + } + |}] + +let payload_variants = + {|type payloadVariants = InlineRecord({field1: int, field2: bool}) | Args(int, bool) + +let payloadVariant = InlineRecord({field1: 1, field2: true}) + +let payloadVariant2 = Args(1, true) +|} + +let%expect_test "shows a variant constructor with an inline record payload" = + test_hover ~text:payload_variants ~position:(2, 22); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\npayloadVariants\nInlineRecord({field1: int, field2: bool})\n```\n\n---\n```rescript\ntype payloadVariants =\n | InlineRecord({field1: int, field2: bool})\n | Args(int, bool)\n```\n" + } + } + |}] + +let%expect_test "shows a variant constructor with positional payloads" = + test_hover ~text:payload_variants ~position:(4, 23); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\npayloadVariants\nArgs(int, bool)\n```\n\n---\n```rescript\ntype payloadVariants =\n | InlineRecord({field1: int, field2: bool})\n | Args(int, bool)\n```\n" + } + } + |}] + +let%expect_test "expands a recursive variant from another module" = + test_hover ~position:(4, 42) + ~text: + {|module RecursiveVariants = { + type rec t = Action1(int) | Action2(float) | Batch(array) +} + +let recursiveVariant = RecursiveVariants.Action1(1) +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nRecursiveVariants.t\nAction1(int)\n```\n\n---\n```rescript\ntype RecursiveVariants.t =\n | Action1(int)\n | Action2(float)\n | Batch(array)\n```\n" + } + } + |}] + +let%expect_test "expands an alias of a variant type" = + test_hover ~position:(2, 6) + ~text: + {|type variant = CoolVariant | OtherCoolVariant + +type aliased = variant +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\ntype aliased = variant\n```\n\n---\n```rescript\ntype variant = CoolVariant | OtherCoolVariant\n```\n" + } + } + |}] + +let%expect_test "recognizes res.doc as documentation" = + test_hover ~position:(0, 32) + ~text:{|@res.doc("Shown on hover") let resDoc = 1 +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nint\n```\n---\nShown on hover" + } + } + |}] + +let%expect_test "ignores doc attributes from another namespace" = + test_hover ~position:(0, 34) + ~text:{|@ns.doc("Not shown on hover") let nsDoc = 1 +|}; + [%expect + {| { "contents": { "kind": "markdown", "value": "```rescript\nint\n```" } } |}] + +let%expect_test "ignores the legacy ocaml.doc attribute" = + test_hover ~position:(0, 37) + ~text:{|@ocaml.doc("Not shown on hover") let ocamlDoc = 1 +|}; + [%expect + {| { "contents": { "kind": "markdown", "value": "```rescript\nint\n```" } } |}] + +let%expect_test "returns no hover for a binding inside a line comment" = + test_hover ~position:(0, 23) ~text:{|// let fff = "hello"; fff +|}; + [%expect {| |}] + +let%expect_test "returns no hover for a record field inside a line comment" = + test_hover ~position:(3, 6) + ~text: + {|type recordWithDocstringField = {someField: bool} +let x: recordWithDocstringField = {someField: true} + +// x.someField +|}; + [%expect {| |}] + +let%expect_test "preserves fenced examples and nested comments in res.doc" = + test_hover ~position:(9, 9) + ~text: + {|@res.doc(" Doc comment with a triple-backquote example + + ```res example + let a = 10 + /* + * stuff + */ + ``` +") +let docComment1 = 12 +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nint\n```\n---\n Doc comment with a triple-backquote example\n\n ```res example\n let a = 10\n /*\n * stuff\n */\n ```\n" + } + } + |}] + +let%expect_test "preserves fenced examples and nested comments in a doc comment" + = + test_hover ~position:(10, 6) + ~text: + {|/** + Doc comment with a triple-backquote example + + ```res example + let a = 10 + /* + * stuff + */ + ``` +*/ +let docComment2 = 12 +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nint\n```\n---\n\n Doc comment with a triple-backquote example\n\n ```res example\n let a = 10\n /*\n * stuff\n */\n ```\n" + } + } + |}] + +let%expect_test "resolves a field in an inline record access chain" = + test_hover ~position:(2, 41) + ~text: + {|type person = {details: {name: string}} + +let getName = (person: person) => person.details.name +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\ntype person.details = {name: string}\n```" + } + } + |}] + +let nested_records = + {|type options = { + extra?: { + name: string, + superExtra?: {age: int}, + otherExtra: option<{test: bool, anotherInlined: {record: bool}}>, + }, +} + +let options = { + extra: { + name: "test", + superExtra: { + age: 2222, + }, + otherExtra: Some({ + test: true, + anotherInlined: { + record: true, + }, + }), + }, +} +|} + +let%expect_test "infers the outer type of a nested record literal" = + test_hover ~text:nested_records ~position:(8, 7); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\noptions\n```\n\n---\n```rescript\ntype options = {\n extra?: {\n name: string,\n superExtra?: {age: int},\n otherExtra: option<\n {\n test: bool,\n anotherInlined: {record: bool},\n },\n >,\n },\n}\n```\n\n\n---\n```rescript\ntype options.extra = {\n name: string,\n superExtra?: {age: int},\n otherExtra: option<\n {\n test: bool,\n anotherInlined: {record: bool},\n },\n >,\n}\n```\n" + } + } + |}] + +let%expect_test "shows the enclosing inline record at its string field" = + test_hover ~text:nested_records ~position:(10, 6); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\ntype options.extra = {\n name: string,\n superExtra?: {age: int},\n otherExtra: option<\n {\n test: bool,\n anotherInlined: {record: bool},\n },\n >,\n}\n```" + } + } + |}] + +let%expect_test "shows the nested optional record at its integer field" = + test_hover ~text:nested_records ~position:(12, 8); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\ntype options.extra.superExtra = {age: int}\n```" + } + } + |}] + +let%expect_test "shows the option-wrapped record at its boolean field" = + test_hover ~text:nested_records ~position:(15, 9); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\ntype options.extra.otherExtra = {\n test: bool,\n anotherInlined: {record: bool},\n}\n```" + } + } + |}] + +let%expect_test "shows the deepest inline record at its boolean field" = + test_hover ~text:nested_records ~position:(17, 11); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\ntype options.extra.otherExtra.anotherInlined = {\n record: bool,\n}\n```" + } + } + |}] diff --git a/tests/lsp_tests/hover_jsx.ml b/tests/lsp_tests/hover_jsx.ml new file mode 100644 index 00000000000..d00d7c3bc6d --- /dev/null +++ b/tests/lsp_tests/hover_jsx.ml @@ -0,0 +1,288 @@ +module Hover_test = Hover + +open Lsp +open Lsp.Types + +let ( /+ ) = Filename.concat + +let jsx_rescript_json = + {|{ + "name": "hover-jsx-test", + "sources": {"dir": "."}, + "dependencies": ["@rescript/react"], + "jsx": {"version": 4}, + "package-specs": {"module": "esmodule", "in-source": false}, + "suffix": ".res.js" +}|} + +let test_hover_with_interface ~interface ~text ~position = + let root = + Filename.get_temp_dir_name () + /+ if Option.is_some interface then "hover-jsx-interface" else "hover-jsx" + in + let uri = Uri.of_path (root /+ "test.res") in + let doc = Test.make_document ~text ~uri in + let doc, documents = + match interface with + | None -> (doc, [doc]) + | Some text -> + let interface_doc = + Test.make_document ~text ~uri:(Uri.of_path (root /+ "test.resi")) + in + (interface_doc, [doc; interface_doc]) + in + let uri = doc.uri in + Test.setup_react ~root; + Test.setup_project ~root ~rescript_json:jsx_rescript_json ~run_build:true + ~documents; + + let line, character = position in + + Test.with_client ~root (fun client -> + Test.perform_all client + [ + Test.open_document doc; + Hover_test.hover ~uri ~position:(Position.create ~line ~character); + ]) + |> ignore + +let test_jsx_hover ~text ~position = + test_hover_with_interface ~interface:None ~text ~position + +let test_jsx_interface_hover ~interface ~text ~position = + test_hover_with_interface ~interface:(Some interface) ~text ~position + +let%expect_test "infers a value inside a module containing a React component" = + test_jsx_hover ~position:(1, 6) + ~text: + {|module HoverInsideModuleWithComponent = { + let x = 2 + @react.component + let make = () => React.null +} +|}; + [%expect + {| { "contents": { "kind": "markdown", "value": "```rescript\nint\n```" } } |}] + +let%expect_test "infers a React component prop from its use" = + test_jsx_hover ~position:(1, 13) + ~text:{|@react.component +let make = (~name) => React.string(name) +|}; + [%expect + {| { "contents": { "kind": "markdown", "value": "```rescript\nstring\n```" } } |}] + +let%expect_test "shows an annotated prop in a nested React component" = + test_jsx_hover ~position:(2, 15) + ~text: + {|module C2 = { + @react.component + let make2 = (~name: string) => React.string(name) +} +|}; + [%expect + {| { "contents": { "kind": "markdown", "value": "```rescript\nstring\n```" } } |}] + +let%expect_test "shows the type of an intrinsic JSX tag" = + test_jsx_hover ~position:(0, 10) ~text:{|let q =
+|}; + [%expect + {| { "contents": { "kind": "markdown", "value": "```rescript\nstring\n```" } } |}] + +let%expect_test "shows the type of an intrinsic JSX attribute" = + test_jsx_hover ~position:(0, 14) ~text:{|let _ =
+|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nJsxDOM.domProps\n```\n\n---\n```rescript\ntype JsxDOM.domProps = {\n key?: string,\n children?: Jsx.element,\n ref?: domRef,\n allow?: string,\n @as(\"aria-current\") ariaCurrent?: [\n | #date\n | #\"false\"\n | #location\n | #page\n | #step\n | #time\n | #\"true\"\n ],\n @as(\"aria-details\") ariaDetails?: string,\n @as(\"aria-disabled\") ariaDisabled?: bool,\n @as(\"aria-hidden\") ariaHidden?: bool,\n @as(\"aria-invalid\") ariaInvalid?: [\n | #\"false\"\n | #grammar\n | #spelling\n | #\"true\"\n ],\n @as(\"aria-keyshortcuts\") ariaKeyshortcuts?: string,\n @as(\"aria-label\") ariaLabel?: string,\n @as(\"aria-roledescription\") ariaRoledescription?: string,\n @as(\"aria-autocomplete\") ariaAutocomplete?: [\n | #both\n | #inline\n | #list\n | #none\n ],\n @as(\"aria-checked\") ariaChecked?: [\n | #\"false\"\n | #mixed\n | #\"true\"\n ],\n @as(\"aria-expanded\") ariaExpanded?: bool,\n @as(\"aria-haspopup\") ariaHaspopup?: [\n | #dialog\n | #\"false\"\n | #grid\n | #listbox\n | #menu\n | #tree\n | #\"true\"\n ],\n @as(\"aria-level\") ariaLevel?: int,\n @as(\"aria-modal\") ariaModal?: bool,\n @as(\"aria-multiline\") ariaMultiline?: bool,\n @as(\"aria-multiselectable\") ariaMultiselectable?: bool,\n @as(\"aria-orientation\") ariaOrientation?: [\n | #horizontal\n | #undefined\n | #vertical\n ],\n @as(\"aria-placeholder\") ariaPlaceholder?: string,\n @as(\"aria-pressed\") ariaPressed?: [\n | #\"false\"\n | #mixed\n | #\"true\"\n ],\n @as(\"aria-readonly\") ariaReadonly?: bool,\n @as(\"aria-required\") ariaRequired?: bool,\n @as(\"aria-selected\") ariaSelected?: bool,\n @as(\"aria-sort\") ariaSort?: string,\n @as(\"aria-valuemax\") ariaValuemax?: float,\n @as(\"aria-valuemin\") ariaValuemin?: float,\n @as(\"aria-valuenow\") ariaValuenow?: float,\n @as(\"aria-valuetext\") ariaValuetext?: string,\n @as(\"aria-atomic\") ariaAtomic?: bool,\n @as(\"aria-busy\") ariaBusy?: bool,\n @as(\"aria-live\") ariaLive?: [\n | #assertive\n | #off\n | #polite\n | #rude\n ],\n @as(\"aria-relevant\") ariaRelevant?: string,\n @as(\"aria-dropeffect\") ariaDropeffect?: [\n | #copy\n | #execute\n | #link\n | #move\n | #none\n | #popup\n ],\n @as(\"aria-grabbed\") ariaGrabbed?: bool,\n @as(\"aria-activedescendant\") ariaActivedescendant?: string,\n @as(\"aria-colcount\") ariaColcount?: int,\n @as(\"aria-colindex\") ariaColindex?: int,\n @as(\"aria-colspan\") ariaColspan?: int,\n @as(\"aria-controls\") ariaControls?: string,\n @as(\"aria-describedby\") ariaDescribedby?: string,\n @as(\"aria-errormessage\") ariaErrormessage?: string,\n @as(\"aria-flowto\") ariaFlowto?: string,\n @as(\"aria-labelledby\") ariaLabelledby?: string,\n @as(\"aria-owns\") ariaOwns?: string,\n @as(\"aria-posinset\") ariaPosinset?: int,\n @as(\"aria-rowcount\") ariaRowcount?: int,\n @as(\"aria-rowindex\") ariaRowindex?: int,\n @as(\"aria-rowspan\") ariaRowspan?: int,\n @as(\"aria-setsize\") ariaSetsize?: int,\n defaultChecked?: bool,\n defaultValue?: string,\n accessKey?: string,\n capture?: [#environment | #user],\n className?: string,\n contentEditable?: bool,\n contextMenu?: string,\n @as(\"data-testid\") dataTestId?: string,\n dir?: string,\n draggable?: bool,\n hidden?: bool,\n id?: string,\n inert?: bool,\n lang?: string,\n popover?: popover,\n popoverTarget?: string,\n popoverTargetAction?: popoverTargetAction,\n role?: string,\n style?: style,\n spellCheck?: bool,\n tabIndex?: int,\n title?: string,\n itemID?: string,\n itemProp?: string,\n itemRef?: string,\n itemScope?: bool,\n itemType?: string,\n accept?: string,\n acceptCharset?: string,\n action?: string,\n allowFullScreen?: bool,\n alt?: string,\n @as(\"as\") as_?: string,\n async?: bool,\n autoComplete?: string,\n autoCapitalize?: string,\n autoFocus?: bool,\n autoPlay?: bool,\n challenge?: string,\n charSet?: string,\n checked?: bool,\n cite?: string,\n crossOrigin?: string,\n cols?: int,\n colSpan?: int,\n content?: string,\n controls?: bool,\n coords?: string,\n data?: string,\n dateTime?: string,\n default?: bool,\n defer?: bool,\n disabled?: bool,\n download?: string,\n encType?: string,\n form?: string,\n formAction?: string,\n formTarget?: string,\n formMethod?: string,\n frameBorder?: int,\n headers?: string,\n height?: string,\n high?: int,\n href?: string,\n hrefLang?: string,\n htmlFor?: string,\n httpEquiv?: string,\n icon?: string,\n inputMode?: string,\n integrity?: string,\n keyType?: string,\n kind?: string,\n label?: string,\n list?: string,\n loading?: [#eager | #lazy],\n loop?: bool,\n low?: int,\n manifest?: string,\n max?: string,\n maxLength?: int,\n media?: string,\n mediaGroup?: string,\n method?: string,\n min?: string,\n minLength?: int,\n multiple?: bool,\n muted?: bool,\n name?: string,\n nonce?: string,\n noValidate?: bool,\n @as(\"open\") open_?: bool,\n optimum?: int,\n pattern?: string,\n placeholder?: string,\n playsInline?: bool,\n poster?: string,\n preload?: string,\n radioGroup?: string,\n readOnly?: bool,\n rel?: string,\n required?: bool,\n reversed?: bool,\n rows?: int,\n rowSpan?: int,\n sandbox?: string,\n scope?: string,\n scoped?: bool,\n scrolling?: string,\n selected?: bool,\n shape?: string,\n size?: int,\n sizes?: string,\n span?: int,\n src?: string,\n srcDoc?: string,\n srcLang?: string,\n srcSet?: string,\n start?: int,\n step?: float,\n summary?: string,\n target?: string,\n @as(\"type\") type_?: string,\n useMap?: string,\n value?: string,\n width?: string,\n wrap?: string,\n onCancel?: JsxEvent.Synthetic.t => unit,\n onCancelCapture?: JsxEvent.Synthetic.t => unit,\n onClose?: JsxEvent.Synthetic.t => unit,\n onCloseCapture?: JsxEvent.Synthetic.t => unit,\n onFullscreenChange?: JsxEvent.Synthetic.t => unit,\n onFullscreenChangeCapture?: JsxEvent.Synthetic.t => unit,\n onFullscreenError?: JsxEvent.Synthetic.t => unit,\n onFullscreenErrorCapture?: JsxEvent.Synthetic.t => unit,\n onBeforeToggle?: JsxEvent.Toggle.t => unit,\n onBeforeToggleCapture?: JsxEvent.Toggle.t => unit,\n onToggle?: JsxEvent.Toggle.t => unit,\n onToggleCapture?: JsxEvent.Toggle.t => unit,\n onCopy?: JsxEvent.Clipboard.t => unit,\n onCopyCapture?: JsxEvent.Clipboard.t => unit,\n onCut?: JsxEvent.Clipboard.t => unit,\n onCutCapture?: JsxEvent.Clipboard.t => unit,\n onPaste?: JsxEvent.Clipboard.t => unit,\n onPasteCapture?: JsxEvent.Clipboard.t => unit,\n onCompositionEnd?: JsxEvent.Composition.t => unit,\n onCompositionEndCapture?: JsxEvent.Composition.t => unit,\n onCompositionStart?: JsxEvent.Composition.t => unit,\n onCompositionStartCapture?: JsxEvent.Composition.t => unit,\n onCompositionUpdate?: JsxEvent.Composition.t => unit,\n onCompositionUpdateCapture?: JsxEvent.Composition.t => unit,\n onKeyDown?: JsxEvent.Keyboard.t => unit,\n onKeyDownCapture?: JsxEvent.Keyboard.t => unit,\n onKeyPress?: JsxEvent.Keyboard.t => unit,\n onKeyPressCapture?: JsxEvent.Keyboard.t => unit,\n onKeyUp?: JsxEvent.Keyboard.t => unit,\n onKeyUpCapture?: JsxEvent.Keyboard.t => unit,\n onFocus?: JsxEvent.Focus.t => unit,\n onFocusCapture?: JsxEvent.Focus.t => unit,\n onBlur?: JsxEvent.Focus.t => unit,\n onBlurCapture?: JsxEvent.Focus.t => unit,\n onBeforeInput?: JsxEvent.Form.t => unit,\n onBeforeInputCapture?: JsxEvent.Form.t => unit,\n onChange?: JsxEvent.Form.t => unit,\n onChangeCapture?: JsxEvent.Form.t => unit,\n onInput?: JsxEvent.Form.t => unit,\n onInputCapture?: JsxEvent.Form.t => unit,\n onReset?: JsxEvent.Form.t => unit,\n onResetCapture?: JsxEvent.Form.t => unit,\n onSubmit?: JsxEvent.Form.t => unit,\n onSubmitCapture?: JsxEvent.Form.t => unit,\n onInvalid?: JsxEvent.Form.t => unit,\n onInvalidCapture?: JsxEvent.Form.t => unit,\n onAuxClick?: JsxEvent.Mouse.t => unit,\n onAuxClickCapture?: JsxEvent.Mouse.t => unit,\n onClick?: JsxEvent.Mouse.t => unit,\n onClickCapture?: JsxEvent.Mouse.t => unit,\n onContextMenu?: JsxEvent.Mouse.t => unit,\n onContextMenuCapture?: JsxEvent.Mouse.t => unit,\n onDoubleClick?: JsxEvent.Mouse.t => unit,\n onDoubleClickCapture?: JsxEvent.Mouse.t => unit,\n onDrag?: JsxEvent.Mouse.t => unit,\n onDragCapture?: JsxEvent.Mouse.t => unit,\n onDragEnd?: JsxEvent.Mouse.t => unit,\n onDragEndCapture?: JsxEvent.Mouse.t => unit,\n onDragEnter?: JsxEvent.Mouse.t => unit,\n onDragEnterCapture?: JsxEvent.Mouse.t => unit,\n onDragExit?: JsxEvent.Mouse.t => unit,\n onDragExitCapture?: JsxEvent.Mouse.t => unit,\n onDragLeave?: JsxEvent.Mouse.t => unit,\n onDragLeaveCapture?: JsxEvent.Mouse.t => unit,\n onDragOver?: JsxEvent.Mouse.t => unit,\n onDragOverCapture?: JsxEvent.Mouse.t => unit,\n onDragStart?: JsxEvent.Mouse.t => unit,\n onDragStartCapture?: JsxEvent.Mouse.t => unit,\n onDrop?: JsxEvent.Mouse.t => unit,\n onDropCapture?: JsxEvent.Mouse.t => unit,\n onMouseDown?: JsxEvent.Mouse.t => unit,\n onMouseDownCapture?: JsxEvent.Mouse.t => unit,\n onMouseEnter?: JsxEvent.Mouse.t => unit,\n onMouseLeave?: JsxEvent.Mouse.t => unit,\n onMouseMove?: JsxEvent.Mouse.t => unit,\n onMouseMoveCapture?: JsxEvent.Mouse.t => unit,\n onMouseOut?: JsxEvent.Mouse.t => unit,\n onMouseOutCapture?: JsxEvent.Mouse.t => unit,\n onMouseOver?: JsxEvent.Mouse.t => unit,\n onMouseOverCapture?: JsxEvent.Mouse.t => unit,\n onMouseUp?: JsxEvent.Mouse.t => unit,\n onMouseUpCapture?: JsxEvent.Mouse.t => unit,\n onSelect?: JsxEvent.Selection.t => unit,\n onSelectCapture?: JsxEvent.Selection.t => unit,\n onTouchCancel?: JsxEvent.Touch.t => unit,\n onTouchCancelCapture?: JsxEvent.Touch.t => unit,\n onTouchEnd?: JsxEvent.Touch.t => unit,\n onTouchEndCapture?: JsxEvent.Touch.t => unit,\n onTouchMove?: JsxEvent.Touch.t => unit,\n onTouchMoveCapture?: JsxEvent.Touch.t => unit,\n onTouchStart?: JsxEvent.Touch.t => unit,\n onTouchStartCapture?: JsxEvent.Touch.t => unit,\n onPointerOver?: JsxEvent.Pointer.t => unit,\n onPointerOverCapture?: JsxEvent.Pointer.t => unit,\n onPointerEnter?: JsxEvent.Pointer.t => unit,\n onPointerDown?: JsxEvent.Pointer.t => unit,\n onPointerDownCapture?: JsxEvent.Pointer.t => unit,\n onPointerMove?: JsxEvent.Pointer.t => unit,\n onPointerMoveCapture?: JsxEvent.Pointer.t => unit,\n onPointerUp?: JsxEvent.Pointer.t => unit,\n onPointerUpCapture?: JsxEvent.Pointer.t => unit,\n onPointerCancel?: JsxEvent.Pointer.t => unit,\n onPointerCancelCapture?: JsxEvent.Pointer.t => unit,\n onPointerOut?: JsxEvent.Pointer.t => unit,\n onPointerOutCapture?: JsxEvent.Pointer.t => unit,\n onPointerLeave?: JsxEvent.Pointer.t => unit,\n onGotPointerCapture?: JsxEvent.Pointer.t => unit,\n onGotPointerCaptureCapture?: JsxEvent.Pointer.t => unit,\n onLostPointerCapture?: JsxEvent.Pointer.t => unit,\n onLostPointerCaptureCapture?: JsxEvent.Pointer.t => unit,\n onScroll?: JsxEvent.UI.t => unit,\n onScrollCapture?: JsxEvent.UI.t => unit,\n onScrollEnd?: JsxEvent.UI.t => unit,\n onScrollEndCapture?: JsxEvent.UI.t => unit,\n onWheel?: JsxEvent.Wheel.t => unit,\n onWheelCapture?: JsxEvent.Wheel.t => unit,\n onAbort?: JsxEvent.Media.t => unit,\n onAbortCapture?: JsxEvent.Media.t => unit,\n onCanPlay?: JsxEvent.Media.t => unit,\n onCanPlayCapture?: JsxEvent.Media.t => unit,\n onCanPlayThrough?: JsxEvent.Media.t => unit,\n onCanPlayThroughCapture?: JsxEvent.Media.t => unit,\n onDurationChange?: JsxEvent.Media.t => unit,\n onDurationChangeCapture?: JsxEvent.Media.t => unit,\n onEmptied?: JsxEvent.Media.t => unit,\n onEmptiedCapture?: JsxEvent.Media.t => unit,\n onEncrypted?: JsxEvent.Media.t => unit,\n onEncryptedCapture?: JsxEvent.Media.t => unit,\n onEnded?: JsxEvent.Media.t => unit,\n onEndedCapture?: JsxEvent.Media.t => unit,\n onError?: JsxEvent.Media.t => unit,\n onErrorCapture?: JsxEvent.Media.t => unit,\n onLoadedData?: JsxEvent.Media.t => unit,\n onLoadedDataCapture?: JsxEvent.Media.t => unit,\n onLoadedMetadata?: JsxEvent.Media.t => unit,\n onLoadedMetadataCapture?: JsxEvent.Media.t => unit,\n onLoadStart?: JsxEvent.Media.t => unit,\n onLoadStartCapture?: JsxEvent.Media.t => unit,\n onPause?: JsxEvent.Media.t => unit,\n onPauseCapture?: JsxEvent.Media.t => unit,\n onPlay?: JsxEvent.Media.t => unit,\n onPlayCapture?: JsxEvent.Media.t => unit,\n onPlaying?: JsxEvent.Media.t => unit,\n onPlayingCapture?: JsxEvent.Media.t => unit,\n onProgress?: JsxEvent.Media.t => unit,\n onProgressCapture?: JsxEvent.Media.t => unit,\n onRateChange?: JsxEvent.Media.t => unit,\n onRateChangeCapture?: JsxEvent.Media.t => unit,\n onResize?: JsxEvent.Media.t => unit,\n onResizeCapture?: JsxEvent.Media.t => unit,\n onSeeked?: JsxEvent.Media.t => unit,\n onSeekedCapture?: JsxEvent.Media.t => unit,\n onSeeking?: JsxEvent.Media.t => unit,\n onSeekingCapture?: JsxEvent.Media.t => unit,\n onStalled?: JsxEvent.Media.t => unit,\n onStalledCapture?: JsxEvent.Media.t => unit,\n onSuspend?: JsxEvent.Media.t => unit,\n onSuspendCapture?: JsxEvent.Media.t => unit,\n onTimeUpdate?: JsxEvent.Media.t => unit,\n onTimeUpdateCapture?: JsxEvent.Media.t => unit,\n onVolumeChange?: JsxEvent.Media.t => unit,\n onVolumeChangeCapture?: JsxEvent.Media.t => unit,\n onWaiting?: JsxEvent.Media.t => unit,\n onWaitingCapture?: JsxEvent.Media.t => unit,\n onLoad?: JsxEvent.Image.t => unit,\n onLoadCapture?: JsxEvent.Image.t => unit,\n onAnimationStart?: JsxEvent.Animation.t => unit,\n onAnimationStartCapture?: JsxEvent.Animation.t => unit,\n onAnimationEnd?: JsxEvent.Animation.t => unit,\n onAnimationEndCapture?: JsxEvent.Animation.t => unit,\n onAnimationIteration?: JsxEvent.Animation.t => unit,\n onAnimationIterationCapture?: JsxEvent.Animation.t => unit,\n onTransitionCancel?: JsxEvent.Transition.t => unit,\n onTransitionCancelCapture?: JsxEvent.Transition.t => unit,\n onTransitionRun?: JsxEvent.Transition.t => unit,\n onTransitionRunCapture?: JsxEvent.Transition.t => unit,\n onTransitionStart?: JsxEvent.Transition.t => unit,\n onTransitionStartCapture?: JsxEvent.Transition.t => unit,\n onTransitionEnd?: JsxEvent.Transition.t => unit,\n onTransitionEndCapture?: JsxEvent.Transition.t => unit,\n accentHeight?: string,\n accumulate?: string,\n additive?: string,\n alignmentBaseline?: string,\n allowReorder?: string,\n alphabetic?: string,\n amplitude?: string,\n arabicForm?: string,\n ascent?: string,\n attributeName?: string,\n attributeType?: string,\n autoReverse?: string,\n azimuth?: string,\n baseFrequency?: string,\n baseProfile?: string,\n baselineShift?: string,\n bbox?: string,\n begin?: string,\n bias?: string,\n by?: string,\n calcMode?: string,\n capHeight?: string,\n clip?: string,\n clipPath?: string,\n clipPathUnits?: string,\n clipRule?: string,\n colorInterpolation?: string,\n colorInterpolationFilters?: string,\n colorProfile?: string,\n colorRendering?: string,\n contentScriptType?: string,\n contentStyleType?: string,\n cursor?: string,\n cx?: string,\n cy?: string,\n d?: string,\n decelerate?: string,\n descent?: string,\n diffuseConstant?: string,\n direction?: string,\n display?: string,\n divisor?: string,\n dominantBaseline?: string,\n dur?: string,\n dx?: string,\n dy?: string,\n edgeMode?: string,\n elevation?: string,\n enableBackground?: string,\n end?: string,\n exponent?: string,\n externalResourcesRequired?: string,\n fill?: string,\n fillOpacity?: string,\n fillRule?: string,\n filter?: string,\n filterRes?: string,\n filterUnits?: string,\n floodColor?: string,\n floodOpacity?: string,\n focusable?: string,\n fontFamily?: string,\n fontSize?: string,\n fontSizeAdjust?: string,\n fontStretch?: string,\n fontStyle?: string,\n fontVariant?: string,\n fontWeight?: string,\n fomat?: string,\n from?: string,\n fx?: string,\n fy?: string,\n g1?: string,\n g2?: string,\n glyphName?: string,\n glyphOrientationHorizontal?: string,\n glyphOrientationVertical?: string,\n glyphRef?: string,\n gradientTransform?: string,\n gradientUnits?: string,\n hanging?: string,\n horizAdvX?: string,\n horizOriginX?: string,\n ideographic?: string,\n imageRendering?: string,\n @as(\"in\") in_?: string,\n in2?: string,\n intercept?: string,\n k?: string,\n k1?: string,\n k2?: string,\n k3?: string,\n k4?: string,\n kernelMatrix?: string,\n kernelUnitLength?: string,\n kerning?: string,\n keyPoints?: string,\n keySplines?: string,\n keyTimes?: string,\n lengthAdjust?: string,\n letterSpacing?: string,\n lightingColor?: string,\n limitingConeAngle?: string,\n local?: string,\n markerEnd?: string,\n markerHeight?: string,\n markerMid?: string,\n markerStart?: string,\n markerUnits?: string,\n markerWidth?: string,\n mask?: string,\n maskContentUnits?: string,\n maskUnits?: string,\n mathematical?: string,\n mode?: string,\n numOctaves?: string,\n offset?: string,\n opacity?: string,\n operator?: string,\n order?: string,\n orient?: string,\n orientation?: string,\n origin?: string,\n overflow?: string,\n overflowX?: string,\n overflowY?: string,\n overlinePosition?: string,\n overlineThickness?: string,\n paintOrder?: string,\n panose1?: string,\n pathLength?: string,\n patternContentUnits?: string,\n patternTransform?: string,\n patternUnits?: string,\n pointerEvents?: string,\n points?: string,\n pointsAtX?: string,\n pointsAtY?: string,\n pointsAtZ?: string,\n preserveAlpha?: string,\n preserveAspectRatio?: string,\n primitiveUnits?: string,\n r?: string,\n radius?: string,\n referrerPolicy?: string,\n refX?: string,\n refY?: string,\n renderingIntent?: string,\n repeatCount?: string,\n repeatDur?: string,\n requiredExtensions?: string,\n requiredFeatures?: string,\n restart?: string,\n result?: string,\n rotate?: string,\n rx?: string,\n ry?: string,\n scale?: string,\n seed?: string,\n shapeRendering?: string,\n slope?: string,\n slot?: string,\n spacing?: string,\n specularConstant?: string,\n specularExponent?: string,\n speed?: string,\n spreadMethod?: string,\n startOffset?: string,\n stdDeviation?: string,\n stemh?: string,\n stemv?: string,\n stitchTiles?: string,\n stopColor?: string,\n stopOpacity?: string,\n strikethroughPosition?: string,\n strikethroughThickness?: string,\n string?: string,\n stroke?: string,\n strokeDasharray?: string,\n strokeDashoffset?: string,\n strokeLinecap?: string,\n strokeLinejoin?: string,\n strokeMiterlimit?: string,\n strokeOpacity?: string,\n strokeWidth?: string,\n surfaceScale?: string,\n systemLanguage?: string,\n tableValues?: string,\n targetX?: string,\n targetY?: string,\n textAnchor?: string,\n textDecoration?: string,\n textLength?: string,\n textRendering?: string,\n to?: string,\n transform?: string,\n u1?: string,\n u2?: string,\n underlinePosition?: string,\n underlineThickness?: string,\n unicode?: string,\n unicodeBidi?: string,\n unicodeRange?: string,\n unitsPerEm?: string,\n vAlphabetic?: string,\n vHanging?: string,\n vIdeographic?: string,\n vMathematical?: string,\n values?: string,\n vectorEffect?: string,\n version?: string,\n vertAdvX?: string,\n vertAdvY?: string,\n vertOriginX?: string,\n vertOriginY?: string,\n viewBox?: string,\n viewTarget?: string,\n visibility?: string,\n widths?: string,\n wordSpacing?: string,\n writingMode?: string,\n x?: string,\n x1?: string,\n x2?: string,\n xChannelSelector?: string,\n xHeight?: string,\n xlinkActuate?: string,\n xlinkArcrole?: string,\n xlinkHref?: string,\n xlinkRole?: string,\n xlinkShow?: string,\n xlinkTitle?: string,\n xlinkType?: string,\n xmlns?: string,\n xmlnsXlink?: string,\n xmlBase?: string,\n xmlLang?: string,\n xmlSpace?: string,\n y?: string,\n y1?: string,\n y2?: string,\n yChannelSelector?: string,\n z?: string,\n zoomAndPan?: string,\n about?: string,\n datatype?: string,\n inlist?: string,\n prefix?: string,\n property?: string,\n resource?: string,\n typeof?: string,\n vocab?: string,\n dangerouslySetInnerHTML?: {\"__html\": string},\n suppressContentEditableWarning?: bool,\n}\n```\n\n\n---\n```rescript\n@notUndefined type Jsx.element\n```\n\n\n---\n```rescript\ntype domRef\n```\n\n\n---\n```rescript\ntype popover =\n | @as(\"auto\") Auto\n | @as(\"manual\") Manual\n | @as(\"hint\") Hint\n```\n\n\n---\n```rescript\ntype popoverTargetAction =\n | @as(\"toggle\") Toggle\n | @as(\"show\") Show\n | @as(\"hide\") Hide\n```\n\n\n---\n```rescript\ntype style = JsxDOMStyle.t\n```\n\n\n---\n```rescript\ntype JsxEvent.Synthetic.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Toggle.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Clipboard.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Composition.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Keyboard.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Focus.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Form.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Mouse.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Selection.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Touch.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Pointer.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.UI.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Wheel.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Media.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Image.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Animation.t = synthetic\n```\n\n\n---\n```rescript\ntype JsxEvent.Transition.t = synthetic\n```\n" + } + } + |}] + +let%expect_test "shows a JSX component with documentation and optional props" = + test_jsx_hover ~position:(6, 9) + ~text: + {|module M4 = { + /** Doc Comment For M4 */ + @react.component + let make = (~first, ~fun="", ~second="") => React.string(first ++ fun ++ second) +} + +let _ = +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nReact.component>\n```\n---\n Doc Comment For M4 \n\n---\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\n\n\n---\n```rescript\ntype M4.props<'first, 'fun, 'second> = {\n first: 'first,\n fun?: 'fun,\n second?: 'second,\n}\n```\n" + } + } + |}] + +let fragment_component = + {|module SectionHeader = { + @react.component + let make = (~children) => children +} + +let z = <> {React.string("abc")} +|} + +let%expect_test "shows a component opening tag inside a JSX fragment" = + test_jsx_hover ~text:fragment_component ~position:(5, 18); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nReact.component>\n```\n\n---\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\n\n\n---\n```rescript\ntype SectionHeader.props<'children> = {children: 'children}\n```\n\n\n---\n```rescript\ntype React.element = Jsx.element\n```\n" + } + } + |}] + +let%expect_test "shows hover at a component closing tag inside a JSX fragment" = + test_jsx_hover ~text:fragment_component ~position:(5, 55); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nReact.component\n```\n\n---\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\n\n\n---\n```rescript\ntype React.fragmentProps = {children?: element}\n```\n" + } + } + |}] + +let%expect_test "shows a component prop inside a JSX fragment" = + test_jsx_hover ~position:(6, 12) + ~text: + {|module Comp = { + @react.component + let make = (~age) => React.int(age) +} + +let _ = { + <> +} +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nComp.props\n```\n\n---\n```rescript\ntype Comp.props<'age> = {age: 'age}\n```\n" + } + } + |}] + +let%expect_test "shows a component prop inside nested JSX fragments" = + test_jsx_hover ~position:(6, 16) + ~text: + {|module Comp = { + @react.component + let make = (~age) => React.int(age) +} + +let _ = { + <> {<> } +} +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nComp.props\n```\n\n---\n```rescript\ntype Comp.props<'age> = {age: 'age}\n```\n" + } + } + |}] + +let children_component = + {|module Comp = { + @react.component + let make = (~children: React.element) => children +} + +module Comp1 = Comp + +let _ = + +
+
+ + +let _ = + +
+
+ +|} + +let%expect_test + "returns no hover after a JSX closing tag with multiple children" = + test_jsx_hover ~text:children_component ~position:(11, 10); + [%expect {| |}] + +let%expect_test "returns no hover after an aliased JSX component closing tag" = + test_jsx_hover ~text:children_component ~position:(17, 10); + [%expect {| |}] + +let%expect_test "infers optional props of a function returning a React element" + = + test_jsx_hover ~position:(8, 4) + ~text: + {|module CompV4 = { + type props<'n, 's> = {n?: 'n, s: 's} + let make = props => { + let _ = props.n == Some(10) + React.string(props.s) + } +} + +let mk = CompV4.make +|}; + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nCompV4.props => React.element\n```\n\n---\n```rescript\ntype CompV4.props<'n, 's> = {n?: 'n, s: 's}\n```\n\n\n---\n```rescript\ntype React.element = Jsx.element\n```\n" + } + } + |}] + +let component_implementation = + {|@react.component +let make = (~first) => React.string(first) +let y = 1 +|} + +let component_interface = + {|@react.component +let make: (~first: string) => React.element + +let y: int +|} + +let%expect_test "shows a React component signature in an interface" = + test_jsx_interface_hover ~text:component_implementation + ~interface:component_interface ~position:(1, 4); + [%expect + {| + { + "contents": { + "kind": "markdown", + "value": "```rescript\nprops\n```\n\n---\n```rescript\ntype props<'first> = {first: 'first}\n```\n" + } + } + |}] + +let%expect_test + "shows a value signature next to a React component in an interface" = + test_jsx_interface_hover ~text:component_implementation + ~interface:component_interface ~position:(3, 4); + [%expect + {| { "contents": { "kind": "markdown", "value": "```rescript\nint\n```" } } |}] diff --git a/tests/lsp_tests/inlay_hint.ml b/tests/lsp_tests/inlay_hint.ml new file mode 100644 index 00000000000..31e5a0ec122 --- /dev/null +++ b/tests/lsp_tests/inlay_hint.ml @@ -0,0 +1,170 @@ +open Lsp +open Types + +let hints doc start end_ = + Client_request.InlayHint + (InlayHintParams.create ~textDocument:(Test.text_document doc) + ~range:(Test.range start end_) ()) + +let enable client = + Test.configure client + (`Assoc [("inlayHints", `Assoc [("enable", `Bool true)])]) + +let%expect_test "shows inferred dictionary and dictionary pattern types" = + Test.with_project ~name:"inlay-hint" + ~text: + {|let ints = dict{"a": 1} +let spread = dict{...ints, "b": 2} +let dict{"a": ?first} = ints +|} + (fun ~root ~doc client -> + enable client; + Test.snapshot ~root client (hints doc (0, 0) (3, 0))); + [%expect + {| + [ + { + "kind": 1, + "label": ": option", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 20, "line": 2 } + }, + { + "kind": 1, + "label": ": dict", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 10, "line": 1 } + }, + { + "kind": 1, + "label": ": dict", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 8, "line": 0 } + } + ] + |}] + +let%expect_test "shows inferred plain and tagged template types" = + Test.with_project ~name:"inlay-hint" + ~text: + {|@module("tag") +external tag: taggedTemplate = "default" +let value = "x" +let template = `value: ${value}` +let tagged = tag`value: ${value}` +|} + (fun ~root ~doc client -> + enable client; + Test.snapshot ~root client (hints doc (0, 0) (5, 0))); + [%expect + {| + [ + { + "kind": 1, + "label": ": string", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 10, "line": 4 } + }, + { + "kind": 1, + "label": ": string", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 12, "line": 3 } + }, + { + "kind": 1, + "label": ": string", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 9, "line": 2 } + } + ] + |}] + +let%expect_test "omits generated React component bindings from inlay hints" = + Test.with_project ~name:"inlay-hint-jsx" ~jsx:true + ~text:{|@react.component +let make = (~name) => React.string(name) +|} + (fun ~root ~doc client -> + enable client; + Test.snapshot ~root client (hints doc (0, 0) (2, 0))); + [%expect {| [] |}] + +let%expect_test "does not return inlay hints when disabled" = + Test.with_project ~name:"inlay-hint" ~text:{|let add = (x, y) => x + y +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (hints doc (0, 0) (1, 0))); + [%expect {| null |}] + +let%expect_test "shows inferred function and destructured record types" = + Test.with_project ~name:"inlay-hint" + ~text: + {|let add = (x, y) => x + y +type foo = {name: string, age: int} +let alice = {name: "Alice", age: 42} +let {name, age} = alice +|} + (fun ~root ~doc client -> + enable client; + Test.snapshot ~root client (hints doc (0, 0) (4, 0))); + [%expect + {| + [ + { + "kind": 1, + "label": ": int", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 14, "line": 3 } + }, + { + "kind": 1, + "label": ": string", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 9, "line": 3 } + }, + { + "kind": 1, + "label": ": foo", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 9, "line": 2 } + }, + { + "kind": 1, + "label": ": (int, int) => int", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 7, "line": 0 } + } + ] + |}] + +let%expect_test "restricts inlay hints to the requested lines" = + Test.with_project ~name:"inlay-hint" + ~text:{|let add = (x, y) => x + y +let withAs = (~xx as yyy) => yyy + 1 +|} + (fun ~root ~doc client -> + enable client; + Test.snapshot ~root client (hints doc (1, 0) (1, 35))); + [%expect + {| + [ + { + "kind": 1, + "label": ": (~xx: int) => int", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 10, "line": 1 } + } + ] + |}] diff --git a/tests/lsp_tests/output_configuration.ml b/tests/lsp_tests/output_configuration.ml new file mode 100644 index 00000000000..23b97e8fe8d --- /dev/null +++ b/tests/lsp_tests/output_configuration.ml @@ -0,0 +1,108 @@ +open Lsp +open Types + +let ( /+ ) = Filename.concat + +let with_dependency ~in_source f = + let root = Filename.temp_file "rescript-lsp-output-config-" "" in + Sys.remove root; + Test.mkdir_p root; + Fun.protect + ~finally:(fun () -> Test.remove_project root) + (fun () -> + let dependency = root /+ "node_modules" /+ "child-package" in + let config = + `Assoc + [ + ("name", `String "child-package"); + ("namespace", `String "ChildPackage"); + ("sources", `Assoc [("dir", `String "src")]); + ( "package-specs", + `Assoc + [("module", `String "esmodule"); ("in-source", `Bool in_source)] + ); + ("suffix", `String ".mjs"); + ] + |> Yojson.Safe.to_string + in + Test.write_file (dependency /+ "rescript.json") config; + Test.write_file + (dependency /+ "package.json") + {|{"name":"child-package","version":"1.0.0"}|}; + let doc = + Test.make_document + ~uri:(Uri.of_path (dependency /+ "src" /+ "Child.res")) + ~text:{|let answer = 42 +|} + in + Test.write_file (Uri.to_path doc.uri) doc.text; + let root_doc = + Test.make_document + ~uri:(Uri.of_path (root /+ "Main.res")) + ~text:{|let answer = 1 +|} + in + Test.setup_project ~root ~run_build:true ~documents:[root_doc] + ~rescript_json: + {|{ + "name": "root-package", + "namespace": "RootPackage", + "dependencies": ["child-package"], + "sources": {"dir": "."}, + "package-specs": {"module": "commonjs", "in-source": false}, + "suffix": ".cjs" +}|}; + (* Workspace builds apply the root's output settings to dependencies. + Model an independently produced dependency output, retaining the real + build metadata above for discovery and interface creation. *) + let compiled = + if in_source then dependency /+ "src" /+ "Child.mjs" + else dependency /+ "lib" /+ "es6" /+ "src" /+ "Child.mjs" + in + Test.write_file compiled {|export const answer = 42; +|}; + Test.with_client ~root (fun client -> + Test.perform client (Test.open_document doc); + f ~root ~root_doc ~doc client)) + +let open_compiled doc = + Client_request.UnknownRequest + { + meth = "textDocument/openCompiled"; + params = + Some + (Jsonrpc.Structured.t_of_yojson + (TextDocumentIdentifier.yojson_of_t (Test.text_document doc))); + } + +let%expect_test "uses the dependency's module format and suffix for output" = + with_dependency ~in_source:false (fun ~root ~root_doc ~doc client -> + Test.snapshot ~root client (open_compiled root_doc); + Test.snapshot ~root client (open_compiled doc)); + [%expect + {| + { "uri": "file:///workspace/lib/js/./Main.cjs" } + { + "uri": "file:///workspace/node_modules/child-package/lib/es6/src/Child.mjs" + } + |}] + +let%expect_test "uses the dependency's in-source output setting" = + with_dependency ~in_source:true (fun ~root ~root_doc:_ ~doc client -> + Test.snapshot ~root client (open_compiled doc)); + [%expect + {| { "uri": "file:///workspace/node_modules/child-package/src/Child.mjs" } |}] + +let%expect_test + "creates a nested dependency's interface from a flat namespaced artifact" = + with_dependency ~in_source:false (fun ~root ~root_doc:_ ~doc client -> + assert ( + Sys.file_exists + (root /+ "node_modules" /+ "child-package" /+ "lib" /+ "rescript" + /+ "Child-ChildPackage.cmi")); + Create_interface.create_and_print ~root ~doc client); + [%expect + {| + { "uri": "file:///workspace/node_modules/child-package/src/Child.resi" } + let answer: int + |}] diff --git a/tests/lsp_tests/prepare_rename.ml b/tests/lsp_tests/prepare_rename.ml new file mode 100644 index 00000000000..0322255ee13 --- /dev/null +++ b/tests/lsp_tests/prepare_rename.ml @@ -0,0 +1,41 @@ +open Lsp +open Types + +let prepare_rename doc pos = + Client_request.TextDocumentPrepareRename + (PrepareRenameParams.create ~textDocument:(Test.text_document doc) + ~position:(Test.position pos) ()) + +let%expect_test "selects the identifier range for renaming" = + Test.with_project ~name:"prepare-rename" ~text:{|let x = 12 +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (prepare_rename doc (0, 4))); + [%expect + {| + { + "end": { "character": 5, "line": 0 }, + "start": { "character": 4, "line": 0 } + } + |}] + +let%expect_test "selects a labeled parameter use for renaming" = + Test.with_project ~name:"prepare-rename" ~text:{|let foo = (~xx) => xx + 1 +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (prepare_rename doc (0, 19))); + [%expect + {| + { + "end": { "character": 21, "line": 0 }, + "start": { "character": 19, "line": 0 } + } + |}] + +let%expect_test "does not prepare a rename inside a comment" = + Test.with_project ~name:"prepare-rename" ~text:{|let x = 12 +// x +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (prepare_rename doc (1, 3))); + [%expect {| null |}] diff --git a/tests/lsp_tests/project_recovery.ml b/tests/lsp_tests/project_recovery.ml new file mode 100644 index 00000000000..7493003b94e --- /dev/null +++ b/tests/lsp_tests/project_recovery.ml @@ -0,0 +1,108 @@ +open Lsp +open Types + +let notify_log ~root ~type_ client = + Test.Client.send_notification client + (Client_notification.DidChangeWatchedFiles + (DidChangeWatchedFilesParams.create + ~changes: + [ + FileEvent.create ~type_ + ~uri: + (Uri.of_path + (Filename.concat root "lib/rescript/.compiler.log")); + ])) + +let test_recovery type_ = + Test.with_project ~name:"first-build" ~run_build:false + ~text:{|let value = 1 +|} (fun ~root ~doc client -> + let hover = + Client_request.TextDocumentHover + (HoverParams.create ~textDocument:(Test.text_document doc) + ~position:(Test.position (0, 5)) + ()) + in + Test.snapshot ~root client hover; + ignore (Test.Client.take_notifications client); + (* An early log event can arrive before build metadata exists. It must + leave the session usable and must not repeat initialization errors. *) + notify_log ~root ~type_ client; + Test.synchronize client; + let messages = + Test.Client.take_notifications client + |> List.filter (fun (n : Jsonrpc.Notification.t) -> + n.method_ = "window/showMessage") + in + Printf.printf "repeated initialization messages: %d\n" + (List.length messages); + Test.run_rescript_build ~root; + notify_log ~root ~type_ client; + Test.snapshot ~root client hover; + (* This request uses compiler_config, not only the analysis package cache. *) + Test.snapshot ~root client + (Client_request.UnknownRequest + { + meth = "textDocument/openCompiled"; + params = + Some + (Jsonrpc.Structured.t_of_yojson + (TextDocumentIdentifier.yojson_of_t (Test.text_document doc))); + }); + Test.change_document client doc ~version:1 ~text:{|let unsaved = 2 +|}; + notify_log ~root ~type_:FileChangeType.Changed client; + let symbols = + Client_request.DocumentSymbol + (DocumentSymbolParams.create ~textDocument:(Test.text_document doc) ()) + in + (* The unsaved buffer survives rediscovery; disk still has a valid value. *) + Test.snapshot ~root client symbols) + +let%expect_test "recovers after the first compiler log is created" = + test_recovery FileChangeType.Created; + [%expect + {| + null + repeated initialization messages: 0 + { "contents": { "kind": "markdown", "value": "```rescript\nint\n```" } } + { "uri": "file:///workspace/lib/es6/./Test.res.js" } + [ + { + "kind": 16, + "name": "unsaved", + "range": { + "end": { "character": 15, "line": 0 }, + "start": { "character": 0, "line": 0 } + }, + "selectionRange": { + "end": { "character": 15, "line": 0 }, + "start": { "character": 0, "line": 0 } + } + } + ] + |}] + +let%expect_test "recovers when the client reports the first build as a change" = + test_recovery FileChangeType.Changed; + [%expect + {| + null + repeated initialization messages: 0 + { "contents": { "kind": "markdown", "value": "```rescript\nint\n```" } } + { "uri": "file:///workspace/lib/es6/./Test.res.js" } + [ + { + "kind": 16, + "name": "unsaved", + "range": { + "end": { "character": 15, "line": 0 }, + "start": { "character": 0, "line": 0 } + }, + "selectionRange": { + "end": { "character": 15, "line": 0 }, + "start": { "character": 0, "line": 0 } + } + } + ] + |}] diff --git a/tests/lsp_tests/record_rest.ml b/tests/lsp_tests/record_rest.ml new file mode 100644 index 00000000000..7fe2c336f01 --- /dev/null +++ b/tests/lsp_tests/record_rest.ml @@ -0,0 +1,144 @@ +let text = + {|type config = {name: string, version: string} +module SubConfig = { + type t = {version: string} +} +let getVersion = (config: config) => + switch config { + | {name: _, ...SubConfig.t as rest} => + rest.version + } +let getVersionFromParam = ({name: _, ...SubConfig.t as paramRest}: config) => { + paramRest.version +} +let {name: _, ...SubConfig.t as localRest} = {name: "v", version: "1"} +let {...SubConfig.t as wholeRest} = {version: "2"} +|} + +let%expect_test "finds the declaration of a record-rest binding in a switch" = + Test.with_project ~name:"record-rest" ~text (fun ~root ~doc client -> + Test.snapshot ~root client (Definition.definition doc (7, 5))); + [%expect + {| + [ + { + "range": { + "end": { "character": 36, "line": 6 }, + "start": { "character": 32, "line": 6 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test "completes a record-rest parameter from an unsaved prefix" = + Test.with_project ~name:"record-rest" ~text (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text: + {|type config = {name: string, version: string} +module SubConfig = { + type t = {version: string} +} +let getVersion = (config: config) => + switch config { + | {name: _, ...SubConfig.t as rest} => + rest.version + } +let getVersionFromParam = ({name: _, ...SubConfig.t as paramRest}: config) => { + param +} +let {name: _, ...SubConfig.t as localRest} = {name: "v", version: "1"} +let {...SubConfig.t as wholeRest} = {version: "2"} +|}; + Test.snapshot ~root client (Completion.completion doc (10, 7))); + [%expect + {| + [ + { + "detail": "SubConfig.t", + "documentation": { + "kind": "markdown", + "value": "```rescript\ntype t = {version: string}\n```" + }, + "kind": 12, + "label": "paramRest", + "tags": [] + } + ] + |}] + +let%expect_test "completes a type annotation in a whole-record rest pattern" = + Test.with_project ~name:"record-rest" ~text (fun ~root ~doc client -> + Test.snapshot ~root client (Completion.completion doc (13, 18))); + [%expect + {| + [ + { + "detail": "type t", + "documentation": { + "kind": "markdown", + "value": "```rescript\ntype t = {version: string}\n```" + }, + "kind": 22, + "label": "t", + "tags": [] + } + ] + |}] + +let%expect_test "shows inferred function and record-rest binding hints" = + Test.with_project ~name:"record-rest" ~text (fun ~root ~doc client -> + Inlay_hint.enable client; + Test.snapshot ~root client (Inlay_hint.hints doc (0, 0) (14, 0))); + [%expect + {| + [ + { + "kind": 1, + "label": ": SubConfig.t", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 32, "line": 13 } + }, + { + "kind": 1, + "label": ": SubConfig.t", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 41, "line": 12 } + }, + { + "kind": 1, + "label": ": config => string", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 23, "line": 9 } + }, + { + "kind": 1, + "label": ": config => string", + "paddingLeft": true, + "paddingRight": false, + "position": { "character": 14, "line": 4 } + } + ] + |}] + +let%expect_test "encodes semantic tokens for typed record-rest patterns" = + Test.with_project ~name:"record-rest" ~text (fun ~root ~doc client -> + Test.snapshot ~root client (Semantic_tokens.tokens doc)); + [%expect + {| + { + "data": [ + 0, 5, 6, 2, 0, 0, 10, 4, 6, 0, 0, 6, 6, 2, 0, 0, 8, 7, 6, 0, 0, 9, 6, 2, + 0, 1, 7, 9, 4, 0, 1, 7, 1, 2, 0, 0, 5, 7, 6, 0, 0, 9, 6, 2, 0, 2, 4, 10, + 1, 0, 0, 14, 6, 1, 0, 0, 8, 6, 2, 0, 1, 9, 6, 1, 0, 1, 5, 4, 6, 0, 0, 12, + 9, 4, 0, 0, 10, 1, 2, 0, 0, 5, 4, 1, 0, 1, 4, 4, 1, 0, 0, 5, 7, 6, 0, 2, + 4, 19, 1, 0, 0, 24, 4, 6, 0, 0, 12, 9, 4, 0, 0, 10, 1, 2, 0, 0, 5, 9, 1, + 0, 0, 12, 6, 2, 0, 1, 2, 9, 1, 0, 0, 10, 7, 6, 0, 2, 5, 4, 6, 0, 0, 12, + 9, 4, 0, 0, 10, 1, 2, 0, 0, 5, 9, 1, 0, 0, 14, 4, 6, 0, 0, 11, 7, 6, 0, + 1, 8, 9, 4, 0, 0, 10, 1, 2, 0, 0, 5, 9, 1, 0, 0, 14, 7, 6, 0 + ] + } + |}] diff --git a/tests/lsp_tests/references.ml b/tests/lsp_tests/references.ml new file mode 100644 index 00000000000..3035ccf8110 --- /dev/null +++ b/tests/lsp_tests/references.ml @@ -0,0 +1,261 @@ +open Lsp +open Types + +let references doc pos = + Client_request.TextDocumentReferences + (ReferenceParams.create ~textDocument:(Test.text_document doc) + ~position:(Test.position pos) + ~context:(ReferenceContext.create ~includeDeclaration:true) + ()) + +let%expect_test "finds a consumer from a namespaced module declaration" = + Test.with_project ~name:"namespaced-references" + ~rescript_json: + {|{"name":"namespaced-references","namespace":"my-namespace","sources":{"dir":"."}}|} + ~text:{|let myFunc2 = () => 42 +|} + ~files:[("Consumer.res", {|let myFunc1 = () => Test.myFunc2() +|})] + (fun ~root ~doc client -> + Test.snapshot ~root client (references doc (0, 5))); + [%expect + {| + [ + { + "range": { + "end": { "character": 32, "line": 0 }, + "start": { "character": 25, "line": 0 } + }, + "uri": "file:///workspace/./Consumer.res" + }, + { + "range": { + "end": { "character": 11, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test "finds a namespaced declaration from a consumer" = + Test.with_project ~name:"namespaced-references" + ~rescript_json: + {|{"name":"namespaced-references","namespace":"my-namespace","sources":{"dir":"."}}|} + ~text:{|let myFunc1 = () => Other.myFunc2() +|} + ~files:[("Other.res", {|let myFunc2 = () => 42 +|})] + (fun ~root ~doc client -> + Test.snapshot ~root client (references doc (0, 26))); + [%expect + {| + [ + { + "range": { + "end": { "character": 33, "line": 0 }, + "start": { "character": 26, "line": 0 } + }, + "uri": "file:///workspace/./Test.res" + }, + { + "range": { + "end": { "character": 11, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "uri": "file:///workspace/./Other.res" + } + ] + |}] + +let%expect_test "finds uses through a module alias in another file" = + Test.with_project ~name:"references" ~text:{|let x = 12 +|} + ~files: + [ + ( "Consumer.res", + {|module Ref = Test +let first = Ref.x +let second = Test.x +|} ); + ] + (fun ~root ~doc client -> + Test.snapshot ~root client (references doc (0, 4))); + [%expect + {| + [ + { + "range": { + "end": { "character": 17, "line": 1 }, + "start": { "character": 16, "line": 1 } + }, + "uri": "file:///workspace/./Consumer.res" + }, + { + "range": { + "end": { "character": 19, "line": 2 }, + "start": { "character": 18, "line": 2 } + }, + "uri": "file:///workspace/./Consumer.res" + }, + { + "range": { + "end": { "character": 5, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +(* TODO: Generated component bindings currently repeat the declaration range. *) +let%expect_test "finds references to a nested React component from JSX" = + Test.with_project ~name:"references-jsx" ~jsx:true + ~text: + {|module Comp = { + @react.component + let make = () => React.null +} +let first = +let second = +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (references doc (4, 14))); + [%expect + {| + [ + { + "range": { + "end": { "character": 10, "line": 2 }, + "start": { "character": 6, "line": 2 } + }, + "uri": "file:///workspace/Test.res" + }, + { + "range": { + "end": { "character": 10, "line": 2 }, + "start": { "character": 6, "line": 2 } + }, + "uri": "file:///workspace/Test.res" + }, + { + "range": { + "end": { "character": 10, "line": 2 }, + "start": { "character": 6, "line": 2 } + }, + "uri": "file:///workspace/Test.res" + }, + { + "range": { + "end": { "character": 17, "line": 4 }, + "start": { "character": 13, "line": 4 } + }, + "uri": "file:///workspace/Test.res" + }, + { + "range": { + "end": { "character": 18, "line": 5 }, + "start": { "character": 14, "line": 5 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test "finds the declaration and local uses of a value" = + Test.with_project ~name:"references" + ~text:{|let x = 12 +let a = x +let b = a +let c = x +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (references doc (0, 4))); + [%expect + {| + [ + { + "range": { + "end": { "character": 5, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "uri": "file:///workspace/Test.res" + }, + { + "range": { + "end": { "character": 9, "line": 1 }, + "start": { "character": 8, "line": 1 } + }, + "uri": "file:///workspace/Test.res" + }, + { + "range": { + "end": { "character": 9, "line": 3 }, + "start": { "character": 8, "line": 3 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test "finds a labeled parameter and its use" = + Test.with_project ~name:"references" ~text:{|let foo = (~xx) => xx + 1 +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (references doc (0, 19))); + [%expect + {| + [ + { + "range": { + "end": { "character": 14, "line": 0 }, + "start": { "character": 11, "line": 0 } + }, + "uri": "file:///workspace/Test.res" + }, + { + "range": { + "end": { "character": 21, "line": 0 }, + "start": { "character": 19, "line": 0 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test "finds references across implementation interface and consumer" + = + Test.with_project ~name:"references" ~text:{|let x = 12 +|} + ~files: + [("Test.resi", {|let x: int +|}); ("Consumer.res", {|let a = Test.x +|})] + (fun ~root ~doc client -> + Test.snapshot ~root client (references doc (0, 4))); + [%expect + {| + [ + { + "range": { + "end": { "character": 14, "line": 0 }, + "start": { "character": 13, "line": 0 } + }, + "uri": "file:///workspace/./Consumer.res" + }, + { + "range": { + "end": { "character": 5, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "uri": "file:///workspace/./Test.resi" + }, + { + "range": { + "end": { "character": 5, "line": 0 }, + "start": { "character": 4, "line": 0 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] diff --git a/tests/lsp_tests/rename.ml b/tests/lsp_tests/rename.ml new file mode 100644 index 00000000000..5924bf8479a --- /dev/null +++ b/tests/lsp_tests/rename.ml @@ -0,0 +1,259 @@ +open Lsp +open Types + +let rename doc pos new_name = + Client_request.TextDocumentRename + (RenameParams.create ~textDocument:(Test.text_document doc) + ~position:(Test.position pos) ~newName:new_name ()) + +(* TODO: The newUri values are currently double encoded. This snapshot records + the defect rather than normalizing it into a valid destination URI. *) +let%expect_test "records file renames and qualified edits for a source module" = + Test.with_project ~name:"rename" + ~text:{|let first = Other.x +let second = Other.x +|} + ~files:[("Other.res", {|let x = 12 +|}); ("Other.resi", {|let x: int +|})] + (fun ~root ~doc client -> + Test.snapshot ~root client (rename doc (0, 13) "Renamed")); + [%expect + {| + { + "documentChanges": [ + { + "kind": "rename", + "newUri": "file:///file%3A///workspace/./Renamed.resi", + "oldUri": "file:///workspace/./Other.resi" + }, + { + "kind": "rename", + "newUri": "file:///file%3A///workspace/./Renamed.res", + "oldUri": "file:///workspace/./Other.res" + }, + { + "edits": [ + { + "newText": "Renamed", + "range": { + "end": { "character": 17, "line": 0 }, + "start": { "character": 12, "line": 0 } + } + }, + { + "newText": "Renamed", + "range": { + "end": { "character": 18, "line": 1 }, + "start": { "character": 13, "line": 1 } + } + } + ], + "textDocument": { "uri": "file:///workspace/Test.res", "version": 0 } + } + ] + } + |}] + +let%expect_test "renames a pattern binding without renaming the record field" = + Test.with_project ~name:"rename" + ~text: + {|type person = {name: string} +let person = {name: "Alice"} +let {name: localName} = person +let greeting = localName +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (rename doc (2, 15) "displayName")); + [%expect + {| + { + "documentChanges": [ + { + "edits": [ + { + "newText": "displayName", + "range": { + "end": { "character": 20, "line": 2 }, + "start": { "character": 11, "line": 2 } + } + }, + { + "newText": "displayName", + "range": { + "end": { "character": 24, "line": 3 }, + "start": { "character": 15, "line": 3 } + } + } + ], + "textDocument": { "uri": "file:///workspace/Test.res", "version": 0 } + } + ] + } + |}] + +(* TODO: Renaming the module currently omits its JSX tag references. *) +let%expect_test + "records current rename edits for a component module used in JSX" = + Test.with_project ~name:"rename-jsx" ~jsx:true + ~text: + {|module Comp = { + @react.component + let make = () => React.null +} +let first = +let second = +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (rename doc (0, 8) "Panel")); + [%expect + {| + { + "documentChanges": [ + { + "edits": [ + { + "newText": "Panel", + "range": { + "end": { "character": 11, "line": 0 }, + "start": { "character": 7, "line": 0 } + } + } + ], + "textDocument": { "uri": "file:///workspace/Test.res", "version": 0 } + } + ] + } + |}] + +let%expect_test "renames a value and all local uses" = + Test.with_project ~name:"rename" ~text:{|let x = 12 +let a = x +let c = x +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (rename doc (0, 4) "y")); + [%expect + {| + { + "documentChanges": [ + { + "edits": [ + { + "newText": "y", + "range": { + "end": { "character": 5, "line": 0 }, + "start": { "character": 4, "line": 0 } + } + }, + { + "newText": "y", + "range": { + "end": { "character": 9, "line": 1 }, + "start": { "character": 8, "line": 1 } + } + }, + { + "newText": "y", + "range": { + "end": { "character": 9, "line": 2 }, + "start": { "character": 8, "line": 2 } + } + } + ], + "textDocument": { "uri": "file:///workspace/Test.res", "version": 0 } + } + ] + } + |}] + +let%expect_test "renames a labeled parameter and its use" = + Test.with_project ~name:"rename" ~text:{|let foo = (~xx) => xx + 1 +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (rename doc (0, 19) "yy")); + [%expect + {| + { + "documentChanges": [ + { + "edits": [ + { + "newText": "yy", + "range": { + "end": { "character": 14, "line": 0 }, + "start": { "character": 11, "line": 0 } + } + }, + { + "newText": "yy", + "range": { + "end": { "character": 21, "line": 0 }, + "start": { "character": 19, "line": 0 } + } + } + ], + "textDocument": { "uri": "file:///workspace/Test.res", "version": 0 } + } + ] + } + |}] + +let%expect_test "renames an export in its interface and consumer" = + Test.with_project ~name:"rename" ~text:{|let x = 12 +|} + ~files: + [("Test.resi", {|let x: int +|}); ("Consumer.res", {|let a = Test.x +|})] + (fun ~root ~doc client -> + Test.snapshot ~root client (rename doc (0, 4) "y")); + [%expect + {| + { + "documentChanges": [ + { + "edits": [ + { + "newText": "y", + "range": { + "end": { "character": 5, "line": 0 }, + "start": { "character": 4, "line": 0 } + } + } + ], + "textDocument": { "uri": "file:///workspace/Test.res", "version": 0 } + }, + { + "edits": [ + { + "newText": "y", + "range": { + "end": { "character": 5, "line": 0 }, + "start": { "character": 4, "line": 0 } + } + } + ], + "textDocument": { + "uri": "file:///workspace/./Test.resi", + "version": 0 + } + }, + { + "edits": [ + { + "newText": "y", + "range": { + "end": { "character": 14, "line": 0 }, + "start": { "character": 13, "line": 0 } + } + } + ], + "textDocument": { + "uri": "file:///workspace/./Consumer.res", + "version": 0 + } + } + ] + } + |}] diff --git a/tests/lsp_tests/semantic_tokens.ml b/tests/lsp_tests/semantic_tokens.ml new file mode 100644 index 00000000000..d72ab191cb9 --- /dev/null +++ b/tests/lsp_tests/semantic_tokens.ml @@ -0,0 +1,104 @@ +open Lsp +open Types + +let tokens doc = + Client_request.SemanticTokensFull + (SemanticTokensParams.create ~textDocument:(Test.text_document doc) ()) + +let%expect_test "encodes tokens inside a dictionary literal" = + Test.with_project ~name:"semantic-tokens" ~run_build:false + ~text:{|let d = dict{"foo": bar} +|} (fun ~root ~doc client -> + Test.snapshot ~root client (tokens doc)); + [%expect {| { "data": [ 0, 4, 1, 1, 0, 0, 16, 3, 1, 0 ] } |}] + +let%expect_test "encodes array access with literal and variable indices" = + Test.with_project ~name:"semantic-tokens" ~run_build:false + ~text:{|let x = xs[0] +let x = xs[index] +|} (fun ~root ~doc client -> + Test.snapshot ~root client (tokens doc)); + [%expect + {| + { + "data": [ + 0, 4, 1, 1, 0, 0, 4, 2, 1, 0, 1, 4, 1, 1, 0, 0, 4, 2, 1, 0, 0, 3, 5, 1, 0 + ] + } + |}] + +let%expect_test "encodes array mutation" = + Test.with_project ~name:"semantic-tokens" ~run_build:false + ~text:{|xs[0] = 42 +|} (fun ~root ~doc client -> + Test.snapshot ~root client (tokens doc)); + [%expect {| { "data": [ 0, 0, 2, 1, 0 ] } |}] + +let%expect_test "encodes nested module types and aliased argument labels" = + Test.with_project ~name:"semantic-tokens" ~run_build:false + ~text: + {|module XX = { + module YY = { + type t = int + } +} +open XX.YY +type tt = t +let add = (~hello as x, ~world) => x + world +let _ = add(~hello=3, ...) +|} + (fun ~root ~doc client -> Test.snapshot ~root client (tokens doc)); + [%expect + {| + { + "data": [ + 0, 7, 2, 4, 0, 1, 9, 2, 4, 0, 1, 9, 1, 2, 0, 0, 4, 3, 2, 0, 3, 5, 2, 4, + 0, 0, 3, 2, 4, 0, 1, 5, 2, 2, 0, 0, 5, 1, 2, 0, 1, 4, 3, 1, 0, 0, 17, 1, + 1, 0, 0, 3, 6, 1, 0, 0, 11, 1, 1, 0, 0, 4, 5, 1, 0, 1, 8, 3, 1, 0 + ] + } + |}] + +let%expect_test "encodes intrinsic and nested component JSX tags" = + Test.with_project ~name:"semantic-tokens" ~run_build:false + ~text:{|let _ =
+|} + (fun ~root ~doc client -> Test.snapshot ~root client (tokens doc)); + [%expect + {| + { + "data": [ + 0, 8, 1, 3, 0, 0, 1, 3, 7, 0, 0, 15, 1, 3, 0, 0, 2, 1, 3, 0, 0, 1, 13, 4, + 0, 0, 14, 6, 4, 0, 0, 7, 1, 3, 0, 0, 3, 1, 3, 0, 0, 2, 3, 7, 0, 0, 3, 1, + 3, 0 + ] + } + |}] + +let%expect_test "encodes semantic tokens for array literals and spreads" = + Test.with_project ~name:"semantic-tokens" ~run_build:false + ~text:{|let xs = [1, 2] +let ys = [...xs, 3] +|} (fun ~root ~doc client -> + Test.snapshot ~root client (tokens doc)); + [%expect {| { "data": [ 0, 4, 2, 1, 0, 1, 4, 2, 1, 0, 0, 9, 2, 1, 0 ] } |}] + +let%expect_test "encodes semantic tokens for list literals and spreads" = + Test.with_project ~name:"semantic-tokens" ~run_build:false + ~text:{|let xs = list{1, 2} +let ys = list{...xs, 3} +|} + (fun ~root ~doc client -> Test.snapshot ~root client (tokens doc)); + [%expect {| { "data": [ 0, 4, 2, 1, 0, 1, 4, 2, 1, 0, 0, 13, 2, 1, 0 ] } |}] + +let%expect_test "clears semantic tokens when the buffer becomes empty" = + Test.with_project ~name:"semantic-tokens" ~run_build:false + ~text:{|let x = 1 +|} (fun ~root ~doc client -> + Test.snapshot ~root client (tokens doc); + Test.change_document client doc ~version:1 ~text:{||}; + Test.snapshot ~root client (tokens doc)); + [%expect {| + { "data": [ 0, 4, 1, 1, 0 ] } + { "data": [] } + |}] diff --git a/tests/lsp_tests/signature_help.ml b/tests/lsp_tests/signature_help.ml new file mode 100644 index 00000000000..050a3a54eff --- /dev/null +++ b/tests/lsp_tests/signature_help.ml @@ -0,0 +1,305 @@ +open Lsp +open Types + +let signature doc pos = + Client_request.SignatureHelp + (SignatureHelpParams.create ~textDocument:(Test.text_document doc) + ~position:(Test.position pos) ()) + +let%expect_test "selects an optional labeled argument" = + Test.with_project ~name:"signature-help" + ~text: + {|let someFunc = (one: int, ~two: option=?, ()) => { + ignore(one) + ignore(two) +} +let _ = someFunc(123, ~two="123", ()) +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (signature doc (4, 28))); + [%expect + {| + { + "activeParameter": 1, + "activeSignature": 0, + "signatures": [ + { + "activeParameter": 1, + "label": "(int, ~two: string=?, unit) => unit", + "parameters": [ + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 1, 4 ] + }, + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 7, 20 ] + }, + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 22, 26 ] + } + ] + } + ] + } + |}] + +let%expect_test "accounts for the piped argument when selecting a parameter" = + Test.with_project ~name:"signature-help" + ~text: + {|let otherFunc = (first: string, second: int, third: float) => { + ignore(first) + ignore(second) + ignore(third) +} +let _ = "hello"->otherFunc(1, 2.0) +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (signature doc (5, 26))); + [%expect + {| + { + "activeParameter": 1, + "activeSignature": 0, + "signatures": [ + { + "activeParameter": 1, + "label": "(string, int, float) => unit", + "parameters": [ + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 1, 7 ] + }, + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 9, 12 ] + }, + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 14, 19 ] + } + ] + } + ] + } + |}] + +let%expect_test "distinguishes a constructor with a single tuple payload" = + Test.with_project ~name:"signature-help" + ~text:{|type unary = Unary((int, string)) +let unary = Unary(1, "test") +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (signature doc (1, 22))); + [%expect + {| + { + "activeParameter": 0, + "activeSignature": 0, + "signatures": [ + { + "activeParameter": 0, + "label": "Unary((int, string))", + "parameters": [ + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 6, 19 ] + } + ] + } + ] + } + |}] + +let%expect_test "shows constructor signature help in a destructuring pattern" = + Test.with_project ~name:"signature-help" + ~text: + {|type t = Pair(int, string) +let read = value => switch value { +| Pair(first, second) => second +} +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (signature doc (2, 15))); + [%expect + {| + { + "activeParameter": 1, + "activeSignature": 0, + "signatures": [ + { + "activeParameter": 1, + "label": "Pair(int, string)", + "parameters": [ + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 5, 8 ] + }, + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 10, 16 ] + } + ] + } + ] + } + |}] + +let%expect_test "selects the next constructor argument in the gap after a comma" + = + Test.with_project ~name:"signature-help" + ~text:{|type t = Three(string, array) +let value = Three("", []) +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (signature doc (1, 22))); + [%expect + {| + { + "activeParameter": 1, + "activeSignature": 0, + "signatures": [ + { + "activeParameter": 1, + "label": "Three(string, array)", + "parameters": [ + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 6, 12 ] + }, + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 14, 24 ] + } + ] + } + ] + } + |}] + +(* TODO: Recovery for an omitted constructor argument currently returns no + signature, unlike the whitespace gap before an existing argument above. *) +let%expect_test "returns no signature for a missing constructor payload" = + let text = + {|type t = Three(string, array) +let value = Three("", []) +|} + in + Test.with_project ~name:"signature-help" ~text (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(text ^ {|let next = Three("", )|}); + Test.snapshot ~root client (signature doc (2, 21))); + [%expect {| { "signatures": [] } |}] + +let function_source = + {|let otherFunc = (first: string, second: int, third: float) => { + ignore(first) + ignore(second) + ignore(third) +} +|} + +let%expect_test "shows the first parameter of an incomplete function call" = + Test.with_project ~name:"signature-help" ~text:function_source + (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(function_source ^ {|let _ = otherFunc(|}); + Test.snapshot ~root client (signature doc (5, 18))); + [%expect + {| + { + "activeParameter": 0, + "activeSignature": 0, + "signatures": [ + { + "activeParameter": 0, + "label": "(string, int, float) => unit", + "parameters": [ + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 1, 7 ] + }, + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 9, 12 ] + }, + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 14, 19 ] + } + ] + } + ] + } + |}] + +let%expect_test "selects the second parameter after a comma" = + Test.with_project ~name:"signature-help" ~text:function_source + (fun ~root ~doc client -> + Test.change_document client doc ~version:1 + ~text:(function_source ^ {|let _ = otherFunc("123", 123, 123.0) +|}); + Test.snapshot ~root client (signature doc (5, 25))); + [%expect + {| + { + "activeParameter": 1, + "activeSignature": 0, + "signatures": [ + { + "activeParameter": 1, + "label": "(string, int, float) => unit", + "parameters": [ + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 1, 7 ] + }, + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 9, 12 ] + }, + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 14, 19 ] + } + ] + } + ] + } + |}] + +let%expect_test "shows a documented constructor payload signature" = + Test.with_project ~name:"signature-help" + ~text:{|type t = + | /** Two is fun! */ Two(string) +let two = Two("true") +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (signature doc (2, 14))); + [%expect + {| + { + "activeParameter": 0, + "activeSignature": 0, + "signatures": [ + { + "activeParameter": 0, + "documentation": { "kind": "markdown", "value": " Two is fun! " }, + "label": "Two(string)", + "parameters": [ + { + "documentation": { "kind": "markdown", "value": "" }, + "label": [ 4, 10 ] + } + ] + } + ] + } + |}] + +let%expect_test "returns no signatures outside a call" = + Test.with_project ~name:"signature-help" ~text:{|let x = 12 +|} + (fun ~root ~doc client -> Test.snapshot ~root client (signature doc (0, 4))); + [%expect {| { "signatures": [] } |}] diff --git a/tests/lsp_tests/test.ml b/tests/lsp_tests/test.ml new file mode 100644 index 00000000000..ea461c171d0 --- /dev/null +++ b/tests/lsp_tests/test.ml @@ -0,0 +1,441 @@ +let ( // ) = Filename.concat + +(* Dune runs inline tests from this library's build directory. Resolve its + declared CLI dependency before setup changes into temporary workspaces. *) +let executable = + Sys.getcwd () // ".." // ".." // "rewatch-ocaml" // "rescript_ocaml.exe" + +let source_root () = + Sys.getenv_opt "DUNE_SOURCEROOT" |> Option.value ~default:(Sys.getcwd ()) + +(* These tests invoke the native CLI without the npm launcher that normally + sets RESCRIPT_RUNTIME. Both builds and the LSP inherit the same runtime. *) +let () = + Unix.putenv "RESCRIPT_RUNTIME" + (source_root () // "packages" // "@rescript" // "runtime") + +let rec mkdir_p path = + if path = "" || Sys.file_exists path then () + else ( + mkdir_p (Filename.dirname path); + Unix.mkdir path 0o755) + +let write_file path content = + mkdir_p (Filename.dirname path); + let oc = open_out_bin path in + Fun.protect + ~finally:(fun () -> close_out_noerr oc) + (fun () -> output_string oc content) + +let with_chdir dir f = + let cwd = Sys.getcwd () in + Fun.protect + ~finally:(fun () -> Sys.chdir cwd) + (fun () -> + Sys.chdir dir; + f ()) + +let run_rescript_build ~root = + let null_device = if Sys.os_type = "Win32" then "NUL" else "/dev/null" in + let dev_null = Unix.openfile null_device [Unix.O_WRONLY] 0 in + Fun.protect + ~finally:(fun () -> Unix.close dev_null) + (fun () -> + with_chdir root (fun () -> + let pid = + Unix.create_process_env executable [|executable; "build"|] + (Unix.environment ()) Unix.stdin dev_null dev_null + in + match snd (Unix.waitpid [] pid) with + | Unix.WEXITED 0 -> () + | Unix.WEXITED code -> + failwith (Printf.sprintf "rescript build exited with code %d" code) + | Unix.WSIGNALED signal -> + failwith + (Printf.sprintf "rescript build killed by signal %d" signal) + | Unix.WSTOPPED signal -> + failwith + (Printf.sprintf "rescript build stopped by signal %d" signal))) + +module Client = struct + (** Helpers for spawning the ReScript language server in tests, sending + LSP requests/notifications over stdio, and reading responses back. *) + + type t = { + process_stdout: in_channel; + process_stdin: out_channel; + mutable next_id: int; + mutable stopped: bool; + mutable notifications: Jsonrpc.Notification.t list; + } + + let frame (json : Yojson.Safe.t) : string = + let body = Yojson.Safe.to_string json in + Printf.sprintf "Content-Length: %d\r\n\r\n%s" (String.length body) body + + let read_headers t = + let rec loop acc = + match input_line t.process_stdout with + | line when String.trim line = "" -> Some acc + | line -> + let acc = + match String.index_opt line ':' with + | None -> acc + | Some i -> + let k = String.sub line 0 i in + let v = + String.trim (String.sub line (i + 1) (String.length line - i - 1)) + in + (k, v) :: acc + in + loop acc + | exception End_of_file -> if acc = [] then None else Some acc + in + loop [] + + let read_message t = + match read_headers t with + | None -> None + | Some headers -> ( + let len = int_of_string (List.assoc "Content-Length" headers) in + match really_input_string t.process_stdout len with + | body -> Some (Yojson.Safe.from_string body) + | exception End_of_file -> None) + + let start () = + let process_stdout, process_stdin = + Unix.open_process_args executable [|executable; "lsp"; "--stdio"|] + in + set_binary_mode_in process_stdout true; + set_binary_mode_out process_stdin true; + { + process_stdout; + process_stdin; + next_id = 0; + stopped = false; + notifications = []; + } + + let send_packet t (packet : Jsonrpc.Packet.t) = + let json = Jsonrpc.Packet.yojson_of_t packet in + output_string t.process_stdin (frame json); + flush t.process_stdin + + let next_id t = + t.next_id <- t.next_id + 1; + t.next_id + + (** Send a typed LSP request and return the assigned id. *) + let send_request t (req : 'r Lsp.Client_request.t) = + let id = `Int (next_id t) in + let jsonrpc_req = Lsp.Client_request.to_jsonrpc_request req ~id in + send_packet t (Jsonrpc.Packet.Request jsonrpc_req); + id + + (** Send a typed LSP notification. *) + let send_notification t (notif : Lsp.Client_notification.t) = + let jsonrpc_notif = Lsp.Client_notification.to_jsonrpc notif in + send_packet t (Jsonrpc.Packet.Notification jsonrpc_notif) + + (** Keep notifications for assertions and acknowledge refresh requests while + waiting for the response. This lets tests inspect every publication, not + just the final diagnostic state. *) + let rec read_response t id = + match read_message t with + | None -> failwith "Helper.read_response: unexpected EOF" + | Some json -> ( + match Jsonrpc.Packet.t_of_yojson json with + | Response resp when resp.id = id -> resp + | Notification notification -> + t.notifications <- notification :: t.notifications; + read_response t id + | Request request + when List.mem request.method_ + [ + "workspace/diagnostic/refresh"; + "workspace/codeLens/refresh"; + "workspace/inlayHint/refresh"; + ] -> + send_packet t + (Jsonrpc.Packet.Response (Jsonrpc.Response.ok request.id `Null)); + read_response t id + | _ -> read_response t id) + + let take_notifications t = + let notifications = List.rev t.notifications in + t.notifications <- []; + notifications + + (** Send a typed request and synchronously wait for its response, decoded + back into the request's result type. *) + let request (type r) t (req : r Lsp.Client_request.t) : r = + let id = send_request t req in + let resp = read_response t id in + match resp.result with + | Ok json -> Lsp.Client_request.response_of_json req json + | Error err -> failwith ("LSP error response: " ^ err.message) + + let rec read_request t method_ = + match read_message t with + | None -> failwith "Helper.read_request: unexpected EOF" + | Some json -> ( + match Jsonrpc.Packet.t_of_yojson json with + | Request request when request.method_ = method_ -> request + | Notification notification -> + t.notifications <- notification :: t.notifications; + read_request t method_ + | _ -> read_request t method_) + + let respond_ok t (request : Jsonrpc.Request.t) = + Jsonrpc.Response.ok request.id `Null |> fun response -> + send_packet t (Jsonrpc.Packet.Response response) + + (** Read the next packet of any kind. Useful when waiting for a server + notification (e.g. publishDiagnostics). *) + (* let read_packet t = + match read_message t with + | None -> failwith "Helper.read_packet: unexpected EOF" + | Some json -> Jsonrpc.Packet.t_of_yojson json *) + + let stop t = + if t.stopped then Unix.WEXITED 0 + else ( + t.stopped <- true; + (try close_out_noerr t.process_stdin with _ -> ()); + try Unix.close_process (t.process_stdout, t.process_stdin) + with _ -> Unix.WEXITED 0) +end + +open Lsp +open Types + +let make_document ~uri ~text = + TextDocumentItem.create ~uri ~languageId:(LanguageKind.Other "rescript") + ~version:0 ~text + +let write_document path (doc : TextDocumentItem.t) = + let path = path // (doc.uri |> Uri.to_path |> Filename.basename) in + write_file path doc.text + +let setup_project ~root ~rescript_json ~run_build ~documents = + mkdir_p root; + write_document root + (TextDocumentItem.create ~languageId:LanguageKind.JSON ~text:rescript_json + ~uri:(Uri.of_string "rescript.json") + ~version:0); + List.iter (write_document root) documents; + if run_build then run_rescript_build ~root + +let client_capabilities = + ClientCapabilities.create + ~textDocument: + (TextDocumentClientCapabilities.create + ~diagnostic:(DiagnosticClientCapabilities.create ()) + ()) + ~workspace: + (WorkspaceClientCapabilities.create + ~diagnostics: + (DiagnosticWorkspaceClientCapabilities.create ~refreshSupport:true ()) + ()) + () + +let initialize_client ~capabilities ~root client = + let init_params = + InitializeParams.create ~capabilities ~rootUri:(DocumentUri.of_path root) () + in + let id = Client.send_request client (Client_request.Initialize init_params) in + assert ((Client.read_response client id).result |> Result.is_ok); + Client.send_notification client + (Client_notification.Initialized (InitializedParams.t_of_yojson (`Assoc []))); + let registration = Client.read_request client "client/registerCapability" in + Client.respond_ok client registration + +type action = + | Request : 'result Client_request.t * ('result -> unit) -> action + | Notification of Client_notification.t + +let perform client = function + | Request (request, on_response) -> + Client.request client request |> on_response + | Notification notification -> Client.send_notification client notification + +let perform_all client actions = List.iter (perform client) actions + +let start_client_with_capabilities ~capabilities ~root = + let client = Client.start () in + try + initialize_client ~capabilities ~root client; + client + with exn -> + ignore (Client.stop client); + raise exn + +let with_client ?(capabilities = client_capabilities) ~root f = + let client = start_client_with_capabilities ~capabilities ~root in + Fun.protect + ~finally:(fun () -> ignore (Client.stop client)) + (fun () -> f client) + +let open_document (doc : TextDocumentItem.t) = + let notification = + Client_notification.TextDocumentDidOpen + (DidOpenTextDocumentParams.create + ~textDocument: + (TextDocumentItem.create ~uri:doc.uri + ~languageId:(LanguageKind.Other "rescript") ~version:0 + ~text:doc.text)) + in + Notification notification + +let change_document client (doc : TextDocumentItem.t) ~version ~text = + Client.send_notification client + (Client_notification.TextDocumentDidChange + (DidChangeTextDocumentParams.create + ~textDocument: + (VersionedTextDocumentIdentifier.create ~uri:doc.uri ~version) + ~contentChanges: + [ + `TextDocumentContentChangeWholeDocument + (TextDocumentContentChangeWholeDocument.create ~text); + ])) + +let configure client settings = + Client.send_notification client + (Client_notification.ChangeConfiguration + (DidChangeConfigurationParams.create ~settings)); + let request = Client.read_request client "workspace/configuration" in + Client.send_packet client + (Jsonrpc.Packet.Response (Jsonrpc.Response.ok request.id (`List [settings]))) + +let position (line, character) = Position.create ~line ~character + +let range start end_ = + Range.create ~start:(position start) ~end_:(position end_) + +let text_document (doc : TextDocumentItem.t) = + TextDocumentIdentifier.create ~uri:doc.uri + +(* Only replace the temporary workspace prefix; keep relative paths, ranges and + response ordering intact so snapshots still catch navigation/edit regressions. *) +let normalize_json ~root json = + let prefixes = + [ + (* File rename currently encodes an already encoded URI as a path. Keep + that defect visible in snapshots while removing the random root. *) + ( Uri.to_string (Uri.of_path (Uri.to_string (Uri.of_path root))), + "file:///file%3A///workspace" ); + (Uri.to_string (Uri.of_path root), "file:///workspace"); + (root, "/workspace"); + ] + in + let normalize_string value = + List.find_map + (fun (prefix, replacement) -> + let length = String.length prefix in + if + String.starts_with ~prefix value + && (String.length value = length + || value.[length] = '/' + || value.[length] = '\\') + then + let suffix = String.sub value length (String.length value - length) in + let suffix = + if Sys.win32 then + String.map + (function + | '\\' -> '/' + | c -> c) + suffix + else suffix + in + Some (replacement ^ suffix) + else None) + prefixes + |> Option.value ~default:value + in + let rec normalize = function + | `String value -> `String (normalize_string value) + | `Assoc fields -> + `Assoc + (List.map + (fun (key, value) -> (normalize_string key, normalize value)) + fields) + | `List values -> `List (List.map normalize values) + | value -> value + in + normalize json + +let print_json ~root json = + normalize_json ~root json |> Yojson.Safe.pretty_to_string |> print_endline + +let snapshot ~root client request = + Client.request client request + |> Client_request.yojson_of_result request + |> print_json ~root + +(* A round trip is a barrier for preceding notifications. No timing assumptions + or sleeps are needed to assert the complete diagnostic publication sequence. + An unsupported request also provides a barrier without creating dump files + or requiring window/showDocument support. *) +let synchronize client = + let id = + Client.send_request client + (Client_request.UnknownRequest {meth = "test/synchronize"; params = None}) + in + ignore (Client.read_response client id) + +let setup_react ~root = + let source = + source_root () // "tests" // "dependencies" // "rescript-react" + in + let destination = root // "node_modules" // "@rescript" // "react" in + let sources = + Sys.readdir (source // "src") + |> Array.to_list + |> List.filter (fun name -> + Filename.check_suffix name ".res" || Filename.check_suffix name ".resi") + |> List.map (Filename.concat "src") + in + List.iter + (fun path -> + let content = + In_channel.with_open_bin (source // path) In_channel.input_all + in + write_file (destination // path) content) + ("rescript.json" :: "package.json" :: sources) + +let rec remove_project path = + if (Unix.lstat path).st_kind = Unix.S_DIR then ( + Sys.readdir path |> Array.iter (fun name -> remove_project (path // name)); + Unix.rmdir path) + else Sys.remove path + +let with_project ?(files = []) ?(run_build = true) ?(jsx = false) ?rescript_json + ?(capabilities = client_capabilities) ~name ~text f = + let root = Filename.temp_file ("rescript-lsp-" ^ name ^ "-") "" in + Sys.remove root; + mkdir_p root; + Fun.protect + ~finally:(fun () -> remove_project root) + (fun () -> + let doc = make_document ~uri:(Uri.of_path (root // "Test.res")) ~text in + let documents = + doc + :: List.map + (fun (file, text) -> + make_document ~uri:(Uri.of_path (root // file)) ~text) + files + in + let rescript_json = + match rescript_json with + | Some config -> config + | None when jsx -> + {|{"name":"lsp-test","sources":{"dir":"."},"dependencies":["@rescript/react"],"jsx":{"version":4},"package-specs":{"module":"esmodule","in-source":false},"suffix":".res.js"}|} + | None -> + {|{"name":"lsp-test","sources":{"dir":"."},"package-specs":{"module":"esmodule","in-source":false},"suffix":".res.js"}|} + in + if jsx then setup_react ~root; + setup_project ~root ~rescript_json ~run_build ~documents; + with_client ~capabilities ~root (fun client -> + perform client (open_document doc); + f ~root ~doc client)) diff --git a/tests/lsp_tests/type_definition.ml b/tests/lsp_tests/type_definition.ml new file mode 100644 index 00000000000..41bb24ec394 --- /dev/null +++ b/tests/lsp_tests/type_definition.ml @@ -0,0 +1,93 @@ +open Lsp +open Types + +let type_definition doc pos = + Client_request.TextDocumentTypeDefinition + (TypeDefinitionParams.create ~textDocument:(Test.text_document doc) + ~position:(Test.position pos) ()) + +let%expect_test "finds a record type through a module alias" = + Test.with_project ~name:"type-definition" + ~text:{|module Alias = Other +let value = Alias.make() +|} + ~files: + [ + ( "Other.res", + {|type t = {name: string} +let make = () => {name: "Alice"} +|} ); + ] + (fun ~root ~doc client -> + Test.snapshot ~root client (type_definition doc (1, 5))); + [%expect + {| + [ + { + "range": { + "end": { "character": 23, "line": 0 }, + "start": { "character": 0, "line": 0 } + }, + "uri": "file:///workspace/Other.res" + } + ] + |}] + +let%expect_test "finds the variant type of an inferred binding" = + Test.with_project ~name:"type-definition" + ~text:{|type variant = Foo | Bar +let x = Foo +|} (fun ~root ~doc client -> + Test.snapshot ~root client (type_definition doc (1, 4))); + [%expect + {| + [ + { + "range": { + "end": { "character": 24, "line": 0 }, + "start": { "character": 0, "line": 0 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test "finds the record type of an inferred binding" = + Test.with_project ~name:"type-definition" + ~text:{|type record = {item: string} +let y = {item: "foo"} +|} + (fun ~root ~doc client -> + Test.snapshot ~root client (type_definition doc (1, 4))); + [%expect + {| + [ + { + "range": { + "end": { "character": 28, "line": 0 }, + "start": { "character": 0, "line": 0 } + }, + "uri": "file:///workspace/Test.res" + } + ] + |}] + +let%expect_test "finds a type declared in another file" = + Test.with_project ~name:"type-definition" ~text:{|let x = Other.Foo +|} + ~files:[("Other.res", {|type variant = Foo | Bar +|})] + (fun ~root ~doc client -> + Test.snapshot ~root client (type_definition doc (0, 4))); + [%expect + {| + [ + { + "range": { + "end": { "character": 24, "line": 0 }, + "start": { "character": 0, "line": 0 } + }, + "uri": "file:///workspace/Other.res" + } + ] + |}] diff --git a/tests/rewatch_ounit_tests/cli_tests.ml b/tests/rewatch_ounit_tests/cli_tests.ml index 6e9e888cffa..aa543f303ad 100644 --- a/tests/rewatch_ounit_tests/cli_tests.ml +++ b/tests/rewatch_ounit_tests/cli_tests.ml @@ -34,6 +34,24 @@ let watch_options arguments = let tests = "cli_tests" >:: fun _context -> + check + (parse ["lsp"; "--stdio"] = Cli.Lsp) + "lsp selects the stdio language server"; + check (rejects ["lsp"]) "lsp requires --stdio"; + List.iter + (fun flag -> + check + (rejects ["lsp"; "--stdio"; flag]) + "lsp rejects verbosity options after the command"; + check + (rejects [flag; "lsp"; "--stdio"]) + "lsp rejects verbosity options before the command") + ["--quiet"; "-q"; "--verbose"; "-v"; "-vv"]; + check (shows_help ["lsp"; "--help"]) "lsp displays command help"; + check (shows_help ["help"; "lsp"]) "help recognizes lsp"; + check (shows_version ["lsp"; "--version"]) "lsp accepts the global version"; + check (rejects ["lsp"; "--socket"]) "lsp rejects unsupported transports"; + check (rejects ["lsp"; "project"]) "lsp does not accept a build folder"; check (match parse [] with | Cli.Build _ -> true From 6c3b7b0ed4e1dd541460e28b8eba0e4b03770b8d Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 16 Nov 2026 23:15:33 -0300 Subject: [PATCH 02/13] Add --clientProcessId argument in lsp subcommand Accept the positive client PID that some editors append automatically so their standard launch command works. Keep --stdio mandatory and leave process monitoring outside this compatibility option. Command modified (LSP client compatibility): Before (text): rescript lsp --stdio --clientProcessId 123: rejected After (text): rescript lsp --stdio --clientProcessId 123: accepted The PID must be a positive integer and is not monitored. Update CLI parsing tests and help snapshots for the optional argument. Signed-off-by: Pedro Castro --- rewatch-ocaml/cli.ml | 36 ++++++++++++++--- tests/build_tests/cli_help/input.js | 53 ++++++++++++++++++++++++-- tests/rewatch_ounit_tests/cli_tests.ml | 19 +++++++++ 3 files changed, 99 insertions(+), 9 deletions(-) diff --git a/rewatch-ocaml/cli.ml b/rewatch-ocaml/cli.ml index 442911e523b..86ab7aa49b6 100644 --- a/rewatch-ocaml/cli.ml +++ b/rewatch-ocaml/cli.ml @@ -219,12 +219,36 @@ let compiler_args_term = Compiler_args {verbosity; path} let lsp_term = - Arg.( - required - & vflag None - [ - (Some Lsp, info ["stdio"] ~doc:"Use standard input/output (required)."); - ]) + let stdio = + Arg.( + required + & vflag None + [ + ( Some Lsp, + info ["stdio"] ~doc:"Use standard input/output (required)." ); + ]) + in + let client_process_id = + let parse value = + match int_of_string_opt value with + | Some pid when pid > 0 -> Ok pid + | Some _ | None -> + Error (`Msg "client process ID must be a positive integer") + in + let converter = Arg.conv (parse, Stdlib.Format.pp_print_int) in + Arg.( + value + & opt (some converter) None + & info ["clientProcessId"] ~docv:"PID" + ~doc: + "Accept a client process ID for editor compatibility. The server \ + does not monitor this process.") + in + let+ command = stdio and+ client_process_id in + (* Some editors append this argument automatically. It is accepted only for + launch compatibility; shutdown and exit still follow the LSP lifecycle. *) + ignore client_process_id; + command let exits = [ diff --git a/tests/build_tests/cli_help/input.js b/tests/build_tests/cli_help/input.js index b9628ffd78d..1160d018f78 100755 --- a/tests/build_tests/cli_help/input.js +++ b/tests/build_tests/cli_help/input.js @@ -39,7 +39,7 @@ const cliHelp = " help [OPTION]… [COMMAND]\n" + " Print this message or command help.\n" + "\n" + - " lsp --stdio [OPTION]…\n" + + " lsp [--clientProcessId=PID] --stdio [OPTION]…\n" + " Start the ReScript language server over stdio.\n" + "\n" + " watch [OPTION]… [FOLDER]\n" + @@ -319,6 +319,46 @@ const compilerArgsHelp = " rescript(1)\n" + "\n"; +const lspHelp = + "NAME\n" + + " rescript-lsp - Start the ReScript language server over stdio.\n" + + "\n" + + "SYNOPSIS\n" + + " rescript lsp [--clientProcessId=PID] --stdio [OPTION]…\n" + + "\n" + + "OPTIONS\n" + + " --clientProcessId=PID\n" + + " Accept a client process ID for editor compatibility. The server\n" + + " does not monitor this process.\n" + + "\n" + + " --stdio (required)\n" + + " Use standard input/output (required).\n" + + "\n" + + "COMMON OPTIONS\n" + + " --help[=FMT] (default=auto)\n" + + " Show this help in format FMT. The value FMT must be one of auto,\n" + + " pager, groff or plain. With auto, the format is pager or plain\n" + + " whenever the TERM env var is dumb or undefined.\n" + + "\n" + + " --version\n" + + " Show version information.\n" + + "\n" + + "EXIT STATUS\n" + + " rescript lsp exits with:\n" + + "\n" + + " 0 on success.\n" + + "\n" + + " 1 on build, configuration, dependency, or file system errors.\n" + + "\n" + + " 2 on command-line usage errors.\n" + + "\n" + + " 129-143\n" + + " when interrupted by a signal (128 plus the signal number).\n" + + "\n" + + "SEE ALSO\n" + + " rescript(1)\n" + + "\n"; + /** * @param {string[]} params * @param {{ stdout: string; stderr: string; status: number; }} expected @@ -345,7 +385,7 @@ async function test(params, expected) { await test(["lsp"], { stdout: "", stderr: - "Usage: rescript lsp [--help] --stdio [OPTION]…\n" + + "Usage: rescript lsp [--help] [--clientProcessId=PID] --stdio [OPTION]…\n" + "rescript: required option --stdio is missing\n", status: 2, }); @@ -354,7 +394,7 @@ for (const flag of ["--quiet", "--verbose"]) { await test(["lsp", "--stdio", flag], { stdout: "", stderr: - "Usage: rescript lsp [--help] --stdio [OPTION]…\n" + + "Usage: rescript lsp [--help] [--clientProcessId=PID] --stdio [OPTION]…\n" + `rescript: unknown option ${flag}\n`, status: 2, }); @@ -447,3 +487,10 @@ await test(["compiler-args", "-h"], { stderr: "", status: 0, }); + +for (const params of [ + ["lsp", "--help"], + ["help", "lsp"], +]) { + await test(params, { stdout: lspHelp, stderr: "", status: 0 }); +} diff --git a/tests/rewatch_ounit_tests/cli_tests.ml b/tests/rewatch_ounit_tests/cli_tests.ml index aa543f303ad..1e63825d10a 100644 --- a/tests/rewatch_ounit_tests/cli_tests.ml +++ b/tests/rewatch_ounit_tests/cli_tests.ml @@ -38,6 +38,25 @@ let tests = (parse ["lsp"; "--stdio"] = Cli.Lsp) "lsp selects the stdio language server"; check (rejects ["lsp"]) "lsp requires --stdio"; + List.iter + (fun arguments -> + check (parse arguments = Cli.Lsp) "lsp accepts the client process ID") + [ + ["lsp"; "--stdio"; "--clientProcessId"; "123"]; + ["lsp"; "--clientProcessId=123"; "--stdio"]; + ]; + check + (rejects ["lsp"; "--clientProcessId"; "123"]) + "a client process ID does not replace --stdio"; + check + (rejects ["lsp"; "--stdio"; "--clientProcessId"]) + "the client process ID requires a value"; + List.iter + (fun value -> + check + (rejects ["lsp"; "--stdio"; "--clientProcessId=" ^ value]) + "lsp rejects invalid client process IDs") + ["abc"; "0"; "-1"; "1.5"; "999999999999999999999999999999999999"]; List.iter (fun flag -> check From 46e18ef00b5cf6e46b3fc79dde33280ce30359e3 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 22 Nov 2026 19:02:43 -0300 Subject: [PATCH 03/13] Keep the language server running after invalid input Why: A malformed message or handler exception could terminate the server, interrupting unrelated editor requests. Protocol modified (message error recovery): Before (text): Malformed input: terminate the server. Request exception: terminate the server. Notification exception: terminate the server. After (text): Malformed input: skip it and continue reading. Request exception: return a JSON-RPC error and retain session state. Notification exception: log to stderr and continue reading. Diagnostic modified (document store): Before (diagnostic): InvalidRequest: Document store not found to get After (diagnostic): RequestFailed: Cannot get document : it is not open. Add end-to-end snapshots for error recovery, state preservation, and clean shutdown. Capture subprocess stderr and preserve actual exit codes. Verified with dune runtest and make dead-code. Signed-off-by: Pedro Castro --- lsp/src/document_store.ml | 22 +-- lsp/src/server.ml | 42 +++-- tests/lsp_tests/protocol_errors.ml | 272 +++++++++++++++++++++++++++++ tests/lsp_tests/test.ml | 58 ++++-- 4 files changed, 357 insertions(+), 37 deletions(-) create mode 100644 tests/lsp_tests/protocol_errors.ml diff --git a/lsp/src/document_store.ml b/lsp/src/document_store.ml index 53ee5054234..6d244162f1d 100644 --- a/lsp/src/document_store.ml +++ b/lsp/src/document_store.ml @@ -4,18 +4,17 @@ type t = {documents: (Uri.t, Document.t) Hashtbl.t} let make () = {documents = Hashtbl.create 50} -let raise ~message = - Jsonrpc.Response.Error.raise - (Jsonrpc.Response.Error.make ~code:InvalidRequest ~message ()) +let raise ~code ~message = + Jsonrpc.Response.Error.raise (Jsonrpc.Response.Error.make ~code ~message ()) let add t ~doc = let uri = Document.uri doc in (match Hashtbl.mem t.documents uri with | false -> Hashtbl.add t.documents uri doc | true -> - raise + raise ~code:RequestFailed ~message: - (Printf.sprintf "Document store already has %s to open" + (Printf.sprintf "Cannot open document %s: it is already open." (Uri.to_string uri))); t @@ -23,9 +22,9 @@ let update t ~doc = let uri = Document.uri doc in (match Hashtbl.find_opt t.documents uri with | None -> - raise + raise ~code:RequestFailed ~message: - (Printf.sprintf "Document store not found %s to update" + (Printf.sprintf "Cannot update document %s: it is not open." (Uri.to_string uri)) | Some _ -> Hashtbl.replace t.documents uri doc); t @@ -34,9 +33,9 @@ let remove t ~uri = (match Hashtbl.mem t.documents uri with | true -> Hashtbl.remove t.documents uri | false -> - raise + raise ~code:RequestFailed ~message: - (Printf.sprintf "Document store not found %s to remove" + (Printf.sprintf "Cannot close document %s: it is not open." (Uri.to_string uri))); t @@ -46,6 +45,7 @@ let get t ~uri = match get_opt t ~uri with | Some doc -> doc | None -> - raise + raise ~code:RequestFailed ~message: - (Printf.sprintf "Document store not found %s to get" (Uri.to_string uri)) + (Printf.sprintf "Cannot get document %s: it is not open." + (Uri.to_string uri)) diff --git a/lsp/src/server.ml b/lsp/src/server.ml index 0b80615d874..91b998cedd3 100644 --- a/lsp/src/server.ml +++ b/lsp/src/server.ml @@ -203,9 +203,17 @@ let rec input_loop ~input ~state with_ = | Some packet -> let state = with_ state packet in input_loop ~input ~state with_ - | exception _ -> failwith "Server.input_loop" + | exception _ -> input_loop ~input ~state with_ | None -> () +let response_error_of_exn = function + | Jsonrpc.Response.Error.E error -> error + | exn -> + Jsonrpc.Response.Error.make ~code:InternalError + ~message:"uncaught exception" + ~data:(`String (Printexc.to_string exn)) + () + let listen ~input ~output ~on_request ~on_notification ~on_response ~state = let lifecycle = ref Awaiting_initialize in let handle_request server request = @@ -229,16 +237,20 @@ let listen ~input ~output ~on_request ~on_notification ~on_response ~state = ~message:"Server has already received a shutdown request"); server.state | Awaiting_initialize | Running -> - let response, state = - match Lsp.Client_request.of_jsonrpc request with - | Error message -> - let code = Jsonrpc.Response.Error.Code.InvalidParams in - let err = Jsonrpc.Response.Error.make ~code ~message () in - (Jsonrpc.Response.{id = request.id; result = Error err}, state) - | Ok packed -> - let result, state = on_request packed server in - (Jsonrpc.Response.{id = request.id; result}, state) + let result, state = + try + match Lsp.Client_request.of_jsonrpc request with + | Error message -> + let err = + Jsonrpc.Response.Error.make ~code:InternalError ~message () + in + (Error err, server.state) + | Ok packed -> on_request packed server + with + | Eio.Cancel.Cancelled _ as exn -> raise exn + | exn -> (Error (response_error_of_exn exn), server.state) in + let response = Jsonrpc.Response.{id = request.id; result} in respond server response; (match response.result with | Ok _ when is_initialize_request request -> lifecycle := Running @@ -251,7 +263,15 @@ let listen ~input ~output ~on_request ~on_notification ~on_response ~state = else match !lifecycle with | Awaiting_initialize | Shutdown_requested -> server.state - | Running -> on_notification (notification_of_jsonrpc notification) server + | Running -> ( + try on_notification (notification_of_jsonrpc notification) server with + | Eio.Cancel.Cancelled _ as exn -> raise exn + | exn -> + (* A notification has no response ID. Report its failure on stderr, + keep the current state, and continue with the next message. *) + Format.eprintf "Uncaught error when handling notification %s: %s@." + notification.method_ (Printexc.to_string exn); + server.state) in let input = Chan.of_source input in Chan.with_sink output (fun channel -> diff --git a/tests/lsp_tests/protocol_errors.ml b/tests/lsp_tests/protocol_errors.ml new file mode 100644 index 00000000000..b6f92c48b39 --- /dev/null +++ b/tests/lsp_tests/protocol_errors.ml @@ -0,0 +1,272 @@ +open Lsp +open Types + +let with_project f = + Test.with_project ~name:"protocol-errors" ~run_build:false + ~text:{|let original = 1|} f + +(* A successful request after each rejected message checks both liveness and + preservation of the initialized state and the original document contents. *) +let check_document client doc = + ignore + (Test.Client.request client + (Client_request.TextDocumentDiagnostic + (DocumentDiagnosticParams.create + ~textDocument:(Test.text_document doc) ()))); + match + Test.Client.request client + (Client_request.DocumentSymbol + (DocumentSymbolParams.create ~textDocument:(Test.text_document doc) ())) + with + | Some (`DocumentSymbol symbols) -> + List.iter + (fun (symbol : DocumentSymbol.t) -> print_endline symbol.name) + symbols + | _ -> failwith "Expected document symbols" + +let request_error client request = + let id = Test.Client.send_request client request in + match (Test.Client.read_response client id).result with + | Error error -> error + | Ok _ -> failwith "Expected an error response" + +let print_request_error client request = + let error = request_error client request in + print_endline (Jsonrpc.Response.Error.Code.to_string error.code) + +let%expect_test "preserves request exception codes, messages, and data" = + with_project (fun ~root ~doc client -> + let uri = Uri.of_path (Filename.concat root "Unsupported.txt") in + let error = + request_error client + (Client_request.ExecuteCommand + (ExecuteCommandParams.create ~command:"rescript/createInterface" + ~arguments: + [ + `String (Uri.to_string uri); + `String + (Uri.to_string + (Uri.of_path (Filename.concat root "Unsupported.cmi"))); + ] + ())) + in + assert ( + error.message = "unsupported file extension for " ^ Uri.to_path uri); + print_endline (Jsonrpc.Response.Error.Code.to_string error.code); + Option.get error.data |> Yojson.Safe.pretty_to_string |> print_endline; + check_document client doc); + [%expect + {| + InvalidRequest + { "extension": ".txt" } + original + |}] + +let%expect_test "converts unexpected request exceptions to internal errors" = + with_project (fun ~root:_ ~doc client -> + (* The custom handler decodes its own parameters. A missing URI raises + inside the handler rather than during initial request decoding. *) + let error = + request_error client + (Client_request.UnknownRequest + {meth = "textDocument/openCompiled"; params = Some (`Assoc [])}) + in + Jsonrpc.Response.Error.yojson_of_t error + |> Yojson.Safe.pretty_to_string |> print_endline; + check_document client doc); + [%expect + {| + { + "data": "Ppx_yojson_conv_lib__Yojson_conv.Of_yojson_error(_, _)", + "code": -32603, + "message": "uncaught exception" + } + original + |}] + +let print_notification_errors client = + Test.Client.stderr client |> String.split_on_char '\n' + |> List.iter (fun line -> + if + String.starts_with ~prefix:"Uncaught error when handling notification" + line + then print_endline "Rejected notification") + +let%expect_test "rejects hover on an unopened file without ending the session" = + with_project (fun ~root ~doc client -> + let uri = Uri.of_path (Filename.concat root "Unopened.res") in + print_request_error client + (Client_request.TextDocumentHover + (HoverParams.create + ~textDocument:(TextDocumentIdentifier.create ~uri) + ~position:(Position.create ~line:0 ~character:0) + ())); + check_document client doc); + [%expect {| + RequestFailed + original + |}] + +let%expect_test + "rejects completion on an unopened file without ending the session" = + with_project (fun ~root ~doc client -> + let uri = Uri.of_path (Filename.concat root "Unopened.res") in + print_request_error client + (Client_request.TextDocumentCompletion + (CompletionParams.create + ~textDocument:(TextDocumentIdentifier.create ~uri) + ~position:(Position.create ~line:0 ~character:0) + ())); + check_document client doc); + [%expect {| + RequestFailed + original + |}] + +let%expect_test "duplicate didOpen preserves the original document" = + with_project (fun ~root:_ ~doc client -> + let replacement = {doc with text = "let replacement = 2"} in + Test.perform client (Test.open_document replacement); + check_document client doc; + print_notification_errors client); + [%expect {| + original + Rejected notification + |}] + +let close_document client uri = + Test.Client.send_notification client + (Client_notification.TextDocumentDidClose + (DidCloseTextDocumentParams.create + ~textDocument:(TextDocumentIdentifier.create ~uri))) + +let%expect_test "rejects didClose for an unopened file and continues" = + with_project (fun ~root ~doc client -> + close_document client (Uri.of_path (Filename.concat root "Unopened.res")); + check_document client doc; + print_notification_errors client); + [%expect {| + original + Rejected notification + |}] + +let reject_open client uri = + Test.perform client + (Test.open_document (Test.make_document ~uri ~text:"let unsupported = 1")); + (* A rejected open must not have inserted anything into the store. *) + close_document client uri + +let%expect_test "rejects untitled buffers without storing them" = + with_project (fun ~root:_ ~doc client -> + reject_open client (Uri.of_string "untitled:Untitled-1"); + check_document client doc; + print_notification_errors client); + [%expect {| + original + Rejected notification + |}] + +let%expect_test "rejects non-ReScript extensions without storing them" = + with_project (fun ~root ~doc client -> + reject_open client (Uri.of_path (Filename.concat root "Unsupported.txt")); + check_document client doc; + print_notification_errors client); + [%expect {| + original + Rejected notification + |}] + +let%expect_test "invalid request parameters preserve the initialized state" = + with_project (fun ~root:_ ~doc client -> + print_request_error client + (Client_request.UnknownRequest + {meth = "textDocument/hover"; params = Some (`Assoc [])}); + check_document client doc); + [%expect {| + InternalError + original + |}] + +let%expect_test "invalid notification parameters do not end the session" = + with_project (fun ~root:_ ~doc client -> + Test.Client.send_packet client + (Jsonrpc.Packet.Notification + (Jsonrpc.Notification.create ~method_:"textDocument/didOpen" + ~params:(`Assoc []) ())); + check_document client doc; + print_notification_errors client); + [%expect {| + original + Rejected notification + |}] + +let check_body_recovery client doc bodies = + Test.synchronize client; + List.iter (Test.Client.send_body client) bodies; + check_document client doc; + Test.Client.request client Client_request.Shutdown; + Test.Client.send_notification client Client_notification.Exit; + let status = Test.Client.stop client in + let stderr = Test.Client.stderr client in + if stderr <> "" then failwith ("Unexpected stderr: " ^ stderr); + match status with + | Unix.WEXITED code -> Printf.printf "Exit code: %d\n" code + | _ -> failwith "Expected a normal exit" + +let%expect_test "incomplete JSON is skipped and keeps the session running" = + with_project (fun ~root:_ ~doc client -> + check_body_recovery client doc [{|{"jsonrpc":|}]); + [%expect {| + original + Exit code: 0 + |}] + +let%expect_test "invalid JSON tokens are skipped and keep the session running" = + with_project (fun ~root:_ ~doc client -> + check_body_recovery client doc [{|not JSON|}]); + [%expect {| + original + Exit code: 0 + |}] + +let%expect_test + "consecutive invalid bodies do not prevent reading the next message" = + with_project (fun ~root:_ ~doc client -> + check_body_recovery client doc [{|{"jsonrpc":|}; {|not JSON|}]); + [%expect {| + original + Exit code: 0 + |}] + +let%expect_test + "invalid JSON-RPC packets are skipped and keep the session running" = + with_project (fun ~root:_ ~doc client -> + check_body_recovery client doc [{|42|}]); + [%expect {| + original + Exit code: 0 + |}] + +let%expect_test "null params are rejected without shutting down the server" = + with_project (fun ~root:_ ~doc client -> + check_body_recovery client doc + [{|{"jsonrpc":"2.0","id":100,"method":"shutdown","params":null}|}]); + [%expect {| + original + Exit code: 0 + |}] + +let%expect_test "shutdown without params followed by exit succeeds" = + with_project (fun ~root:_ ~doc:_ client -> + let id = Test.Client.send_request client Client_request.Shutdown in + let response = Test.Client.read_response client id in + assert (response.result = Ok `Null); + print_endline "Shutdown accepted"; + Test.Client.send_notification client Client_notification.Exit; + match Test.Client.stop client with + | Unix.WEXITED code -> Printf.printf "Exit code: %d\n" code + | _ -> failwith "Expected a normal exit"); + [%expect {| + Shutdown accepted + Exit code: 0 + |}] diff --git a/tests/lsp_tests/test.ml b/tests/lsp_tests/test.ml index ea461c171d0..802af0f2002 100644 --- a/tests/lsp_tests/test.ml +++ b/tests/lsp_tests/test.ml @@ -64,13 +64,15 @@ module Client = struct type t = { process_stdout: in_channel; process_stdin: out_channel; + process_stderr: in_channel; + stderr: string ref; + stderr_reader: Thread.t; mutable next_id: int; - mutable stopped: bool; + mutable status: Unix.process_status option; mutable notifications: Jsonrpc.Notification.t list; } - let frame (json : Yojson.Safe.t) : string = - let body = Yojson.Safe.to_string json in + let frame body : string = Printf.sprintf "Content-Length: %d\r\n\r\n%s" (String.length body) body let read_headers t = @@ -103,24 +105,40 @@ module Client = struct | exception End_of_file -> None) let start () = - let process_stdout, process_stdin = - Unix.open_process_args executable [|executable; "lsp"; "--stdio"|] + let process_stdout, process_stdin, process_stderr = + Unix.open_process_args_full executable + [|executable; "lsp"; "--stdio"|] + (Unix.environment ()) in set_binary_mode_in process_stdout true; set_binary_mode_out process_stdin true; + set_binary_mode_in process_stderr true; + (* Drain stderr concurrently: a rejected notification must not block the + server when the pipe fills, including on Windows. Join before reading. *) + let stderr = ref "" in + let stderr_reader = + Thread.create (fun () -> stderr := In_channel.input_all process_stderr) () + in { process_stdout; process_stdin; + process_stderr; + stderr; + stderr_reader; next_id = 0; - stopped = false; + status = None; notifications = []; } - let send_packet t (packet : Jsonrpc.Packet.t) = - let json = Jsonrpc.Packet.yojson_of_t packet in - output_string t.process_stdin (frame json); + let send_body t body = + output_string t.process_stdin (frame body); flush t.process_stdin + let send_json t json = send_body t (Yojson.Safe.to_string json) + + let send_packet t (packet : Jsonrpc.Packet.t) = + send_json t (Jsonrpc.Packet.yojson_of_t packet) + let next_id t = t.next_id <- t.next_id + 1; t.next_id @@ -198,12 +216,22 @@ module Client = struct | Some json -> Jsonrpc.Packet.t_of_yojson json *) let stop t = - if t.stopped then Unix.WEXITED 0 - else ( - t.stopped <- true; - (try close_out_noerr t.process_stdin with _ -> ()); - try Unix.close_process (t.process_stdout, t.process_stdin) - with _ -> Unix.WEXITED 0) + match t.status with + | Some status -> status + | None -> + close_out_noerr t.process_stdin; + close_in_noerr t.process_stdout; + Thread.join t.stderr_reader; + let status = + Unix.close_process_full + (t.process_stdout, t.process_stdin, t.process_stderr) + in + t.status <- Some status; + status + + let stderr t = + ignore (stop t); + !(t.stderr) end open Lsp From 4f3d55fdd70ea28cf5b81efdd27cbeb0a7d0b9c4 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 22 Nov 2026 19:07:59 -0300 Subject: [PATCH 04/13] Back to `InvalidParams` Request parameter decoding failures describe invalid client input, not internal server failures. Return the appropriate JSON-RPC error code and update the protocol regression snapshot, retaining the initialized state. Protocol modified (invalid request parameters): Before (text): Invalid hover parameters -> InternalError (-32603) After (text): Invalid hover parameters -> InvalidParams (-32602) Signed-off-by: Pedro Castro --- lsp/src/server.ml | 2 +- tests/lsp_tests/protocol_errors.ml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lsp/src/server.ml b/lsp/src/server.ml index 91b998cedd3..63967613a7b 100644 --- a/lsp/src/server.ml +++ b/lsp/src/server.ml @@ -242,7 +242,7 @@ let listen ~input ~output ~on_request ~on_notification ~on_response ~state = match Lsp.Client_request.of_jsonrpc request with | Error message -> let err = - Jsonrpc.Response.Error.make ~code:InternalError ~message () + Jsonrpc.Response.Error.make ~code:InvalidParams ~message () in (Error err, server.state) | Ok packed -> on_request packed server diff --git a/tests/lsp_tests/protocol_errors.ml b/tests/lsp_tests/protocol_errors.ml index b6f92c48b39..e38b900ad88 100644 --- a/tests/lsp_tests/protocol_errors.ml +++ b/tests/lsp_tests/protocol_errors.ml @@ -183,7 +183,7 @@ let%expect_test "invalid request parameters preserve the initialized state" = {meth = "textDocument/hover"; params = Some (`Assoc [])}); check_document client doc); [%expect {| - InternalError + InvalidParams original |}] From eedb5d902ff7ed50b561f23dbde079a1ae6ecbc5 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 22 Nov 2026 19:21:41 -0300 Subject: [PATCH 05/13] Read large LSP message bodies in bounded chunks Why: Reading an entire body through the 1 MiB input buffer rejected large documents and left the server unable to process later messages. Protocol modified (message body reads): Before (text): Read the entire Content-Length body in one buffered operation. Bodies larger than 1 MiB exceed the reader limit. After (text): Keep direct reads for bodies up to 1 MiB. Assemble larger bodies from chunks no larger than 1 MiB. Consume exactly Content-Length bytes, preserving the next header. Add regression tests for opening and editing documents over 2 MiB, including subsequent requests to verify message framing remains intact. Verified with dune runtest, make dead-code, and changelog validation. Signed-off-by: Pedro Castro --- lsp/src/server.ml | 17 ++++++++++- tests/lsp_tests/document_changes.ml | 45 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/lsp/src/server.ml b/lsp/src/server.ml index 63967613a7b..4eb53872d49 100644 --- a/lsp/src/server.ml +++ b/lsp/src/server.ml @@ -81,7 +81,22 @@ end = struct Eio.Mutex.use_rw ~protect:true input.mutex @@ fun () -> if Eio.Buf_read.eof_seen input.buf then Ok None else - match Eio.Buf_read.take size input.buf with + match + if size <= max_size then Eio.Buf_read.take size input.buf + else + (* [take] requires its entire argument to fit in the reader's buffer. + Assemble large JSON bodies in bounded chunks, consuming exactly the + declared length so the following header remains untouched. *) + let body = Buffer.create max_size in + let rec read_chunks remaining = + if remaining > 0 then ( + let length = min remaining max_size in + Buffer.add_string body (Eio.Buf_read.take length input.buf); + read_chunks (remaining - length)) + in + read_chunks size; + Buffer.contents body + with | data -> Ok (Some data) | exception End_of_file -> Ok None diff --git a/tests/lsp_tests/document_changes.ml b/tests/lsp_tests/document_changes.ml index bae0a23be30..45dd3b03038 100644 --- a/tests/lsp_tests/document_changes.ml +++ b/tests/lsp_tests/document_changes.ml @@ -1,6 +1,51 @@ open Lsp open Types +let large_document ~name = + "/*" + ^ String.make ((2 * 1024 * 1024) + 137) 'x' + ^ "*/\nlet " ^ name ^ " = 1\n" + +let print_symbol_names client doc = + match + Test.Client.request client + (Client_request.DocumentSymbol + (DocumentSymbolParams.create ~textDocument:(Test.text_document doc) ())) + with + | Some (`DocumentSymbol symbols) -> + List.iter + (fun (symbol : DocumentSymbol.t) -> print_endline symbol.name) + symbols + | _ -> failwith "Expected document symbols" + +let%expect_test + "opens a document larger than the input buffer and keeps reading" = + Test.with_project ~name:"large-document-open" ~run_build:false + ~text:(large_document ~name:"opened") (fun ~root:_ ~doc client -> + print_symbol_names client doc; + Test.change_document client doc ~version:1 ~text:{|let after_open = 2|}; + print_symbol_names client doc); + [%expect {| + opened + after_open + |}] + +let%expect_test + "applies a change larger than the input buffer and keeps reading" = + Test.with_project ~name:"large-document-change" ~run_build:false + ~text:{|let original = 1|} (fun ~root:_ ~doc client -> + print_symbol_names client doc; + Test.change_document client doc ~version:1 + ~text:(large_document ~name:"changed"); + print_symbol_names client doc; + Test.change_document client doc ~version:2 ~text:{|let after_change = 2|}; + print_symbol_names client doc); + [%expect {| + original + changed + after_change + |}] + let%expect_test "applies a partial text change before computing document symbols" = Test.with_project ~name:"partial-text-change" ~run_build:false From ae00b14333c47f26b0761458ac5ce762641c6f3e Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 22 Nov 2026 19:51:01 -0300 Subject: [PATCH 06/13] Offer the create-interface code action for implementations without an interface Advertise its command, and refuse to overwrite existing interface files Signed-off-by: Pedro Castro --- lsp/src/code_actions.ml | 3 +- lsp/src/custom_requests.ml | 36 +++--- lsp/src/rescript_language_server.ml | 1 + tests/lsp_tests/code_action.ml | 66 +++++++++++ tests/lsp_tests/create_interface.ml | 167 ++++++++++++++++++++++++++++ 5 files changed, 259 insertions(+), 14 deletions(-) diff --git a/lsp/src/code_actions.ml b/lsp/src/code_actions.ml index cd5d4c76417..b6c4db39519 100644 --- a/lsp/src/code_actions.ml +++ b/lsp/src/code_actions.ml @@ -457,7 +457,8 @@ module Create_interface_file = struct let should_create = match Document.kind doc with - | Res -> not (Fs.exists ~fs:state.fs ~follow:false (Uri.to_path uri)) + | Res -> + not (Fs.exists ~fs:state.fs ~follow:false (Uri.to_path uri ^ "i")) | _ -> false in diff --git a/lsp/src/custom_requests.ml b/lsp/src/custom_requests.ml index d92501166d2..c3276c88dc7 100644 --- a/lsp/src/custom_requests.ml +++ b/lsp/src/custom_requests.ml @@ -49,19 +49,29 @@ module Create_interface_file = struct let make ~uri ~cmi_uri ~(state : State.t) = match Document.kind_of_uri uri with | Res -> ( - match - Analysis.Create_interface.command ~path:(Uri.to_path uri) - ~source:(Document_store.get ~uri state.store |> Document.text) - ~cmi_file:(cmi_uri |> Uri.to_path) - with - | Ok content -> - let resi_file = Uri.to_path uri ^ "i" in - let () = - Fs.save ~append:false ~create:(`Or_truncate 0o644) ~fs:state.fs - resi_file content - in - Ok (Uri.of_path resi_file) - | Error e -> Error e) + let resi_file = Uri.to_path uri ^ "i" in + let already_exists () = + Error + (Printf.sprintf "Cannot create interface file %s: it already exists." + resi_file) + in + if Fs.exists ~fs:state.fs ~follow:false resi_file then already_exists () + else + match + Analysis.Create_interface.command ~path:(Uri.to_path uri) + ~source:(Document_store.get ~uri state.store |> Document.text) + ~cmi_file:(cmi_uri |> Uri.to_path) + with + | Ok content -> ( + try + (* A file may appear after the availability check, including after + a code action was offered. Never truncate an existing interface. *) + Fs.save ~append:false ~create:(`Exclusive 0o644) ~fs:state.fs + resi_file content; + Ok (Uri.of_path resi_file) + with Eio.Io (Eio.Fs.E (Eio.Fs.Already_exists _), _) -> + already_exists ()) + | Error e -> Error e) | _ -> Error (Printf.sprintf diff --git a/lsp/src/rescript_language_server.ml b/lsp/src/rescript_language_server.ml index ad452b4f937..c310967245e 100644 --- a/lsp/src/rescript_language_server.ml +++ b/lsp/src/rescript_language_server.ml @@ -63,6 +63,7 @@ let initialization (client_capabilities : ClientCapabilities.t) = ~commands: [ Execute_commands.Open_compiled.name; + Execute_commands.Create_interface.name; Execute_commands.Switch_implementation_interface.name; Execute_commands.Dump_server_state.name; Execute_commands.Dump_cmt.name; diff --git a/tests/lsp_tests/code_action.ml b/tests/lsp_tests/code_action.ml index 5e939c94042..129b2a2bf28 100644 --- a/tests/lsp_tests/code_action.ml +++ b/tests/lsp_tests/code_action.ml @@ -45,6 +45,17 @@ let value = switch variant { }, "kind": "refactor.rewrite", "title": "Expand catch-all" + }, + { + "command": { + "arguments": [ + "file:///workspace/Test.res", + "file:///workspace/lib/rescript/Test.cmi" + ], + "command": "rescript/createInterface", + "title": "Create interface file" + }, + "title": "Create interface file" } ] |}] @@ -105,6 +116,17 @@ let%expect_test "extracts a local module into its own file" = }, "kind": "refactor.rewrite", "title": "Extract local module \"ExtractableModule\" to file \"ExtractableModule.res\"" + }, + { + "command": { + "arguments": [ + "file:///workspace/Test.res", + "file:///workspace/lib/rescript/Test.cmi" + ], + "command": "rescript/createInterface", + "title": "Create interface file" + }, + "title": "Create interface file" } ] |}] @@ -170,6 +192,17 @@ let value = if kind == First { }, "kind": "refactor.rewrite", "title": "Replace with switch" + }, + { + "command": { + "arguments": [ + "file:///workspace/Test.res", + "file:///workspace/lib/rescript/Test.cmi" + ], + "command": "rescript/createInterface", + "title": "Create interface file" + }, + "title": "Create interface file" } ] |}] @@ -227,6 +260,17 @@ let%expect_test "offers a type annotation for an inferred string binding" = }, "kind": "refactor.rewrite", "title": "Add Documentation template" + }, + { + "command": { + "arguments": [ + "file:///workspace/Test.res", + "file:///workspace/lib/rescript/Test.cmi" + ], + "command": "rescript/createInterface", + "title": "Create interface file" + }, + "title": "Create interface file" } ] |}] @@ -263,6 +307,17 @@ let noBraces = () => name }, "kind": "refactor.rewrite", "title": "Add braces to function" + }, + { + "command": { + "arguments": [ + "file:///workspace/Test.res", + "file:///workspace/lib/rescript/Test.cmi" + ], + "command": "rescript/createInterface", + "title": "Create interface file" + }, + "title": "Create interface file" } ] |}] @@ -297,6 +352,17 @@ let%expect_test "does not offer another annotation for an annotated binding" = }, "kind": "refactor.rewrite", "title": "Add Documentation template" + }, + { + "command": { + "arguments": [ + "file:///workspace/Test.res", + "file:///workspace/lib/rescript/Test.cmi" + ], + "command": "rescript/createInterface", + "title": "Create interface file" + }, + "title": "Create interface file" } ] |}] diff --git a/tests/lsp_tests/create_interface.ml b/tests/lsp_tests/create_interface.ml index e3f96c63add..2af3926f0be 100644 --- a/tests/lsp_tests/create_interface.ml +++ b/tests/lsp_tests/create_interface.ml @@ -18,6 +18,173 @@ let create_and_print ~root ~doc client = In_channel.with_open_bin (Uri.to_path interface.uri) In_channel.input_all |> print_string +let interface_actions client doc = + Test.Client.request client + (Client_request.CodeAction + (CodeActionParams.create ~textDocument:(Test.text_document doc) + ~range:(Test.range (0, 0) (0, 0)) + ~context:(CodeActionContext.create ~diagnostics:[] ()) + ())) + |> Option.value ~default:[] + |> List.filter_map (function + | `CodeAction (action : CodeAction.t) + when action.title = "Create interface file" -> + Some action + | _ -> None) + +let print_interface_actions ~root client doc = + interface_actions client doc |> List.map CodeAction.yojson_of_t + |> fun actions -> Test.print_json ~root (`List actions) + +let%expect_test "advertises interface creation as an executable command" = + Test.with_project ~name:"interface-command-capability" ~run_build:false + ~text:{|let value = 42|} (fun ~root ~doc:_ _ -> + let client = Test.Client.start () in + Fun.protect + ~finally:(fun () -> ignore (Test.Client.stop client)) + (fun () -> + let initialized = + Test.Client.request client + (Client_request.Initialize + (InitializeParams.create ~capabilities:Test.client_capabilities + ~rootUri:(Uri.of_path root) ())) + in + match initialized.capabilities.executeCommandProvider with + | Some {commands} -> + List.filter (( = ) "rescript/createInterface") commands + |> List.iter print_endline + | None -> failwith "Expected executable commands")); + [%expect {| rescript/createInterface |}] + +let%expect_test + "offers and executes interface creation for a saved implementation" = + Test.with_project ~name:"interface-code-action" + ~capabilities:Execute_commands.capabilities ~text:{|let value = 42|} + (fun ~root ~doc client -> + assert (Sys.file_exists (Uri.to_path doc.uri)); + print_interface_actions ~root client doc; + let command = + match interface_actions client doc with + | [{command = Some command}] -> command + | _ -> failwith "Expected one create-interface command" + in + let id = + Test.Client.send_request client + (Client_request.ExecuteCommand + (ExecuteCommandParams.create ~command:command.command + ?arguments:command.arguments ())) + in + let show_document = + Test.Client.read_request client "window/showDocument" + in + let params = + Option.get show_document.params + |> Jsonrpc.Structured.yojson_of_t |> ShowDocumentParams.t_of_yojson + in + Test.print_json ~root + (TextDocumentIdentifier.yojson_of_t + (TextDocumentIdentifier.create ~uri:params.uri)); + assert (params.takeFocus = Some true); + Test.Client.send_packet client + (Jsonrpc.Packet.Response + (Jsonrpc.Response.ok show_document.id + (`Assoc [("success", `Bool true)]))); + assert ((Test.Client.read_response client id).result = Ok `Null); + In_channel.with_open_bin (Uri.to_path params.uri) In_channel.input_all + |> print_string; + print_interface_actions ~root client doc); + [%expect + {| + [ + { + "command": { + "arguments": [ + "file:///workspace/Test.res", + "file:///workspace/lib/rescript/Test.cmi" + ], + "command": "rescript/createInterface", + "title": "Create interface file" + }, + "title": "Create interface file" + } + ] + { "uri": "file:///workspace/Test.resi" } + let value: int + [] + |}] + +let%expect_test "does not offer interface creation without build metadata" = + Test.with_project ~name:"interface-unbuilt" ~run_build:false + ~text:{|let value = 42|} (fun ~root ~doc client -> + print_interface_actions ~root client doc); + [%expect {| [] |}] + +let%expect_test + "refuses to overwrite a handwritten interface through the custom request" = + let handwritten = {|// Keep this handwritten interface. +let value: int +|} in + Test.with_project ~name:"interface-existing" ~text:{|let value = 42|} + ~files:[("Test.resi", handwritten)] + (fun ~root ~doc client -> + print_interface_actions ~root client doc; + let path = Uri.to_path doc.uri ^ "i" in + let id = Test.Client.send_request client (create_interface doc) in + (match (Test.Client.read_response client id).result with + | Ok _ -> failwith "Expected refusal to overwrite the interface" + | Error error -> + assert ( + error.message + = "Cannot create interface file " ^ path ^ ": it already exists."); + print_endline "Refused to overwrite Test.resi"); + assert (In_channel.with_open_bin path In_channel.input_all = handwritten); + print_endline "Handwritten interface unchanged"); + [%expect + {| + [] + Refused to overwrite Test.resi + Handwritten interface unchanged + |}] + +let%expect_test + "refuses a stale interface-creation command after an interface appears" = + Test.with_project ~name:"interface-stale-action" ~text:{|let value = 42|} + (fun ~root:_ ~doc client -> + let command = + match interface_actions client doc with + | [{command = Some command}] -> command + | _ -> failwith "Expected one create-interface command" + in + let path = Uri.to_path doc.uri ^ "i" in + let handwritten = + {|// Added after requesting the code action. +let value: int +|} + in + Test.write_file path handwritten; + let id = + Test.Client.send_request client + (Client_request.ExecuteCommand + (ExecuteCommandParams.create ~command:command.command + ?arguments:command.arguments ())) + in + (match (Test.Client.read_response client id).result with + | Ok _ -> failwith "Expected refusal to overwrite the interface" + | Error error -> + assert ( + String.ends_with + ~suffix: + ("Cannot create interface file " ^ path ^ ": it already exists.") + error.message); + print_endline "Refused stale create-interface command"); + assert (In_channel.with_open_bin path In_channel.input_all = handwritten); + print_endline "Handwritten interface unchanged"); + [%expect + {| + Refused stale create-interface command + Handwritten interface unchanged + |}] + let%expect_test "creates an interface for components with optional props" = Test.with_project ~name:"create-interface-jsx" ~jsx:true ~text: From a6d5a9532b072d3b1d82f3fcf2f12192da7132f8 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 22 Nov 2026 20:07:57 -0300 Subject: [PATCH 07/13] Format editor buffers without requiring a workspace-local `rescript` executable - Leave documents with syntax errors unchanged without error popups. Signed-off-by: Pedro Castro --- lsp/README.md | 1 - lsp/src/document.ml | 6 -- lsp/src/dune | 3 - lsp/src/formatter.ml | 123 ---------------------------- lsp/src/rescript_language_server.ml | 23 ++++-- tests/lsp_tests/formatting.ml | 92 ++++++++++++++------- 6 files changed, 80 insertions(+), 168 deletions(-) delete mode 100644 lsp/src/formatter.ml diff --git a/lsp/README.md b/lsp/README.md index c8d98ad22bb..24988292cda 100644 --- a/lsp/README.md +++ b/lsp/README.md @@ -107,7 +107,6 @@ The server library lives in `lsp/src` and has an opam package named | [diagnostics.ml](src/diagnostics.ml) | Separate diagnostic sources, snapshot updates, URI/range conversion, and publication. | | [code_actions.ml](src/code_actions.ml), [custom_requests.ml](src/custom_requests.ml), [execute_commands.ml](src/execute_commands.ml) | Analysis actions, interface creation, compiled-file navigation, and debugging commands. | | [configuration.ml](src/configuration.ml) | Settings decoding and defaults. | -| [formatter.ml](src/formatter.ml) | Runs the project's `rescript format` command on the buffer and computes text edits; its process helper uses Unix on Windows and Eio on Linux/macOS. | | [fs.ml](src/fs.ml) | Filesystem helpers over the Eio filesystem capability. | ### Project discovery and recovery diff --git a/lsp/src/document.ml b/lsp/src/document.ml index 24b875e30b6..0e600de9750 100644 --- a/lsp/src/document.ml +++ b/lsp/src/document.ml @@ -19,12 +19,6 @@ let kind_of_uri uri = let kind doc = doc |> Text_document.documentUri |> kind_of_uri -let extension_of_kind (kind : kind) = - match kind with - | Res -> "res" - | Resi -> "resi" - | Other -> assert false - let make (doc : DidOpenTextDocumentParams.t) ~position_encoding = let t_doc = Text_document.make ~position_encoding doc in t_doc diff --git a/lsp/src/dune b/lsp/src/dune index 3ec232bdb2d..fe70749ed9e 100644 --- a/lsp/src/dune +++ b/lsp/src/dune @@ -3,9 +3,6 @@ (libraries lsp eio - eio_main - eio.unix - unix analysis str ppx_deriving_yojson.runtime) diff --git a/lsp/src/formatter.ml b/lsp/src/formatter.ml deleted file mode 100644 index ffc27513bd5..00000000000 --- a/lsp/src/formatter.ml +++ /dev/null @@ -1,123 +0,0 @@ -module Process = struct - type result = {status: Unix.process_status; stdout: string} - - let rec waitpid pid = - match Unix.waitpid [] pid with - | _, status -> status - | exception Unix.Unix_error (Unix.EINTR, _, _) -> waitpid pid - - let with_temp_file f = - let path, channel = - Filename.open_temp_file ~mode:[Open_binary] "rescript-lsp-process-" ".tmp" - in - Fun.protect - ~finally:(fun () -> - close_out_noerr channel; - try Sys.remove path with Sys_error _ -> ()) - (fun () -> f path channel) - - let run_unix ~stdin program args = - (* Windows cannot select() on anonymous pipes. Files avoid pipe-buffer - deadlocks even if a child writes both streams before reading its stdin. *) - with_temp_file (fun input_path input -> - output_string input stdin; - flush input; - with_temp_file (fun output_path output -> - with_temp_file (fun _ error -> - In_channel.with_open_bin input_path (fun input -> - let pid = - Unix.create_process program - (Array.of_list (program :: args)) - (Unix.descr_of_in_channel input) - (Unix.descr_of_out_channel output) - (Unix.descr_of_out_channel error) - in - let reaped = ref false in - Fun.protect - ~finally:(fun () -> - if not !reaped then ( - (try Unix.kill pid Sys.sigkill - with Unix.Unix_error (Unix.ESRCH, _, _) -> ()); - ignore (waitpid pid))) - (fun () -> - let status = waitpid pid in - reaped := true; - let stdout = - In_channel.with_open_bin output_path - In_channel.input_all - in - {status; stdout}))))) - - let run_eio ~stdin program args = - (* The worker needs its own effect handler: Eio operations cannot run in a - plain systhread using the calling fiber's scheduler. *) - Eio_main.run (fun env -> - let stdout = Buffer.create 4096 in - let status = - Eio.Switch.run (fun sw -> - let manager = Eio.Stdenv.process_mgr env in - let input, writer = Eio.Process.pipe ~sw manager in - let process = - Eio.Process.spawn ~sw manager ~executable:program ~stdin:input - ~stdout:(Eio.Flow.buffer_sink stdout) - ~stderr:Eio.Flow.null (program :: args) - in - Eio.Flow.close input; - Eio.Fiber.fork ~sw (fun () -> - Fun.protect - ~finally:(fun () -> Eio.Flow.close writer) - (fun () -> - try Eio.Flow.copy (Eio.Flow.string_source stdin) writer - with Eio.Io (Eio.Net.E (Connection_reset _), _) -> - (* A child may exit or close stdin without consuming all - input. Its exit status and diagnostics still matter. *) - ())); - match Eio.Process.await process with - | `Exited code -> Unix.WEXITED code - | `Signaled signal -> Unix.WSIGNALED signal) - in - (* Switch completion also waits for the output copying fibers. *) - {status; stdout = Buffer.contents stdout}) - - let run ~stdin program args = - Eio_unix.run_in_systhread ~label:"lsp process" (fun () -> - if Sys.win32 then run_unix ~stdin program args - else run_eio ~stdin program args) -end - -open Lsp - -let run ~uri ~(state : State.t) = - let doc = Document_store.get ~uri state.store in - let source = Document.text doc in - let kind_file = Document.kind doc in - - let executable = - let executable_name = "rescript" in - let root_path = State.workspace_root state |> Uri.to_path in - let ( /+ ) = Filename.concat in - root_path /+ "node_modules" /+ ".bin" /+ executable_name - in - - match Fs.exists ~follow:true ~fs:state.fs executable with - | false -> - Error - (Printf.sprintf "Unable to find rescript binary at %s" - (Filename.dirname executable)) - | true -> ( - let extension_name = Document.extension_of_kind kind_file in - try - let result = - Process.run ~stdin:source executable - ["format"; "--stdin"; "." ^ extension_name] - in - match result.status with - | Unix.WEXITED 0 -> Ok (Diff.edit ~from:source ~to_:result.stdout) - | _ -> - Error - (Printf.sprintf "Failed to format %s" - (uri |> Uri.to_path |> Filename.basename)) - with exn -> - Error - (Printf.sprintf "Unexpected result to format %s. %s" (Uri.to_path uri) - (Printexc.to_string exn))) diff --git a/lsp/src/rescript_language_server.ml b/lsp/src/rescript_language_server.ml index c310967245e..7dab6531be8 100644 --- a/lsp/src/rescript_language_server.ml +++ b/lsp/src/rescript_language_server.ml @@ -513,11 +513,24 @@ let on_request (Client_request.E request) (server : State.t Server.t) = in (ok resp, state) | TextDocumentFormatting {textDocument = {uri}} -> ( - match Formatter.run ~uri ~state with - | Ok text_edit -> (ok (Some text_edit), state) - | Error message -> - Server.show_message_notification ~kind:MessageType.Error message server; - (error message, state)) + let doc = Document_store.get ~uri state.store in + let source = Document.text doc in + let kind_file = Document.kind doc in + match Analysis.Commands.format ~source ~kind_file with + | Ok edits -> + (* Analysis returns full-document replacements. Compute edits against the + original buffer instead of using the formatted text's replacement range. *) + ( ok + (Some + (List.concat_map + (fun (edit : Lsp.Types.TextEdit.t) -> + Lsp.Diff.edit ~from:source ~to_:edit.newText) + edits)), + state ) + | Error _ -> + (* Incomplete code is normal while editing; leave it unchanged without + reporting a formatting failure to the user. *) + (ok None, state)) | ExecuteCommand {command; arguments} -> ( let open Execute_commands in match diff --git a/tests/lsp_tests/formatting.ml b/tests/lsp_tests/formatting.ml index fadf2d66840..d5c5381ad79 100644 --- a/tests/lsp_tests/formatting.ml +++ b/tests/lsp_tests/formatting.ml @@ -1,45 +1,46 @@ open Lsp open Types -let rejects_invalid_document ~extension ~text ~corrected = +let formatting doc = + Client_request.TextDocumentFormatting + (DocumentFormattingParams.create ~textDocument:(Test.text_document doc) + ~options:(FormattingOptions.create ~tabSize:2 ~insertSpaces:true ()) + ()) + +let ignores_invalid_document ~extension ~text ~corrected = Test.with_project ~name:"format-invalid" ~run_build:false ~text:{||} (fun ~root ~doc:_ client -> - let executable = Filename.concat root "node_modules/.bin/rescript" in - let binary = - In_channel.with_open_bin Test.executable In_channel.input_all - in - Test.write_file executable binary; - Unix.chmod executable 0o755; let doc = Test.make_document ~text ~uri:(Uri.of_path (Filename.concat root ("Invalid." ^ extension))) in Test.perform client (Test.open_document doc); - let request = - Client_request.TextDocumentFormatting - (DocumentFormattingParams.create - ~textDocument:(Test.text_document doc) - ~options: - (FormattingOptions.create ~tabSize:2 ~insertSpaces:true ()) - ()) - in + Test.synchronize client; + (* Ignore the unbuilt-workspace notification, but retain any messages + caused by formatting incomplete code. *) + ignore (Test.Client.take_notifications client); + let request = formatting doc in for _ = 1 to 3 do - let id = Test.Client.send_request client request in - match (Test.Client.read_response client id).result with - | Ok _ -> failwith "Expected a formatting error" - | Error error -> print_endline error.message + Test.snapshot ~root client request done; Test.change_document client doc ~version:1 ~text:corrected; - Test.snapshot ~root client request) + Test.snapshot ~root client request; + Test.synchronize client; + let messages = + Test.Client.take_notifications client + |> List.filter (fun (n : Jsonrpc.Notification.t) -> + n.method_ = "window/showMessage") + in + Printf.printf "formatting messages: %d\n" (List.length messages)) -let%expect_test "rejects repeated formatting of an invalid implementation" = - rejects_invalid_document ~extension:"res" ~text:{|let value =|} +let%expect_test "ignores repeated formatting of an invalid implementation" = + ignores_invalid_document ~extension:"res" ~text:{|let value =|} ~corrected:{|let value=1|}; [%expect {| - Failed to format Invalid.res - Failed to format Invalid.res - Failed to format Invalid.res + null + null + null [ { "newText": "let value = 1\n", @@ -49,16 +50,17 @@ let%expect_test "rejects repeated formatting of an invalid implementation" = } } ] + formatting messages: 0 |}] -let%expect_test "rejects repeated formatting of an invalid interface" = - rejects_invalid_document ~extension:"resi" ~text:{|let value:|} +let%expect_test "ignores repeated formatting of an invalid interface" = + ignores_invalid_document ~extension:"resi" ~text:{|let value:|} ~corrected:{|let value:int|}; [%expect {| - Failed to format Invalid.resi - Failed to format Invalid.resi - Failed to format Invalid.resi + null + null + null [ { "newText": "let value: int\n", @@ -68,4 +70,34 @@ let%expect_test "rejects repeated formatting of an invalid interface" = } } ] + formatting messages: 0 |}] + +let%expect_test "formats an unsaved buffer without a workspace-local CLI" = + Test.with_project ~name:"format-buffer" ~run_build:false + ~text:{|let saved = 0 +|} (fun ~root ~doc client -> + Printf.printf "workspace-local CLI: %b\n" + (Sys.file_exists (Filename.concat root "node_modules/.bin/rescript")); + Test.change_document client doc ~version:1 ~text:{|let unsaved=1|}; + Test.snapshot ~root client (formatting doc)); + [%expect + {| + workspace-local CLI: false + [ + { + "newText": "let unsaved = 1\n", + "range": { + "end": { "character": 0, "line": 1 }, + "start": { "character": 0, "line": 0 } + } + } + ] + |}] + +let%expect_test "returns no edits for an already formatted buffer" = + Test.with_project ~name:"format-unchanged" ~run_build:false + ~text:{|let value = 1 +|} (fun ~root ~doc client -> + Test.snapshot ~root client (formatting doc)); + [%expect {| [] |}] From 51b3d2f5496fc19a084056aee1668b7d63cb7282 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 22 Nov 2026 20:17:22 -0300 Subject: [PATCH 08/13] Format code Normalize the language-server library's dependency list to Dune's compact formatting. This changes no dependencies or build behavior. Signed-off-by: Pedro Castro --- lsp/src/dune | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lsp/src/dune b/lsp/src/dune index fe70749ed9e..3b2d301847b 100644 --- a/lsp/src/dune +++ b/lsp/src/dune @@ -1,11 +1,6 @@ (library (name rescript_language_server) - (libraries - lsp - eio - analysis - str - ppx_deriving_yojson.runtime) + (libraries lsp eio analysis str ppx_deriving_yojson.runtime) (inline_tests) (preprocess (pps ppx_deriving_yojson ppx_expect)) From 956b7efb173dfc48209690c529fbcbfd22f98a11 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 22 Nov 2026 20:37:13 -0300 Subject: [PATCH 09/13] Give language-server commands unique per-instance IDs so multiple ReScript - Projects can initialize in the same VS Code window. Plain command names remain supported for direct client calls. Fix bug reported in https://github.com/rescript-lang/rescript/pull/8425#issuecomment-6926317819 Signed-off-by: Pedro Castro --- lsp/README.md | 6 + lsp/src/code_actions.ml | 18 ++- lsp/src/execute_commands.ml | 25 ++++ lsp/src/rescript_language_server.ml | 26 +--- lsp/src/state.ml | 9 +- tests/lsp_tests/code_action.ml | 12 +- tests/lsp_tests/create_interface.ml | 12 +- tests/lsp_tests/execute_commands.ml | 197 ++++++++++++++++++++++++++-- tests/lsp_tests/test.ml | 37 +++++- 9 files changed, 291 insertions(+), 51 deletions(-) diff --git a/lsp/README.md b/lsp/README.md index 24988292cda..5445c365da9 100644 --- a/lsp/README.md +++ b/lsp/README.md @@ -258,6 +258,12 @@ warning number. Monorepo compiler-log discovery uses `cmt_scan` build roots in | `rescript/dumpServerState` | Writes a temporary `.json` dump of session state and opens it. | | `rescript/dumpCmt` | Writes a temporary `.txt` dump of typed metadata and opens it. | +Advertised execute-command IDs and code-action commands append a random +per-session suffix, such as `rescript/openCompiled:`, so multiple +servers can coexist in clients that register commands globally. The plain names +above remain accepted by `workspace/executeCommand` for direct client calls, +but are not advertised. A suffixed ID is accepted only by its owning server. + State dumps include document versions/lengths, diagnostics, configuration, initialization parameters, analysis state, and compiler configuration. The file-opening command flow is: diff --git a/lsp/src/code_actions.ml b/lsp/src/code_actions.ml index b6c4db39519..f402ace6c7a 100644 --- a/lsp/src/code_actions.ml +++ b/lsp/src/code_actions.ml @@ -445,7 +445,10 @@ module Open_compiled_file = struct ~command: (Command.create ~arguments:[`String (Uri.to_string uri)] - ~command:Execute_commands.Open_compiled.name ~title ()) + ~command: + (Execute_commands.scoped_name ~state + Execute_commands.Open_compiled.name) + ~title ()) ~title (); ] | None -> [] @@ -479,7 +482,10 @@ module Create_interface_file = struct `String (Uri.to_string uri); `String (Uri.of_path cmi_file |> Uri.to_string); ] - ~command:Execute_commands.Create_interface.name ~title ()) + ~command: + (Execute_commands.scoped_name ~state + Execute_commands.Create_interface.name) + ~title ()) ~title (); ] | _ -> [] @@ -498,7 +504,9 @@ module Switch_implementation_interface_file = struct ~command: (Command.create ~arguments:[`String (Uri.of_path target |> Uri.to_string)] - ~command:Execute_commands.Switch_implementation_interface.name + ~command: + (Execute_commands.scoped_name ~state + Execute_commands.Switch_implementation_interface.name) ~title ()) ~title (); ] @@ -513,7 +521,9 @@ module Switch_implementation_interface_file = struct ~command: (Command.create ~arguments:[`String (Uri.of_path target |> Uri.to_string)] - ~command:Execute_commands.Switch_implementation_interface.name + ~command: + (Execute_commands.scoped_name ~state + Execute_commands.Switch_implementation_interface.name) ~title ()) ~title (); ] diff --git a/lsp/src/execute_commands.ml b/lsp/src/execute_commands.ml index a734b509b70..a464244a082 100644 --- a/lsp/src/execute_commands.ml +++ b/lsp/src/execute_commands.ml @@ -1,6 +1,9 @@ open Lsp open Lsp.Types +let scoped_name ~(state : State.t) name = + name ^ ":" ^ state.execute_command_id_suffix + let request_show_document ~uri ~takeFocus (server : State.t Server.t) = let state = Server.state server in let client_support_window_show_document = @@ -136,3 +139,25 @@ module Dump_cmt = struct of string: [uri]" name) end + +let commands = + [ + (Open_compiled.name, Open_compiled.execute); + (Create_interface.name, Create_interface.execute); + ( Switch_implementation_interface.name, + Switch_implementation_interface.execute ); + (Dump_server_state.name, Dump_server_state.execute); + (Dump_cmt.name, Dump_cmt.execute); + ] + +let advertised_names ~state = + List.map (fun (name, _) -> scoped_name ~state name) commands + +let find ~state command = + (* Plain names remain available for clients that invoke commands directly, + but accept scoped names only from this session, not another server. *) + List.find_map + (fun (name, execute) -> + if command = name || command = scoped_name ~state name then Some execute + else None) + commands diff --git a/lsp/src/rescript_language_server.ml b/lsp/src/rescript_language_server.ml index 7dab6531be8..18c540143eb 100644 --- a/lsp/src/rescript_language_server.ml +++ b/lsp/src/rescript_language_server.ml @@ -1,7 +1,7 @@ open Lsp open Lsp.Types -let initialization (client_capabilities : ClientCapabilities.t) = +let initialization ~state (client_capabilities : ClientCapabilities.t) = let textDocumentSync = `TextDocumentSyncOptions (TextDocumentSyncOptions.create ~openClose:true @@ -60,14 +60,7 @@ let initialization (client_capabilities : ClientCapabilities.t) = in let executeCommandProvider = ExecuteCommandOptions.create - ~commands: - [ - Execute_commands.Open_compiled.name; - Execute_commands.Create_interface.name; - Execute_commands.Switch_implementation_interface.name; - Execute_commands.Dump_server_state.name; - Execute_commands.Dump_cmt.name; - ] + ~commands:(Execute_commands.advertised_names ~state) () in let diagnosticProvider = @@ -251,7 +244,7 @@ let on_initialize (params : InitializeParams.t) (server : State.t Server.t) = discover_project_context ~notify_errors:true ~workspace_root server in - let initialization_info = initialization params.capabilities in + let initialization_info = initialization ~state params.capabilities in let position_encoding = match initialization_info.capabilities.positionEncoding with @@ -532,18 +525,7 @@ let on_request (Client_request.E request) (server : State.t Server.t) = reporting a formatting failure to the user. *) (ok None, state)) | ExecuteCommand {command; arguments} -> ( - let open Execute_commands in - match - List.assoc_opt command - [ - (Open_compiled.name, Open_compiled.execute); - (Create_interface.name, Create_interface.execute); - ( Switch_implementation_interface.name, - Switch_implementation_interface.execute ); - (Dump_server_state.name, Dump_server_state.execute); - (Dump_cmt.name, Dump_cmt.execute); - ] - with + match Execute_commands.find ~state command with | Some execute -> ( match execute ~arguments server with | Ok None -> (ok `Null, state) diff --git a/lsp/src/state.ml b/lsp/src/state.ml index f16e363c22c..e7f33e98356 100644 --- a/lsp/src/state.ml +++ b/lsp/src/state.ml @@ -15,10 +15,17 @@ type t = { store: Document_store.t; configuration: Configuration.t; fs: Eio.Fs.dir_ty Eio.Path.t; + execute_command_id_suffix: string; } let make ~store ~configuration ~fs = - {status = Uninitialized; store; configuration; fs} + (* Some clients register advertised commands globally, even when each + project has its own server. Keep IDs unique and stable for this session. *) + let random = Random.State.make_self_init () in + let execute_command_id_suffix = + String.init 32 (fun _ -> "0123456789abcdef".[Random.State.int random 16]) + in + {status = Uninitialized; store; configuration; fs; execute_command_id_suffix} let initialize t ~params ~diagnostics ~analysis_state ~compiler_config ~position_encoding = diff --git a/tests/lsp_tests/code_action.ml b/tests/lsp_tests/code_action.ml index 129b2a2bf28..9b0e8cfb474 100644 --- a/tests/lsp_tests/code_action.ml +++ b/tests/lsp_tests/code_action.ml @@ -52,7 +52,7 @@ let value = switch variant { "file:///workspace/Test.res", "file:///workspace/lib/rescript/Test.cmi" ], - "command": "rescript/createInterface", + "command": "rescript/createInterface:", "title": "Create interface file" }, "title": "Create interface file" @@ -123,7 +123,7 @@ let%expect_test "extracts a local module into its own file" = "file:///workspace/Test.res", "file:///workspace/lib/rescript/Test.cmi" ], - "command": "rescript/createInterface", + "command": "rescript/createInterface:", "title": "Create interface file" }, "title": "Create interface file" @@ -199,7 +199,7 @@ let value = if kind == First { "file:///workspace/Test.res", "file:///workspace/lib/rescript/Test.cmi" ], - "command": "rescript/createInterface", + "command": "rescript/createInterface:", "title": "Create interface file" }, "title": "Create interface file" @@ -267,7 +267,7 @@ let%expect_test "offers a type annotation for an inferred string binding" = "file:///workspace/Test.res", "file:///workspace/lib/rescript/Test.cmi" ], - "command": "rescript/createInterface", + "command": "rescript/createInterface:", "title": "Create interface file" }, "title": "Create interface file" @@ -314,7 +314,7 @@ let noBraces = () => name "file:///workspace/Test.res", "file:///workspace/lib/rescript/Test.cmi" ], - "command": "rescript/createInterface", + "command": "rescript/createInterface:", "title": "Create interface file" }, "title": "Create interface file" @@ -359,7 +359,7 @@ let%expect_test "does not offer another annotation for an annotated binding" = "file:///workspace/Test.res", "file:///workspace/lib/rescript/Test.cmi" ], - "command": "rescript/createInterface", + "command": "rescript/createInterface:", "title": "Create interface file" }, "title": "Create interface file" diff --git a/tests/lsp_tests/create_interface.ml b/tests/lsp_tests/create_interface.ml index 2af3926f0be..b9e994e238d 100644 --- a/tests/lsp_tests/create_interface.ml +++ b/tests/lsp_tests/create_interface.ml @@ -51,10 +51,13 @@ let%expect_test "advertises interface creation as an executable command" = in match initialized.capabilities.executeCommandProvider with | Some {commands} -> - List.filter (( = ) "rescript/createInterface") commands - |> List.iter print_endline + List.filter + (String.starts_with ~prefix:"rescript/createInterface:") + commands + |> List.iter (fun command -> + Test.print_json ~root (`String command)) | None -> failwith "Expected executable commands")); - [%expect {| rescript/createInterface |}] + [%expect {| "rescript/createInterface:" |}] let%expect_test "offers and executes interface creation for a saved implementation" = @@ -68,6 +71,7 @@ let%expect_test | [{command = Some command}] -> command | _ -> failwith "Expected one create-interface command" in + assert (List.mem command.command (Test.Client.commands client)); let id = Test.Client.send_request client (Client_request.ExecuteCommand @@ -102,7 +106,7 @@ let%expect_test "file:///workspace/Test.res", "file:///workspace/lib/rescript/Test.cmi" ], - "command": "rescript/createInterface", + "command": "rescript/createInterface:", "title": "Create interface file" }, "title": "Create interface file" diff --git a/tests/lsp_tests/execute_commands.ml b/tests/lsp_tests/execute_commands.ml index 805c33e4fce..68e23e82e93 100644 --- a/tests/lsp_tests/execute_commands.ml +++ b/tests/lsp_tests/execute_commands.ml @@ -15,6 +15,10 @@ let execute ?arguments command = Client_request.ExecuteCommand (ExecuteCommandParams.create ~command ?arguments ()) +let scoped_command client name = + Test.Client.commands client + |> List.find (String.starts_with ~prefix:(name ^ ":")) + let read_dump client command inspect = let id = Test.Client.send_request client command in let request = Test.Client.read_request client "window/showDocument" in @@ -56,7 +60,9 @@ let%expect_test "opens server state as JSON in a unique temporary file" = read_dump client (execute "rescript/dumpServerState") inspect in let second = - read_dump client (execute "rescript/dumpServerState") inspect + read_dump client + (execute (scoped_command client "rescript/dumpServerState")) + inspect in Printf.printf "unique paths: %b\n" (first <> second)); [%expect @@ -77,14 +83,15 @@ let%expect_test "opens server state as JSON in a unique temporary file" = let%expect_test "opens CMT metadata as text in a temporary file" = Test.with_project ~name:"dump-cmt" ~capabilities ~text:{|let value = 1|} (fun ~root:_ ~doc client -> - read_dump client - (execute - ~arguments:[`String (Uri.to_string doc.uri)] - "rescript/dumpCmt") - (fun content -> - Printf.printf "contains CMT metadata: %b\n" - (String.starts_with ~prefix:"file module_name: Test\n" content)) - |> ignore); + List.iter + (fun command -> + read_dump client + (execute ~arguments:[`String (Uri.to_string doc.uri)] command) + (fun content -> + Printf.printf "contains CMT metadata: %b\n" + (String.starts_with ~prefix:"file module_name: Test\n" content)) + |> ignore) + ["rescript/dumpCmt"; scoped_command client "rescript/dumpCmt"]); [%expect {| temporary file: true @@ -92,6 +99,11 @@ let%expect_test "opens CMT metadata as text in a temporary file" = takeFocus: true contains CMT metadata: true null + temporary file: true + extension: .txt + takeFocus: true + contains CMT metadata: true + null |}] let%expect_test "dump commands report missing showDocument support" = @@ -129,3 +141,170 @@ let%expect_test "dumpCmt still rejects invalid arguments" = {| Invalid arguments for workspace/executeCommand rescript/dumpCmt. Expected a list of string: [uri] |}] + +let%expect_test "advertises disjoint command IDs for simultaneous servers" = + Test.with_project ~name:"command-instances" ~capabilities ~run_build:false + ~text:{|let value = 1|} (fun ~root ~doc:_ first -> + Test.with_client ~capabilities ~root (fun second -> + let first_commands = Test.Client.commands first in + let second_commands = Test.Client.commands second in + Test.print_json ~root + (`List (List.map (fun name -> `String name) first_commands)); + let suffixes commands = + List.map + (fun command -> + match String.split_on_char ':' command with + | [_; suffix] -> suffix + | _ -> failwith "Expected a scoped command") + commands + |> List.sort_uniq String.compare + in + assert (List.length (suffixes first_commands) = 1); + assert (List.length (suffixes second_commands) = 1); + assert (List.length second_commands = List.length first_commands); + Printf.printf "disjoint command IDs: %b\n" + (not + (List.exists + (fun command -> List.mem command second_commands) + first_commands)); + List.iter + (fun (client, foreign_command) -> + let id = + Test.Client.send_request client (execute foreign_command) + in + match (Test.Client.read_response client id).result with + | Ok _ -> + failwith "Expected rejection of another server's command" + | Error error -> + assert ( + error.message + = "Unknown command " ^ foreign_command + ^ " for workspace/executeCommand request"); + print_endline "foreign command rejected") + [ + (first, scoped_command second "rescript/dumpServerState"); + (second, scoped_command first "rescript/dumpServerState"); + ])); + [%expect + {| + [ + "rescript/openCompiled:", "rescript/createInterface:", + "rescript/switchImplementationInterface:", + "rescript/dumpServerState:", "rescript/dumpCmt:" + ] + disjoint command IDs: true + foreign command rejected + foreign command rejected + |}] + +let%expect_test + "accepts plain and scoped commands without advertising plain IDs" = + Test.with_project ~name:"command-aliases" ~run_build:false + ~text:{|let value = 1|} (fun ~root:_ ~doc:_ client -> + List.iter + (fun name -> + assert (not (List.mem name (Test.Client.commands client))); + List.iter + (fun command -> + let id = Test.Client.send_request client (execute command) in + match (Test.Client.read_response client id).result with + | Ok _ -> failwith "Expected invalid arguments" + | Error error -> + assert ( + String.starts_with + ~prefix: + ("Invalid arguments for workspace/executeCommand " ^ name) + error.message)) + [name; scoped_command client name]; + Printf.printf "%s: plain and scoped dispatch\n" name) + [ + "rescript/openCompiled"; + "rescript/createInterface"; + "rescript/switchImplementationInterface"; + "rescript/dumpCmt"; + ]); + [%expect + {| + rescript/openCompiled: plain and scoped dispatch + rescript/createInterface: plain and scoped dispatch + rescript/switchImplementationInterface: plain and scoped dispatch + rescript/dumpCmt: plain and scoped dispatch + |}] + +let%expect_test "navigation code actions use stable advertised IDs" = + Test.with_project ~name:"command-navigation" ~capabilities + ~text:{|let value = 1|} + ~files:[("Test.resi", {|let value: int|})] + (fun ~root ~doc client -> + let navigate doc = + let request = + Client_request.CodeAction + (CodeActionParams.create ~textDocument:(Test.text_document doc) + ~range:(Test.range (0, 0) (0, 0)) + ~context:(CodeActionContext.create ~diagnostics:[] ()) + ()) + in + let commands () = + Test.Client.request client request + |> Option.value ~default:[] + |> List.filter_map (function + | `CodeAction (action : CodeAction.t) -> action.command + | `Command command -> Some command) + in + let actions = commands () in + assert (actions = commands ()); + List.iter + (fun (command : Command.t) -> + assert (List.mem command.command (Test.Client.commands client)); + let id = + Test.Client.send_request client + (execute ?arguments:command.arguments command.command) + in + let request = + Test.Client.read_request client "window/showDocument" + in + let params = + Option.get request.params |> Jsonrpc.Structured.yojson_of_t + |> ShowDocumentParams.t_of_yojson + in + assert (params.takeFocus = Some true); + Test.print_json ~root + (`Assoc + [ + ("command", `String command.command); + ("uri", `String (Uri.to_string params.uri)); + ]); + Test.Client.send_packet client + (Jsonrpc.Packet.Response + (Jsonrpc.Response.ok request.id + (`Assoc [("success", `Bool true)]))); + assert ((Test.Client.read_response client id).result = Ok `Null)) + actions + in + navigate doc; + let interface = + Test.make_document + ~uri:(Uri.of_path (Filename.concat root "Test.resi")) + ~text:{|let value: int|} + in + Test.perform client (Test.open_document interface); + navigate interface); + [%expect + {| + { + "command": "rescript/openCompiled:", + "uri": "file:///workspace/lib/es6/./Test.res.js" + } + { + "command": "rescript/switchImplementationInterface:", + "uri": "file:///workspace/Test.resi" + } + { + "command": "rescript/openCompiled:", + "uri": "file:///workspace/lib/es6/./Test.res.js" + } + { + "command": "rescript/switchImplementationInterface:", + "uri": "file:///workspace/Test.res" + } + |}] diff --git a/tests/lsp_tests/test.ml b/tests/lsp_tests/test.ml index 802af0f2002..8333b00a33d 100644 --- a/tests/lsp_tests/test.ml +++ b/tests/lsp_tests/test.ml @@ -70,6 +70,7 @@ module Client = struct mutable next_id: int; mutable status: Unix.process_status option; mutable notifications: Jsonrpc.Notification.t list; + mutable commands: string list; } let frame body : string = @@ -128,6 +129,7 @@ module Client = struct next_id = 0; status = None; notifications = []; + commands = []; } let send_body t body = @@ -184,6 +186,8 @@ module Client = struct t.notifications <- []; notifications + let commands t = t.commands + (** Send a typed request and synchronously wait for its response, decoded back into the request's result type. *) let request (type r) t (req : r Lsp.Client_request.t) : r = @@ -271,8 +275,13 @@ let initialize_client ~capabilities ~root client = let init_params = InitializeParams.create ~capabilities ~rootUri:(DocumentUri.of_path root) () in - let id = Client.send_request client (Client_request.Initialize init_params) in - assert ((Client.read_response client id).result |> Result.is_ok); + let initialized = + Client.request client (Client_request.Initialize init_params) + in + client.commands <- + (match initialized.capabilities.executeCommandProvider with + | Some {commands} -> commands + | None -> []); Client.send_notification client (Client_notification.Initialized (InitializedParams.t_of_yojson (`Assoc []))); let registration = Client.read_request client "client/registerCapability" in @@ -343,8 +352,9 @@ let range start end_ = let text_document (doc : TextDocumentItem.t) = TextDocumentIdentifier.create ~uri:doc.uri -(* Only replace the temporary workspace prefix; keep relative paths, ranges and - response ordering intact so snapshots still catch navigation/edit regressions. *) +(* Replace nondeterministic workspace paths and per-session command suffixes; + keep relative paths, ranges and response ordering intact. Command identity + and routing are also checked against the unnormalized initialize response. *) let normalize_json ~root json = let prefixes = [ @@ -381,8 +391,25 @@ let normalize_json ~root json = prefixes |> Option.value ~default:value in + let normalize_command value = + match String.index_opt value ':' with + | Some index when String.starts_with ~prefix:"rescript/" value -> + let suffix = + String.sub value (index + 1) (String.length value - index - 1) + in + if + String.length suffix = 32 + && String.for_all + (function + | '0' .. '9' | 'a' .. 'f' -> true + | _ -> false) + suffix + then String.sub value 0 (index + 1) ^ "" + else value + | _ -> value + in let rec normalize = function - | `String value -> `String (normalize_string value) + | `String value -> `String (normalize_string value |> normalize_command) | `Assoc fields -> `Assoc (List.map From df1ec7869ad564eb1fd0b79447a49d0c9afc438b Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 22 Nov 2026 20:46:53 -0300 Subject: [PATCH 10/13] Fix Windows drive-case mismatches in LSP diagnostics Why: Compiler logs and editors can use different drive-letter casing. Structural URI comparison treats these as separate documents, causing compiler errors to disappear when a file opens. Representation modified (document and diagnostic keys): Before (text): D:/project/Broken.res and d:/project/Broken.res use separate keys. Pull diagnostics for the open document return an empty list. After (text): Serialized URI keys identify both paths as the same document. Pull diagnostics retain compiler errors. Filename case remains distinct. Add unit and end-to-end regressions for URI lookup, diagnostic merging, open/close ownership, and clearing errors after a clean build. Document the unchanged pull behavior for documents without an editor. Signed-off-by: Pedro Castro --- lsp/README.md | 5 ++ lsp/src/diagnostics.ml | 98 +++++++++++++++++++++++++++++++++- lsp/src/document_store.ml | 58 +++++++++++++++----- lsp/src/state.ml | 2 +- tests/lsp_tests/diagnostics.ml | 76 ++++++++++++++++++++++++++ 5 files changed, 225 insertions(+), 14 deletions(-) diff --git a/lsp/README.md b/lsp/README.md index 5445c365da9..d1b3498176f 100644 --- a/lsp/README.md +++ b/lsp/README.md @@ -155,6 +155,11 @@ Avoid publishing the same diagnostic through both channels: clients can retain them separately and display duplicates. Supported clients are asked to refresh pull diagnostics after compiler-log updates. +Document and diagnostic keys use the URI's serialized form so Windows drive +letters match regardless of the case used by the compiler or client. Filename +case is preserved. Pull-capable clients decide when to request diagnostics; +documents opened without a visible editor may not be pulled by the client. + ### Diagnostic scenarios and design history Three editor scenarios motivated the ownership model: diff --git a/lsp/src/diagnostics.ml b/lsp/src/diagnostics.ml index 5a6b6f34527..63be0e090fa 100644 --- a/lsp/src/diagnostics.ml +++ b/lsp/src/diagnostics.ml @@ -1,7 +1,14 @@ open Lsp open Lsp.Types -module Uri_map = Map.Make (Uri) +(* Compiler paths and client URIs may differ in drive-letter case. Compare + their wire forms, as Document_store does, without lowercasing file names. *) +module Uri_map = Map.Make (struct + type t = Uri.t + + let compare left right = + String.compare (Uri.to_string left) (Uri.to_string right) +end) type diagnostics = Diagnostic.t list Uri_map.t @@ -394,3 +401,92 @@ let%expect_test "compiler syntax diagnostics don't clear type diagnostics" = A.res: B.res: C.res: |}] + +let%expect_test "Windows compiler paths share the open document's identity" = + (* Exercise real backslash paths even when this test runs on Unix. *) + let win32 = !Uri.Private.win32 in + Fun.protect + ~finally:(fun () -> Uri.Private.win32 := win32) + (fun () -> + Uri.Private.win32 := true; + let workspace_root = Uri.of_path {|D:\a\project|} in + let compiler_uri = Uri.of_path {|D:\a\project\src\Broken.res|} in + let client_uri = Uri.of_string "file:///d%3A/a/project/src/Broken.res" in + assert (Uri.compare compiler_uri client_uri <> 0); + let source = "let value = 1\nlet other = 2" in + let doc = + Document.make + (DidOpenTextDocumentParams.create + ~textDocument: + (TextDocumentItem.create ~uri:client_uri ~text:source ~version:0 + ~languageId:(LanguageKind.Other "rescript"))) + ~position_encoding:`UTF16 + in + let doc_store = Document_store.make () in + ignore (Document_store.add doc_store ~doc); + let entry path kind = + {Compiler_log.Parse.kind; path; message = "compiler"; range = None} + in + let convert path kind = + to_lsp_format ~include_syntax:true ~include_non_syntax:true + workspace_root doc_store + [entry path kind] + in + let absolute = + Compiler_log.Parse.Full_path {|D:\a\project\src\Broken.res|} + in + let relative = Compiler_log.Parse.Relative_path {|src\Broken.res|} in + let compiler = convert absolute Common_error in + let relative_compiler = convert relative Common_error in + Printf.printf "absolute compiler diagnostics: %d\n" + (List.length (Uri_map.find client_uri compiler)); + Printf.printf "relative compiler diagnostics: %d\n" + (List.length (Uri_map.find client_uri relative_compiler)); + Printf.printf "open compiler syntax diagnostics: %d\n" + (Uri_map.cardinal (convert absolute Syntax_error)); + let compiler_diagnostic = List.hd (Uri_map.find client_uri compiler) in + Printf.printf "fallback range uses open buffer: %b\n" + (compiler_diagnostic.range = Document.range_of_text source); + let t = + make ~diagnostics:compiler + ~send:(fun ({diagnostics} : PublishDiagnosticsParams.t) -> + Printf.printf "pushed diagnostics: %d\n" (List.length diagnostics)) + |> update_syntax ~uri:client_uri + ~new_diagnostics: + [ + Diagnostic.create + ~range:(Document.range_of_text source) + ~message:(`String "buffer") (); + ] + in + Printf.printf "merged URI keys: %d\n" (Uri_map.cardinal (get_all t)); + Printf.printf "merged diagnostics: %d\n" + (List.length (Uri_map.find client_uri (get_all t))); + send ~include_syntax:false ~force_publish_uris:[client_uri] + ~should_publish:(fun uri -> + Document_store.get_opt doc_store ~uri = None) + t; + ignore (Document_store.remove doc_store ~uri:compiler_uri); + let t = clear_syntax ~uri:compiler_uri t in + send t; + send (update_compiler ~new_diagnostics:(empty ()) t); + Printf.printf "filename case remains distinct: %b\n" + (Uri_map.cardinal + (Uri_map.empty |> Uri_map.add client_uri [] + |> Uri_map.add + (Uri.of_string "file:///d%3A/a/project/src/broken.res") + []) + = 2)); + [%expect + {| + absolute compiler diagnostics: 1 + relative compiler diagnostics: 1 + open compiler syntax diagnostics: 0 + fallback range uses open buffer: true + merged URI keys: 1 + merged diagnostics: 2 + pushed diagnostics: 0 + pushed diagnostics: 1 + pushed diagnostics: 0 + filename case remains distinct: true + |}] diff --git a/lsp/src/document_store.ml b/lsp/src/document_store.ml index 6d244162f1d..e0f8b3bacce 100644 --- a/lsp/src/document_store.ml +++ b/lsp/src/document_store.ml @@ -1,6 +1,8 @@ open Lsp -type t = {documents: (Uri.t, Document.t) Hashtbl.t} +(* URI serialization normalizes drive letters, unlike Uri.equal/hash. Keep + the original client URI in the document, but use its wire form as the key. *) +type t = {documents: (string, Document.t) Hashtbl.t} let make () = {documents = Hashtbl.create 50} @@ -8,38 +10,34 @@ let raise ~code ~message = Jsonrpc.Response.Error.raise (Jsonrpc.Response.Error.make ~code ~message ()) let add t ~doc = - let uri = Document.uri doc in + let uri = Document.uri doc |> Uri.to_string in (match Hashtbl.mem t.documents uri with | false -> Hashtbl.add t.documents uri doc | true -> raise ~code:RequestFailed ~message: - (Printf.sprintf "Cannot open document %s: it is already open." - (Uri.to_string uri))); + (Printf.sprintf "Cannot open document %s: it is already open." uri)); t let update t ~doc = - let uri = Document.uri doc in + let uri = Document.uri doc |> Uri.to_string in (match Hashtbl.find_opt t.documents uri with | None -> raise ~code:RequestFailed - ~message: - (Printf.sprintf "Cannot update document %s: it is not open." - (Uri.to_string uri)) + ~message:(Printf.sprintf "Cannot update document %s: it is not open." uri) | Some _ -> Hashtbl.replace t.documents uri doc); t let remove t ~uri = + let uri = Uri.to_string uri in (match Hashtbl.mem t.documents uri with | true -> Hashtbl.remove t.documents uri | false -> raise ~code:RequestFailed - ~message: - (Printf.sprintf "Cannot close document %s: it is not open." - (Uri.to_string uri))); + ~message:(Printf.sprintf "Cannot close document %s: it is not open." uri)); t -let get_opt t ~uri = Hashtbl.find_opt t.documents uri +let get_opt t ~uri = Hashtbl.find_opt t.documents (Uri.to_string uri) let get t ~uri = match get_opt t ~uri with @@ -49,3 +47,39 @@ let get t ~uri = ~message: (Printf.sprintf "Cannot get document %s: it is not open." (Uri.to_string uri)) + +let%expect_test "drive-letter variants identify the same open document" = + let upper = Uri.of_string "file:///D%3A/project/Broken.res" in + let lower = Uri.of_string "file:///d%3A/project/Broken.res" in + let make_doc uri text version = + Document.make + (Lsp.Types.DidOpenTextDocumentParams.create + ~textDocument: + (Lsp.Types.TextDocumentItem.create ~uri ~text ~version + ~languageId:(Lsp.Types.LanguageKind.Other "rescript"))) + ~position_encoding:`UTF16 + in + let store = make () in + let doc = make_doc upper "let value = 1" 0 in + ignore (add store ~doc); + Printf.printf "alternate drive lookup: %b\n" (get store ~uri:lower = doc); + Printf.printf "original client URI retained: %b\n" + (Uri.equal (Document.uri (get store ~uri:lower)) upper); + (try + ignore (add store ~doc:(make_doc lower "let value = 2" 0)); + failwith "Expected a duplicate-document error" + with Jsonrpc.Response.Error.E error -> print_endline error.message); + ignore (update store ~doc:(make_doc lower "let value = 3" 1)); + Printf.printf "updated through alternate drive: %s\n" + (Document.text (get store ~uri:upper)); + ignore (remove store ~uri:upper); + Printf.printf "closed through alternate drive: %b\n" + (get_opt store ~uri:lower = None); + [%expect + {| + alternate drive lookup: true + original client URI retained: true + Cannot open document file:///d%3A/project/Broken.res: it is already open. + updated through alternate drive: let value = 3 + closed through alternate drive: true + |}] diff --git a/lsp/src/state.ml b/lsp/src/state.ml index e7f33e98356..df1f1450b01 100644 --- a/lsp/src/state.ml +++ b/lsp/src/state.ml @@ -95,7 +95,7 @@ let to_yojson (t : t) : Yojson.Safe.t = let document_store_to_yojson (store : Document_store.t) = store.documents |> Hashtbl.to_seq |> Seq.map (fun (uri, doc) -> - ( Lsp.Uri.to_string uri, + ( uri, `Assoc [ ("version", `Int (Lsp.Text_document.version doc)); diff --git a/tests/lsp_tests/diagnostics.ml b/tests/lsp_tests/diagnostics.ml index 1a77f86ba3f..f24c6870350 100644 --- a/tests/lsp_tests/diagnostics.ml +++ b/tests/lsp_tests/diagnostics.ml @@ -371,3 +371,79 @@ Somewhere wanted: string } { "kind": "full", "items": [] } |}] + +let%expect_test + "Windows drive casing preserves compiler errors across open and close" = + Test.with_project ~name:"diagnostics-drive-case" ~text:{|let value = 1|} + (fun ~root ~doc:_ client -> + ignore (publications client); + (* A slash-prefixed Windows drive also reproduces the URI mismatch on + Unix. The document stays in memory; no file on that drive is needed. *) + let doc = + Test.make_document + ~uri:(Uri.of_string "file:///d%3A/a/project/src/Broken.res") + ~text:{|let value: int = "broken"|} + in + write_log ~root client + {|#Start(1) +We've found a bug for you! +/D:/a/project/src/Broken.res:1:18-25 + +This has type: string +Somewhere wanted: int + +#Done(2) +|}; + ignore (publications client); + Test.perform client (Test.open_document doc); + print_endline "open document pushes:"; + print_publications ~root client; + print_endline "open document pull:"; + Test.snapshot ~root client (Syntax_test.diagnostics doc); + close_document client doc; + print_endline "closed document pushes:"; + print_publications ~root client; + write_log ~root client {|#Start(3) +#Done(4) +|}; + print_endline "clean build pushes:"; + print_publications ~root client); + [%expect + {| + open document pushes: + [ { "diagnostics": [], "uri": "file:///d%3A/a/project/src/Broken.res" } ] + open document pull: + { + "kind": "full", + "items": [ + { + "message": "This has type: string\nSomewhere wanted: int", + "range": { + "end": { "character": 25, "line": 0 }, + "start": { "character": 17, "line": 0 } + }, + "severity": 1, + "source": "ReScript" + } + ] + } + closed document pushes: + [ + { + "diagnostics": [ + { + "message": "This has type: string\nSomewhere wanted: int", + "range": { + "end": { "character": 25, "line": 0 }, + "start": { "character": 17, "line": 0 } + }, + "severity": 1, + "source": "ReScript" + } + ], + "uri": "file:///d%3A/a/project/src/Broken.res" + } + ] + clean build pushes: + [ { "diagnostics": [], "uri": "file:///d%3A/a/project/src/Broken.res" } ] + |}] From d6777483bf7d1776b10dc5f2d82f9c86199e416f Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 22 Nov 2026 21:18:34 -0300 Subject: [PATCH 11/13] Reuse rewatch configuration decoding in the language server Why: The LSP maintained a separate rescript.json decoder whose defaults and namespace rules could diverge from the build system. Representation modified (project configuration): Before (text): The LSP decodes its own partial schema and computes artifact paths. Missing package-specs defaults to CommonJS out-of-source output. After (text): Config.of_string decodes Eio-loaded contents using the build schema. Rewatch helpers resolve namespaces and generated artifact paths. Missing package-specs uses the build's ES module in-source default. Keep ppx_deriving_yojson for editor settings and decode source-directory metadata with Yojson directly. Update documentation and license scopes. Add tests for decoder parity, output defaults, multiple outputs, namespaces, settings validation, and malformed source-directory metadata. Signed-off-by: Pedro Castro --- licenses/components.json | 2 +- lsp/README.md | 7 +- lsp/src/compiler_config.ml | 466 ++---------------- lsp/src/configuration.ml | 51 ++ lsp/src/dune | 9 +- lsp/src/helpers.ml | 157 +----- lsp/src/source_dirs.ml | 40 +- lsp/src/state.ml | 2 +- .../darwin-arm64/THIRD_PARTY_LICENSES | 2 +- .../linux-arm64/THIRD_PARTY_LICENSES | 2 +- .../@rescript/linux-x64/THIRD_PARTY_LICENSES | 2 +- .../@rescript/win32-x64/THIRD_PARTY_LICENSES | 2 +- rewatch-ocaml/config.ml | 27 +- rewatch-ocaml/config.mli | 1 + tests/lsp_tests/dune | 2 +- tests/lsp_tests/execute_commands.ml | 4 +- tests/lsp_tests/output_configuration.ml | 68 ++- tests/lsp_tests/project_recovery.ml | 4 +- tests/rewatch_ounit_tests/config_tests.ml | 27 + 19 files changed, 298 insertions(+), 577 deletions(-) diff --git a/licenses/components.json b/licenses/components.json index ddf8f3116e0..f2f49eeb32d 100644 --- a/licenses/components.json +++ b/licenses/components.json @@ -329,7 +329,7 @@ "opam": "ppx_deriving_yojson", "source": "https://github.com/ocaml-ppx/ppx_deriving_yojson", "license": "MIT", - "scope": "JSON codecs in the language-server library in rescript" + "scope": "JSON codecs for language-server editor settings in rescript" }, { "name": "Cmdliner", diff --git a/lsp/README.md b/lsp/README.md index d1b3498176f..50cab5c3fd6 100644 --- a/lsp/README.md +++ b/lsp/README.md @@ -91,7 +91,12 @@ updating its compiler. The server library lives in `lsp/src` and has an opam package named `rescript-language-server`. It depends on the OCaml `lsp` library, Eio, -`ppx_deriving_yojson`, and the in-tree analysis library; tests use `ppx_expect`. +Yojson, `ppx_deriving_yojson`, and the in-tree analysis and rewatch libraries; +tests use `ppx_expect`. +Project configuration uses rewatch's decoder, namespace rules, and artifact-path +helpers. Only editor settings and the required `.sourcedirs.json` fields are +decoded locally: editor settings use derived codecs, while source-directory +metadata uses Yojson directly. ### Code map diff --git a/lsp/src/compiler_config.ml b/lsp/src/compiler_config.ml index ece1b623c6f..028a58c8c6b 100644 --- a/lsp/src/compiler_config.ml +++ b/lsp/src/compiler_config.ml @@ -1,428 +1,68 @@ -module Parse = struct - type namespace = Namespace_bool of bool | Namespace_string of string - - let namespace_to_yojson = function - | Namespace_bool value -> `Bool value - | Namespace_string value -> `String value - - let namespace_of_yojson = function - | `Bool value -> Ok (Namespace_bool value) - | `String value -> Ok (Namespace_string value) - | json -> - Error - ("Expected namespace to be a boolean or string, got " - ^ Yojson.Safe.to_string json) - - type module_format = Commonjs | Es6 | Es6_global | Esmodule - - let module_format_to_yojson = function - | Commonjs -> `String "commonjs" - | Es6 -> `String "es6" - | Es6_global -> `String "es6-global" - | Esmodule -> `String "esmodule" - - let module_format_of_yojson = function - | `String "commonjs" -> Ok Commonjs - | `String "es6" -> Ok Es6 - | `String "es6-global" -> Ok Es6_global - | `String "esmodule" -> Ok Esmodule - | _ -> Error "Compiler_config.module_format" - - type module_format_object = { - in_source: bool option; [@key "in-source"] [@default None] - module_: module_format; [@key "module"] - suffix: string option; [@default None] - } - [@@deriving yojson {strict = false}] - - type package_spec = - | Module_format of module_format - | Module_format_object of module_format_object - - let package_spec_to_yojson = function - | Module_format module_format -> module_format_to_yojson module_format - | Module_format_object module_format_object -> - module_format_object_to_yojson module_format_object - - let package_spec_of_yojson json = - match module_format_of_yojson json with - | Ok module_format -> Ok (Module_format module_format) - | Error _ -> ( - match module_format_object_of_yojson json with - | Ok module_format_object -> - Ok (Module_format_object module_format_object) - | Error message -> Error message) - - type package_specs = package_spec list - - let package_specs_to_yojson package_specs = - `List (List.map package_spec_to_yojson package_specs) - - let package_specs_of_yojson json = - let rec collect = function - | [] -> Ok [] - | json :: rest -> ( - match package_spec_of_yojson json with - | Ok package_spec -> ( - match collect rest with - | Ok package_specs -> Ok (package_spec :: package_specs) - | Error _ as error -> error) - | Error _ as error -> error) - in - - match json with - | `List package_specs -> collect package_specs - | json -> ( - match package_spec_of_yojson json with - | Ok package_spec -> Ok [package_spec] - | Error _ as error -> error) - - type dependencie_object = { - name: string; - features: string list option; [@default None] - } - [@@deriving yojson {strict = false}] - - type dependencies = String of string | Object of dependencie_object - - let dependencies_to_yojson = function - | String name -> `String name - | Object dependency -> dependencie_object_to_yojson dependency - - let dependencies_of_yojson = function - | `String name -> Ok (String name) - | `Assoc _ as json -> ( - match dependencie_object_of_yojson json with - | Ok dependency -> Ok (Object dependency) - | Error message -> Error message) - | _ -> Error "Expected a dependency name or object" - - type t = { - name: string; - namespace: namespace option; [@default None] - package_specs: package_specs option; [@key "package-specs"] [@default None] - suffix: string option; [@default None] - dependencies: dependencies list option; [@default None] - dev_dependencies: dependencies list option; - [@key "dev-dependencies"] [@default None] - (* Old fields, deprecated *) - bs_dependencies: dependencies list option; - [@key "bs-dependencies"] [@default None] - bs_dev_dependencies: dependencies list option; - [@key "bs-dev-dependencies"] [@default None] - } - [@@deriving yojson {strict = false}] - - let%expect_test "namespace codecs accept the compiler's JSON forms" = - List.iter - (fun json -> - match namespace_of_yojson json with - | Ok namespace -> - namespace_to_yojson namespace - |> Yojson.Safe.to_string |> print_endline - | Error message -> print_endline message) - [`Bool true; `Bool false; `String "App"; `Int 1]; - [%expect - {| - true - false - "App" - Expected namespace to be a boolean or string, got 1 - |}] - - let%expect_test "package specs codecs accept single values and lists" = - List.iter - (fun text -> - match package_specs_of_yojson (Yojson.Safe.from_string text) with - | Ok specs -> - package_specs_to_yojson specs - |> Yojson.Safe.to_string |> print_endline - | Error message -> print_endline message) - [ - {|"commonjs"|}; - {|["es6","es6-global","esmodule"]|}; - {|{"module":"esmodule","in-source":true,"suffix":".mjs"}|}; - {|[]|}; - {|["commonjs",42]|}; - ]; - [%expect - {| - ["commonjs"] - ["es6","es6-global","esmodule"] - [{"in-source":true,"module":"esmodule","suffix":".mjs"}] - [] - Compiler_config.Parse.module_format_object - |}] - - let%expect_test "parse build schema" = - let prin_config config = - match config with - | Error message -> print_endline ("Error: " ^ message) - | Ok config -> ( - Printf.printf "name=%s\n" config.name; - (match config.namespace with - | Some (Namespace_string namespace) -> - Printf.printf "namespace=%s\n" namespace - | Some (Namespace_bool namespace) -> - Printf.printf "namespace=%b\n" namespace - | None -> print_endline "namespace=None"); - (match config.dependencies with - | None -> print_endline "dependencies=None" - | Some deps -> - let deps_names = - deps - |> List.map (fun dep -> - match dep with - | String name -> name - | Object {name} -> name) - |> String.concat ", " - in - Printf.printf "dependencies=Some(%s)\n" deps_names); - (match config.package_specs with - | Some specs -> - let r = - specs - |> List.map (fun spec -> - package_spec_to_yojson spec |> Yojson.Safe.pretty_to_string) - |> String.concat ", " - in - Printf.sprintf "package_specs=Some(%s)" r |> print_endline - | None -> print_endline "package_specs=None"); - match config.suffix with - | Some suffix -> Printf.sprintf "suffix=%s" suffix |> print_endline - | None -> print_endline "suffix=None") - in - - let json = - Yojson.Safe.from_string - {|{ - "name": "app", - "namespace": "App", - "dependencies": [], - "package-specs": [ - "esmodule", - { - "in-source": true, - "module": "commonjs", - "suffix": ".cjs" - } - ], - "suffix": ".js" - }|} - in - prin_config (of_yojson json); - [%expect - {| - name=app - namespace=App - dependencies=Some() - package_specs=Some("esmodule", { "in-source": true, "module": "commonjs", "suffix": ".cjs" }) - suffix=.js - |}]; - - let json_2 = - Yojson.Safe.from_string - {|{ - "name": "@rescript-lang/guide", - "namespace": false, - "dependencies": [ - "@rescript-lang/playground", - "@rescript-lang/shared", - "@rescript/react", - "@rescript/webapi" - ], - "compiler-flags": ["-open WebAPI.Global"], - "sources": [ - { - "dir": "__tests__", - "subdirs": true, - "type": "dev" - }, - { - "dir": "app", - "subdirs": true - } - ], - "warnings": { - "error": "+8" - } - }|} - in - prin_config (of_yojson json_2); - [%expect - {| - name=@rescript-lang/guide - namespace=false - dependencies=Some(@rescript-lang/playground, @rescript-lang/shared, @rescript/react, @rescript/webapi) - package_specs=None - suffix=None - |}]; - - let json_3 = - Yojson.Safe.from_string - {|{ - "name": "rescript-lang.org-monorepo", - "dependencies": [ - "@rescript-lang/shared", - "@rescript-lang/playground", - "@rescript-lang/guide", - "@rescript-lang/docs" - ], - "sources": [], - "jsx": { - "preserve": true, - "version": 4 - }, - "package-specs": { - "module": "esmodule", - "in-source": true - }, - "suffix": ".jsx" - } -|} - in - prin_config (of_yojson json_3); - [%expect - {| - name=rescript-lang.org-monorepo - namespace=None - dependencies=Some(@rescript-lang/shared, @rescript-lang/playground, @rescript-lang/guide, @rescript-lang/docs) - package_specs=Some({ "in-source": true, "module": "esmodule" }) - suffix=.jsx - |}]; - - let json_4 = - Yojson.Safe.from_string - {| -{ - "name": "app", - "dependencies": [ - "@plain/dep", - { "name": "@example/lib", "features": ["native"] } - ] -} -|} - in - prin_config (of_yojson json_4); - [%expect - {| - name=app - namespace=None - dependencies=Some(@plain/dep, @example/lib) - package_specs=None - suffix=None - |}] - - let%expect_test "dependency JSON round trips preserve features" = - let print json = - match dependencies_of_yojson (Yojson.Safe.from_string json) with - | Ok dependency -> - dependencies_to_yojson dependency - |> Yojson.Safe.pretty_to_string |> print_endline - | Error message -> Printf.printf "Error: %s\n" message - in - print {|"@plain/dep"|}; - print {|{"name":"@example/lib","features":["native"]}|}; - print {|{"name":"@example/lib"}|}; - print {|42|}; - print {|{"features":["native"]}|}; - print {|{"name":"@example/lib","features":true}|}; - [%expect - {| - "@plain/dep" - { "name": "@example/lib", "features": [ "native" ] } - { "name": "@example/lib" } - Error: Expected a dependency name or object - Error: Compiler_config.Parse.dependencie_object.name - Error: Compiler_config.Parse.dependencie_object.features - |}] -end - +module Config = Rewatch_ocaml_lib.Config module Uri_map = Map.Make (Lsp.Uri) -type t = Parse.t Uri_map.t +type t = Config.t Uri_map.t let parse ~root ~fs = let ( /+ ) = Filename.concat in - let config_file = let rescript_json = root /+ Constants.rescript_json in - let bsconfig_json = root /+ Constants.bsconfig_json in if Fs.exists ~follow:false ~fs rescript_json then rescript_json - else bsconfig_json + else root /+ Constants.bsconfig_json in - match Fs.load ~fs config_file with | Some content -> ( - match Yojson.Safe.from_string content with - | json -> ( - match Parse.of_yojson json with - | Ok s -> Ok s - | Error msg -> - Error - (Printf.sprintf "Failed to parse compiler config %s. %s" config_file - msg)) - | exception exc -> - Error - (Printf.sprintf "Failed to parse rescript configuration file at %s. %s" - root (Printexc.to_string exc))) + try Ok (Config.of_string ~path:config_file ~root content) + with Config.Error message -> Error message) | None -> Error ("Failed to read rescript configuration file at " ^ root) -type output_config = {suffix: string; folder: string; in_source: bool} -let get_output_config (config : Parse.t) = - let default_suffix = ".js" in - let default_in_source = false in - let folder_name = function - | Parse.Commonjs -> "js" - | Es6_global -> "es6_global" - | Es6 | Esmodule -> "es6" +let get_all_dependecies_names (config : Config.t) = + List.map + (fun (dependency : Config.dependency) -> dependency.name) + (config.dependencies @ config.dev_dependencies) + +(* State dumps expose the effective project settings, not a second copy of + the rescript.json schema or its decoder. *) +let to_yojson (config : Config.t) = + let optional_string = function + | None -> `Null + | Some value -> `String value in - match config.package_specs with - | Some pkg_spec -> ( - match pkg_spec with - | [] -> - { - suffix = config.suffix |> Option.value ~default:default_suffix; - folder = folder_name Parse.Commonjs; - in_source = default_in_source; - } - | Module_format module_ :: _ -> - { - suffix = config.suffix |> Option.value ~default:default_suffix; - folder = folder_name module_; - in_source = default_in_source; - } - | Module_format_object {module_; suffix; in_source} :: _ -> - let suffix = - match (suffix, config.suffix) with - | Some s, _ -> s - | None, Some s -> s - | _ -> default_suffix - in - { - suffix; - folder = folder_name module_; - in_source = in_source |> Option.value ~default:default_in_source; - }) - | None -> - { - suffix = config.suffix |> Option.value ~default:default_suffix; - folder = folder_name Parse.Commonjs; - in_source = default_in_source; - } - -let get_all_dependecies_names (config : Parse.t) = - let names deps = - match deps with - | None -> [] - | Some deps -> - deps - |> List.map (fun dep -> - match dep with - | Parse.String name -> name - | Object {name} -> name) + let dependencies values = + `List + (List.map + (fun (dependency : Config.dependency) -> + `Assoc + ([("name", `String dependency.name)] + @ + match dependency.features with + | None -> [] + | Some features -> + [ + ( "features", + `List (List.map (fun value -> `String value) features) ); + ])) + values) in - (config.dependencies |> names) - @ (config.dev_dependencies |> names) - @ (config.bs_dependencies |> names) - @ (config.bs_dev_dependencies |> names) + `Assoc + [ + ("name", `String config.name); + ("namespace", optional_string (Config.namespace_name config.namespace)); + ( "namespace-entry", + optional_string (Config.namespace_entry config.namespace) ); + ("suffix", `String config.suffix); + ("dependencies", dependencies config.dependencies); + ("dev-dependencies", dependencies config.dev_dependencies); + ( "package-specs", + `List + (List.map + (fun (spec : Config.package_spec) -> + `Assoc + [ + ( "module", + `String (Config.module_format_name spec.module_format) ); + ("in-source", `Bool spec.in_source); + ("suffix", `String (Config.package_spec_suffix config spec)); + ]) + config.package_specs) ); + ] diff --git a/lsp/src/configuration.ml b/lsp/src/configuration.ml index fa39cadfcd7..23c5a8ac2de 100644 --- a/lsp/src/configuration.ml +++ b/lsp/src/configuration.ml @@ -50,3 +50,54 @@ let%expect_test "parse config" = in parse_and_print_config example_config_json_1; [%expect {| { "codeLens": true, "inlayHints": { "enable": true } } |}] + +let%expect_test "settings retain defaults, optional limits, and unknown fields" + = + List.iter + (fun text -> + match of_yojson (Yojson.Safe.from_string text) with + | Ok config -> + let json = to_yojson config in + assert (of_yojson json = Ok config); + print_endline (Yojson.Safe.to_string json) + | Error message -> failwith message) + [ + {|{}|}; + {|{"hover":{},"inlayHints":{},"futureSetting":true}|}; + {|{"hover":{"supportMarkdownLinks":true},"codeLens":true,"inlayHints":{"enable":true,"maxLength":0}}|}; + {|{"inlayHints":{"maxLength":null}}|}; + ]; + [%expect + {| + {} + {} + {"hover":{"supportMarkdownLinks":true},"codeLens":true,"inlayHints":{"enable":true,"maxLength":0}} + {"inlayHints":{"maxLength":null}} + |}] + +let%expect_test "settings reject invalid known fields" = + List.iter + (fun text -> + Printf.printf "%s: %b\n" text + (Result.is_error (of_yojson (Yojson.Safe.from_string text)))) + [ + {|[]|}; + {|{"hover":null}|}; + {|{"codeLens":null}|}; + {|{"codeLens":1}|}; + {|{"hover":{"supportMarkdownLinks":"true"}}|}; + {|{"inlayHints":false}|}; + {|{"inlayHints":{"enable":null}}|}; + {|{"inlayHints":{"maxLength":"25"}}|}; + ]; + [%expect + {| + []: true + {"hover":null}: true + {"codeLens":null}: true + {"codeLens":1}: true + {"hover":{"supportMarkdownLinks":"true"}}: true + {"inlayHints":false}: true + {"inlayHints":{"enable":null}}: true + {"inlayHints":{"maxLength":"25"}}: true + |}] diff --git a/lsp/src/dune b/lsp/src/dune index 3b2d301847b..e78f0f40e19 100644 --- a/lsp/src/dune +++ b/lsp/src/dune @@ -1,6 +1,13 @@ (library (name rescript_language_server) - (libraries lsp eio analysis str ppx_deriving_yojson.runtime) + (libraries + lsp + eio + analysis + rewatch_ocaml_lib + str + yojson + ppx_deriving_yojson.runtime) (inline_tests) (preprocess (pps ppx_deriving_yojson ppx_expect)) diff --git a/lsp/src/helpers.ml b/lsp/src/helpers.ml index 1aa5a7f16cc..3f2069bf854 100644 --- a/lsp/src/helpers.ml +++ b/lsp/src/helpers.ml @@ -50,147 +50,44 @@ let best_root_match ~path entries = else best) None -let relative_to ~root path = - let root = if String.ends_with ~suffix:"/" root then root else root ^ "/" in - - if String.starts_with ~prefix:root path then - let root_len = String.length root in - String.sub path root_len (String.length path - root_len) - else path - -let to_camel_case (text : string) : string = - let len = String.length text in - let buffer = Buffer.create len in - - let is_separator = function - | ' ' | '\t' | '\n' | '\r' | '-' -> true - | _ -> false - in - - let rec loop i capitalize_next = - if i >= len then Buffer.contents buffer - else - let c = text.[i] in - - if is_separator c then loop (i + 1) true - else if capitalize_next then ( - Buffer.add_char buffer (Char.uppercase_ascii c); - loop (i + 1) false) - else ( - Buffer.add_char buffer c; - loop (i + 1) false) - in - - loop 0 true - -let get_cmi_file ~(uri : Uri.t) ~(compiler_config : Compiler_config.t) - ~(fs : Fs.fs) = +let config_for_uri ~(uri : Uri.t) (compiler_config : Compiler_config.t) = let path = Uri.to_path uri in let config_roots = compiler_config |> Compiler_config.Uri_map.to_seq - |> Seq.map (fun (uri, config) -> (uri |> Uri.to_path, config)) - |> List.of_seq |> List.map fst + |> Seq.map (fun (uri, _) -> Uri.to_path uri) + |> List.of_seq in + match best_root_match ~path config_roots with + | Some root -> + Compiler_config.Uri_map.find_opt (Uri.of_path root) compiler_config + | None -> None - let config = - match config_roots |> best_root_match ~path with - | Some root -> - Compiler_config.Uri_map.find_opt (Uri.of_path root) compiler_config - | None -> None - in - match config with +let get_cmi_file ~uri ~compiler_config ~fs = + match config_for_uri ~uri compiler_config with | Some config -> - let namespace = - match config.namespace with - | Some (Namespace_bool true) -> config.name |> to_camel_case - | Some (Namespace_string name) -> name |> to_camel_case - | _ -> "" - in - let suffix_to_append = - if String.length namespace > 0 then "-" ^ namespace else "" + let open Rewatch_ocaml_lib in + let cmi_file = + Filename.concat + (Build_artifacts.artifact_dir config.root) + (Source.compiler_asset_basename config (Uri.to_path uri) ^ ".cmi") in - let resi_file = - match best_root_match ~path config_roots with - | Some package_root_path -> - let cmi_file = - let open Filename in - let ( /+ ) = concat in - let relative_path = relative_to ~root:package_root_path path in - let cmi = - let stem = basename relative_path |> remove_extension in - stem ^ suffix_to_append ^ ".cmi" - in - (* Build artifacts are flat, regardless of the source directory. *) - package_root_path /+ Constants.compiler_dir_partial_path /+ cmi - in - let result = - match Fs.exists ~follow:false ~fs cmi_file with - | true -> Some cmi_file - | false -> None - in - result - | None -> None - in - resi_file + if Fs.exists ~follow:false ~fs cmi_file then Some cmi_file else None | None -> None -let get_compiled_file ~(uri : Uri.t) ~(compiler_config : Compiler_config.t) - ~(fs : Fs.fs) = - let path = Uri.to_path uri in - let config_roots = - compiler_config |> Compiler_config.Uri_map.to_seq - |> Seq.map (fun (uri, config) -> (uri |> Uri.to_path, config)) - |> List.of_seq |> List.map fst - in - - let config = - match config_roots |> best_root_match ~path with - | Some root -> - Compiler_config.Uri_map.find_opt (Uri.of_path root) compiler_config - | None -> None - in - match config with +let get_compiled_file ~uri ~compiler_config ~fs = + match config_for_uri ~uri compiler_config with | Some config -> - let {Compiler_config.suffix; folder; in_source} = - Compiler_config.get_output_config config + let open Rewatch_ocaml_lib in + let relative_path = + Project_context.relative_to config.root (Uri.to_path uri) in - - let js_file_path = - let file_path = - let open Filename in - let ( /+ ) = concat in - if in_source then - let filename = basename path in - let js_file = remove_extension filename ^ suffix in - Some (dirname path /+ js_file) - else - match best_root_match ~path config_roots with - | Some package_root_path -> - (* - Some example with sources - package_root_path: /workspace/rescript-lang.org/apps/guide - path: /workspace/rescript-lang.org/apps/guide/app/GuideHome.res - compiled js: /workspace/rescript-lang.org/apps/guide/lib/es6/app/GuideHome.jsx - *) - (* app/GuideHome.res *) - let relative_path = relative_to ~root:package_root_path path in - let sources_dir = dirname relative_path in - let js_file = - let res_file = basename relative_path in - remove_extension res_file ^ suffix - in - Some - (package_root_path /+ Constants.build_output_folder /+ folder - /+ sources_dir /+ js_file) - | None -> None - in - match file_path with - | Some file_path when Fs.exists ~fs ~follow:false file_path -> - Some (file_path |> Uri.of_path) - | _ -> None - in - - js_file_path + config.package_specs + |> List.find_map (fun spec -> + let path = + Build_artifacts.generated_js_path config relative_path spec + in + if Fs.exists ~follow:false ~fs path then Some (Uri.of_path path) + else None) | None -> None let load_full uri (analysis_state : Analysis.Shared_types.state) = diff --git a/lsp/src/source_dirs.ml b/lsp/src/source_dirs.ml index 227ff9470c5..fa8e6ba99cb 100644 --- a/lsp/src/source_dirs.ml +++ b/lsp/src/source_dirs.ml @@ -1,12 +1,10 @@ -type cmt_scan_item = {build_root: string} [@@deriving yojson {strict = false}] - -type source_dirs = {cmt_scan: cmt_scan_item list} -[@@deriving yojson {strict = false}] - let get_build_roots_from_json json = - match source_dirs_of_yojson json with - | Ok {cmt_scan} -> Some (List.map (fun {build_root} -> build_root) cmt_scan) - | Error _ -> None + let open Yojson.Safe.Util in + try + json |> member "cmt_scan" |> to_list + |> List.map (fun item -> item |> member "build_root" |> to_string) + |> Option.some + with Type_error _ -> None let get_build_roots_from_file ~fs path = match Fs.load ~fs path with @@ -78,3 +76,29 @@ let%expect_test "get_build_roots" = json_3 |> get_build_roots_from_json |> print_build_roots; [%expect {| |}] + +let%expect_test "source directory metadata rejects incomplete scan entries" = + List.iter + (fun text -> + match get_build_roots_from_json (Yojson.Safe.from_string text) with + | None -> print_endline "invalid" + | Some roots -> + `List (List.map (fun root -> `String root) roots) + |> Yojson.Safe.to_string |> print_endline) + [ + {|{}|}; + {|{"cmt_scan":null}|}; + {|{"cmt_scan":[]}|}; + {|{"cmt_scan":[{"build_root":"lib/rescript"},{}]}|}; + {|{"cmt_scan":[{"build_root":null}]}|}; + {|{"version":2,"cmt_scan":[{"build_root":"lib/rescript","scan_dirs":[]}]}|}; + ]; + [%expect + {| + invalid + invalid + [] + invalid + invalid + ["lib/rescript"] + |}] diff --git a/lsp/src/state.ml b/lsp/src/state.ml index df1f1450b01..fc1925ebd42 100644 --- a/lsp/src/state.ml +++ b/lsp/src/state.ml @@ -118,7 +118,7 @@ let to_yojson (t : t) : Yojson.Safe.t = let compiler_config_to_yojson (compiler_config : Compiler_config.t) = compiler_config |> Compiler_config.Uri_map.to_seq |> Seq.map (fun (uri, config) -> - (Lsp.Uri.to_string uri, Compiler_config.Parse.to_yojson config)) + (Lsp.Uri.to_string uri, Compiler_config.to_yojson config)) |> List.of_seq |> fun fields -> `Assoc fields in diff --git a/packages/@rescript/darwin-arm64/THIRD_PARTY_LICENSES b/packages/@rescript/darwin-arm64/THIRD_PARTY_LICENSES index 639dc857052..36647dc74a3 100644 --- a/packages/@rescript/darwin-arm64/THIRD_PARTY_LICENSES +++ b/packages/@rescript/darwin-arm64/THIRD_PARTY_LICENSES @@ -2277,7 +2277,7 @@ PPX_DERIVING_YOJSON RUNTIME Version: 3.10.0 Source: https://github.com/ocaml-ppx/ppx_deriving_yojson License: MIT -Included in: JSON codecs in the language-server library in rescript +Included in: JSON codecs for language-server editor settings in rescript Copyright (c) 2014-2018 whitequark diff --git a/packages/@rescript/linux-arm64/THIRD_PARTY_LICENSES b/packages/@rescript/linux-arm64/THIRD_PARTY_LICENSES index 41fea420227..ab7582dba97 100644 --- a/packages/@rescript/linux-arm64/THIRD_PARTY_LICENSES +++ b/packages/@rescript/linux-arm64/THIRD_PARTY_LICENSES @@ -2404,7 +2404,7 @@ PPX_DERIVING_YOJSON RUNTIME Version: 3.10.0 Source: https://github.com/ocaml-ppx/ppx_deriving_yojson License: MIT -Included in: JSON codecs in the language-server library in rescript +Included in: JSON codecs for language-server editor settings in rescript Copyright (c) 2014-2018 whitequark diff --git a/packages/@rescript/linux-x64/THIRD_PARTY_LICENSES b/packages/@rescript/linux-x64/THIRD_PARTY_LICENSES index b0f1d6c5785..8a8c4ee676d 100644 --- a/packages/@rescript/linux-x64/THIRD_PARTY_LICENSES +++ b/packages/@rescript/linux-x64/THIRD_PARTY_LICENSES @@ -2404,7 +2404,7 @@ PPX_DERIVING_YOJSON RUNTIME Version: 3.10.0 Source: https://github.com/ocaml-ppx/ppx_deriving_yojson License: MIT -Included in: JSON codecs in the language-server library in rescript +Included in: JSON codecs for language-server editor settings in rescript Copyright (c) 2014-2018 whitequark diff --git a/packages/@rescript/win32-x64/THIRD_PARTY_LICENSES b/packages/@rescript/win32-x64/THIRD_PARTY_LICENSES index 7391a21acf6..64402791567 100644 --- a/packages/@rescript/win32-x64/THIRD_PARTY_LICENSES +++ b/packages/@rescript/win32-x64/THIRD_PARTY_LICENSES @@ -2174,7 +2174,7 @@ PPX_DERIVING_YOJSON RUNTIME Version: 3.10.0 Source: https://github.com/ocaml-ppx/ppx_deriving_yojson License: MIT -Included in: JSON codecs in the language-server library in rescript +Included in: JSON codecs for language-server editor settings in rescript Copyright (c) 2014-2018 whitequark diff --git a/rewatch-ocaml/config.ml b/rewatch-ocaml/config.ml index f41df7eeb12..20718c79455 100644 --- a/rewatch-ocaml/config.ml +++ b/rewatch-ocaml/config.ml @@ -318,18 +318,7 @@ let deprecation_diagnostics path ~name fields = (String.concat "\n" deprecated); ] -let load path = - let root = - with_read_errors path (fun () -> - Platform.canonicalize_path (Filename.dirname path)) - in - let path = Filename.concat root (Filename.basename path) in - let contents = - with_read_errors path (fun () -> - if (Unix.stat path).Unix.st_kind = Unix.S_DIR then - fail_read path (Unix.error_message Unix.EISDIR); - File_util.read_file path) - in +let of_string ~path ~root contents = (match Strict_json.check contents with | Ok () -> () | Error {line; column; message} -> @@ -448,6 +437,20 @@ let load path = diagnostics; } +let load path = + let root = + with_read_errors path (fun () -> + Platform.canonicalize_path (Filename.dirname path)) + in + let path = Filename.concat root (Filename.basename path) in + let contents = + with_read_errors path (fun () -> + if (Unix.stat path).Unix.st_kind = Unix.S_DIR then + fail_read path (Unix.error_message Unix.EISDIR); + File_util.read_file path) + in + of_string ~path ~root contents + let load_root root = load (path_in_root root) let package_spec_suffix (config : t) (spec : package_spec) = diff --git a/rewatch-ocaml/config.mli b/rewatch-ocaml/config.mli index 36299039226..b9cdabdae59 100644 --- a/rewatch-ocaml/config.mli +++ b/rewatch-ocaml/config.mli @@ -8,6 +8,7 @@ val path_in_root : string -> string val exists_in_root : string -> bool val source_is_dev : t -> string -> bool val with_root_options : t -> t -> t +val of_string : path:string -> root:string -> string -> t val load : string -> t val load_root : string -> t val package_spec_suffix : t -> package_spec -> string diff --git a/tests/lsp_tests/dune b/tests/lsp_tests/dune index c704af295ce..2a499890bd3 100644 --- a/tests/lsp_tests/dune +++ b/tests/lsp_tests/dune @@ -5,6 +5,6 @@ (inline_tests (deps ../../rewatch-ocaml/rescript_ocaml.exe)) (preprocess - (pps ppx_deriving_yojson ppx_expect)) + (pps ppx_expect)) (flags (-w "-9-32-33"))) diff --git a/tests/lsp_tests/execute_commands.ml b/tests/lsp_tests/execute_commands.ml index 68e23e82e93..8be3b682d00 100644 --- a/tests/lsp_tests/execute_commands.ml +++ b/tests/lsp_tests/execute_commands.ml @@ -293,7 +293,7 @@ let%expect_test "navigation code actions use stable advertised IDs" = {| { "command": "rescript/openCompiled:", - "uri": "file:///workspace/lib/es6/./Test.res.js" + "uri": "file:///workspace/lib/es6/Test.res.js" } { "command": "rescript/switchImplementationInterface:", @@ -301,7 +301,7 @@ let%expect_test "navigation code actions use stable advertised IDs" = } { "command": "rescript/openCompiled:", - "uri": "file:///workspace/lib/es6/./Test.res.js" + "uri": "file:///workspace/lib/es6/Test.res.js" } { "command": "rescript/switchImplementationInterface:", diff --git a/tests/lsp_tests/output_configuration.ml b/tests/lsp_tests/output_configuration.ml index 23b97e8fe8d..b5174742573 100644 --- a/tests/lsp_tests/output_configuration.ml +++ b/tests/lsp_tests/output_configuration.ml @@ -75,13 +75,79 @@ let open_compiled doc = (TextDocumentIdentifier.yojson_of_t (Test.text_document doc))); } +let%expect_test "uses the build's output defaults when package specs are absent" + = + Test.with_project ~name:"output-defaults" ~text:{|let value = 1|} + ~rescript_json:{|{"name":"output-defaults","sources":{"dir":"."}}|} + (fun ~root ~doc client -> Test.snapshot ~root client (open_compiled doc)); + [%expect {| { "uri": "file:///workspace/Test.js" } |}] + +let%expect_test + "uses the build's default in-source setting within package specs" = + Test.with_project ~name:"output-default-in-source" ~text:{|let value = 1|} + ~rescript_json: + {|{"name":"output-default-in-source","sources":{"dir":"."},"suffix":".js","package-specs":{"module":"commonjs","suffix":".cjs"}}|} + (fun ~root ~doc client -> Test.snapshot ~root client (open_compiled doc)); + [%expect {| { "uri": "file:///workspace/Test.cjs" } |}] + +let%expect_test "selects the first existing configured output" = + Test.with_project ~name:"output-multiple" ~text:{|let value = 1|} + ~rescript_json: + {|{"name":"output-multiple","sources":{"dir":"."},"package-specs":[{"module":"commonjs","suffix":".cjs","in-source":false},{"module":"esmodule","suffix":".mjs","in-source":false}]}|} + (fun ~root ~doc client -> + Test.snapshot ~root client (open_compiled doc); + Sys.remove (root /+ "lib" /+ "js" /+ "Test.cjs"); + Test.snapshot ~root client (open_compiled doc)); + [%expect + {| + { "uri": "file:///workspace/lib/js/Test.cjs" } + { "uri": "file:///workspace/lib/es6/Test.mjs" } + |}] + +let%expect_test + "uses the build's scoped-package namespace for interface artifacts" = + Test.with_project ~name:"namespace-package" ~text:{|let value = 1|} + ~rescript_json: + {|{"name":"@example/my-lib","namespace":true,"sources":{"dir":"."}}|} + (fun ~root ~doc client -> + assert ( + Sys.file_exists (root /+ "lib" /+ "rescript" /+ "Test-ExampleMyLib.cmi")); + Create_interface.create_and_print ~root ~doc client); + [%expect + {| + { "uri": "file:///workspace/Test.resi" } + let value: int + |}] + +let%expect_test "uses the build's namespace-entry artifact names" = + Test.with_project ~name:"namespace-entry" ~text:{|let value = Other.value|} + ~files:[("Other.res", {|let value = 1|})] + ~rescript_json: + {|{"name":"namespace-entry","namespace":"my_lib","namespace-entry":"Test","sources":{"dir":"."}}|} + (fun ~root ~doc client -> + let other = + Test.make_document ~text:{|let value = 1|} + ~uri:(Uri.of_path (root /+ "Other.res")) + in + assert (Sys.file_exists (root /+ "lib" /+ "rescript" /+ "Other-@MyLib.cmi")); + Test.perform client (Test.open_document other); + Create_interface.create_and_print ~root ~doc:other client; + Create_interface.create_and_print ~root ~doc client); + [%expect + {| + { "uri": "file:///workspace/Other.resi" } + let value: int + { "uri": "file:///workspace/Test.resi" } + let value: int + |}] + let%expect_test "uses the dependency's module format and suffix for output" = with_dependency ~in_source:false (fun ~root ~root_doc ~doc client -> Test.snapshot ~root client (open_compiled root_doc); Test.snapshot ~root client (open_compiled doc)); [%expect {| - { "uri": "file:///workspace/lib/js/./Main.cjs" } + { "uri": "file:///workspace/lib/js/Main.cjs" } { "uri": "file:///workspace/node_modules/child-package/lib/es6/src/Child.mjs" } diff --git a/tests/lsp_tests/project_recovery.ml b/tests/lsp_tests/project_recovery.ml index 7493003b94e..7aa1503b315 100644 --- a/tests/lsp_tests/project_recovery.ml +++ b/tests/lsp_tests/project_recovery.ml @@ -66,7 +66,7 @@ let%expect_test "recovers after the first compiler log is created" = null repeated initialization messages: 0 { "contents": { "kind": "markdown", "value": "```rescript\nint\n```" } } - { "uri": "file:///workspace/lib/es6/./Test.res.js" } + { "uri": "file:///workspace/lib/es6/Test.res.js" } [ { "kind": 16, @@ -90,7 +90,7 @@ let%expect_test "recovers when the client reports the first build as a change" = null repeated initialization messages: 0 { "contents": { "kind": "markdown", "value": "```rescript\nint\n```" } } - { "uri": "file:///workspace/lib/es6/./Test.res.js" } + { "uri": "file:///workspace/lib/es6/Test.res.js" } [ { "kind": 16, diff --git a/tests/rewatch_ounit_tests/config_tests.ml b/tests/rewatch_ounit_tests/config_tests.ml index 603afee8568..e3d650449b3 100644 --- a/tests/rewatch_ounit_tests/config_tests.ml +++ b/tests/rewatch_ounit_tests/config_tests.ml @@ -45,6 +45,32 @@ let with_config_file test _context = let path = Filename.concat root "rescript.json" in test ~root ~path) +let in_memory_decoding_tests = + with_config_file (fun ~root ~path -> + let contents = + {|{"name":"@example/app","namespace":true,"dependencies":[{"name":"dep","features":["native"]}],"package-specs":{"module":"esmodule","suffix":".mjs"}}|} + in + let decoded = Config.of_string ~path ~root contents in + check (not (Sys.file_exists path)) "decoding does not read the filesystem"; + write_file path contents; + check + (decoded = Config.load path) + "in-memory and filesystem decoding use the same schema and defaults"; + let invalid = {|{"name":"first","name":"second"}|} in + let error f = + try + ignore (f ()); + assert_failure "Expected a configuration error" + with Config.Error message -> message + in + let decoded_error = + error (fun () -> Config.of_string ~path ~root invalid) + in + write_file path invalid; + check + (decoded_error = error (fun () -> Config.load path)) + "configuration errors are identical regardless of the I/O backend") + let loading_tests = with_config_file (fun ~root ~path -> let missing_path = Filename.concat root "missing.json" in @@ -922,6 +948,7 @@ let tests = >::: [ "strict_json" >:: strict_json_tests; "loading" >:: loading_tests; + "in_memory_decoding" >:: in_memory_decoding_tests; "gentype_discovery" >:: gentype_discovery_tests; "validation" >:: validation_tests; "compiler_jobs" >:: compiler_job_tests; From 51aea94257f152548207ccd32d085a71b845cb36 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 23 Nov 2026 01:11:12 -0300 Subject: [PATCH 12/13] Move LSP inline tests into a dedicated test library Keep ppx_expect and its transitive runtimes out of the shipped rescript binary by moving all 13 inline tests to tests/lsp_unit_tests. Extract rescript_language_server_core so tests exercise the production implementation while preserving the existing listen interface. Run both LSP suites through make test-lsp and update the documentation. Remove the unlinked test dependencies from the license inventory and regenerate the third-party notices Signed-off-by: Pedro Castro --- Makefile | 2 +- licenses/components.json | 98 -- lsp/README.md | 19 +- lsp/src/compiler_log.ml | 1010 ---------------- lsp/src/configuration.ml | 78 -- lsp/src/diagnostics.ml | 266 ----- lsp/src/document.ml | 50 - lsp/src/document_store.ml | 36 - lsp/src/dune | 14 +- lsp/src/rescript_language_server.ml | 1 + lsp/src/source_dirs.ml | 89 -- .../darwin-arm64/THIRD_PARTY_LICENSES | 434 ------- .../linux-arm64/THIRD_PARTY_LICENSES | 434 ------- .../@rescript/linux-x64/THIRD_PARTY_LICENSES | 434 ------- .../@rescript/win32-x64/THIRD_PARTY_LICENSES | 434 ------- tests/dune | 2 +- tests/lsp_unit_tests/README.md | 14 + tests/lsp_unit_tests/compiler_log.ml | 1011 +++++++++++++++++ tests/lsp_unit_tests/configuration.ml | 79 ++ tests/lsp_unit_tests/diagnostics.ml | 270 +++++ tests/lsp_unit_tests/document.ml | 52 + tests/lsp_unit_tests/document_store.ml | 39 + tests/lsp_unit_tests/dune | 6 + tests/lsp_unit_tests/source_dirs.ml | 90 ++ 24 files changed, 1587 insertions(+), 3375 deletions(-) create mode 100644 tests/lsp_unit_tests/README.md create mode 100644 tests/lsp_unit_tests/compiler_log.ml create mode 100644 tests/lsp_unit_tests/configuration.ml create mode 100644 tests/lsp_unit_tests/diagnostics.ml create mode 100644 tests/lsp_unit_tests/document.ml create mode 100644 tests/lsp_unit_tests/document_store.ml create mode 100644 tests/lsp_unit_tests/dune create mode 100644 tests/lsp_unit_tests/source_dirs.ml diff --git a/Makefile b/Makefile index 10f9498f2a8..2ff11bf2e55 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,7 @@ test-rewatch: lib ./rewatch/tests/suite.sh $(RESCRIPT_EXE) test-lsp: lib - @dune runtest tests/lsp_tests + @dune runtest tests/lsp_unit_tests tests/lsp_tests test-all: test test-gentype test-analysis test-tools test-rewatch test-lsp diff --git a/licenses/components.json b/licenses/components.json index f2f49eeb32d..f05a62ef49a 100644 --- a/licenses/components.json +++ b/licenses/components.json @@ -226,104 +226,6 @@ "license": "ISC", "scope": "runtime dependency of Eio" }, - { - "name": "ppx_expect runtime", - "opam": "ppx_expect", - "source": "https://github.com/janestreet/ppx_expect", - "license": "MIT", - "scope": "runtime dependency of the language-server library in rescript" - }, - { - "name": "Ppxlib", - "opam": "ppxlib", - "source": "https://github.com/ocaml-ppx/ppxlib", - "license": "MIT", - "scope": "runtime dependency of ppx_expect" - }, - { - "name": "Stdio", - "opam": "stdio", - "source": "https://github.com/janestreet/stdio", - "license": "MIT", - "scope": "runtime dependency of the language-server PPX runtimes" - }, - { - "name": "Base", - "opam": "base", - "source": "https://github.com/janestreet/base", - "license": "MIT", - "scope": "runtime dependency of the language-server PPX runtimes" - }, - { - "name": "ocaml_intrinsics_kernel", - "opam": "ocaml_intrinsics_kernel", - "source": "https://github.com/janestreet/ocaml_intrinsics_kernel", - "license": "MIT", - "scope": "runtime dependency of Base" - }, - { - "name": "Sexplib0", - "opam": "sexplib0", - "source": "https://github.com/janestreet/sexplib0", - "license": "MIT", - "scope": "runtime dependency of Base and the language-server PPX runtimes" - }, - { - "name": "ppx_here runtime", - "opam": "ppx_here", - "source": "https://github.com/janestreet/ppx_here", - "license": "MIT", - "scope": "runtime dependency of ppx_expect" - }, - { - "name": "ppx_inline_test runtime", - "opam": "ppx_inline_test", - "source": "https://github.com/janestreet/ppx_inline_test", - "license": "MIT", - "scope": "runtime dependency of ppx_expect" - }, - { - "name": "time_now", - "opam": "time_now", - "source": "https://github.com/janestreet/time_now", - "license": "MIT", - "scope": "runtime dependency of ppx_inline_test" - }, - { - "name": "ppx_hash runtime", - "opam": "ppx_hash", - "source": "https://github.com/janestreet/ppx_hash", - "license": "MIT", - "scope": "runtime dependency of Base" - }, - { - "name": "ppx_enumerate runtime", - "opam": "ppx_enumerate", - "source": "https://github.com/janestreet/ppx_enumerate", - "license": "MIT", - "scope": "runtime dependency of Base" - }, - { - "name": "ppx_compare runtime", - "opam": "ppx_compare", - "source": "https://github.com/janestreet/ppx_compare", - "license": "MIT", - "scope": "runtime dependency of Base" - }, - { - "name": "ppx_sexp_conv runtime", - "opam": "ppx_sexp_conv", - "source": "https://github.com/janestreet/ppx_sexp_conv", - "license": "MIT", - "scope": "runtime dependency of Base" - }, - { - "name": "jane-street-headers", - "opam": "jane-street-headers", - "source": "https://github.com/janestreet/jane-street-headers", - "license": "MIT", - "scope": "C support for Jane Street runtime libraries" - }, { "name": "ppx_deriving_yojson runtime", "opam": "ppx_deriving_yojson", diff --git a/lsp/README.md b/lsp/README.md index 50cab5c3fd6..aa719cd18df 100644 --- a/lsp/README.md +++ b/lsp/README.md @@ -91,8 +91,12 @@ updating its compiler. The server library lives in `lsp/src` and has an opam package named `rescript-language-server`. It depends on the OCaml `lsp` library, Eio, -Yojson, `ppx_deriving_yojson`, and the in-tree analysis and rewatch libraries; -tests use `ppx_expect`. +Yojson, `ppx_deriving_yojson`, and the in-tree analysis and rewatch libraries. +The private `rescript_language_server_core` library contains the implementation; +the `rescript_language_server` library exposes the CLI entrypoint. Unit tests +import the core library from `tests/lsp_unit_tests`, keeping `ppx_expect` and its +test runtimes out of the shipped executable. + Project configuration uses rewatch's decoder, namespace rules, and artifact-path helpers. Only editor settings and the required `.sourcedirs.json` fields are decoded locally: editor settings use derived codecs, while source-directory @@ -318,18 +322,17 @@ analysis artifact lookup is not a complete implementation of either feature. ## Development and tests -From the repository root, build the toolchain/runtime and run the E2E suite: +From the repository root, build the toolchain/runtime and run both LSP suites: ```sh opam exec -- make test-lsp ``` -After those artifacts are built, run only the E2E tests or the server's inline -tests: +After those artifacts are built, run either suite separately: ```sh opam exec -- dune runtest tests/lsp_tests -opam exec -- dune runtest lsp +opam exec -- dune runtest tests/lsp_unit_tests ``` The E2E tests are OCaml `ppx_expect` snapshots. Their shared client launches the @@ -337,7 +340,9 @@ actual CLI over stdio using Unix process APIs for Windows/Linux/macOS support. Tests create temporary projects, build them, edit buffers, send requests and notifications, and normalize workspace paths in snapshots. Coverage includes editor features, diagnostic ownership, build recovery, formatting, and command -capability handling. The server also has inline tests for its local helpers. +capability handling. The separate unit-test library covers configuration, +compiler-log parsing, diagnostics, and document helpers using the production +implementation directly. `Test.setup_project` writes `rescript.json` and documents and can run a build; `Test.with_project` provides temporary workspace setup and cleanup. Tests use diff --git a/lsp/src/compiler_log.ml b/lsp/src/compiler_log.ml index dedad285030..a7c50b6ca46 100644 --- a/lsp/src/compiler_log.ml +++ b/lsp/src/compiler_log.ml @@ -502,1013 +502,3 @@ end = struct build diagnostics @ dependency_cycle_diagnostics end - -let%expect_test "parse log" = - let diagnostic_of_entry (entry : Parse.diagnostic_entry) = - let range = - match entry.range with - | None -> `String "None" - | Some range -> Lsp.Types.Range.yojson_of_t range - in - Yojson.Safe.pretty_to_string - (`Assoc [("message", `String entry.message); ("range", range)]) - in - let print_logs logs = - logs - |> List.iter (fun (entry : Parse.diagnostic_entry) -> - let path = - match entry.path with - | Parse.Relative_path p -> Printf.sprintf "Relative_path(%s)" p - | Full_path p -> Printf.sprintf "Full_path(%s)" p - in - print_endline - ((match entry.kind with - | Syntax_error -> "Syntax_error" - | Warning {number; configured_as_error} -> - if configured_as_error then - Printf.sprintf "Warning %d (configured as error)" number - else Printf.sprintf "Warning %d" number - | Unknown -> "Unknown" - | Circular_dependency -> "Circular_dependency" - | Common_error -> "Common_error") - ^ " - " ^ path); - diagnostic_of_entry entry |> print_endline; - print_newline ()) - in - let example_log_1 = - {| - #Start(1600519680823) - - Syntax error! - /Users/chenglou/github/reason-react/src/test.res:1:8-2:3 - - 1 │ let a = - 2 │ let b = - 3 │ - - This let-binding misses an expression - - - Warning number 8 - /Users/chenglou/github/reason-react/src/test.res:3:5-8 - - 1 │ let a = j`šŸ˜€` - 2 │ let b = `šŸ˜€` - 3 │ let None = None - 4 │ let bla: int = " - 5 │ hi - - You forgot to handle a possible case here, for example: - Some _ - - - We've found a bug for you! - /Users/chenglou/github/reason-react/src/test.res:3:9 - - 1 │ let a = 1 - 2 │ let b = "hi" - 3 │ let a = b + 1 - - This has type: string - Somewhere wanted: int - - #Done(1600519680836) - |} - in - - Parse.parse_log_content example_log_1 |> print_logs; - [%expect - {| - Syntax_error - Full_path(/Users/chenglou/github/reason-react/src/test.res) - { - "message": "This let-binding misses an expression", - "range": { - "end": { "character": 3, "line": 1 }, - "start": { "character": 7, "line": 0 } - } - } - - Warning 8 - Full_path(/Users/chenglou/github/reason-react/src/test.res) - { - "message": "You forgot to handle a possible case here, for example:\nSome _", - "range": { - "end": { "character": 8, "line": 2 }, - "start": { "character": 4, "line": 2 } - } - } - - Common_error - Full_path(/Users/chenglou/github/reason-react/src/test.res) - { - "message": "This has type: string\nSomewhere wanted: int", - "range": { - "end": { "character": 9, "line": 2 }, - "start": { "character": 8, "line": 2 } - } - } - |}]; - - let example_log_2 = {|#Start(1780532423603) - #Done(1780532423840)|} in - - Parse.parse_log_content example_log_2 |> print_logs; - [%expect {| |}]; - - (* https://github.com/rescript-lang/rescript-vscode/issues/386#issuecomment-1221093517 *) - let example_log_3 = - {| - #Start(1660943070627) - File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/fragmentsUsage/Fragments.res", lines 11-13, characters 6-7: - 11 | ......Todos { - | ...TodoItem - | } - 13 | ... - Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null - File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/clientUsage/PromiseChaining.res", lines 17-21, characters 6-7: - 17 | ......os: allTodos { - | id - | text - | completed - | } - 21 | ... - Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null - File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/clientUsage/ClientBasics.res", lines 18-22, characters 6-7: - 18 | ......os: allTodos { - | id - | text - | completed - | } - 22 | ... - Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null - File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/docs/Docs.res", lines 7-11, characters 6-7: - 7 | ......os: allTodos { - | id - | text - | completed - | } - 11 | ... - Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null - File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/fragmentsUsage/Query_Fragments.res", lines 6-9, characters 6-7: - 6 | ......os: allTodos { - | # This references the TodoItem fragment definition module above! - | ...TodoItem - | } - 9 | ... - Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null - File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Mutation.res", lines 18-22, characters 6-7: - 18 | ......os: allTodos { - | id - | completed - | text - | } - 22 | ... - Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null - File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_Lazy.res", lines 3-7, characters 6-7: - 3 | ......os: allTodos { - | id - | text - | completed - | } - 7 | ... - Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null - File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_OverlySimple.res", lines 3-7, characters 4-5: - 3 | ....os: allTodos { - | id - | text - | completed - | } - 7 | . - Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null - File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_SubscribeToMore.res", lines 5-9, characters 6-7: - 5 | ......os: allTodos { - | id - | completed - | text - | } - 9 | ... - Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null - File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_Typical.res", lines 4-8, characters 6-7: - 4 | ......os: allTodos { - | id - | text - | completed - | } - 8 | ... - Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null - #Done(1660943070848) - |} - in - - Parse.parse_log_content example_log_3 |> print_logs; - [%expect - {| - Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/fragmentsUsage/Fragments.res) - { - "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", - "range": { - "end": { "character": 7, "line": 12 }, - "start": { "character": 5, "line": 10 } - } - } - - Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/clientUsage/PromiseChaining.res) - { - "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", - "range": { - "end": { "character": 7, "line": 20 }, - "start": { "character": 5, "line": 16 } - } - } - - Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/clientUsage/ClientBasics.res) - { - "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", - "range": { - "end": { "character": 7, "line": 21 }, - "start": { "character": 5, "line": 17 } - } - } - - Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/docs/Docs.res) - { - "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", - "range": { - "end": { "character": 7, "line": 10 }, - "start": { "character": 5, "line": 6 } - } - } - - Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/fragmentsUsage/Query_Fragments.res) - { - "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", - "range": { - "end": { "character": 7, "line": 8 }, - "start": { "character": 5, "line": 5 } - } - } - - Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Mutation.res) - { - "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", - "range": { - "end": { "character": 7, "line": 21 }, - "start": { "character": 5, "line": 17 } - } - } - - Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_Lazy.res) - { - "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", - "range": { - "end": { "character": 7, "line": 6 }, - "start": { "character": 5, "line": 2 } - } - } - - Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_OverlySimple.res) - { - "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", - "range": { - "end": { "character": 5, "line": 6 }, - "start": { "character": 3, "line": 2 } - } - } - - Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_SubscribeToMore.res) - { - "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", - "range": { - "end": { "character": 7, "line": 8 }, - "start": { "character": 5, "line": 4 } - } - } - - Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_Typical.res) - { - "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", - "range": { - "end": { "character": 7, "line": 7 }, - "start": { "character": 5, "line": 3 } - } - } - |}]; - - (* https://github.com/rescript-lang/rescript-vscode/issues/86#issuecomment-786186698 *) - let example_log_4 = - {|#Start(1614285167013) - - Warning number 33 - /home/misha/projects/productionmason/web/auth/src/ErrorHandlingMiddleware.res:1:1-15 - - 1 │ open CommonBase - 2 │ - 3 │ external jsExnToExpressError: Js.Exn.t => Express.Error.t = "%identity" - - unused open CommonBase. - - - Warning number 27 - /home/misha/projects/productionmason/web/auth/src/config/Config.res:10:22-27 - - 8 │ external stringifyAnyWithSpace: ('a, @bs.as(json`null`) _, int) => str - ing = "stringify" - 9 │ - 10 │ let validateConfig = config => { - 11 │ let googleApplicationCredentialsPath = - 12 │ NodeJs.Process.env(NodeJs.Process.process)->Js.Dict.get("GOOGLE_AP - PLICATION_CREDENTIALS") - - unused variable config. - - - Warning number 34 - /home/misha/projects/productionmason/web/auth/src/express-handler/ExpressHandler.re:48:5-26 - - 46 ┆ module Input = { - 47 ┆ [@decco] - 48 ┆ type t = Request.input; - 49 ┆ }; - 50 ┆ - - unused type t. - - - Warning number 32 - /home/misha/projects/productionmason/web/auth/src/express-handler/ExpressHandler.re - - unused value t_encode. - - - We've found a bug for you! - /home/misha/projects/productionmason/web/auth/tests/Auth_Test.res:224:45 - - 222 ┆ ->AsyncResult.mapOk(x => { - 223 ┆ expect(x.data.users->Array.length)->toBeGreaterThan(0) - 224 ┆ expect(x.data.users->Array.getExn(0).last_name)->toBe(Some("Glenliv - et")) - 225 ┆ Ok() - 226 ┆ }) - - This has type: int - Somewhere wanted: array<'a> - - #Done(1614285167075)|} - in - - Parse.parse_log_content example_log_4 |> print_logs; - [%expect - {| - Warning 33 - Full_path(/home/misha/projects/productionmason/web/auth/src/ErrorHandlingMiddleware.res) - { - "message": "unused open CommonBase.", - "range": { - "end": { "character": 15, "line": 0 }, - "start": { "character": 0, "line": 0 } - } - } - - Warning 27 - Full_path(/home/misha/projects/productionmason/web/auth/src/config/Config.res) - { - "message": "unused variable config.", - "range": { - "end": { "character": 27, "line": 9 }, - "start": { "character": 21, "line": 9 } - } - } - - Warning 34 - Full_path(/home/misha/projects/productionmason/web/auth/src/express-handler/ExpressHandler.re) - { - "message": "unused type t.", - "range": { - "end": { "character": 26, "line": 47 }, - "start": { "character": 4, "line": 47 } - } - } - - Warning 32 - Full_path(/home/misha/projects/productionmason/web/auth/src/express-handler/ExpressHandler.re) - { "message": "unused value t_encode.", "range": "None" } - - Common_error - Full_path(/home/misha/projects/productionmason/web/auth/tests/Auth_Test.res) - { - "message": "This has type: int\nSomewhere wanted: array<'a>", - "range": { - "end": { "character": 45, "line": 223 }, - "start": { "character": 44, "line": 223 } - } - } - |}]; - - let example_log_5 = - {|#Start(1780595107359) - - Can't continue... Found a circular dependency in your code: - Demo (src/Demo.res) - → Other (src/Other.res) - → Demo (src/Demo.res) - Possible solutions: - - Extract shared code into a new module both depend on. - #Done(1780595107364) - |} - in - - Parse.parse_log_content example_log_5 |> print_logs; - [%expect - {| - Circular_dependency - Relative_path(src/Demo.res) - { - "message": "Can't continue... Found a circular dependency in your code:\nDemo (src/Demo.res)\n→ Other (src/Other.res)\n→ Demo (src/Demo.res)\nPossible solutions:\n- Extract shared code into a new module both depend on.", - "range": "None" - } - - Circular_dependency - Relative_path(src/Other.res) - { - "message": "Can't continue... Found a circular dependency in your code:\nDemo (src/Demo.res)\n→ Other (src/Other.res)\n→ Demo (src/Demo.res)\nPossible solutions:\n- Extract shared code into a new module both depend on.", - "range": "None" - } - |}]; - - let example_log_6 = - {|#Start(1780595245481) - FAILED: dependency cycle: src/Demo.cmj -> src/Other.cmj -> src/Demo.cmj. - #Done(1780595245488)|} - in - - Parse.parse_log_content example_log_6 |> print_logs; - [%expect - {| - Circular_dependency - Relative_path(src/Demo.res) - { - "message": "FAILED: dependency cycle: src/Demo.cmj -> src/Other.cmj -> src/Demo.cmj.", - "range": "None" - } - - Circular_dependency - Relative_path(src/Other.res) - { - "message": "FAILED: dependency cycle: src/Demo.cmj -> src/Other.cmj -> src/Demo.cmj.", - "range": "None" - } - |}]; - - let example_log_7 = - {|#Start(1780595410580) - - We've found a bug for you! - /tmp/my-rescript-app/src/Demo.res:1:9-15 - - 1 │ let a = Other.a - 2 │ - - The value a can't be found in Other - - FAILED: cannot make progress due to previous errors. - #Done(1780595410597)|} - in - - Parse.parse_log_content example_log_7 |> print_logs; - [%expect - {| - Common_error - Full_path(/tmp/my-rescript-app/src/Demo.res) - { - "message": "The value a can't be found in Other\nFAILED: cannot make progress due to previous errors.", - "range": { - "end": { "character": 15, "line": 0 }, - "start": { "character": 8, "line": 0 } - } - } - |}]; - - let example_log_8 = - {|#Start(1780603624843) - Error in lsp-test: - - Syntax error! - /home/pedro/Desktop/projects/lsp-test/src/ArrayUtils.res:1:41-2:0 - - 1 │ let empty = arr => Array.length(arr) === - 2 │ - - Did you forget to write an expression here? - - #Done(1780603624849)|} - in - Parse.parse_log_content example_log_8 |> print_logs; - [%expect - {| - Syntax_error - Full_path(/home/pedro/Desktop/projects/lsp-test/src/ArrayUtils.res) - { - "message": "Did you forget to write an expression here?", - "range": { - "end": { "character": 0, "line": 1 }, - "start": { "character": 40, "line": 0 } - } - } - |}]; - - let example_log_9 = - {|#Start(1780630901455) - - We've found a bug for you! - /home/pedro/Desktop/projects/lsp-test/src/ArrayUtils.res:1:41-43 - - 1 │ let empty = arr => Array.length(arr) == "2"; - 2 │ - - This has type: string - But it's being compared to something of type: int - - You can only compare things of the same type. - - You can convert string to int with Int.fromString. - - #Done(1780630901468)|} - in - - Parse.parse_log_content example_log_9 |> print_logs; - [%expect - {| - Common_error - Full_path(/home/pedro/Desktop/projects/lsp-test/src/ArrayUtils.res) - { - "message": "This has type: string\nBut it's being compared to something of type: int\nYou can only compare things of the same type.\nYou can convert string to int with Int.fromString.", - "range": { - "end": { "character": 43, "line": 0 }, - "start": { "character": 40, "line": 0 } - } - } - |}]; - - let example_log_10 = - {|#Start(1781383030890) - - Warning number 8 (configured as error) - /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:6:3-9:3 - - 4 │ - 5 │ let f = (a: t) => { - 6 │ switch a { - 7 │ | A => () - 8 │ | B => () - 9 │ } - 10 │ } - 11 │ - - You forgot to handle a possible case here, for example: - | C - - - Warning number 37 - /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:3:1-18 - - 1 │ open ReactRouter.Routes - 2 │ - 3 │ type t = A | B | C - 4 │ - 5 │ let f = (a: t) => { - - constructor A is never used to build values. - (However, this constructor appears in patterns.) - - - Warning number 37 - /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:3:1-18 - - 1 │ open ReactRouter.Routes - 2 │ - 3 │ type t = A | B | C - 4 │ - 5 │ let f = (a: t) => { - - constructor B is never used to build values. - (However, this constructor appears in patterns.) - - - Warning number 37 - /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:3:1-18 - - 1 │ open ReactRouter.Routes - 2 │ - 3 │ type t = A | B | C - 4 │ - 5 │ let f = (a: t) => { - - unused constructor C. - - - Warning number 32 - /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:5:5 - - 3 │ type t = A | B | C - 4 │ - 5 │ let f = (a: t) => { - 6 │ switch a { - 7 │ | A => () - - unused value f. - - #Done(1781383030936)|} - in - Parse.parse_log_content example_log_10 |> print_logs; - [%expect - {| - Warning 8 (configured as error) - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) - { - "message": "You forgot to handle a possible case here, for example:\n| C", - "range": { - "end": { "character": 3, "line": 8 }, - "start": { "character": 2, "line": 5 } - } - } - - Warning 37 - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) - { - "message": "constructor A is never used to build values.\n(However, this constructor appears in patterns.)", - "range": { - "end": { "character": 18, "line": 2 }, - "start": { "character": 0, "line": 2 } - } - } - - Warning 37 - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) - { - "message": "constructor B is never used to build values.\n(However, this constructor appears in patterns.)", - "range": { - "end": { "character": 18, "line": 2 }, - "start": { "character": 0, "line": 2 } - } - } - - Warning 37 - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) - { - "message": "unused constructor C.", - "range": { - "end": { "character": 18, "line": 2 }, - "start": { "character": 0, "line": 2 } - } - } - - Warning 32 - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) - { - "message": "unused value f.", - "range": { - "end": { "character": 5, "line": 4 }, - "start": { "character": 4, "line": 4 } - } - } - |}]; - - let example_log_10 = - {|#Start(1780630901455) - - We've found a bug for you! - tests/build_tests/super_errors/fixtures/access_record_field_on_option.res:12:15 - - 10 │ } - 11 │ - 12 │ let f = X.x.c.d - 13 │ - - You're trying to access the record field d, but the value you're trying to access it on is an option. - You need to unwrap the option first before accessing the record field. - - Possible solutions: - - Use Option.map to transform the option: xx->Option.map(field => field.d) - - Or use Option.getOr with a default: xx->Option.getOr(defaultRecord).d - - #Done(1781383030936)|} - in - - Parse.parse_log_content example_log_10 |> print_logs; - [%expect - {| - Common_error - Relative_path(tests/build_tests/super_errors/fixtures/access_record_field_on_option.res) - { - "message": "You're trying to access the record field d, but the value you're trying to access it on is an option.\nYou need to unwrap the option first before accessing the record field.\nPossible solutions:\n- Use Option.map to transform the option: xx->Option.map(field => field.d)\n- Or use Option.getOr with a default: xx->Option.getOr(defaultRecord).d", - "range": { - "end": { "character": 15, "line": 11 }, - "start": { "character": 14, "line": 11 } - } - } - |}]; - - let example_log_11 = - {|#Start(1780630901455) - - We've found a bug for you! - tests/build_tests/super_errors/fixtures/arity_mismatch.res:2:21-27 - - 1 │ let makeVar = (~f, ()) => 34 - 2 │ let makeVariables = makeVar(~f=f => f) - 3 │ - - This function call is incorrect. - The function has type: - (~f: 'a => 'a, unit) => int - - - The function takes 1 unlabelled argument, but is called with none - - - We've found a bug for you! - tests/build_tests/super_errors/fixtures/array_item_type_mismatch.res:1:16-22 - - 1 │ let x = [1, 2, "hello"] - 2 │ - - This array item has type: string - But this array is expected to have items of type: int - - Arrays can only contain items of the same type. - - Possible solutions: - - Convert all values in the array to the same type. - - Use a tuple, if your array is of fixed length. Tuples can mix types freely, and compiles to a JavaScript array. Example of a tuple: `let myTuple = (10, "hello", 15.5, true) - - You can convert string to int with Int.fromString. - - We've found a bug for you! - tests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:4:5-7:1 - - 2 │ type t = .. - 3 │ type t += E(int) - 4 │ } = { - 5 │ type t = .. - 6 │ type t += E(string) - 7 │ } - 8 │ - - Signature mismatch: - Modules do not match: - { - type t = .. - type t += E(string) - } - is not included in - { - type t = .. - type t += E(int) - } - Extension declarations do not match: - type t += E(string) - is not included in - type t += E(int) - tests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:3:13-18: - Expected declaration - tests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:6:13-21: - Actual declaration - - We've found a bug for you! - tests/build_tests/super_errors/fixtures/functor_apply_arg_mismatch.res:13:22-29 - - 11 │ } - 12 │ - 13 │ module Result = Make(Concrete) - 14 │ let _ = Result.bar - 15 │ - - Signature mismatch: - Modules do not match: { - let unrelated: string - } is not included in HasFoo - The value `foo' is required but not provided - tests/build_tests/super_errors/fixtures/functor_apply_arg_mismatch.res:2:3-14: - Expected declaration - - We've found a bug for you! - tests/build_tests/super_errors/fixtures/include_missing_field.res:4:5-6:1 - - 2 │ let x: int - 3 │ let y: string - 4 │ } = { - 5 │ let x = 1 - 6 │ } - 7 │ - - Signature mismatch: - Modules do not match: - { - let x: int - } - is not included in - { - let x: int - let y: string - } - The value `y' is required but not provided - tests/build_tests/super_errors/fixtures/include_missing_field.res:3:3-15: - Expected declaration - - We've found a bug for you! - tests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:5:5-9:1 - - 3 │ let x: int - 4 │ } - 5 │ } = { - 6 │ module type T = { - 7 │ let x: string - 8 │ } - 9 │ } - 10 │ - - Signature mismatch: - Modules do not match: - { - module type T = { - let x: string - } - } - is not included in - { - module type T = { - let x: int - } - } - Module type declarations do not match: - module type T = { - let x: string - } - does not match - module type T = { - let x: int - } - At position module type T = - Modules do not match: - { - let x: string - } - is not included in - { - let x: int - } - At position module type T = - Values do not match: let x: string is not included in let x: int - tests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:3:5-14: - Expected declaration - tests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:7:5-17: - Actual declaration - - #Done(1781383030936)|} - in - - Parse.parse_log_content example_log_11 |> print_logs; - [%expect - {| - Common_error - Relative_path(tests/build_tests/super_errors/fixtures/arity_mismatch.res) - { - "message": "This function call is incorrect.\nThe function has type:\n(~f: 'a => 'a, unit) => int\n- The function takes 1 unlabelled argument, but is called with none", - "range": { - "end": { "character": 27, "line": 1 }, - "start": { "character": 20, "line": 1 } - } - } - - Common_error - Relative_path(tests/build_tests/super_errors/fixtures/array_item_type_mismatch.res) - { - "message": "This array item has type: string\nBut this array is expected to have items of type: int\nArrays can only contain items of the same type.\nPossible solutions:\n- Convert all values in the array to the same type.\n- Use a tuple, if your array is of fixed length. Tuples can mix types freely, and compiles to a JavaScript array. Example of a tuple: `let myTuple = (10, \"hello\", 15.5, true)\nYou can convert string to int with Int.fromString.", - "range": { - "end": { "character": 22, "line": 0 }, - "start": { "character": 15, "line": 0 } - } - } - - Common_error - Relative_path(tests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res) - { - "message": "Signature mismatch:\nModules do not match:\n{\ntype t = ..\ntype t += E(string)\n}\nis not included in\n{\ntype t = ..\ntype t += E(int)\n}\nExtension declarations do not match:\ntype t += E(string)\nis not included in\ntype t += E(int)\ntests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:3:13-18:\nExpected declaration\ntests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:6:13-21:\nActual declaration", - "range": { - "end": { "character": 1, "line": 6 }, - "start": { "character": 4, "line": 3 } - } - } - - Common_error - Relative_path(tests/build_tests/super_errors/fixtures/functor_apply_arg_mismatch.res) - { - "message": "Signature mismatch:\nModules do not match: {\nlet unrelated: string\n} is not included in HasFoo\nThe value `foo' is required but not provided\ntests/build_tests/super_errors/fixtures/functor_apply_arg_mismatch.res:2:3-14:\nExpected declaration", - "range": { - "end": { "character": 29, "line": 12 }, - "start": { "character": 21, "line": 12 } - } - } - - Common_error - Relative_path(tests/build_tests/super_errors/fixtures/include_missing_field.res) - { - "message": "Signature mismatch:\nModules do not match:\n{\nlet x: int\n}\nis not included in\n{\nlet x: int\nlet y: string\n}\nThe value `y' is required but not provided\ntests/build_tests/super_errors/fixtures/include_missing_field.res:3:3-15:\nExpected declaration", - "range": { - "end": { "character": 1, "line": 5 }, - "start": { "character": 4, "line": 3 } - } - } - - Common_error - Relative_path(tests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res) - { - "message": "Signature mismatch:\nModules do not match:\n{\nmodule type T = {\nlet x: string\n}\n}\nis not included in\n{\nmodule type T = {\nlet x: int\n}\n}\nModule type declarations do not match:\nmodule type T = {\nlet x: string\n}\ndoes not match\nmodule type T = {\nlet x: int\n}\nAt position module type T = \nModules do not match:\n{\nlet x: string\n}\nis not included in\n{\nlet x: int\n}\nAt position module type T = \nValues do not match: let x: string is not included in let x: int\ntests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:3:5-14:\nExpected declaration\ntests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:7:5-17:\nActual declaration", - "range": { - "end": { "character": 1, "line": 8 }, - "start": { "character": 4, "line": 4 } - } - } - |}]; - - let example_log_12 = - {|#Start(1781743112207) - Error in build_warn_as_error: - - Warning number 110 (configured as error) - /home/pedro/Desktop/projects/rescript-compiler/tests/build_tests/build_warn_as_error/src/Demo.res:1:17-21 - - 1 │ let todo = _ => %todo - 2 │ - - Todo found. - - This code is not implemented yet and will crash at runtime. Make sure you implement this before running the code. - - #Done(1781743112217)|} - in - - Parse.parse_log_content example_log_12 |> print_logs; - [%expect - {| - Warning 110 (configured as error) - Full_path(/home/pedro/Desktop/projects/rescript-compiler/tests/build_tests/build_warn_as_error/src/Demo.res) - { - "message": "Todo found.\nThis code is not implemented yet and will crash at runtime. Make sure you implement this before running the code.", - "range": { - "end": { "character": 21, "line": 0 }, - "start": { "character": 16, "line": 0 } - } - } - |}]; - - let example_log_13 = - {|#Start(1781744629915) - - We've found a bug for you! - /home/pedro/Desktop/projects/rescript-compiler/tests/build_tests/gpr_978/src/gpr_978_module.res - - M is exported twice - - #Done(1781744629934)|} - in - - Parse.parse_log_content example_log_13 |> print_logs; - [%expect - {| - Common_error - Full_path(/home/pedro/Desktop/projects/rescript-compiler/tests/build_tests/gpr_978/src/gpr_978_module.res) - { "message": "M is exported twice", "range": "None" } - |}]; - - let example_log_14 = - {|#Start(1781910915195) - - We've found a bug for you! - /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/scripts/LogAlgoliaEnvStatus.res:13:37-85 - - 11 ┆ switch Node.Process.argv[1] { - 12 ┆ | Some(entrypoint) => - 13 ┆ Node.URL.fileURLToPath(url) === Node.Path.resolve(Node.Process.cwd(), - ┆ entrypoint) - 14 ┆ | None => false - 15 ┆ } - - This has type: string - But it's being compared to something of type: int - - You can only compare things of the same type. - - You can convert string to int with Int.fromString. - - - We've found a bug for you! - /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/scripts/gendocs.res:23:3-24:21 - - 21 │ let args = Process.argv->Array.slice(~start=2) - 22 │ let dirname = - 23 │ url - 24 │ ->URL.fileURLToPath - 25 │ ->Path.dirname - 26 │ - - This has type: int - But this function argument is expecting: string - - You can convert int to string with Int.toString. - - #Done(1781910915345)|} - in - - Parse.parse_log_content example_log_14 |> print_logs; - [%expect - {| - Common_error - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/scripts/LogAlgoliaEnvStatus.res) - { - "message": "This has type: string\nBut it's being compared to something of type: int\nYou can only compare things of the same type.\nYou can convert string to int with Int.fromString.", - "range": { - "end": { "character": 85, "line": 12 }, - "start": { "character": 36, "line": 12 } - } - } - - Common_error - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/scripts/gendocs.res) - { - "message": "This has type: int\nBut this function argument is expecting: string\nYou can convert int to string with Int.toString.", - "range": { - "end": { "character": 21, "line": 23 }, - "start": { "character": 2, "line": 22 } - } - } - |}] diff --git a/lsp/src/configuration.ml b/lsp/src/configuration.ml index 23c5a8ac2de..9979aa07b4f 100644 --- a/lsp/src/configuration.ml +++ b/lsp/src/configuration.ml @@ -23,81 +23,3 @@ let default = code_lens = false; inlay_hints = {enable = false; max_length = Some 25}; } - -let%expect_test "parse config" = - let parse_and_print_config json = - match of_yojson (Yojson.Safe.from_string json) with - | Ok c -> c |> to_yojson |> Yojson.Safe.pretty_to_string |> print_endline - | Error _ -> print_endline "Error" - in - - let example_config_json_1 = - {| - { - "askToStartBuild": false, - "inlayHints": { "enable": true, "maxLength": 25 }, - "codeLens": true, - "signatureHelp": { "enabled": true, "forConstructorPayloads": true }, - "incrementalTypechecking": { "enable": true, "acrossFiles": false }, - "cache": { "projectConfig": { "enable": true } }, - "binaryPath": null, - "platformPath": null, - "runtimePath": null, - "compileStatus": { "enable": true }, - "logLevel": "info" - } - |} - in - parse_and_print_config example_config_json_1; - [%expect {| { "codeLens": true, "inlayHints": { "enable": true } } |}] - -let%expect_test "settings retain defaults, optional limits, and unknown fields" - = - List.iter - (fun text -> - match of_yojson (Yojson.Safe.from_string text) with - | Ok config -> - let json = to_yojson config in - assert (of_yojson json = Ok config); - print_endline (Yojson.Safe.to_string json) - | Error message -> failwith message) - [ - {|{}|}; - {|{"hover":{},"inlayHints":{},"futureSetting":true}|}; - {|{"hover":{"supportMarkdownLinks":true},"codeLens":true,"inlayHints":{"enable":true,"maxLength":0}}|}; - {|{"inlayHints":{"maxLength":null}}|}; - ]; - [%expect - {| - {} - {} - {"hover":{"supportMarkdownLinks":true},"codeLens":true,"inlayHints":{"enable":true,"maxLength":0}} - {"inlayHints":{"maxLength":null}} - |}] - -let%expect_test "settings reject invalid known fields" = - List.iter - (fun text -> - Printf.printf "%s: %b\n" text - (Result.is_error (of_yojson (Yojson.Safe.from_string text)))) - [ - {|[]|}; - {|{"hover":null}|}; - {|{"codeLens":null}|}; - {|{"codeLens":1}|}; - {|{"hover":{"supportMarkdownLinks":"true"}}|}; - {|{"inlayHints":false}|}; - {|{"inlayHints":{"enable":null}}|}; - {|{"inlayHints":{"maxLength":"25"}}|}; - ]; - [%expect - {| - []: true - {"hover":null}: true - {"codeLens":null}: true - {"codeLens":1}: true - {"hover":{"supportMarkdownLinks":"true"}}: true - {"inlayHints":false}: true - {"inlayHints":{"enable":null}}: true - {"inlayHints":{"maxLength":"25"}}: true - |}] diff --git a/lsp/src/diagnostics.ml b/lsp/src/diagnostics.ml index 63be0e090fa..7c9e2f445b3 100644 --- a/lsp/src/diagnostics.ml +++ b/lsp/src/diagnostics.ml @@ -76,34 +76,6 @@ let update_syntax ~uri ~(new_diagnostics : Diagnostic.t list) t = let clear_syntax ~uri t = update_syntax ~uri ~new_diagnostics:[] t -let%expect_test "get_all merges diagnostics from every source" = - let uri = Uri.of_path "/workspace/A.res" in - let range = - Range.create - ~start:(Position.create ~line:0 ~character:0) - ~end_:(Position.create ~line:0 ~character:1) - in - let diagnostic message = - Diagnostic.create ~range ~message:(`String message) () - in - let t = - { - compiler = Uri_map.singleton uri [diagnostic "compiler"]; - compiler_syntax = Uri_map.singleton uri [diagnostic "compiler syntax"]; - syntax = Uri_map.singleton uri [diagnostic "syntax"]; - send = (fun _ -> ()); - } - in - get_all t |> Uri_map.find uri - |> List.iter (fun (diagnostic : Diagnostic.t) -> - match diagnostic.message with - | `String message -> print_endline message - | `MarkupContent {value} -> print_endline value); - [%expect {| - syntax - compiler - compiler syntax |}] - let send ?(include_syntax = true) ?(force_publish_uris = []) ?(should_publish = fun _ -> true) t = let diagnostics = diagnostics ~include_syntax t in @@ -120,40 +92,6 @@ let send ?(include_syntax = true) ?(force_publish_uris = []) if (not (should_publish uri)) || not (Uri_map.mem uri diagnostics) then t.send (PublishDiagnosticsParams.create ~uri ~diagnostics:[] ())) -let%expect_test "send can reserve an open document for pull diagnostics" = - let open_uri = Uri.of_path "/workspace/Open.res" in - let closed_uri = Uri.of_path "/workspace/Closed.res" in - let range = - Range.create - ~start:(Position.create ~line:0 ~character:0) - ~end_:(Position.create ~line:0 ~character:1) - in - let diagnostic message = - Diagnostic.create ~range ~message:(`String message) () - in - let print ({uri; diagnostics; _} : PublishDiagnosticsParams.t) = - Printf.printf "%s: %d\n" - (Filename.basename (Uri.to_path uri)) - (List.length diagnostics) - in - let t = - { - compiler = - Uri_map.empty - |> Uri_map.add open_uri [diagnostic "open compiler"] - |> Uri_map.add closed_uri [diagnostic "closed compiler"]; - compiler_syntax = Uri_map.empty; - syntax = Uri_map.singleton open_uri [diagnostic "open syntax"]; - send = print; - } - in - send ~include_syntax:false ~force_publish_uris:[open_uri] - ~should_publish:(fun uri -> Uri.compare uri open_uri <> 0) - t; - [%expect {| - Closed.res: 1 - Open.res: 0 |}] - (* Convert parsed compiler-log entries into LSP diagnostics grouped by document URI. Compiler logs may report paths either relative to the workspace root or as absolute paths, so this function normalizes each entry into a DocumentUri @@ -286,207 +224,3 @@ let collect_diagnostics_from_log_using_source_dirs workspace_root fs = in Fs.load ~fs compiler_log_path) |> diagnostics_from_completed_logs - -let%expect_test "only completed compiler logs form a diagnostics snapshot" = - let print = function - | None -> print_endline "incomplete" - | Some diagnostics -> - Printf.printf "complete: %d diagnostics\n" (List.length diagnostics) - in - diagnostics_from_completed_logs ["#Start(1)\n"] |> print; - [%expect {| incomplete |}]; - - diagnostics_from_completed_logs ["#Start(1)\n#Done(2)\n"] |> print; - [%expect {| complete: 0 diagnostics |}]; - - diagnostics_from_completed_logs ["#Start(1)\n#Done(2)\n"; "#Start(3)\n"] - |> print; - [%expect {| incomplete |}] - -let%expect_test "compiler syntax diagnostics don't clear type diagnostics" = - let workspace_root = Uri.of_path "/workspace" in - let uri_a = Uri.of_path "/workspace/A.res" in - let uri_b = Uri.of_path "/workspace/B.res" in - let uri_c = Uri.of_path "/workspace/C.res" in - let range = - Range.create - ~start:(Position.create ~line:0 ~character:0) - ~end_:(Position.create ~line:0 ~character:1) - in - let diagnostic message = - Diagnostic.create ~range ~message:(`String message) () - in - let entry uri kind message = - let open Compiler_log.Parse in - {kind; path = Full_path (Uri.to_path uri); message; range = Some range} - in - let print t = - diagnostics t - |> Uri_map.iter (fun uri diagnostics -> - let messages = - diagnostics - |> List.map (fun (diagnostic : Diagnostic.t) -> - match diagnostic.message with - | `String message -> message - | `MarkupContent {value} -> value) - in - Printf.printf "%s: %s\n" - (Filename.basename (Uri.to_path uri)) - (match messages with - | [] -> "" - | messages -> String.concat ", " messages)) - in - let doc_store = Document_store.make () in - let t = make ~diagnostics:(empty ()) ~send:(fun _ -> ()) in - let t = - update_from_compiler_log ~workspace_root ~doc_store - [entry uri_b Common_error "type B"; entry uri_c Common_error "type C"] - t - in - print t; - [%expect {| - B.res: type B - C.res: type C |}]; - - let doc = - Document.make - (DidOpenTextDocumentParams.create - ~textDocument: - (TextDocumentItem.create ~languageId:(LanguageKind.Other "rescript") - ~uri:uri_a ~text:"let x =" ~version:1)) - ~position_encoding:`UTF16 - in - ignore (Document_store.add doc_store ~doc); - let t = update_syntax ~uri:uri_a ~new_diagnostics:[diagnostic "syntax A"] t in - let t = - update_from_compiler_log ~workspace_root ~doc_store - [entry uri_a Syntax_error "compiler syntax A"] - t - in - print t; - [%expect {| - A.res: syntax A - B.res: type B - C.res: type C |}]; - - ignore (Document_store.remove doc_store ~uri:uri_a); - let t = clear_syntax ~uri:uri_a t in - let t = - update_from_compiler_log ~workspace_root ~doc_store - [entry uri_a Syntax_error "compiler syntax A"] - t - in - print t; - [%expect - {| - A.res: compiler syntax A - B.res: type B - C.res: type C |}]; - - let t = - update_from_compiler_log ~workspace_root ~doc_store - [entry uri_b Common_error "type B fixed later"] - t - in - print t; - [%expect - {| - A.res: - B.res: type B fixed later - C.res: |}]; - - let t = update_from_compiler_log ~workspace_root ~doc_store [] t in - print t; - [%expect {| - A.res: - B.res: - C.res: |}] - -let%expect_test "Windows compiler paths share the open document's identity" = - (* Exercise real backslash paths even when this test runs on Unix. *) - let win32 = !Uri.Private.win32 in - Fun.protect - ~finally:(fun () -> Uri.Private.win32 := win32) - (fun () -> - Uri.Private.win32 := true; - let workspace_root = Uri.of_path {|D:\a\project|} in - let compiler_uri = Uri.of_path {|D:\a\project\src\Broken.res|} in - let client_uri = Uri.of_string "file:///d%3A/a/project/src/Broken.res" in - assert (Uri.compare compiler_uri client_uri <> 0); - let source = "let value = 1\nlet other = 2" in - let doc = - Document.make - (DidOpenTextDocumentParams.create - ~textDocument: - (TextDocumentItem.create ~uri:client_uri ~text:source ~version:0 - ~languageId:(LanguageKind.Other "rescript"))) - ~position_encoding:`UTF16 - in - let doc_store = Document_store.make () in - ignore (Document_store.add doc_store ~doc); - let entry path kind = - {Compiler_log.Parse.kind; path; message = "compiler"; range = None} - in - let convert path kind = - to_lsp_format ~include_syntax:true ~include_non_syntax:true - workspace_root doc_store - [entry path kind] - in - let absolute = - Compiler_log.Parse.Full_path {|D:\a\project\src\Broken.res|} - in - let relative = Compiler_log.Parse.Relative_path {|src\Broken.res|} in - let compiler = convert absolute Common_error in - let relative_compiler = convert relative Common_error in - Printf.printf "absolute compiler diagnostics: %d\n" - (List.length (Uri_map.find client_uri compiler)); - Printf.printf "relative compiler diagnostics: %d\n" - (List.length (Uri_map.find client_uri relative_compiler)); - Printf.printf "open compiler syntax diagnostics: %d\n" - (Uri_map.cardinal (convert absolute Syntax_error)); - let compiler_diagnostic = List.hd (Uri_map.find client_uri compiler) in - Printf.printf "fallback range uses open buffer: %b\n" - (compiler_diagnostic.range = Document.range_of_text source); - let t = - make ~diagnostics:compiler - ~send:(fun ({diagnostics} : PublishDiagnosticsParams.t) -> - Printf.printf "pushed diagnostics: %d\n" (List.length diagnostics)) - |> update_syntax ~uri:client_uri - ~new_diagnostics: - [ - Diagnostic.create - ~range:(Document.range_of_text source) - ~message:(`String "buffer") (); - ] - in - Printf.printf "merged URI keys: %d\n" (Uri_map.cardinal (get_all t)); - Printf.printf "merged diagnostics: %d\n" - (List.length (Uri_map.find client_uri (get_all t))); - send ~include_syntax:false ~force_publish_uris:[client_uri] - ~should_publish:(fun uri -> - Document_store.get_opt doc_store ~uri = None) - t; - ignore (Document_store.remove doc_store ~uri:compiler_uri); - let t = clear_syntax ~uri:compiler_uri t in - send t; - send (update_compiler ~new_diagnostics:(empty ()) t); - Printf.printf "filename case remains distinct: %b\n" - (Uri_map.cardinal - (Uri_map.empty |> Uri_map.add client_uri [] - |> Uri_map.add - (Uri.of_string "file:///d%3A/a/project/src/broken.res") - []) - = 2)); - [%expect - {| - absolute compiler diagnostics: 1 - relative compiler diagnostics: 1 - open compiler syntax diagnostics: 0 - fallback range uses open buffer: true - merged URI keys: 1 - merged diagnostics: 2 - pushed diagnostics: 0 - pushed diagnostics: 1 - pushed diagnostics: 0 - filename case remains distinct: true - |}] diff --git a/lsp/src/document.ml b/lsp/src/document.ml index 0e600de9750..5e9370d84fa 100644 --- a/lsp/src/document.ml +++ b/lsp/src/document.ml @@ -46,53 +46,3 @@ let range_of_text (text : string) : Range.t = Range.create ~start:(Position.create ~line:0 ~character:0) ~end_:(end_position 0 0 0) - -let%expect_test "range_of_text" = - let print text = - let range = range_of_text text in - Yojson.Safe.pretty_to_string - (`Assoc - [ - ("start", range.start |> Position.yojson_of_t); - ("end", range.end_ |> Position.yojson_of_t); - ]) - |> print_endline - in - print ""; - print "let a = 1"; - print "let a = 1\nlet b = 2"; - print "let a = 1\n"; - print "\xC3\xA9"; - print "ab"; - print "ab\ncd"; - [%expect - {| - { - "start": { "character": 0, "line": 0 }, - "end": { "character": 0, "line": 0 } - } - { - "start": { "character": 0, "line": 0 }, - "end": { "character": 9, "line": 0 } - } - { - "start": { "character": 0, "line": 0 }, - "end": { "character": 9, "line": 1 } - } - { - "start": { "character": 0, "line": 0 }, - "end": { "character": 0, "line": 1 } - } - { - "start": { "character": 0, "line": 0 }, - "end": { "character": 2, "line": 0 } - } - { - "start": { "character": 0, "line": 0 }, - "end": { "character": 2, "line": 0 } - } - { - "start": { "character": 0, "line": 0 }, - "end": { "character": 2, "line": 1 } - } - |}] diff --git a/lsp/src/document_store.ml b/lsp/src/document_store.ml index e0f8b3bacce..3fc276913dc 100644 --- a/lsp/src/document_store.ml +++ b/lsp/src/document_store.ml @@ -47,39 +47,3 @@ let get t ~uri = ~message: (Printf.sprintf "Cannot get document %s: it is not open." (Uri.to_string uri)) - -let%expect_test "drive-letter variants identify the same open document" = - let upper = Uri.of_string "file:///D%3A/project/Broken.res" in - let lower = Uri.of_string "file:///d%3A/project/Broken.res" in - let make_doc uri text version = - Document.make - (Lsp.Types.DidOpenTextDocumentParams.create - ~textDocument: - (Lsp.Types.TextDocumentItem.create ~uri ~text ~version - ~languageId:(Lsp.Types.LanguageKind.Other "rescript"))) - ~position_encoding:`UTF16 - in - let store = make () in - let doc = make_doc upper "let value = 1" 0 in - ignore (add store ~doc); - Printf.printf "alternate drive lookup: %b\n" (get store ~uri:lower = doc); - Printf.printf "original client URI retained: %b\n" - (Uri.equal (Document.uri (get store ~uri:lower)) upper); - (try - ignore (add store ~doc:(make_doc lower "let value = 2" 0)); - failwith "Expected a duplicate-document error" - with Jsonrpc.Response.Error.E error -> print_endline error.message); - ignore (update store ~doc:(make_doc lower "let value = 3" 1)); - Printf.printf "updated through alternate drive: %s\n" - (Document.text (get store ~uri:upper)); - ignore (remove store ~uri:upper); - Printf.printf "closed through alternate drive: %b\n" - (get_opt store ~uri:lower = None); - [%expect - {| - alternate drive lookup: true - original client URI retained: true - Cannot open document file:///d%3A/project/Broken.res: it is already open. - updated through alternate drive: let value = 3 - closed through alternate drive: true - |}] diff --git a/lsp/src/dune b/lsp/src/dune index e78f0f40e19..dc6f48c4b62 100644 --- a/lsp/src/dune +++ b/lsp/src/dune @@ -1,5 +1,7 @@ (library - (name rescript_language_server) + (name rescript_language_server_core) + (modules + (:standard \ rescript_language_server)) (libraries lsp eio @@ -8,8 +10,14 @@ str yojson ppx_deriving_yojson.runtime) - (inline_tests) (preprocess - (pps ppx_deriving_yojson ppx_expect)) + (pps ppx_deriving_yojson)) + (flags + (:standard -w +a-4-9-30-40-41-42-44-48-70))) + +(library + (name rescript_language_server) + (modules rescript_language_server) + (libraries lsp eio analysis yojson rescript_language_server_core) (flags (:standard -w +a-4-9-30-40-41-42-44-48-70))) diff --git a/lsp/src/rescript_language_server.ml b/lsp/src/rescript_language_server.ml index 18c540143eb..bd27ae833aa 100644 --- a/lsp/src/rescript_language_server.ml +++ b/lsp/src/rescript_language_server.ml @@ -1,5 +1,6 @@ open Lsp open Lsp.Types +open Rescript_language_server_core let initialization ~state (client_capabilities : ClientCapabilities.t) = let textDocumentSync = diff --git a/lsp/src/source_dirs.ml b/lsp/src/source_dirs.ml index fa8e6ba99cb..3b3b0dea2ab 100644 --- a/lsp/src/source_dirs.ml +++ b/lsp/src/source_dirs.ml @@ -13,92 +13,3 @@ let get_build_roots_from_file ~fs path = | json -> get_build_roots_from_json json | exception _ -> None) | None -> None - -let%expect_test "get_build_roots" = - let print_build_roots result = - match result with - | None -> () - | Some l -> List.iter print_endline l - in - let json_1 = - Yojson.Safe.from_string - {| -{ - "cmt_scan": [ - { - "build_root": "path/to/lib/bs" - } - ] -} - |} - in - - json_1 |> get_build_roots_from_json |> print_build_roots; - [%expect {| path/to/lib/bs |}]; - - let json_2 = - Yojson.Safe.from_string - {| -{ -"cmt_scan": [ - { - "build_root": "path/to/lib/bs" - }, - { - "build_root": "path2/to/lib/bs" - } -] -} - |} - in - - json_2 |> get_build_roots_from_json |> print_build_roots; - [%expect {| - path/to/lib/bs - path2/to/lib/bs - |}]; - - let json_3 = - Yojson.Safe.from_string - {| -{ -"cmt_scan": [ -{ - "build_root": [] -}, -{ - "build_root": {} -} -] -} -|} - in - - json_3 |> get_build_roots_from_json |> print_build_roots; - [%expect {| |}] - -let%expect_test "source directory metadata rejects incomplete scan entries" = - List.iter - (fun text -> - match get_build_roots_from_json (Yojson.Safe.from_string text) with - | None -> print_endline "invalid" - | Some roots -> - `List (List.map (fun root -> `String root) roots) - |> Yojson.Safe.to_string |> print_endline) - [ - {|{}|}; - {|{"cmt_scan":null}|}; - {|{"cmt_scan":[]}|}; - {|{"cmt_scan":[{"build_root":"lib/rescript"},{}]}|}; - {|{"cmt_scan":[{"build_root":null}]}|}; - {|{"version":2,"cmt_scan":[{"build_root":"lib/rescript","scan_dirs":[]}]}|}; - ]; - [%expect - {| - invalid - invalid - [] - invalid - invalid - ["lib/rescript"] - |}] diff --git a/packages/@rescript/darwin-arm64/THIRD_PARTY_LICENSES b/packages/@rescript/darwin-arm64/THIRD_PARTY_LICENSES index 36647dc74a3..441a99ca742 100644 --- a/packages/@rescript/darwin-arm64/THIRD_PARTY_LICENSES +++ b/packages/@rescript/darwin-arm64/THIRD_PARTY_LICENSES @@ -1838,440 +1838,6 @@ Included in: runtime dependency of Eio ------------------------------------------------------------------------------- -PPX_EXPECT RUNTIME -================== -Version: v0.17.3 -Source: https://github.com/janestreet/ppx_expect -License: MIT -Included in: runtime dependency of the language-server library in rescript - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPXLIB -====== -Version: 0.39.0 -Source: https://github.com/ocaml-ppx/ppxlib -License: MIT -Included in: runtime dependency of ppx_expect - -The MIT License - -Copyright (c) 2018 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -STDIO -===== -Version: v0.17.0 -Source: https://github.com/janestreet/stdio -License: MIT -Included in: runtime dependency of the language-server PPX runtimes - -The MIT License - -Copyright (c) 2016--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -BASE -==== -Version: v0.17.3 -Source: https://github.com/janestreet/base -License: MIT -Included in: runtime dependency of the language-server PPX runtimes - -The MIT License - -Copyright (c) 2016--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -OCAML_INTRINSICS_KERNEL -======================= -Version: v0.17.3 -Source: https://github.com/janestreet/ocaml_intrinsics_kernel -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2020--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -SEXPLIB0 -======== -Version: v0.17.0 -Source: https://github.com/janestreet/sexplib0 -License: MIT -Included in: runtime dependency of Base and the language-server PPX runtimes - -The MIT License - -Copyright (c) 2005--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_HERE RUNTIME -================ -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_here -License: MIT -Included in: runtime dependency of ppx_expect - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_INLINE_TEST RUNTIME -======================= -Version: v0.17.1 -Source: https://github.com/janestreet/ppx_inline_test -License: MIT -Included in: runtime dependency of ppx_expect - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -TIME_NOW -======== -Version: v0.17.0 -Source: https://github.com/janestreet/time_now -License: MIT -Included in: runtime dependency of ppx_inline_test - -The MIT License - -Copyright (c) 2019--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_HASH RUNTIME -================ -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_hash -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_ENUMERATE RUNTIME -===================== -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_enumerate -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_COMPARE RUNTIME -=================== -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_compare -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_SEXP_CONV RUNTIME -===================== -Version: v0.17.1 -Source: https://github.com/janestreet/ppx_sexp_conv -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -JANE-STREET-HEADERS -=================== -Version: v0.17.0 -Source: https://github.com/janestreet/jane-street-headers -License: MIT -Included in: C support for Jane Street runtime libraries - -The MIT License - -Copyright (c) 2016--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - PPX_DERIVING_YOJSON RUNTIME =========================== Version: 3.10.0 diff --git a/packages/@rescript/linux-arm64/THIRD_PARTY_LICENSES b/packages/@rescript/linux-arm64/THIRD_PARTY_LICENSES index ab7582dba97..90c6582944b 100644 --- a/packages/@rescript/linux-arm64/THIRD_PARTY_LICENSES +++ b/packages/@rescript/linux-arm64/THIRD_PARTY_LICENSES @@ -1965,440 +1965,6 @@ Included in: runtime dependency of Eio ------------------------------------------------------------------------------- -PPX_EXPECT RUNTIME -================== -Version: v0.17.3 -Source: https://github.com/janestreet/ppx_expect -License: MIT -Included in: runtime dependency of the language-server library in rescript - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPXLIB -====== -Version: 0.39.0 -Source: https://github.com/ocaml-ppx/ppxlib -License: MIT -Included in: runtime dependency of ppx_expect - -The MIT License - -Copyright (c) 2018 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -STDIO -===== -Version: v0.17.0 -Source: https://github.com/janestreet/stdio -License: MIT -Included in: runtime dependency of the language-server PPX runtimes - -The MIT License - -Copyright (c) 2016--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -BASE -==== -Version: v0.17.3 -Source: https://github.com/janestreet/base -License: MIT -Included in: runtime dependency of the language-server PPX runtimes - -The MIT License - -Copyright (c) 2016--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -OCAML_INTRINSICS_KERNEL -======================= -Version: v0.17.3 -Source: https://github.com/janestreet/ocaml_intrinsics_kernel -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2020--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -SEXPLIB0 -======== -Version: v0.17.0 -Source: https://github.com/janestreet/sexplib0 -License: MIT -Included in: runtime dependency of Base and the language-server PPX runtimes - -The MIT License - -Copyright (c) 2005--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_HERE RUNTIME -================ -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_here -License: MIT -Included in: runtime dependency of ppx_expect - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_INLINE_TEST RUNTIME -======================= -Version: v0.17.1 -Source: https://github.com/janestreet/ppx_inline_test -License: MIT -Included in: runtime dependency of ppx_expect - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -TIME_NOW -======== -Version: v0.17.0 -Source: https://github.com/janestreet/time_now -License: MIT -Included in: runtime dependency of ppx_inline_test - -The MIT License - -Copyright (c) 2019--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_HASH RUNTIME -================ -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_hash -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_ENUMERATE RUNTIME -===================== -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_enumerate -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_COMPARE RUNTIME -=================== -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_compare -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_SEXP_CONV RUNTIME -===================== -Version: v0.17.1 -Source: https://github.com/janestreet/ppx_sexp_conv -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -JANE-STREET-HEADERS -=================== -Version: v0.17.0 -Source: https://github.com/janestreet/jane-street-headers -License: MIT -Included in: C support for Jane Street runtime libraries - -The MIT License - -Copyright (c) 2016--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - PPX_DERIVING_YOJSON RUNTIME =========================== Version: 3.10.0 diff --git a/packages/@rescript/linux-x64/THIRD_PARTY_LICENSES b/packages/@rescript/linux-x64/THIRD_PARTY_LICENSES index 8a8c4ee676d..3429068e8ec 100644 --- a/packages/@rescript/linux-x64/THIRD_PARTY_LICENSES +++ b/packages/@rescript/linux-x64/THIRD_PARTY_LICENSES @@ -1965,440 +1965,6 @@ Included in: runtime dependency of Eio ------------------------------------------------------------------------------- -PPX_EXPECT RUNTIME -================== -Version: v0.17.3 -Source: https://github.com/janestreet/ppx_expect -License: MIT -Included in: runtime dependency of the language-server library in rescript - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPXLIB -====== -Version: 0.39.0 -Source: https://github.com/ocaml-ppx/ppxlib -License: MIT -Included in: runtime dependency of ppx_expect - -The MIT License - -Copyright (c) 2018 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -STDIO -===== -Version: v0.17.0 -Source: https://github.com/janestreet/stdio -License: MIT -Included in: runtime dependency of the language-server PPX runtimes - -The MIT License - -Copyright (c) 2016--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -BASE -==== -Version: v0.17.3 -Source: https://github.com/janestreet/base -License: MIT -Included in: runtime dependency of the language-server PPX runtimes - -The MIT License - -Copyright (c) 2016--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -OCAML_INTRINSICS_KERNEL -======================= -Version: v0.17.3 -Source: https://github.com/janestreet/ocaml_intrinsics_kernel -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2020--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -SEXPLIB0 -======== -Version: v0.17.0 -Source: https://github.com/janestreet/sexplib0 -License: MIT -Included in: runtime dependency of Base and the language-server PPX runtimes - -The MIT License - -Copyright (c) 2005--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_HERE RUNTIME -================ -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_here -License: MIT -Included in: runtime dependency of ppx_expect - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_INLINE_TEST RUNTIME -======================= -Version: v0.17.1 -Source: https://github.com/janestreet/ppx_inline_test -License: MIT -Included in: runtime dependency of ppx_expect - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -TIME_NOW -======== -Version: v0.17.0 -Source: https://github.com/janestreet/time_now -License: MIT -Included in: runtime dependency of ppx_inline_test - -The MIT License - -Copyright (c) 2019--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_HASH RUNTIME -================ -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_hash -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_ENUMERATE RUNTIME -===================== -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_enumerate -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_COMPARE RUNTIME -=================== -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_compare -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_SEXP_CONV RUNTIME -===================== -Version: v0.17.1 -Source: https://github.com/janestreet/ppx_sexp_conv -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -JANE-STREET-HEADERS -=================== -Version: v0.17.0 -Source: https://github.com/janestreet/jane-street-headers -License: MIT -Included in: C support for Jane Street runtime libraries - -The MIT License - -Copyright (c) 2016--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - PPX_DERIVING_YOJSON RUNTIME =========================== Version: 3.10.0 diff --git a/packages/@rescript/win32-x64/THIRD_PARTY_LICENSES b/packages/@rescript/win32-x64/THIRD_PARTY_LICENSES index 64402791567..532df2f18cf 100644 --- a/packages/@rescript/win32-x64/THIRD_PARTY_LICENSES +++ b/packages/@rescript/win32-x64/THIRD_PARTY_LICENSES @@ -1735,440 +1735,6 @@ Included in: runtime dependency of Eio ------------------------------------------------------------------------------- -PPX_EXPECT RUNTIME -================== -Version: v0.17.3 -Source: https://github.com/janestreet/ppx_expect -License: MIT -Included in: runtime dependency of the language-server library in rescript - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPXLIB -====== -Version: 0.39.0 -Source: https://github.com/ocaml-ppx/ppxlib -License: MIT -Included in: runtime dependency of ppx_expect - -The MIT License - -Copyright (c) 2018 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -STDIO -===== -Version: v0.17.0 -Source: https://github.com/janestreet/stdio -License: MIT -Included in: runtime dependency of the language-server PPX runtimes - -The MIT License - -Copyright (c) 2016--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -BASE -==== -Version: v0.17.3 -Source: https://github.com/janestreet/base -License: MIT -Included in: runtime dependency of the language-server PPX runtimes - -The MIT License - -Copyright (c) 2016--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -OCAML_INTRINSICS_KERNEL -======================= -Version: v0.17.3 -Source: https://github.com/janestreet/ocaml_intrinsics_kernel -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2020--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -SEXPLIB0 -======== -Version: v0.17.0 -Source: https://github.com/janestreet/sexplib0 -License: MIT -Included in: runtime dependency of Base and the language-server PPX runtimes - -The MIT License - -Copyright (c) 2005--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_HERE RUNTIME -================ -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_here -License: MIT -Included in: runtime dependency of ppx_expect - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_INLINE_TEST RUNTIME -======================= -Version: v0.17.1 -Source: https://github.com/janestreet/ppx_inline_test -License: MIT -Included in: runtime dependency of ppx_expect - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -TIME_NOW -======== -Version: v0.17.0 -Source: https://github.com/janestreet/time_now -License: MIT -Included in: runtime dependency of ppx_inline_test - -The MIT License - -Copyright (c) 2019--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_HASH RUNTIME -================ -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_hash -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_ENUMERATE RUNTIME -===================== -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_enumerate -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_COMPARE RUNTIME -=================== -Version: v0.17.0 -Source: https://github.com/janestreet/ppx_compare -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -PPX_SEXP_CONV RUNTIME -===================== -Version: v0.17.1 -Source: https://github.com/janestreet/ppx_sexp_conv -License: MIT -Included in: runtime dependency of Base - -The MIT License - -Copyright (c) 2015--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - -JANE-STREET-HEADERS -=================== -Version: v0.17.0 -Source: https://github.com/janestreet/jane-street-headers -License: MIT -Included in: C support for Jane Street runtime libraries - -The MIT License - -Copyright (c) 2016--2024 Jane Street Group, LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -------------------------------------------------------------------------------- - PPX_DERIVING_YOJSON RUNTIME =========================== Version: 3.10.0 diff --git a/tests/dune b/tests/dune index 22b63ed819c..0d1e16077a0 100644 --- a/tests/dune +++ b/tests/dune @@ -1 +1 @@ -(dirs ounit_tests rewatch_ounit_tests syntax_tests lsp_tests) +(dirs ounit_tests rewatch_ounit_tests syntax_tests lsp_tests lsp_unit_tests) diff --git a/tests/lsp_unit_tests/README.md b/tests/lsp_unit_tests/README.md new file mode 100644 index 00000000000..c492ec9e625 --- /dev/null +++ b/tests/lsp_unit_tests/README.md @@ -0,0 +1,14 @@ +# Language server unit tests + +These `ppx_expect` tests import the private `rescript_language_server_core` +library directly. Production sources contain no inline tests, so the shipped +`rescript` executable does not link the expect-test runtime or its dependencies. + +Run from the repository root: + +```sh +opam exec -- dune runtest tests/lsp_unit_tests +``` + +`opam exec -- make test-lsp` runs these tests and the stdio end-to-end suite in +`tests/lsp_tests`, after building the toolchain and runtime. diff --git a/tests/lsp_unit_tests/compiler_log.ml b/tests/lsp_unit_tests/compiler_log.ml new file mode 100644 index 00000000000..bab84f81060 --- /dev/null +++ b/tests/lsp_unit_tests/compiler_log.ml @@ -0,0 +1,1011 @@ +open Rescript_language_server_core.Compiler_log + +let%expect_test "parse log" = + let diagnostic_of_entry (entry : Parse.diagnostic_entry) = + let range = + match entry.range with + | None -> `String "None" + | Some range -> Lsp.Types.Range.yojson_of_t range + in + Yojson.Safe.pretty_to_string + (`Assoc [("message", `String entry.message); ("range", range)]) + in + let print_logs logs = + logs + |> List.iter (fun (entry : Parse.diagnostic_entry) -> + let path = + match entry.path with + | Parse.Relative_path p -> Printf.sprintf "Relative_path(%s)" p + | Full_path p -> Printf.sprintf "Full_path(%s)" p + in + print_endline + ((match entry.kind with + | Syntax_error -> "Syntax_error" + | Warning {number; configured_as_error} -> + if configured_as_error then + Printf.sprintf "Warning %d (configured as error)" number + else Printf.sprintf "Warning %d" number + | Unknown -> "Unknown" + | Circular_dependency -> "Circular_dependency" + | Common_error -> "Common_error") + ^ " - " ^ path); + diagnostic_of_entry entry |> print_endline; + print_newline ()) + in + let example_log_1 = + {| + #Start(1600519680823) + + Syntax error! + /Users/chenglou/github/reason-react/src/test.res:1:8-2:3 + + 1 │ let a = + 2 │ let b = + 3 │ + + This let-binding misses an expression + + + Warning number 8 + /Users/chenglou/github/reason-react/src/test.res:3:5-8 + + 1 │ let a = j`šŸ˜€` + 2 │ let b = `šŸ˜€` + 3 │ let None = None + 4 │ let bla: int = " + 5 │ hi + + You forgot to handle a possible case here, for example: + Some _ + + + We've found a bug for you! + /Users/chenglou/github/reason-react/src/test.res:3:9 + + 1 │ let a = 1 + 2 │ let b = "hi" + 3 │ let a = b + 1 + + This has type: string + Somewhere wanted: int + + #Done(1600519680836) + |} + in + + Parse.parse_log_content example_log_1 |> print_logs; + [%expect + {| + Syntax_error - Full_path(/Users/chenglou/github/reason-react/src/test.res) + { + "message": "This let-binding misses an expression", + "range": { + "end": { "character": 3, "line": 1 }, + "start": { "character": 7, "line": 0 } + } + } + + Warning 8 - Full_path(/Users/chenglou/github/reason-react/src/test.res) + { + "message": "You forgot to handle a possible case here, for example:\nSome _", + "range": { + "end": { "character": 8, "line": 2 }, + "start": { "character": 4, "line": 2 } + } + } + + Common_error - Full_path(/Users/chenglou/github/reason-react/src/test.res) + { + "message": "This has type: string\nSomewhere wanted: int", + "range": { + "end": { "character": 9, "line": 2 }, + "start": { "character": 8, "line": 2 } + } + } + |}]; + + let example_log_2 = {|#Start(1780532423603) + #Done(1780532423840)|} in + + Parse.parse_log_content example_log_2 |> print_logs; + [%expect {| |}]; + + (* https://github.com/rescript-lang/rescript-vscode/issues/386#issuecomment-1221093517 *) + let example_log_3 = + {| + #Start(1660943070627) + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/fragmentsUsage/Fragments.res", lines 11-13, characters 6-7: + 11 | ......Todos { + | ...TodoItem + | } + 13 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/clientUsage/PromiseChaining.res", lines 17-21, characters 6-7: + 17 | ......os: allTodos { + | id + | text + | completed + | } + 21 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/clientUsage/ClientBasics.res", lines 18-22, characters 6-7: + 18 | ......os: allTodos { + | id + | text + | completed + | } + 22 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/docs/Docs.res", lines 7-11, characters 6-7: + 7 | ......os: allTodos { + | id + | text + | completed + | } + 11 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/fragmentsUsage/Query_Fragments.res", lines 6-9, characters 6-7: + 6 | ......os: allTodos { + | # This references the TodoItem fragment definition module above! + | ...TodoItem + | } + 9 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Mutation.res", lines 18-22, characters 6-7: + 18 | ......os: allTodos { + | id + | completed + | text + | } + 22 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_Lazy.res", lines 3-7, characters 6-7: + 3 | ......os: allTodos { + | id + | text + | completed + | } + 7 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_OverlySimple.res", lines 3-7, characters 4-5: + 3 | ....os: allTodos { + | id + | text + | completed + | } + 7 | . + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_SubscribeToMore.res", lines 5-9, characters 6-7: + 5 | ......os: allTodos { + | id + | completed + | text + | } + 9 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + File "/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_Typical.res", lines 4-8, characters 6-7: + 4 | ......os: allTodos { + | id + | text + | completed + | } + 8 | ... + Warning 22 [preprocessor]: Field "allTodos" has been deprecated. Reason: null + #Done(1660943070848) + |} + in + + Parse.parse_log_content example_log_3 |> print_logs; + [%expect + {| + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/fragmentsUsage/Fragments.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 12 }, + "start": { "character": 5, "line": 10 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/clientUsage/PromiseChaining.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 20 }, + "start": { "character": 5, "line": 16 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/clientUsage/ClientBasics.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 21 }, + "start": { "character": 5, "line": 17 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/docs/Docs.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 10 }, + "start": { "character": 5, "line": 6 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/fragmentsUsage/Query_Fragments.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 8 }, + "start": { "character": 5, "line": 5 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Mutation.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 21 }, + "start": { "character": 5, "line": 17 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_Lazy.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 6 }, + "start": { "character": 5, "line": 2 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_OverlySimple.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 5, "line": 6 }, + "start": { "character": 3, "line": 2 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_SubscribeToMore.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 8 }, + "start": { "character": 5, "line": 4 } + } + } + + Warning 22 - Full_path(/home/pedro/Desktop/rescript-apollo-client/EXAMPLES/src/hooksUsage/Query_Typical.res) + { + "message": "Warning 22 [preprocessor]: Field \"allTodos\" has been deprecated. Reason: null", + "range": { + "end": { "character": 7, "line": 7 }, + "start": { "character": 5, "line": 3 } + } + } + |}]; + + (* https://github.com/rescript-lang/rescript-vscode/issues/86#issuecomment-786186698 *) + let example_log_4 = + {|#Start(1614285167013) + + Warning number 33 + /home/misha/projects/productionmason/web/auth/src/ErrorHandlingMiddleware.res:1:1-15 + + 1 │ open CommonBase + 2 │ + 3 │ external jsExnToExpressError: Js.Exn.t => Express.Error.t = "%identity" + + unused open CommonBase. + + + Warning number 27 + /home/misha/projects/productionmason/web/auth/src/config/Config.res:10:22-27 + + 8 │ external stringifyAnyWithSpace: ('a, @bs.as(json`null`) _, int) => str + ing = "stringify" + 9 │ + 10 │ let validateConfig = config => { + 11 │ let googleApplicationCredentialsPath = + 12 │ NodeJs.Process.env(NodeJs.Process.process)->Js.Dict.get("GOOGLE_AP + PLICATION_CREDENTIALS") + + unused variable config. + + + Warning number 34 + /home/misha/projects/productionmason/web/auth/src/express-handler/ExpressHandler.re:48:5-26 + + 46 ┆ module Input = { + 47 ┆ [@decco] + 48 ┆ type t = Request.input; + 49 ┆ }; + 50 ┆ + + unused type t. + + + Warning number 32 + /home/misha/projects/productionmason/web/auth/src/express-handler/ExpressHandler.re + + unused value t_encode. + + + We've found a bug for you! + /home/misha/projects/productionmason/web/auth/tests/Auth_Test.res:224:45 + + 222 ┆ ->AsyncResult.mapOk(x => { + 223 ┆ expect(x.data.users->Array.length)->toBeGreaterThan(0) + 224 ┆ expect(x.data.users->Array.getExn(0).last_name)->toBe(Some("Glenliv + et")) + 225 ┆ Ok() + 226 ┆ }) + + This has type: int + Somewhere wanted: array<'a> + + #Done(1614285167075)|} + in + + Parse.parse_log_content example_log_4 |> print_logs; + [%expect + {| + Warning 33 - Full_path(/home/misha/projects/productionmason/web/auth/src/ErrorHandlingMiddleware.res) + { + "message": "unused open CommonBase.", + "range": { + "end": { "character": 15, "line": 0 }, + "start": { "character": 0, "line": 0 } + } + } + + Warning 27 - Full_path(/home/misha/projects/productionmason/web/auth/src/config/Config.res) + { + "message": "unused variable config.", + "range": { + "end": { "character": 27, "line": 9 }, + "start": { "character": 21, "line": 9 } + } + } + + Warning 34 - Full_path(/home/misha/projects/productionmason/web/auth/src/express-handler/ExpressHandler.re) + { + "message": "unused type t.", + "range": { + "end": { "character": 26, "line": 47 }, + "start": { "character": 4, "line": 47 } + } + } + + Warning 32 - Full_path(/home/misha/projects/productionmason/web/auth/src/express-handler/ExpressHandler.re) + { "message": "unused value t_encode.", "range": "None" } + + Common_error - Full_path(/home/misha/projects/productionmason/web/auth/tests/Auth_Test.res) + { + "message": "This has type: int\nSomewhere wanted: array<'a>", + "range": { + "end": { "character": 45, "line": 223 }, + "start": { "character": 44, "line": 223 } + } + } + |}]; + + let example_log_5 = + {|#Start(1780595107359) + + Can't continue... Found a circular dependency in your code: + Demo (src/Demo.res) + → Other (src/Other.res) + → Demo (src/Demo.res) + Possible solutions: + - Extract shared code into a new module both depend on. + #Done(1780595107364) + |} + in + + Parse.parse_log_content example_log_5 |> print_logs; + [%expect + {| + Circular_dependency - Relative_path(src/Demo.res) + { + "message": "Can't continue... Found a circular dependency in your code:\nDemo (src/Demo.res)\n→ Other (src/Other.res)\n→ Demo (src/Demo.res)\nPossible solutions:\n- Extract shared code into a new module both depend on.", + "range": "None" + } + + Circular_dependency - Relative_path(src/Other.res) + { + "message": "Can't continue... Found a circular dependency in your code:\nDemo (src/Demo.res)\n→ Other (src/Other.res)\n→ Demo (src/Demo.res)\nPossible solutions:\n- Extract shared code into a new module both depend on.", + "range": "None" + } + |}]; + + let example_log_6 = + {|#Start(1780595245481) + FAILED: dependency cycle: src/Demo.cmj -> src/Other.cmj -> src/Demo.cmj. + #Done(1780595245488)|} + in + + Parse.parse_log_content example_log_6 |> print_logs; + [%expect + {| + Circular_dependency - Relative_path(src/Demo.res) + { + "message": "FAILED: dependency cycle: src/Demo.cmj -> src/Other.cmj -> src/Demo.cmj.", + "range": "None" + } + + Circular_dependency - Relative_path(src/Other.res) + { + "message": "FAILED: dependency cycle: src/Demo.cmj -> src/Other.cmj -> src/Demo.cmj.", + "range": "None" + } + |}]; + + let example_log_7 = + {|#Start(1780595410580) + + We've found a bug for you! + /tmp/my-rescript-app/src/Demo.res:1:9-15 + + 1 │ let a = Other.a + 2 │ + + The value a can't be found in Other + + FAILED: cannot make progress due to previous errors. + #Done(1780595410597)|} + in + + Parse.parse_log_content example_log_7 |> print_logs; + [%expect + {| + Common_error - Full_path(/tmp/my-rescript-app/src/Demo.res) + { + "message": "The value a can't be found in Other\nFAILED: cannot make progress due to previous errors.", + "range": { + "end": { "character": 15, "line": 0 }, + "start": { "character": 8, "line": 0 } + } + } + |}]; + + let example_log_8 = + {|#Start(1780603624843) + Error in lsp-test: + + Syntax error! + /home/pedro/Desktop/projects/lsp-test/src/ArrayUtils.res:1:41-2:0 + + 1 │ let empty = arr => Array.length(arr) === + 2 │ + + Did you forget to write an expression here? + + #Done(1780603624849)|} + in + Parse.parse_log_content example_log_8 |> print_logs; + [%expect + {| + Syntax_error - Full_path(/home/pedro/Desktop/projects/lsp-test/src/ArrayUtils.res) + { + "message": "Did you forget to write an expression here?", + "range": { + "end": { "character": 0, "line": 1 }, + "start": { "character": 40, "line": 0 } + } + } + |}]; + + let example_log_9 = + {|#Start(1780630901455) + + We've found a bug for you! + /home/pedro/Desktop/projects/lsp-test/src/ArrayUtils.res:1:41-43 + + 1 │ let empty = arr => Array.length(arr) == "2"; + 2 │ + + This has type: string + But it's being compared to something of type: int + + You can only compare things of the same type. + + You can convert string to int with Int.fromString. + + #Done(1780630901468)|} + in + + Parse.parse_log_content example_log_9 |> print_logs; + [%expect + {| + Common_error - Full_path(/home/pedro/Desktop/projects/lsp-test/src/ArrayUtils.res) + { + "message": "This has type: string\nBut it's being compared to something of type: int\nYou can only compare things of the same type.\nYou can convert string to int with Int.fromString.", + "range": { + "end": { "character": 43, "line": 0 }, + "start": { "character": 40, "line": 0 } + } + } + |}]; + + let example_log_10 = + {|#Start(1781383030890) + + Warning number 8 (configured as error) + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:6:3-9:3 + + 4 │ + 5 │ let f = (a: t) => { + 6 │ switch a { + 7 │ | A => () + 8 │ | B => () + 9 │ } + 10 │ } + 11 │ + + You forgot to handle a possible case here, for example: + | C + + + Warning number 37 + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:3:1-18 + + 1 │ open ReactRouter.Routes + 2 │ + 3 │ type t = A | B | C + 4 │ + 5 │ let f = (a: t) => { + + constructor A is never used to build values. + (However, this constructor appears in patterns.) + + + Warning number 37 + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:3:1-18 + + 1 │ open ReactRouter.Routes + 2 │ + 3 │ type t = A | B | C + 4 │ + 5 │ let f = (a: t) => { + + constructor B is never used to build values. + (However, this constructor appears in patterns.) + + + Warning number 37 + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:3:1-18 + + 1 │ open ReactRouter.Routes + 2 │ + 3 │ type t = A | B | C + 4 │ + 5 │ let f = (a: t) => { + + unused constructor C. + + + Warning number 32 + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res:5:5 + + 3 │ type t = A | B | C + 4 │ + 5 │ let f = (a: t) => { + 6 │ switch a { + 7 │ | A => () + + unused value f. + + #Done(1781383030936)|} + in + Parse.parse_log_content example_log_10 |> print_logs; + [%expect + {| + Warning 8 (configured as error) - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) + { + "message": "You forgot to handle a possible case here, for example:\n| C", + "range": { + "end": { "character": 3, "line": 8 }, + "start": { "character": 2, "line": 5 } + } + } + + Warning 37 - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) + { + "message": "constructor A is never used to build values.\n(However, this constructor appears in patterns.)", + "range": { + "end": { "character": 18, "line": 2 }, + "start": { "character": 0, "line": 2 } + } + } + + Warning 37 - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) + { + "message": "constructor B is never used to build values.\n(However, this constructor appears in patterns.)", + "range": { + "end": { "character": 18, "line": 2 }, + "start": { "character": 0, "line": 2 } + } + } + + Warning 37 - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) + { + "message": "unused constructor C.", + "range": { + "end": { "character": 18, "line": 2 }, + "start": { "character": 0, "line": 2 } + } + } + + Warning 32 - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoutes.res) + { + "message": "unused value f.", + "range": { + "end": { "character": 5, "line": 4 }, + "start": { "character": 4, "line": 4 } + } + } + |}]; + + let example_log_10 = + {|#Start(1780630901455) + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/access_record_field_on_option.res:12:15 + + 10 │ } + 11 │ + 12 │ let f = X.x.c.d + 13 │ + + You're trying to access the record field d, but the value you're trying to access it on is an option. + You need to unwrap the option first before accessing the record field. + + Possible solutions: + - Use Option.map to transform the option: xx->Option.map(field => field.d) + - Or use Option.getOr with a default: xx->Option.getOr(defaultRecord).d + + #Done(1781383030936)|} + in + + Parse.parse_log_content example_log_10 |> print_logs; + [%expect + {| + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/access_record_field_on_option.res) + { + "message": "You're trying to access the record field d, but the value you're trying to access it on is an option.\nYou need to unwrap the option first before accessing the record field.\nPossible solutions:\n- Use Option.map to transform the option: xx->Option.map(field => field.d)\n- Or use Option.getOr with a default: xx->Option.getOr(defaultRecord).d", + "range": { + "end": { "character": 15, "line": 11 }, + "start": { "character": 14, "line": 11 } + } + } + |}]; + + let example_log_11 = + {|#Start(1780630901455) + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/arity_mismatch.res:2:21-27 + + 1 │ let makeVar = (~f, ()) => 34 + 2 │ let makeVariables = makeVar(~f=f => f) + 3 │ + + This function call is incorrect. + The function has type: + (~f: 'a => 'a, unit) => int + + - The function takes 1 unlabelled argument, but is called with none + + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/array_item_type_mismatch.res:1:16-22 + + 1 │ let x = [1, 2, "hello"] + 2 │ + + This array item has type: string + But this array is expected to have items of type: int + + Arrays can only contain items of the same type. + + Possible solutions: + - Convert all values in the array to the same type. + - Use a tuple, if your array is of fixed length. Tuples can mix types freely, and compiles to a JavaScript array. Example of a tuple: `let myTuple = (10, "hello", 15.5, true) + + You can convert string to int with Int.fromString. + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:4:5-7:1 + + 2 │ type t = .. + 3 │ type t += E(int) + 4 │ } = { + 5 │ type t = .. + 6 │ type t += E(string) + 7 │ } + 8 │ + + Signature mismatch: + Modules do not match: + { + type t = .. + type t += E(string) + } + is not included in + { + type t = .. + type t += E(int) + } + Extension declarations do not match: + type t += E(string) + is not included in + type t += E(int) + tests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:3:13-18: + Expected declaration + tests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:6:13-21: + Actual declaration + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/functor_apply_arg_mismatch.res:13:22-29 + + 11 │ } + 12 │ + 13 │ module Result = Make(Concrete) + 14 │ let _ = Result.bar + 15 │ + + Signature mismatch: + Modules do not match: { + let unrelated: string + } is not included in HasFoo + The value `foo' is required but not provided + tests/build_tests/super_errors/fixtures/functor_apply_arg_mismatch.res:2:3-14: + Expected declaration + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/include_missing_field.res:4:5-6:1 + + 2 │ let x: int + 3 │ let y: string + 4 │ } = { + 5 │ let x = 1 + 6 │ } + 7 │ + + Signature mismatch: + Modules do not match: + { + let x: int + } + is not included in + { + let x: int + let y: string + } + The value `y' is required but not provided + tests/build_tests/super_errors/fixtures/include_missing_field.res:3:3-15: + Expected declaration + + We've found a bug for you! + tests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:5:5-9:1 + + 3 │ let x: int + 4 │ } + 5 │ } = { + 6 │ module type T = { + 7 │ let x: string + 8 │ } + 9 │ } + 10 │ + + Signature mismatch: + Modules do not match: + { + module type T = { + let x: string + } + } + is not included in + { + module type T = { + let x: int + } + } + Module type declarations do not match: + module type T = { + let x: string + } + does not match + module type T = { + let x: int + } + At position module type T = + Modules do not match: + { + let x: string + } + is not included in + { + let x: int + } + At position module type T = + Values do not match: let x: string is not included in let x: int + tests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:3:5-14: + Expected declaration + tests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:7:5-17: + Actual declaration + + #Done(1781383030936)|} + in + + Parse.parse_log_content example_log_11 |> print_logs; + [%expect + {| + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/arity_mismatch.res) + { + "message": "This function call is incorrect.\nThe function has type:\n(~f: 'a => 'a, unit) => int\n- The function takes 1 unlabelled argument, but is called with none", + "range": { + "end": { "character": 27, "line": 1 }, + "start": { "character": 20, "line": 1 } + } + } + + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/array_item_type_mismatch.res) + { + "message": "This array item has type: string\nBut this array is expected to have items of type: int\nArrays can only contain items of the same type.\nPossible solutions:\n- Convert all values in the array to the same type.\n- Use a tuple, if your array is of fixed length. Tuples can mix types freely, and compiles to a JavaScript array. Example of a tuple: `let myTuple = (10, \"hello\", 15.5, true)\nYou can convert string to int with Int.fromString.", + "range": { + "end": { "character": 22, "line": 0 }, + "start": { "character": 15, "line": 0 } + } + } + + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res) + { + "message": "Signature mismatch:\nModules do not match:\n{\ntype t = ..\ntype t += E(string)\n}\nis not included in\n{\ntype t = ..\ntype t += E(int)\n}\nExtension declarations do not match:\ntype t += E(string)\nis not included in\ntype t += E(int)\ntests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:3:13-18:\nExpected declaration\ntests/build_tests/super_errors/fixtures/include_extension_constructors_mismatch.res:6:13-21:\nActual declaration", + "range": { + "end": { "character": 1, "line": 6 }, + "start": { "character": 4, "line": 3 } + } + } + + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/functor_apply_arg_mismatch.res) + { + "message": "Signature mismatch:\nModules do not match: {\nlet unrelated: string\n} is not included in HasFoo\nThe value `foo' is required but not provided\ntests/build_tests/super_errors/fixtures/functor_apply_arg_mismatch.res:2:3-14:\nExpected declaration", + "range": { + "end": { "character": 29, "line": 12 }, + "start": { "character": 21, "line": 12 } + } + } + + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/include_missing_field.res) + { + "message": "Signature mismatch:\nModules do not match:\n{\nlet x: int\n}\nis not included in\n{\nlet x: int\nlet y: string\n}\nThe value `y' is required but not provided\ntests/build_tests/super_errors/fixtures/include_missing_field.res:3:3-15:\nExpected declaration", + "range": { + "end": { "character": 1, "line": 5 }, + "start": { "character": 4, "line": 3 } + } + } + + Common_error - Relative_path(tests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res) + { + "message": "Signature mismatch:\nModules do not match:\n{\nmodule type T = {\nlet x: string\n}\n}\nis not included in\n{\nmodule type T = {\nlet x: int\n}\n}\nModule type declarations do not match:\nmodule type T = {\nlet x: string\n}\ndoes not match\nmodule type T = {\nlet x: int\n}\nAt position module type T = \nModules do not match:\n{\nlet x: string\n}\nis not included in\n{\nlet x: int\n}\nAt position module type T = \nValues do not match: let x: string is not included in let x: int\ntests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:3:5-14:\nExpected declaration\ntests/build_tests/super_errors/fixtures/include_modtype_infos_mismatch.res:7:5-17:\nActual declaration", + "range": { + "end": { "character": 1, "line": 8 }, + "start": { "character": 4, "line": 4 } + } + } + |}]; + + let example_log_12 = + {|#Start(1781743112207) + Error in build_warn_as_error: + + Warning number 110 (configured as error) + /home/pedro/Desktop/projects/rescript-compiler/tests/build_tests/build_warn_as_error/src/Demo.res:1:17-21 + + 1 │ let todo = _ => %todo + 2 │ + + Todo found. + + This code is not implemented yet and will crash at runtime. Make sure you implement this before running the code. + + #Done(1781743112217)|} + in + + Parse.parse_log_content example_log_12 |> print_logs; + [%expect + {| + Warning 110 (configured as error) - Full_path(/home/pedro/Desktop/projects/rescript-compiler/tests/build_tests/build_warn_as_error/src/Demo.res) + { + "message": "Todo found.\nThis code is not implemented yet and will crash at runtime. Make sure you implement this before running the code.", + "range": { + "end": { "character": 21, "line": 0 }, + "start": { "character": 16, "line": 0 } + } + } + |}]; + + let example_log_13 = + {|#Start(1781744629915) + + We've found a bug for you! + /home/pedro/Desktop/projects/rescript-compiler/tests/build_tests/gpr_978/src/gpr_978_module.res + + M is exported twice + + #Done(1781744629934)|} + in + + Parse.parse_log_content example_log_13 |> print_logs; + [%expect + {| + Common_error - Full_path(/home/pedro/Desktop/projects/rescript-compiler/tests/build_tests/gpr_978/src/gpr_978_module.res) + { "message": "M is exported twice", "range": "None" } + |}]; + + let example_log_14 = + {|#Start(1781910915195) + + We've found a bug for you! + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/scripts/LogAlgoliaEnvStatus.res:13:37-85 + + 11 ┆ switch Node.Process.argv[1] { + 12 ┆ | Some(entrypoint) => + 13 ┆ Node.URL.fileURLToPath(url) === Node.Path.resolve(Node.Process.cwd(), + ┆ entrypoint) + 14 ┆ | None => false + 15 ┆ } + + This has type: string + But it's being compared to something of type: int + + You can only compare things of the same type. + + You can convert string to int with Int.fromString. + + + We've found a bug for you! + /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/scripts/gendocs.res:23:3-24:21 + + 21 │ let args = Process.argv->Array.slice(~start=2) + 22 │ let dirname = + 23 │ url + 24 │ ->URL.fileURLToPath + 25 │ ->Path.dirname + 26 │ + + This has type: int + But this function argument is expecting: string + + You can convert int to string with Int.toString. + + #Done(1781910915345)|} + in + + Parse.parse_log_content example_log_14 |> print_logs; + [%expect + {| + Common_error - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/scripts/LogAlgoliaEnvStatus.res) + { + "message": "This has type: string\nBut it's being compared to something of type: int\nYou can only compare things of the same type.\nYou can convert string to int with Int.fromString.", + "range": { + "end": { "character": 85, "line": 12 }, + "start": { "character": 36, "line": 12 } + } + } + + Common_error - Full_path(/home/pedro/Desktop/projects/rescript-lang.org/apps/docs/scripts/gendocs.res) + { + "message": "This has type: int\nBut this function argument is expecting: string\nYou can convert int to string with Int.toString.", + "range": { + "end": { "character": 21, "line": 23 }, + "start": { "character": 2, "line": 22 } + } + } + |}] diff --git a/tests/lsp_unit_tests/configuration.ml b/tests/lsp_unit_tests/configuration.ml new file mode 100644 index 00000000000..cda616a1c92 --- /dev/null +++ b/tests/lsp_unit_tests/configuration.ml @@ -0,0 +1,79 @@ +open Rescript_language_server_core.Configuration + +let%expect_test "parse config" = + let parse_and_print_config json = + match of_yojson (Yojson.Safe.from_string json) with + | Ok c -> c |> to_yojson |> Yojson.Safe.pretty_to_string |> print_endline + | Error _ -> print_endline "Error" + in + + let example_config_json_1 = + {| + { + "askToStartBuild": false, + "inlayHints": { "enable": true, "maxLength": 25 }, + "codeLens": true, + "signatureHelp": { "enabled": true, "forConstructorPayloads": true }, + "incrementalTypechecking": { "enable": true, "acrossFiles": false }, + "cache": { "projectConfig": { "enable": true } }, + "binaryPath": null, + "platformPath": null, + "runtimePath": null, + "compileStatus": { "enable": true }, + "logLevel": "info" + } + |} + in + parse_and_print_config example_config_json_1; + [%expect {| { "codeLens": true, "inlayHints": { "enable": true } } |}] + +let%expect_test "settings retain defaults, optional limits, and unknown fields" + = + List.iter + (fun text -> + match of_yojson (Yojson.Safe.from_string text) with + | Ok config -> + let json = to_yojson config in + assert (of_yojson json = Ok config); + print_endline (Yojson.Safe.to_string json) + | Error message -> failwith message) + [ + {|{}|}; + {|{"hover":{},"inlayHints":{},"futureSetting":true}|}; + {|{"hover":{"supportMarkdownLinks":true},"codeLens":true,"inlayHints":{"enable":true,"maxLength":0}}|}; + {|{"inlayHints":{"maxLength":null}}|}; + ]; + [%expect + {| + {} + {} + {"hover":{"supportMarkdownLinks":true},"codeLens":true,"inlayHints":{"enable":true,"maxLength":0}} + {"inlayHints":{"maxLength":null}} + |}] + +let%expect_test "settings reject invalid known fields" = + List.iter + (fun text -> + Printf.printf "%s: %b\n" text + (Result.is_error (of_yojson (Yojson.Safe.from_string text)))) + [ + {|[]|}; + {|{"hover":null}|}; + {|{"codeLens":null}|}; + {|{"codeLens":1}|}; + {|{"hover":{"supportMarkdownLinks":"true"}}|}; + {|{"inlayHints":false}|}; + {|{"inlayHints":{"enable":null}}|}; + {|{"inlayHints":{"maxLength":"25"}}|}; + ]; + [%expect + {| + []: true + {"hover":null}: true + {"codeLens":null}: true + {"codeLens":1}: true + {"hover":{"supportMarkdownLinks":"true"}}: true + {"inlayHints":false}: true + {"inlayHints":{"enable":null}}: true + {"inlayHints":{"maxLength":"25"}}: true + |}] diff --git a/tests/lsp_unit_tests/diagnostics.ml b/tests/lsp_unit_tests/diagnostics.ml new file mode 100644 index 00000000000..bd5de01e3f3 --- /dev/null +++ b/tests/lsp_unit_tests/diagnostics.ml @@ -0,0 +1,270 @@ +open Lsp +open Lsp.Types +open Rescript_language_server_core +open Rescript_language_server_core.Diagnostics + +let%expect_test "get_all merges diagnostics from every source" = + let uri = Uri.of_path "/workspace/A.res" in + let range = + Range.create + ~start:(Position.create ~line:0 ~character:0) + ~end_:(Position.create ~line:0 ~character:1) + in + let diagnostic message = + Diagnostic.create ~range ~message:(`String message) () + in + let t = + { + compiler = Uri_map.singleton uri [diagnostic "compiler"]; + compiler_syntax = Uri_map.singleton uri [diagnostic "compiler syntax"]; + syntax = Uri_map.singleton uri [diagnostic "syntax"]; + send = (fun _ -> ()); + } + in + get_all t |> Uri_map.find uri + |> List.iter (fun (diagnostic : Diagnostic.t) -> + match diagnostic.message with + | `String message -> print_endline message + | `MarkupContent {value} -> print_endline value); + [%expect {| + syntax + compiler + compiler syntax |}] + +let%expect_test "send can reserve an open document for pull diagnostics" = + let open_uri = Uri.of_path "/workspace/Open.res" in + let closed_uri = Uri.of_path "/workspace/Closed.res" in + let range = + Range.create + ~start:(Position.create ~line:0 ~character:0) + ~end_:(Position.create ~line:0 ~character:1) + in + let diagnostic message = + Diagnostic.create ~range ~message:(`String message) () + in + let print ({uri; diagnostics; _} : PublishDiagnosticsParams.t) = + Printf.printf "%s: %d\n" + (Filename.basename (Uri.to_path uri)) + (List.length diagnostics) + in + let t = + { + compiler = + Uri_map.empty + |> Uri_map.add open_uri [diagnostic "open compiler"] + |> Uri_map.add closed_uri [diagnostic "closed compiler"]; + compiler_syntax = Uri_map.empty; + syntax = Uri_map.singleton open_uri [diagnostic "open syntax"]; + send = print; + } + in + send ~include_syntax:false ~force_publish_uris:[open_uri] + ~should_publish:(fun uri -> Uri.compare uri open_uri <> 0) + t; + [%expect {| + Closed.res: 1 + Open.res: 0 |}] + +let%expect_test "only completed compiler logs form a diagnostics snapshot" = + let print = function + | None -> print_endline "incomplete" + | Some diagnostics -> + Printf.printf "complete: %d diagnostics\n" (List.length diagnostics) + in + diagnostics_from_completed_logs ["#Start(1)\n"] |> print; + [%expect {| incomplete |}]; + + diagnostics_from_completed_logs ["#Start(1)\n#Done(2)\n"] |> print; + [%expect {| complete: 0 diagnostics |}]; + + diagnostics_from_completed_logs ["#Start(1)\n#Done(2)\n"; "#Start(3)\n"] + |> print; + [%expect {| incomplete |}] + +let%expect_test "compiler syntax diagnostics don't clear type diagnostics" = + let workspace_root = Uri.of_path "/workspace" in + let uri_a = Uri.of_path "/workspace/A.res" in + let uri_b = Uri.of_path "/workspace/B.res" in + let uri_c = Uri.of_path "/workspace/C.res" in + let range = + Range.create + ~start:(Position.create ~line:0 ~character:0) + ~end_:(Position.create ~line:0 ~character:1) + in + let diagnostic message = + Diagnostic.create ~range ~message:(`String message) () + in + let entry uri kind message = + let open Compiler_log.Parse in + {kind; path = Full_path (Uri.to_path uri); message; range = Some range} + in + let print t = + diagnostics t + |> Uri_map.iter (fun uri diagnostics -> + let messages = + diagnostics + |> List.map (fun (diagnostic : Diagnostic.t) -> + match diagnostic.message with + | `String message -> message + | `MarkupContent {value} -> value) + in + Printf.printf "%s: %s\n" + (Filename.basename (Uri.to_path uri)) + (match messages with + | [] -> "" + | messages -> String.concat ", " messages)) + in + let doc_store = Document_store.make () in + let t = make ~diagnostics:(empty ()) ~send:(fun _ -> ()) in + let t = + update_from_compiler_log ~workspace_root ~doc_store + [entry uri_b Common_error "type B"; entry uri_c Common_error "type C"] + t + in + print t; + [%expect {| + B.res: type B + C.res: type C |}]; + + let doc = + Document.make + (DidOpenTextDocumentParams.create + ~textDocument: + (TextDocumentItem.create ~languageId:(LanguageKind.Other "rescript") + ~uri:uri_a ~text:"let x =" ~version:1)) + ~position_encoding:`UTF16 + in + ignore (Document_store.add doc_store ~doc); + let t = update_syntax ~uri:uri_a ~new_diagnostics:[diagnostic "syntax A"] t in + let t = + update_from_compiler_log ~workspace_root ~doc_store + [entry uri_a Syntax_error "compiler syntax A"] + t + in + print t; + [%expect {| + A.res: syntax A + B.res: type B + C.res: type C |}]; + + ignore (Document_store.remove doc_store ~uri:uri_a); + let t = clear_syntax ~uri:uri_a t in + let t = + update_from_compiler_log ~workspace_root ~doc_store + [entry uri_a Syntax_error "compiler syntax A"] + t + in + print t; + [%expect + {| + A.res: compiler syntax A + B.res: type B + C.res: type C |}]; + + let t = + update_from_compiler_log ~workspace_root ~doc_store + [entry uri_b Common_error "type B fixed later"] + t + in + print t; + [%expect + {| + A.res: + B.res: type B fixed later + C.res: |}]; + + let t = update_from_compiler_log ~workspace_root ~doc_store [] t in + print t; + [%expect {| + A.res: + B.res: + C.res: |}] + +let%expect_test "Windows compiler paths share the open document's identity" = + (* Exercise real backslash paths even when this test runs on Unix. *) + let win32 = !Uri.Private.win32 in + Fun.protect + ~finally:(fun () -> Uri.Private.win32 := win32) + (fun () -> + Uri.Private.win32 := true; + let workspace_root = Uri.of_path {|D:\a\project|} in + let compiler_uri = Uri.of_path {|D:\a\project\src\Broken.res|} in + let client_uri = Uri.of_string "file:///d%3A/a/project/src/Broken.res" in + assert (Uri.compare compiler_uri client_uri <> 0); + let source = "let value = 1\nlet other = 2" in + let doc = + Document.make + (DidOpenTextDocumentParams.create + ~textDocument: + (TextDocumentItem.create ~uri:client_uri ~text:source ~version:0 + ~languageId:(LanguageKind.Other "rescript"))) + ~position_encoding:`UTF16 + in + let doc_store = Document_store.make () in + ignore (Document_store.add doc_store ~doc); + let entry path kind = + {Compiler_log.Parse.kind; path; message = "compiler"; range = None} + in + let convert path kind = + to_lsp_format ~include_syntax:true ~include_non_syntax:true + workspace_root doc_store + [entry path kind] + in + let absolute = + Compiler_log.Parse.Full_path {|D:\a\project\src\Broken.res|} + in + let relative = Compiler_log.Parse.Relative_path {|src\Broken.res|} in + let compiler = convert absolute Common_error in + let relative_compiler = convert relative Common_error in + Printf.printf "absolute compiler diagnostics: %d\n" + (List.length (Uri_map.find client_uri compiler)); + Printf.printf "relative compiler diagnostics: %d\n" + (List.length (Uri_map.find client_uri relative_compiler)); + Printf.printf "open compiler syntax diagnostics: %d\n" + (Uri_map.cardinal (convert absolute Syntax_error)); + let compiler_diagnostic = List.hd (Uri_map.find client_uri compiler) in + Printf.printf "fallback range uses open buffer: %b\n" + (compiler_diagnostic.range = Document.range_of_text source); + let t = + make ~diagnostics:compiler + ~send:(fun ({diagnostics} : PublishDiagnosticsParams.t) -> + Printf.printf "pushed diagnostics: %d\n" (List.length diagnostics)) + |> update_syntax ~uri:client_uri + ~new_diagnostics: + [ + Diagnostic.create + ~range:(Document.range_of_text source) + ~message:(`String "buffer") (); + ] + in + Printf.printf "merged URI keys: %d\n" (Uri_map.cardinal (get_all t)); + Printf.printf "merged diagnostics: %d\n" + (List.length (Uri_map.find client_uri (get_all t))); + send ~include_syntax:false ~force_publish_uris:[client_uri] + ~should_publish:(fun uri -> + Document_store.get_opt doc_store ~uri = None) + t; + ignore (Document_store.remove doc_store ~uri:compiler_uri); + let t = clear_syntax ~uri:compiler_uri t in + send t; + send (update_compiler ~new_diagnostics:(empty ()) t); + Printf.printf "filename case remains distinct: %b\n" + (Uri_map.cardinal + (Uri_map.empty |> Uri_map.add client_uri [] + |> Uri_map.add + (Uri.of_string "file:///d%3A/a/project/src/broken.res") + []) + = 2)); + [%expect + {| + absolute compiler diagnostics: 1 + relative compiler diagnostics: 1 + open compiler syntax diagnostics: 0 + fallback range uses open buffer: true + merged URI keys: 1 + merged diagnostics: 2 + pushed diagnostics: 0 + pushed diagnostics: 1 + pushed diagnostics: 0 + filename case remains distinct: true + |}] diff --git a/tests/lsp_unit_tests/document.ml b/tests/lsp_unit_tests/document.ml new file mode 100644 index 00000000000..e03c102fc43 --- /dev/null +++ b/tests/lsp_unit_tests/document.ml @@ -0,0 +1,52 @@ +open Lsp.Types +open Rescript_language_server_core.Document + +let%expect_test "range_of_text" = + let print text = + let range = range_of_text text in + Yojson.Safe.pretty_to_string + (`Assoc + [ + ("start", range.start |> Position.yojson_of_t); + ("end", range.end_ |> Position.yojson_of_t); + ]) + |> print_endline + in + print ""; + print "let a = 1"; + print "let a = 1\nlet b = 2"; + print "let a = 1\n"; + print "\xC3\xA9"; + print "ab"; + print "ab\ncd"; + [%expect + {| + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 0, "line": 0 } + } + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 9, "line": 0 } + } + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 9, "line": 1 } + } + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 0, "line": 1 } + } + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 2, "line": 0 } + } + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 2, "line": 0 } + } + { + "start": { "character": 0, "line": 0 }, + "end": { "character": 2, "line": 1 } + } + |}] diff --git a/tests/lsp_unit_tests/document_store.ml b/tests/lsp_unit_tests/document_store.ml new file mode 100644 index 00000000000..4cebe2672cd --- /dev/null +++ b/tests/lsp_unit_tests/document_store.ml @@ -0,0 +1,39 @@ +open Lsp +open Rescript_language_server_core +open Rescript_language_server_core.Document_store + +let%expect_test "drive-letter variants identify the same open document" = + let upper = Uri.of_string "file:///D%3A/project/Broken.res" in + let lower = Uri.of_string "file:///d%3A/project/Broken.res" in + let make_doc uri text version = + Document.make + (Lsp.Types.DidOpenTextDocumentParams.create + ~textDocument: + (Lsp.Types.TextDocumentItem.create ~uri ~text ~version + ~languageId:(Lsp.Types.LanguageKind.Other "rescript"))) + ~position_encoding:`UTF16 + in + let store = make () in + let doc = make_doc upper "let value = 1" 0 in + ignore (add store ~doc); + Printf.printf "alternate drive lookup: %b\n" (get store ~uri:lower = doc); + Printf.printf "original client URI retained: %b\n" + (Uri.equal (Document.uri (get store ~uri:lower)) upper); + (try + ignore (add store ~doc:(make_doc lower "let value = 2" 0)); + failwith "Expected a duplicate-document error" + with Jsonrpc.Response.Error.E error -> print_endline error.message); + ignore (update store ~doc:(make_doc lower "let value = 3" 1)); + Printf.printf "updated through alternate drive: %s\n" + (Document.text (get store ~uri:upper)); + ignore (remove store ~uri:upper); + Printf.printf "closed through alternate drive: %b\n" + (get_opt store ~uri:lower = None); + [%expect + {| + alternate drive lookup: true + original client URI retained: true + Cannot open document file:///d%3A/project/Broken.res: it is already open. + updated through alternate drive: let value = 3 + closed through alternate drive: true + |}] diff --git a/tests/lsp_unit_tests/dune b/tests/lsp_unit_tests/dune new file mode 100644 index 00000000000..8734bff7741 --- /dev/null +++ b/tests/lsp_unit_tests/dune @@ -0,0 +1,6 @@ +(library + (name rescript_lsp_unit_tests) + (libraries rescript_language_server_core lsp yojson) + (inline_tests) + (preprocess + (pps ppx_expect))) diff --git a/tests/lsp_unit_tests/source_dirs.ml b/tests/lsp_unit_tests/source_dirs.ml new file mode 100644 index 00000000000..7635ed6cb29 --- /dev/null +++ b/tests/lsp_unit_tests/source_dirs.ml @@ -0,0 +1,90 @@ +open Rescript_language_server_core.Source_dirs + +let%expect_test "get_build_roots" = + let print_build_roots result = + match result with + | None -> () + | Some l -> List.iter print_endline l + in + let json_1 = + Yojson.Safe.from_string + {| +{ + "cmt_scan": [ + { + "build_root": "path/to/lib/bs" + } + ] +} + |} + in + + json_1 |> get_build_roots_from_json |> print_build_roots; + [%expect {| path/to/lib/bs |}]; + + let json_2 = + Yojson.Safe.from_string + {| +{ +"cmt_scan": [ + { + "build_root": "path/to/lib/bs" + }, + { + "build_root": "path2/to/lib/bs" + } +] +} + |} + in + + json_2 |> get_build_roots_from_json |> print_build_roots; + [%expect {| + path/to/lib/bs + path2/to/lib/bs + |}]; + + let json_3 = + Yojson.Safe.from_string + {| +{ +"cmt_scan": [ +{ + "build_root": [] +}, +{ + "build_root": {} +} +] +} +|} + in + + json_3 |> get_build_roots_from_json |> print_build_roots; + [%expect {| |}] + +let%expect_test "source directory metadata rejects incomplete scan entries" = + List.iter + (fun text -> + match get_build_roots_from_json (Yojson.Safe.from_string text) with + | None -> print_endline "invalid" + | Some roots -> + `List (List.map (fun root -> `String root) roots) + |> Yojson.Safe.to_string |> print_endline) + [ + {|{}|}; + {|{"cmt_scan":null}|}; + {|{"cmt_scan":[]}|}; + {|{"cmt_scan":[{"build_root":"lib/rescript"},{}]}|}; + {|{"cmt_scan":[{"build_root":null}]}|}; + {|{"version":2,"cmt_scan":[{"build_root":"lib/rescript","scan_dirs":[]}]}|}; + ]; + [%expect + {| + invalid + invalid + [] + invalid + invalid + ["lib/rescript"] + |}] From 963d40c4adf8c4fef6c64d033ecc49cb2487869c Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 23 Nov 2026 11:11:21 -0300 Subject: [PATCH 13/13] Fix stale tests in definition.ml One outdated snapshot remains: definition.ml:168 expects Test.resi, but master commit c83f5afe4 intentionally changed definition navigation from an interface declaration to its implementation, Test.res. Signed-off-by: Pedro Castro --- tests/lsp_tests/definition.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/lsp_tests/definition.ml b/tests/lsp_tests/definition.ml index cc32e4efc7e..8e7f28288e9 100644 --- a/tests/lsp_tests/definition.ml +++ b/tests/lsp_tests/definition.ml @@ -143,7 +143,8 @@ type typeInner = Inner.tInner ] |}] -let%expect_test "finds a value declaration in an open interface" = +let%expect_test "navigates from an interface declaration to its implementation" + = Test.with_project ~name:"definition" ~text:{|let y = 4 |} ~files:[("Test.resi", {|let y: int @@ -165,7 +166,7 @@ let%expect_test "finds a value declaration in an open interface" = "end": { "character": 5, "line": 0 }, "start": { "character": 4, "line": 0 } }, - "uri": "file:///workspace/Test.resi" + "uri": "file:///workspace/Test.res" } ] |}]