Skip to content

Commit a7ce29f

Browse files
authored
Compatibility with Merlin 503 (#1386)
* Use compat lib where required * Update compiler and merlin version in pkg and ci * Promote normal tests changes
1 parent 6cde996 commit a7ce29f

File tree

8 files changed

+28
-15
lines changed

8 files changed

+28
-15
lines changed

.github/workflows/build-and-test.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ jobs:
4545
- name: Set-up OCaml
4646
uses: ocaml/setup-ocaml@v3
4747
with:
48-
ocaml-compiler: "5.2"
48+
ocaml-compiler: "ocaml-base-compiler.5.3.0"
4949

5050
# Remove this pin once a compatible version of Merlin has been released
51-
# - name: Pin dev Merlin
52-
# run: opam pin https://github.com/ocaml/merlin.git#main
51+
- name: Pin dev Merlin
52+
run: opam --cli=2.1 pin --with-version=5.4-503 https://github.com/ocaml/merlin.git#main
5353

5454
- name: Build and install dependencies
5555
run: opam install .
@@ -81,13 +81,17 @@ jobs:
8181
- name: Set-up OCaml
8282
uses: ocaml/setup-ocaml@v3
8383
with:
84-
ocaml-compiler: "5.2"
84+
ocaml-compiler: "ocaml-base-compiler.5.3.0"
8585

8686
- name: Set git user
8787
run: |
8888
git config --global user.name github-actions[bot]
8989
git config --global user.email github-actions[bot]@users.noreply.github.com
9090
91+
# Remove this pin once a compatible version of Merlin has been released
92+
- name: Pin dev Merlin
93+
run: opam --cli=2.1 pin --with-version=5.4-503 https://github.com/ocaml/merlin.git#main
94+
9195
- name: Install dependencies
9296
run: |
9397
opam install . --deps-only

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
[`ocamllsp/typeSearch`](/ocaml-lsp-server/docs/ocamllsp/typeSearch-spec.md) request (#1369)
2323

2424
- Make MerlinJump code action configurable (#1376)
25+
- Add support for OCaml 5.3 (#1386)
2526

2627
- Add custom [`ocamllsp/jump`](/ocaml-lsp-server/docs/ocamllsp/merlinJump-spec.md) request (#1374)
2728

dune-project

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ possible and does not make any assumptions about IO.
5656
dyn
5757
stdune
5858
(fiber (and (>= 3.1.1) (< 4.0.0)))
59-
(ocaml (and (>= 5.2.0) (< 5.3)))
59+
(ocaml (and (>= 5.3) (< 5.4)))
6060
xdg
6161
ordering
6262
dune-build-info
@@ -70,7 +70,7 @@ possible and does not make any assumptions about IO.
7070
(csexp (>= 1.5))
7171
(ocamlformat-rpc-lib (>= 0.21.0))
7272
(odoc :with-doc)
73-
(merlin-lib (and (>= 5.2) (< 6.0)))
73+
(merlin-lib (and (>= 5.4) (< 6.0)))
7474
(ppx_yojson_conv :with-dev-setup)))
7575

7676
(package

ocaml-lsp-server.opam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ depends: [
3131
"dyn"
3232
"stdune"
3333
"fiber" {>= "3.1.1" & < "4.0.0"}
34-
"ocaml" {>= "5.2.0" & < "5.3"}
34+
"ocaml" {>= "5.3" & < "5.4"}
3535
"xdg"
3636
"ordering"
3737
"dune-build-info"
@@ -45,7 +45,7 @@ depends: [
4545
"csexp" {>= "1.5"}
4646
"ocamlformat-rpc-lib" {>= "0.21.0"}
4747
"odoc" {with-doc}
48-
"merlin-lib" {>= "5.2" & < "6.0"}
48+
"merlin-lib" {>= "5.4" & < "6.0"}
4949
"ppx_yojson_conv" {with-dev-setup}
5050
]
5151
dev-repo: "git+https://github.com/ocaml/ocaml-lsp.git"

ocaml-lsp-server/src/code_actions/action_extract.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
open Import
22
open Option.O
33
module H = Ocaml_parsing.Ast_helper
4+
module Typedtree_utils = Merlin_analysis.Typedtree_utils
45

56
let range_contains_loc range loc =
67
match Range.of_loc_opt loc with
@@ -75,8 +76,12 @@ let tightest_enclosing_binder_position typedtree range =
7576
| Texp_open (_, body) -> found_if_expr_contains body
7677
| Texp_letop { body; _ } -> found_if_case_contains [ body ]
7778
| Texp_function (_, Tfunction_cases { cases; _ }) -> found_if_case_contains cases
78-
| Texp_match (_, cases, _) -> found_if_case_contains cases
79-
| Texp_try (_, cases) -> found_if_case_contains cases
79+
| Texp_match _ ->
80+
let m = Typedtree_utils.texp_match_of_expr expr |> Option.value_exn in
81+
found_if_case_contains m.computation_cases
82+
| Texp_try _ ->
83+
let t = Typedtree_utils.texp_try_of_expr expr |> Option.value_exn in
84+
found_if_case_contains t.value_cases
8085
| _ -> ())
8186
in
8287
let structure_item_iter (iter : I.iterator) (item : Typedtree.structure_item) =

ocaml-lsp-server/src/folding_range.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ let fold_over_parsetree (parsetree : Mreader.parsetree) =
159159
| Ppat_exception _
160160
| Ppat_extension _
161161
| Ppat_open _
162-
| Ppat_any -> Ast_iterator.default_iterator.pat self p
162+
| Ppat_any
163+
| _ -> Ast_iterator.default_iterator.pat self p
163164
in
164165
let expr (self : Ast_iterator.iterator) (expr : Parsetree.expression) =
165166
match expr.pexp_desc with

ocaml-lsp-server/src/semantic_highlighting.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
open Import
22
open Fiber.O
33
module Array_view = Lsp.Private.Array_view
4+
module Parsetree_utils = Merlin_analysis.Parsetree_utils
45

56
(* TODO:
67
@@ -508,7 +509,7 @@ end = struct
508509

509510
let const loc (constant : Parsetree.constant) =
510511
let token_type =
511-
match constant with
512+
match Parsetree_utils.constant_desc constant with
512513
| Parsetree.Pconst_integer _ | Pconst_float _ -> Token_type.of_builtin Number
513514
| Pconst_char _ | Pconst_string _ -> Token_type.of_builtin String
514515
in
@@ -719,7 +720,8 @@ end = struct
719720
| Ppat_tuple _
720721
| Ppat_lazy _
721722
| Ppat_any
722-
| Ppat_interval _ -> `Default_iterator
723+
| Ppat_interval _
724+
| _ -> `Default_iterator
723725
with
724726
| `Default_iterator -> Ast_iterator.default_iterator.pat self pat
725727
| `Custom_iterator -> self.attributes self ppat_attributes

ocaml-lsp-server/test/e2e/__tests__/textDocument-diagnostics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ The type int is not compatible with the type unit",
410410
{
411411
"diagnostics": [
412412
{
413-
"message": "This expression has type unit but an expression was expected of type int",
413+
"message": "The constructor () has type unit but an expression was expected of type int",
414414
"range": {
415415
"end": {
416416
"character": 42,
@@ -457,7 +457,7 @@ The type int is not compatible with the type unit",
457457
"source": "ocamllsp",
458458
},
459459
{
460-
"message": "This expression has type string but an expression was expected of type int",
460+
"message": "This constant has type string but an expression was expected of type int",
461461
"range": {
462462
"end": {
463463
"character": 9,

0 commit comments

Comments
 (0)