Skip to content

Commit 3758043

Browse files
authored
Merge pull request #86 from mbarbin/ppx_deriving_yojson
Switch to ppx_deriving_yojson
2 parents 3ea676a + 540e4a9 commit 3758043

27 files changed

+98
-108
lines changed

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 0.0.20250914 (2025-09-14)
2+
3+
### Changed
4+
5+
- Switch to `ppx_deriving_yojson` (#86, @mbarbin).
6+
7+
### Fixed
8+
9+
- Prepare for compatibility with OCaml 5.4.0 (#86, @mbarbin).
10+
111
## 0.0.20250911 (2025-09-11)
212

313
### Added

crs-dev.opam

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ depends: [
3434
"pp" {>= "2.0.0"}
3535
"pplumbing" {>= "0.0.14"}
3636
"ppx_compare" {>= "v0.17"}
37+
"ppx_deriving_yojson" {>= "3.9"}
3738
"ppx_enumerate" {>= "v0.17"}
3839
"ppx_expect" {>= "v0.17"}
3940
"ppx_hash" {>= "v0.17"}
@@ -42,8 +43,6 @@ depends: [
4243
"ppx_let" {>= "v0.17"}
4344
"ppx_sexp_conv" {>= "v0.17"}
4445
"ppx_sexp_value" {>= "v0.17"}
45-
"ppx_yojson_conv" {>= "v0.17"}
46-
"ppx_yojson_conv_lib" {>= "v0.17"}
4746
"ppxlib" {>= "0.33"}
4847
"print-table" {>= "0.1.0"}
4948
"re" {>= "1.12.0"}

crs-tests.opam

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ depends: [
3131
"pp" {>= "2.0.0"}
3232
"pplumbing" {>= "0.0.14"}
3333
"ppx_compare" {>= "v0.17"}
34+
"ppx_deriving_yojson" {>= "3.9"}
3435
"ppx_enumerate" {>= "v0.17"}
3536
"ppx_expect" {>= "v0.17"}
3637
"ppx_hash" {>= "v0.17"}
3738
"ppx_here" {>= "v0.17"}
3839
"ppx_let" {>= "v0.17"}
3940
"ppx_sexp_conv" {>= "v0.17"}
4041
"ppx_sexp_value" {>= "v0.17"}
41-
"ppx_yojson_conv" {>= "v0.17"}
42-
"ppx_yojson_conv_lib" {>= "v0.17"}
4342
"ppxlib" {>= "0.33"}
4443
"print-table" {>= "0.1.0"}
4544
"printbox" {>= "0.12"}

crs.opam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ doc: "https://mbarbin.github.io/crs/"
99
bug-reports: "https://github.com/mbarbin/crs/issues"
1010
depends: [
1111
"dune" {>= "3.17"}
12-
"ocaml" {>= "5.2" & < "5.4~"}
12+
"ocaml" {>= "5.2"}
1313
"base" {>= "v0.17"}
1414
"cmdlang" {>= "0.0.9"}
1515
"file-rewriter" {>= "0.0.3"}
@@ -20,12 +20,12 @@ depends: [
2020
"pp" {>= "2.0.0"}
2121
"pplumbing" {>= "0.0.14"}
2222
"ppx_compare" {>= "v0.17"}
23+
"ppx_deriving_yojson" {>= "3.9"}
2324
"ppx_enumerate" {>= "v0.17"}
2425
"ppx_hash" {>= "v0.17"}
2526
"ppx_here" {>= "v0.17"}
2627
"ppx_sexp_conv" {>= "v0.17"}
2728
"ppx_sexp_value" {>= "v0.17"}
28-
"ppx_yojson_conv" {>= "v0.17"}
2929
"ppxlib" {>= "0.33"}
3030
"print-table" {>= "0.1.0"}
3131
"re" {>= "1.12.0"}

doc/docs/guides/installation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ You can choose to install crs from either:
88
- From source (most recent version, PRs, etc.)
99
- GitHub Actions (see [Setup crs for GitHub Actions](./setup-crs-for-github-actions.md))
1010

11-
Releases are currently versioned using the scheme `0.0.YYYMMDD` while we are in the early stages of development.
11+
Releases are currently versioned using the scheme `0.0.YYYYMMDD` while we are in the early stages of development.
1212

1313
## Pre-compiled Binaries
1414

doc/docs/reference/crs-actions-config/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ $ crs tools config validate invalid-wrong-type.json
192192
File "invalid-wrong-type.json", line 1, characters 0-0:
193193
Error: Invalid config.
194194
In: "bob"
195-
list_of_yojson: list needed
195+
User handle list expected to be a list of json strings.
196196
[123]
197197
```
198198

dune-project

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
"A tool for managing code review comments embedded in source code")
2626
(depends
2727
(ocaml
28-
(and
29-
(>= 5.2)
30-
(< 5.4~)))
28+
(>= 5.2))
3129
(base
3230
(>= v0.17))
3331
(cmdlang
@@ -48,6 +46,8 @@
4846
(>= 0.0.14))
4947
(ppx_compare
5048
(>= v0.17))
49+
(ppx_deriving_yojson
50+
(>= 3.9))
5151
(ppx_enumerate
5252
(>= v0.17))
5353
(ppx_hash
@@ -58,8 +58,6 @@
5858
(>= v0.17))
5959
(ppx_sexp_value
6060
(>= v0.17))
61-
(ppx_yojson_conv
62-
(>= v0.17))
6361
(ppxlib
6462
(>= 0.33))
6563
(print-table
@@ -129,6 +127,8 @@
129127
(>= 0.0.14))
130128
(ppx_compare
131129
(>= v0.17))
130+
(ppx_deriving_yojson
131+
(>= 3.9))
132132
(ppx_enumerate
133133
(>= v0.17))
134134
(ppx_expect
@@ -143,10 +143,6 @@
143143
(>= v0.17))
144144
(ppx_sexp_value
145145
(>= v0.17))
146-
(ppx_yojson_conv
147-
(>= v0.17))
148-
(ppx_yojson_conv_lib
149-
(>= v0.17))
150146
(ppxlib
151147
(>= 0.33))
152148
(print-table
@@ -234,6 +230,8 @@
234230
(>= 0.0.14))
235231
(ppx_compare
236232
(>= v0.17))
233+
(ppx_deriving_yojson
234+
(>= 3.9))
237235
(ppx_enumerate
238236
(>= v0.17))
239237
(ppx_expect
@@ -250,10 +248,6 @@
250248
(>= v0.17))
251249
(ppx_sexp_value
252250
(>= v0.17))
253-
(ppx_yojson_conv
254-
(>= v0.17))
255-
(ppx_yojson_conv_lib
256-
(>= v0.17))
257251
(ppxlib
258252
(>= 0.33))
259253
(print-table

lib/crs_cli/src/annotation.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ let to_reviewdog_diagnostic t : Reviewdog.Diagnostic.t =
126126
; severity = Some (Severity.to_reviewdog t.severity)
127127
; source = None
128128
; code = None
129-
; suggestions = None
129+
; suggestions = []
130130
; original_output = Some (Cr_comment.reindented_content t.cr)
131-
; related_locations = None
131+
; related_locations = []
132132
}
133133
;;

lib/crs_cli/src/cmd__tools__reviewdog__annotate_crs.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let main =
5353
; diagnostics
5454
}
5555
in
56-
let json = Reviewdog.Diagnostic_result.yojson_of_t diagnostic_result in
56+
let json = Reviewdog.Diagnostic_result.to_yojson diagnostic_result in
5757
print_endline (Yojson.Safe.pretty_to_string ~std:true json);
5858
())
5959
;;

lib/crs_cli/src/config.ml

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,27 @@ module Annotation_severity = struct
3636
;;
3737
end
3838

39-
open! Ppx_yojson_conv_lib.Yojson_conv.Primitives
40-
4139
module User_handle = struct
4240
type t = Vcs.User_handle.t [@@deriving sexp_of]
4341

44-
let t_of_yojson json =
45-
match json |> string_of_yojson |> Vcs.User_handle.of_string with
46-
| Ok t -> t
47-
| Error (`Msg msg) ->
48-
raise (Ppx_yojson_conv_lib.Yojson_conv.Of_yojson_error (Failure msg, json))
42+
let of_yojson json =
43+
match (json : Yojson.Safe.t) with
44+
| `String str ->
45+
(match Vcs.User_handle.of_string str with
46+
| Ok _ as ok -> ok
47+
| Error (`Msg msg) -> Error msg)
48+
| _ -> Error "User handle expected to be a json string."
4949
;;
5050
end
5151

5252
module User_list = struct
53-
type t = User_handle.t list [@@deriving of_yojson]
53+
type t = User_handle.t list
54+
55+
let of_yojson json : (t, string) Result.t =
56+
match (json : Yojson.Safe.t) with
57+
| `List xs -> Ppx_deriving_yojson_runtime.map_bind User_handle.of_yojson [] xs
58+
| _ -> Error "User handle list expected to be a list of json strings."
59+
;;
5460
end
5561

5662
type t =
@@ -94,6 +100,18 @@ let get_json_enum_constructor json ~loc ~field_name =
94100
;;
95101

96102
let parse_json json ~loc ~emit_github_annotations =
103+
let of_yojson_exn f json =
104+
match f json with
105+
| Ok x -> x
106+
| Error msg ->
107+
Err.raise
108+
~loc
109+
Pp.O.
110+
[ Pp.text "Invalid config."
111+
; Pp.text "In: " ++ Pp.text (Yojson.Safe.to_string json)
112+
; Pp.text msg
113+
]
114+
in
97115
match json with
98116
| `Assoc fields ->
99117
(* Track which fields have been accessed *)
@@ -104,13 +122,13 @@ let parse_json json ~loc ~emit_github_annotations =
104122
in
105123
let default_repo_owner =
106124
match field "default_repo_owner" with
107-
| Some json -> Some (User_handle.t_of_yojson json)
125+
| Some json -> Some (of_yojson_exn User_handle.of_yojson json)
108126
| None -> None
109127
in
110128
let user_mentions_allowlist =
111129
let field_name = "user_mentions_allowlist" in
112130
match field field_name with
113-
| Some json -> Some (User_list.t_of_yojson json)
131+
| Some json -> Some (of_yojson_exn User_list.of_yojson json)
114132
| None ->
115133
(* See [upgrading-crs] guide in the documentation for more details about
116134
deprecated fields and compatibility transitions in the configs. *)
@@ -129,7 +147,7 @@ let parse_json json ~loc ~emit_github_annotations =
129147
++ Pp.text "."
130148
]
131149
~hints:[ Pp.text "Upgrade the config to use the new name." ];
132-
Some (User_list.t_of_yojson json))
150+
Some (of_yojson_exn User_list.of_yojson json))
133151
in
134152
let severity_field ~field_name =
135153
match field field_name with
@@ -213,27 +231,7 @@ let empty =
213231

214232
let load_exn ~path ~emit_github_annotations =
215233
match Yojson_five.Safe.from_file (Fpath.to_string path) with
234+
| Ok json -> parse_json json ~loc:(Loc.of_file ~path) ~emit_github_annotations
216235
| Error msg ->
217236
Err.raise ~loc:(Loc.of_file ~path) [ Pp.text "Not a valid json file."; Pp.text msg ]
218-
| Ok json ->
219-
(match
220-
match parse_json json ~loc:(Loc.of_file ~path) ~emit_github_annotations with
221-
| t -> Ok t
222-
| exception Ppx_yojson_conv_lib.Yojson_conv.Of_yojson_error (exn, json) ->
223-
Error (exn, json)
224-
with
225-
| Ok t -> t
226-
| Error (exn, json) ->
227-
let msg =
228-
match exn with
229-
| Failure msg -> Pp.text msg
230-
| exn -> Err.exn exn [@coverage off]
231-
in
232-
Err.raise
233-
~loc:(Loc.of_file ~path)
234-
Pp.O.
235-
[ Pp.text "Invalid config."
236-
; Pp.text "In: " ++ Pp.text (Yojson.Safe.to_string json)
237-
; msg
238-
])
239237
;;

0 commit comments

Comments
 (0)