diff --git a/dune-project b/dune-project index 426419d020a..a0eb608d7c6 100644 --- a/dune-project +++ b/dune-project @@ -195,6 +195,8 @@ understood by dune language.")) (package (name ocamlc-loc) (synopsis "Parse ocaml compiler output into structured form") + (conflicts + (ocaml-lsp-server (< 1.15.0))) (depends (ocaml (>= 4.08.0)) (dyn (= :version))) diff --git a/ocamlc-loc.opam b/ocamlc-loc.opam index a11cc1ee0a1..ddafa9f3055 100644 --- a/ocamlc-loc.opam +++ b/ocamlc-loc.opam @@ -15,6 +15,9 @@ depends: [ "dyn" {= version} "odoc" {with-doc} ] +conflicts: [ + "ocaml-lsp-server" {< "1.15.0"} +] dev-repo: "git+https://github.com/ocaml/dune.git" build: [ ["dune" "subst"] {dev} diff --git a/otherlibs/ocamlc_loc/src/lexer.mli b/otherlibs/ocamlc_loc/src/lexer.mli index 757d2c592b4..02514550c7e 100644 --- a/otherlibs/ocamlc_loc/src/lexer.mli +++ b/otherlibs/ocamlc_loc/src/lexer.mli @@ -4,16 +4,18 @@ type lines = | Single of int | Range of int * int +type code = + { code : int + ; name : string + } + type source = - | Code of - { code : int - ; name : string - } + | Code of code | Alert of string type severity = | Error of source option - | Warning of source + | Warning of code | Alert of { name : string ; source : string diff --git a/otherlibs/ocamlc_loc/src/lexer.mll b/otherlibs/ocamlc_loc/src/lexer.mll index e614f577009..ed8c7913672 100644 --- a/otherlibs/ocamlc_loc/src/lexer.mll +++ b/otherlibs/ocamlc_loc/src/lexer.mll @@ -6,13 +6,18 @@ | Single of int | Range of int * int + type code = + { code : int + ; name : string + } + type source = - | Code of { code : int ; name : string } + | Code of code | Alert of string type severity = | Error of source option - | Warning of source + | Warning of code | Alert of { name : string ; source : string } type loc = @@ -62,7 +67,7 @@ and severity = parse { Some (Error None, rest) } | "Warning" blank (digits as code) blank "[" ([^ ']']+ as name) "]:" (blank any as rest) - { Some (Warning (Code { code = int_of_string code ; name }), rest) + { Some (Warning { code = int_of_string code ; name }, rest) } | "Error" blank "(warning" blank (digits as code) blank "[" ([^ ']']+ as name) "]):" @@ -74,11 +79,10 @@ and severity = parse } | (("Error" | "Warning") as kind) " (alert " ([^ ')']+ as alert) "):" (blank any as rest) - { let alert : source = Alert alert in - let res = + { let res = match kind with - | "Error" -> Error (Some alert) - | "Warning" -> Warning alert + | "Error" -> Error (Some (Alert alert)) + | "Warning" -> Alert { name = alert ; source = "" } | _ -> assert false in Some (res, rest) diff --git a/otherlibs/ocamlc_loc/src/ocamlc_loc.ml b/otherlibs/ocamlc_loc/src/ocamlc_loc.ml index f6a555e24f0..48e2596a027 100644 --- a/otherlibs/ocamlc_loc/src/ocamlc_loc.ml +++ b/otherlibs/ocamlc_loc/src/ocamlc_loc.ml @@ -8,6 +8,10 @@ type report = ; related : (loc * string) list } +let dyn_of_code { code; name } = + let open Dyn in + record [ ("code", int code); ("name", string name) ] + let dyn_of_source = let open Dyn in function @@ -18,7 +22,7 @@ let dyn_of_severity = let open Dyn in function | Error w -> variant "Error" [ option dyn_of_source w ] - | Warning w -> variant "Warning" [ dyn_of_source w ] + | Warning w -> variant "Warning" [ dyn_of_code w ] | Alert { name; source } -> variant "Alert" [ record [ ("name", string name); ("source", string source) ] ] diff --git a/otherlibs/ocamlc_loc/src/ocamlc_loc.mli b/otherlibs/ocamlc_loc/src/ocamlc_loc.mli index c98fad98e94..73c12936ad3 100644 --- a/otherlibs/ocamlc_loc/src/ocamlc_loc.mli +++ b/otherlibs/ocamlc_loc/src/ocamlc_loc.mli @@ -1,11 +1,13 @@ [@@@alert unstable "The API of this library is not stable and may change without notice."] +type code = + { code : int + ; name : string + } + type source = - | Code of - { code : int - ; name : string - } + | Code of code | Alert of string type lines = @@ -20,7 +22,7 @@ type loc = type severity = | Error of source option - | Warning of source + | Warning of code | Alert of { name : string ; source : string