Skip to content

Commit 687d9f2

Browse files
committed
Merge branch 'master' of github.com:/ocaml/ocaml-lsp into Add-ocamlformat-mlx
* 'master' of github.com:/ocaml/ocaml-lsp: Rename parameter used to configure nested bindings. (#1568) Upgrade to ocamlformat 0.28.1 (#1569) Improve precision of duration field in `view-metrics` (#1565) Make `code-lens` for toplevel let binding configurable (#1567) Fix 5.4 CI Enable support for OCaml 5.4 and prepare release 1.24.0 (#1559) Prepare release 1.23.1 (#1558)
2 parents faa56da + 8403a24 commit 687d9f2

19 files changed

+295
-130
lines changed

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

Lines changed: 4 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: "ocaml-base-compiler.5.3.0"
48+
ocaml-compiler: "5.4"
4949

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

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

8686
- name: Set git user
8787
run: |
@@ -90,7 +90,7 @@ jobs:
9090
9191
# Remove this pin once a compatible version of Merlin has been released
9292
- name: Pin dev Merlin
93-
run: opam --cli=2.1 pin --with-version=5.5-503 https://github.com/ocaml/merlin.git#main
93+
run: opam --cli=2.1 pin --with-version=5.6-504 https://github.com/voodoos/merlin.git#504-rebase
9494

9595
- name: Install dependencies
9696
run: |

.ocamlformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
version=0.27.0
1+
version=0.28.1
22
profile=janestreet
33
ocaml-version=4.14.0

CHANGES.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
# unreleased
1+
# Unreleased
2+
3+
## Features
4+
5+
- Make `code-lens` for nested let bindings configurable (#1567)
6+
7+
## Fixes
8+
9+
- Improve precision of collected metrics timestamps. (#1565)
10+
11+
# 1.24.0
12+
13+
## Features
14+
15+
- Support for OCaml 5.4 (#1559)
16+
17+
# 1.23.1
218

319
## Features
420

@@ -9,6 +25,7 @@
925

1026
- Fix hover on method calls not showing the type. (#1553, fixes #1552)
1127
- Fix error on opening `.mll` files (#1557)
28+
- Ensure compatibility with both yojson 2.0 and 3.0. (#1534)
1229

1330
# 1.23.0
1431

@@ -26,7 +43,6 @@
2643
- Fix `inlay-hint` for function parameters (#1515)
2744
- More precise diagnostics in the event of a failed identifier search (`Definition_query`) (#1518)
2845
- Remove `ocamlformat` application after `destruct` (that remove some useful parenthesis) (#1519)
29-
- Make compatible with Yojson 3.x by removing `Tuple` and `Variant` (#1534)
3046

3147
# 1.22.0
3248

dune-project

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,22 @@ 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.3) (< 5.4)))
59+
(ocaml (and (>= 5.4) (< 5.5)))
6060
xdg
6161
ordering
6262
dune-build-info
6363
spawn
6464
astring
6565
camlp-streams
6666
(ppx_expect (and (>= v0.17.0) :with-test))
67-
(ocamlformat (and :with-test (= 0.27.0)))
67+
(ocamlformat (and :with-test (= 0.28.1)))
6868
(ocamlc-loc (>= 3.7.0))
6969
(pp (>= 1.1.2))
7070
(csexp (>= 1.5))
7171
(ocamlformat-rpc-lib (>= 0.21.0))
7272
(odoc :with-doc)
73-
(merlin-lib (and (>= 5.5) (< 6.0)))
73+
(merlin-lib (and (>= 5.6) (< 5.7)))
74+
(ocaml-index :post)
7475
(ppx_yojson_conv :with-dev-setup)))
7576

7677
(package

ocaml-lsp-server.opam

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,22 @@ depends: [
3131
"dyn"
3232
"stdune"
3333
"fiber" {>= "3.1.1" & < "4.0.0"}
34-
"ocaml" {>= "5.3" & < "5.4"}
34+
"ocaml" {>= "5.4" & < "5.5"}
3535
"xdg"
3636
"ordering"
3737
"dune-build-info"
3838
"spawn"
3939
"astring"
4040
"camlp-streams"
4141
"ppx_expect" {>= "v0.17.0" & with-test}
42-
"ocamlformat" {with-test & = "0.27.0"}
42+
"ocamlformat" {with-test & = "0.28.1"}
4343
"ocamlc-loc" {>= "3.7.0"}
4444
"pp" {>= "1.1.2"}
4545
"csexp" {>= "1.5"}
4646
"ocamlformat-rpc-lib" {>= "0.21.0"}
4747
"odoc" {with-doc}
48-
"merlin-lib" {>= "5.5" & < "6.0"}
48+
"merlin-lib" {>= "5.6" & < "5.7"}
49+
"ocaml-index" {post}
4950
"ppx_yojson_conv" {with-dev-setup}
5051
]
5152
dev-repo: "git+https://github.com/ocaml/ocaml-lsp.git"

ocaml-lsp-server/docs/ocamllsp/config.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@ interface config {
1515
*/
1616
extendedHover: { enable : boolean }
1717

18-
/**
19-
* Enable/Disable CodeLens
20-
* @default false
21-
* @since 1.16
22-
*/
23-
codelens: { enable : boolean }
18+
codelens: {
19+
/**
20+
* Enable/Disable CodeLens
21+
* @default false
22+
* @since 1.16
23+
*/
24+
enable : boolean,
25+
26+
/**
27+
* Enable CodeLens for nested let bindings
28+
* @default false
29+
* @since 1.25
30+
*/
31+
forNestedBindings : boolean
32+
}
2433

2534
/**
2635
* Enable/Disable Dune diagnostics

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ end = struct
160160
let pat_iter (type k) (iter : I.iterator) (pat : k Typedtree.general_pattern) =
161161
match pat.pat_desc with
162162
| Tpat_var (id, { loc; _ }, _) -> paths := Loc.Map.set !paths loc (Pident id)
163-
| Tpat_alias (pat, id, { loc; _ }, _) ->
163+
| Tpat_alias (pat, id, { loc; _ }, _, _) ->
164164
paths := Loc.Map.set !paths loc (Pident id);
165165
I.default_iterator.pat iter pat
166166
| _ -> I.default_iterator.pat iter pat
@@ -217,9 +217,12 @@ let beta_reduce (paths : Paths.t) (app : Parsetree.expression) =
217217
if is_pure arg then body else with_let ()
218218
| Ppat_var param | Ppat_constraint ({ ppat_desc = Ppat_var param; _ }, _) ->
219219
if is_pure arg then with_subst param else with_let ()
220-
| Ppat_tuple pats ->
220+
| Ppat_tuple (pats, _) ->
221+
let pats = List.map ~f:snd pats in
221222
(match arg.pexp_desc with
222-
| Pexp_tuple args -> List.fold_left2 ~f:beta_reduce_arg ~init:body pats args
223+
| Pexp_tuple args ->
224+
let args = List.map ~f:snd args in
225+
List.fold_left2 ~f:beta_reduce_arg ~init:body pats args
223226
| _ -> with_let ())
224227
| _ -> with_let ()
225228
in
@@ -275,16 +278,16 @@ let inline_edits pipeline task =
275278
env
276279
(iter : I.iterator)
277280
(label : Asttypes.arg_label)
278-
(m_arg_expr : Typedtree.expression option)
281+
(m_arg_expr : Typedtree.apply_arg)
279282
=
280283
match label, m_arg_expr with
281284
(* handle the labeled argument shorthand `f ~x` when inlining `x` *)
282-
| Labelled name, Some { exp_desc = Texp_ident (Pident id, { loc; _ }, _); _ }
285+
| Labelled name, Arg { exp_desc = Texp_ident (Pident id, { loc; _ }, _); _ }
283286
(* inlining is allowed for optional arguments that are being passed a Some
284287
parameter, i.e. `x` may be inlined in `let x = 1 in (fun ?(x = 0) -> x)
285288
~x` *)
286289
| ( Optional name
287-
, Some
290+
, Arg
288291
{ exp_desc =
289292
(* construct is part of desugaring, assumed to be Some *)
290293
Texp_construct
@@ -294,13 +297,14 @@ let inline_edits pipeline task =
294297
when Ident.same task.inlined_var id && not_shadowed env ->
295298
let newText = sprintf "%s:%s" name newText in
296299
insert_edit newText loc
297-
| Optional _, Some ({ exp_desc = Texp_construct _; _ } as arg_expr) ->
300+
| Optional _, Arg ({ exp_desc = Texp_construct _; _ } as arg_expr) ->
298301
iter.expr iter arg_expr
299302
(* inlining is _not_ allowed for optional arguments that are being passed an
300303
optional parameter i.e. `x` may _not_ be inlined in `let x = Some 1 in
301304
(fun ?(x = 0) -> x) ?x` *)
302-
| Optional _, Some _ -> ()
303-
| _, _ -> Option.iter m_arg_expr ~f:(iter.expr iter)
305+
| Optional _, Arg _ -> ()
306+
| _, Arg arg -> iter.expr iter arg
307+
| _, _ -> ()
304308
in
305309
let paths = Paths.of_typedtree task.inlined_expr in
306310
let inlined_pexpr = find_parsetree_loc_exn pipeline task.inlined_expr.exp_loc in

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ let rec mark_value_unused_edit name contexts =
8989
{ range = Range.create ~start:start_pos ~end_:start_pos; newText = "_" }
9090
| _ -> None
9191
: Longident.t Loc.loc
92-
* Types.label_description
92+
* Data_types.label_description
9393
* Typedtree.value Typedtree.general_pattern
9494
-> TextEdit.t option)
9595
in

ocaml-lsp-server/src/config_data.ml

Lines changed: 73 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -192,70 +192,91 @@ module InlayHints = struct
192192
end
193193

194194
module Lens = struct
195-
type t = { enable : bool [@default true] }
195+
type t =
196+
{ enable : bool [@default true]
197+
; for_nested_bindings : bool [@key "forNestedBindings"] [@default false]
198+
}
196199
[@@deriving_inline yojson] [@@yojson.allow_extra_fields]
197200

198201
let _ = fun (_ : t) -> ()
199202

200-
let t_of_yojson =
201-
(let _tp_loc = "ocaml-lsp-server/src/config_data.ml.Lens.t" in
202-
function
203-
| `Assoc field_yojsons as yojson ->
203+
204+
let t_of_yojson =
205+
(let _tp_loc = "ocaml-lsp-server/src/config_data.ml.Lens.t" in
206+
function
207+
| `Assoc field_yojsons as yojson ->
204208
let enable_field = ref Ppx_yojson_conv_lib.Option.None
209+
and for_nested_bindings_field = ref Ppx_yojson_conv_lib.Option.None
205210
and duplicates = ref []
206211
and extra = ref [] in
207-
let rec iter = function
208-
| (field_name, _field_yojson) :: tail ->
209-
(match field_name with
210-
| "enable" ->
211-
(match Ppx_yojson_conv_lib.( ! ) enable_field with
212-
| Ppx_yojson_conv_lib.Option.None ->
213-
let fvalue = bool_of_yojson _field_yojson in
214-
enable_field := Ppx_yojson_conv_lib.Option.Some fvalue
215-
| Ppx_yojson_conv_lib.Option.Some _ ->
216-
duplicates := field_name :: Ppx_yojson_conv_lib.( ! ) duplicates)
217-
| _ -> ());
218-
iter tail
219-
| [] -> ()
220-
in
221-
iter field_yojsons;
222-
(match Ppx_yojson_conv_lib.( ! ) duplicates with
223-
| _ :: _ ->
224-
Ppx_yojson_conv_lib.Yojson_conv_error.record_duplicate_fields
225-
_tp_loc
226-
(Ppx_yojson_conv_lib.( ! ) duplicates)
227-
yojson
228-
| [] ->
229-
(match Ppx_yojson_conv_lib.( ! ) extra with
230-
| _ :: _ ->
231-
Ppx_yojson_conv_lib.Yojson_conv_error.record_extra_fields
232-
_tp_loc
233-
(Ppx_yojson_conv_lib.( ! ) extra)
234-
yojson
235-
| [] ->
236-
let enable_value = Ppx_yojson_conv_lib.( ! ) enable_field in
237-
{ enable =
238-
(match enable_value with
239-
| Ppx_yojson_conv_lib.Option.None -> true
240-
| Ppx_yojson_conv_lib.Option.Some v -> v)
241-
}))
242-
| _ as yojson ->
243-
Ppx_yojson_conv_lib.Yojson_conv_error.record_list_instead_atom _tp_loc yojson
244-
: Ppx_yojson_conv_lib.Yojson.Safe.t -> t)
212+
let rec iter =
213+
function
214+
| (field_name, _field_yojson)::tail ->
215+
((match field_name with
216+
| "enable" ->
217+
(match Ppx_yojson_conv_lib.(!) enable_field with
218+
| Ppx_yojson_conv_lib.Option.None ->
219+
let fvalue = bool_of_yojson _field_yojson in
220+
enable_field :=
221+
(Ppx_yojson_conv_lib.Option.Some fvalue)
222+
| Ppx_yojson_conv_lib.Option.Some _ ->
223+
duplicates := (field_name ::
224+
(Ppx_yojson_conv_lib.(!) duplicates)))
225+
| "forNestedBindings" ->
226+
(match Ppx_yojson_conv_lib.(!) for_nested_bindings_field
227+
with
228+
| Ppx_yojson_conv_lib.Option.None ->
229+
let fvalue = bool_of_yojson _field_yojson in
230+
for_nested_bindings_field :=
231+
(Ppx_yojson_conv_lib.Option.Some fvalue)
232+
| Ppx_yojson_conv_lib.Option.Some _ ->
233+
duplicates := (field_name ::
234+
(Ppx_yojson_conv_lib.(!) duplicates)))
235+
| _ -> ());
236+
iter tail)
237+
| [] -> () in
238+
(iter field_yojsons;
239+
(match Ppx_yojson_conv_lib.(!) duplicates with
240+
| _::_ ->
241+
Ppx_yojson_conv_lib.Yojson_conv_error.record_duplicate_fields
242+
_tp_loc (Ppx_yojson_conv_lib.(!) duplicates) yojson
243+
| [] ->
244+
(match Ppx_yojson_conv_lib.(!) extra with
245+
| _::_ ->
246+
Ppx_yojson_conv_lib.Yojson_conv_error.record_extra_fields
247+
_tp_loc (Ppx_yojson_conv_lib.(!) extra) yojson
248+
| [] ->
249+
let (enable_value, for_nested_bindings_value) =
250+
((Ppx_yojson_conv_lib.(!) enable_field),
251+
(Ppx_yojson_conv_lib.(!) for_nested_bindings_field)) in
252+
{
253+
enable =
254+
((match enable_value with
255+
| Ppx_yojson_conv_lib.Option.None -> true
256+
| Ppx_yojson_conv_lib.Option.Some v -> v));
257+
for_nested_bindings =
258+
((match for_nested_bindings_value with
259+
| Ppx_yojson_conv_lib.Option.None -> false
260+
| Ppx_yojson_conv_lib.Option.Some v -> v))
261+
})))
262+
| _ as yojson ->
263+
Ppx_yojson_conv_lib.Yojson_conv_error.record_list_instead_atom _tp_loc
264+
yojson : Ppx_yojson_conv_lib.Yojson.Safe.t -> t)
245265
;;
246266

247267
let _ = t_of_yojson
248268

249-
let yojson_of_t =
250-
(function
251-
| { enable = v_enable } ->
269+
270+
let yojson_of_t =
271+
(function
272+
| { enable = v_enable; for_nested_bindings = v_for_nested_bindings } ->
252273
let bnds : (string * Ppx_yojson_conv_lib.Yojson.Safe.t) list = [] in
253274
let bnds =
254-
let arg = yojson_of_bool v_enable in
255-
("enable", arg) :: bnds
256-
in
257-
`Assoc bnds
258-
: t -> Ppx_yojson_conv_lib.Yojson.Safe.t)
275+
let arg = yojson_of_bool v_for_nested_bindings in
276+
("forNestedBindings", arg) :: bnds in
277+
let bnds =
278+
let arg = yojson_of_bool v_enable in ("enable", arg) :: bnds in
279+
`Assoc bnds : t -> Ppx_yojson_conv_lib.Yojson.Safe.t)
259280
;;
260281

261282
let _ = yojson_of_t
@@ -921,7 +942,7 @@ let _ = yojson_of_t
921942
[@@@end]
922943

923944
let default =
924-
{ codelens = Some { enable = false }
945+
{ codelens = Some { enable = false; for_nested_bindings = false }
925946
; extended_hover = Some { enable = false }
926947
; standard_hover = Some { enable = true }
927948
; inlay_hints =

ocaml-lsp-server/src/document.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ end = struct
160160
let task =
161161
match
162162
Lev_fiber.Thread.task t.thread ~f:(fun () ->
163-
let start = Unix.time () in
163+
let start = Unix.gettimeofday () in
164164
let pipeline = make_pipeline () in
165165
let res = Mpipeline.with_pipeline pipeline (fun () -> f pipeline) in
166-
let stop = Unix.time () in
166+
let stop = Unix.gettimeofday () in
167167
res, start, stop)
168168
with
169169
| Error `Stopped -> assert false

0 commit comments

Comments
 (0)