diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 689eee755..61b15b91e 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -45,11 +45,11 @@ jobs: - name: Set-up OCaml uses: ocaml/setup-ocaml@v3 with: - ocaml-compiler: "5.2" + ocaml-compiler: "ocaml-base-compiler.5.3.0" # Remove this pin once a compatible version of Merlin has been released - # - name: Pin dev Merlin - # run: opam pin https://github.com/ocaml/merlin.git#main + - name: Pin dev Merlin + run: opam --cli=2.1 pin --with-version=5.4-503 https://github.com/ocaml/merlin.git#main - name: Build and install dependencies run: opam install . @@ -81,13 +81,17 @@ jobs: - name: Set-up OCaml uses: ocaml/setup-ocaml@v3 with: - ocaml-compiler: "5.2" + ocaml-compiler: "ocaml-base-compiler.5.3.0" - name: Set git user run: | git config --global user.name github-actions[bot] git config --global user.email github-actions[bot]@users.noreply.github.com + # Remove this pin once a compatible version of Merlin has been released + - name: Pin dev Merlin + run: opam --cli=2.1 pin --with-version=5.4-503 https://github.com/ocaml/merlin.git#main + - name: Install dependencies run: | opam install . --deps-only diff --git a/CHANGES.md b/CHANGES.md index e1749bd08..77c5c2f37 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,7 @@ [`ocamllsp/typeSearch`](/ocaml-lsp-server/docs/ocamllsp/typeSearch-spec.md) request (#1369) - Make MerlinJump code action configurable (#1376) +- Add support for OCaml 5.3 (#1386) - Add custom [`ocamllsp/jump`](/ocaml-lsp-server/docs/ocamllsp/merlinJump-spec.md) request (#1374) diff --git a/dune-project b/dune-project index a583cd964..8c1d67e8e 100644 --- a/dune-project +++ b/dune-project @@ -56,7 +56,7 @@ possible and does not make any assumptions about IO. dyn stdune (fiber (and (>= 3.1.1) (< 4.0.0))) - (ocaml (and (>= 5.2.0) (< 5.3))) + (ocaml (and (>= 5.3) (< 5.4))) xdg ordering dune-build-info @@ -70,7 +70,7 @@ possible and does not make any assumptions about IO. (csexp (>= 1.5)) (ocamlformat-rpc-lib (>= 0.21.0)) (odoc :with-doc) - (merlin-lib (and (>= 5.2) (< 6.0))) + (merlin-lib (and (>= 5.4) (< 6.0))) (ppx_yojson_conv :with-dev-setup))) (package diff --git a/ocaml-lsp-server.opam b/ocaml-lsp-server.opam index bf21a7132..ac47b51b7 100644 --- a/ocaml-lsp-server.opam +++ b/ocaml-lsp-server.opam @@ -31,7 +31,7 @@ depends: [ "dyn" "stdune" "fiber" {>= "3.1.1" & < "4.0.0"} - "ocaml" {>= "5.2.0" & < "5.3"} + "ocaml" {>= "5.3" & < "5.4"} "xdg" "ordering" "dune-build-info" @@ -45,7 +45,7 @@ depends: [ "csexp" {>= "1.5"} "ocamlformat-rpc-lib" {>= "0.21.0"} "odoc" {with-doc} - "merlin-lib" {>= "5.2" & < "6.0"} + "merlin-lib" {>= "5.4" & < "6.0"} "ppx_yojson_conv" {with-dev-setup} ] dev-repo: "git+https://github.com/ocaml/ocaml-lsp.git" diff --git a/ocaml-lsp-server/src/code_actions/action_extract.ml b/ocaml-lsp-server/src/code_actions/action_extract.ml index 00358f213..7946c50f4 100644 --- a/ocaml-lsp-server/src/code_actions/action_extract.ml +++ b/ocaml-lsp-server/src/code_actions/action_extract.ml @@ -1,6 +1,7 @@ open Import open Option.O module H = Ocaml_parsing.Ast_helper +module Typedtree_utils = Merlin_analysis.Typedtree_utils let range_contains_loc range loc = match Range.of_loc_opt loc with @@ -75,8 +76,12 @@ let tightest_enclosing_binder_position typedtree range = | Texp_open (_, body) -> found_if_expr_contains body | Texp_letop { body; _ } -> found_if_case_contains [ body ] | Texp_function (_, Tfunction_cases { cases; _ }) -> found_if_case_contains cases - | Texp_match (_, cases, _) -> found_if_case_contains cases - | Texp_try (_, cases) -> found_if_case_contains cases + | Texp_match _ -> + let m = Typedtree_utils.texp_match_of_expr expr |> Option.value_exn in + found_if_case_contains m.computation_cases + | Texp_try _ -> + let t = Typedtree_utils.texp_try_of_expr expr |> Option.value_exn in + found_if_case_contains t.value_cases | _ -> ()) in let structure_item_iter (iter : I.iterator) (item : Typedtree.structure_item) = diff --git a/ocaml-lsp-server/src/folding_range.ml b/ocaml-lsp-server/src/folding_range.ml index 68c00e6ac..089e41548 100644 --- a/ocaml-lsp-server/src/folding_range.ml +++ b/ocaml-lsp-server/src/folding_range.ml @@ -159,7 +159,8 @@ let fold_over_parsetree (parsetree : Mreader.parsetree) = | Ppat_exception _ | Ppat_extension _ | Ppat_open _ - | Ppat_any -> Ast_iterator.default_iterator.pat self p + | Ppat_any + | _ -> Ast_iterator.default_iterator.pat self p in let expr (self : Ast_iterator.iterator) (expr : Parsetree.expression) = match expr.pexp_desc with diff --git a/ocaml-lsp-server/src/semantic_highlighting.ml b/ocaml-lsp-server/src/semantic_highlighting.ml index 9aaa4eb07..c48a34e9f 100644 --- a/ocaml-lsp-server/src/semantic_highlighting.ml +++ b/ocaml-lsp-server/src/semantic_highlighting.ml @@ -1,6 +1,7 @@ open Import open Fiber.O module Array_view = Lsp.Private.Array_view +module Parsetree_utils = Merlin_analysis.Parsetree_utils (* TODO: @@ -508,7 +509,7 @@ end = struct let const loc (constant : Parsetree.constant) = let token_type = - match constant with + match Parsetree_utils.constant_desc constant with | Parsetree.Pconst_integer _ | Pconst_float _ -> Token_type.of_builtin Number | Pconst_char _ | Pconst_string _ -> Token_type.of_builtin String in @@ -719,7 +720,8 @@ end = struct | Ppat_tuple _ | Ppat_lazy _ | Ppat_any - | Ppat_interval _ -> `Default_iterator + | Ppat_interval _ + | _ -> `Default_iterator with | `Default_iterator -> Ast_iterator.default_iterator.pat self pat | `Custom_iterator -> self.attributes self ppat_attributes diff --git a/ocaml-lsp-server/test/e2e/__tests__/textDocument-diagnostics.ts b/ocaml-lsp-server/test/e2e/__tests__/textDocument-diagnostics.ts index 9c28eac96..248ffc898 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/textDocument-diagnostics.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/textDocument-diagnostics.ts @@ -410,7 +410,7 @@ The type int is not compatible with the type unit", { "diagnostics": [ { - "message": "This expression has type unit but an expression was expected of type int", + "message": "The constructor () has type unit but an expression was expected of type int", "range": { "end": { "character": 42, @@ -457,7 +457,7 @@ The type int is not compatible with the type unit", "source": "ocamllsp", }, { - "message": "This expression has type string but an expression was expected of type int", + "message": "This constant has type string but an expression was expected of type int", "range": { "end": { "character": 9,