Skip to content

Commit

Permalink
refactor: move Diagnostic.Code to Reporter.Code (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia authored Oct 9, 2023
1 parent 5123a71 commit 2b1ea55
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 27 deletions.
13 changes: 0 additions & 13 deletions src/DiagnosticData.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@ type severity =
| Error
| Bug

(** The signature of message code. An implementer should specify the message code used in their library or application. *)
module type Code =
sig
(** The type of all message codes. *)
type t

(** The default severity of the code. The severity of a message is about whether the message is an error or a warning, etc. To clarify, it is about how serious the message is to the {i end user,} not whether the program should stop or continue. The severity may be overwritten at the time of issuing a message to the end user. *)
val default_severity : t -> severity

(** A concise, ideally Google-able string representation of each message code. Detailed or long descriptions of code should be avoided. For example, [E001] works better than [type-checking error]. The shorter, the better. It will be assumed that the string representation only uses ASCII printable characters. *)
val to_string : t -> string
end

(** The type of text.
When we render a diagnostic, the layout engine of the rendering backend should be the one making layout choices. Therefore, we cannot pass already formatted strings. Instead, a text is defined to be a function that takes a formatter and uses it to render the content. The following two conditions must be satisfied:
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(** Diagnostic display for GitHub Actions. *)

module Make (Code : Diagnostic.Code) = struct
module Make (Code : Reporter.Code) = struct
let command_of_severity =
function
| Diagnostic.Info -> "notice"
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
]

(** The functor to create a printer for GitHub Actions workflow commands. *)
module Make (Code : Diagnostic.Code) : sig
module Make (Code : Reporter.Code) : sig
(** Print a diagnostic as a GitHub Actions workflow command. Only the main message will be printed; backtraces and additional messages are ignored.
Example output:
Expand Down
4 changes: 2 additions & 2 deletions src/Reporter.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
open Bwd
open Bwd.Infix

module type S = ReporterSigs.S
include ReporterSigs

module Make (Code : Diagnostic.Code) : S with module Code := Code =
module Make (Code : Code) : S with module Code := Code =
struct

(* Backtraces *)
Expand Down
8 changes: 5 additions & 3 deletions src/Reporter.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(** The signature of a logger. *)
module type S = ReporterSigs.S
(** The signature of a logger.
@inline *)
include module type of ReporterSigs

(** The functor to generate a logger. *)
module Make (Code : Diagnostic.Code) : S with module Code := Code
module Make (Code : Code) : S with module Code := Code
15 changes: 14 additions & 1 deletion src/ReporterSigs.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
(** The signature of message code. An implementer should specify the message code used in their library or application. *)
module type Code =
sig
(** The type of all message codes. *)
type t

(** The default severity of the code. The severity of a message is about whether the message is an error or a warning, etc. To clarify, it is about how serious the message is to the {i end user,} not whether the program should stop or continue. The severity may be overwritten at the time of issuing a message to the end user. *)
val default_severity : t -> Diagnostic.severity

(** A concise, ideally Google-able string representation of each message code. Detailed or long descriptions of code should be avoided. For example, [E001] works better than [type-checking error]. The shorter, the better. It will be assumed that the string representation only uses ASCII printable characters. *)
val to_string : t -> string
end

module type S =
sig
module Code : Diagnostic.Code
module Code : Code

(** {2 Sending Messages} *)

Expand Down
2 changes: 1 addition & 1 deletion src/lsp/AsaiLsp.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module L = Lsp.Types
module RPC = Jsonrpc

module Make (Code : Diagnostic.Code) =
module Make (Code : Reporter.Code) =
struct
module Server = LspServer.Make(Code)
open Server
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/AsaiLsp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Note: many features are missing and it does not handle [positionEncoding].
@canonical Asai.Lsp.Make *)
module Make (Code : Diagnostic.Code) : sig
module Make (Code : Reporter.Code) : sig
val start : source:string option
-> init:(root:string option -> unit)
-> load_file:(display:(Code.t Diagnostic.t -> unit) -> string -> unit)
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/LspServer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Lsp_Diagnostic = Lsp.Types.Diagnostic
module Request = Lsp.Client_request
module Notification = Lsp.Client_notification

module Make (Code : Diagnostic.Code) =
module Make (Code : Reporter.Code) =
struct
type diagnostic = Code.t Diagnostic.t

Expand Down
2 changes: 1 addition & 1 deletion src/lsp/LspServer.mli
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module L := Lsp.Types
module RPC := Jsonrpc

module Make (Code : Diagnostic.Code) : sig
module Make (Code : Reporter.Code) : sig
type lsp_error =
| DecodeError of string
| HandshakeError of string
Expand Down
2 changes: 1 addition & 1 deletion src/tty/Tty.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

module E = Explicator.Make(Style)

module Make (Code : Diagnostic.Code) =
module Make (Code : Reporter.Code) =
struct
(*
Expand Down
2 changes: 1 addition & 1 deletion src/tty/Tty.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
(** {1 Display} *)

(** This module provides functions to display or interact with diagnostics in UNIX terminals. *)
module Make (Code : Diagnostic.Code) : sig
module Make (Code : Reporter.Code) : sig

(** [display d] prints the diagnostic [d] to the standard output, using terminal control characters for formatting. A message will look like this:
Expand Down

0 comments on commit 2b1ea55

Please sign in to comment.