Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context_to_yojson in messages #1365

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/common/util/messages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ end

module Piece =
struct
let context_to_yojson context = `Assoc [("tag", `Int (ControlSpecC.tag context))]

type t = {
loc: Location.t option; (* only *_each warnings have this, used for deduplication *)
text: string;
context: (ControlSpecC.t [@of_yojson fun x -> Result.Error "ControlSpecC"]) option;
context: (ControlSpecC.t [@to_yojson context_to_yojson] [@of_yojson fun x -> Result.Error "ControlSpecC"]) option;
} [@@deriving eq, ord, hash, yojson]

let text_with_context {text; context; _} =
match context with
| Some context when GobConfig.get_bool "dbg.warn_with_context" -> text ^ " in context " ^ string_of_int (ControlSpecC.hash context) (* TODO: this is kind of useless *)
| Some context when GobConfig.get_bool "dbg.warn_with_context" -> text ^ " in context " ^ string_of_int (ControlSpecC.tag context) (* TODO: this is kind of useless *)
| _ -> text
end

Expand Down