Skip to content

Commit

Permalink
fix: change the type of extra_remarks to a backward list
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Oct 11, 2023
1 parent c62f986 commit fe0f60f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/Diagnostic.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Bwd

include DiagnosticData

let text s fmt =
Expand All @@ -23,7 +25,7 @@ let of_loctext ?(backtrace=Bwd.Emp) ?(extra_remarks=[]) severity message explana
; message
; explanation
; backtrace
; extra_remarks
; extra_remarks = Bwd.of_list extra_remarks
}

let of_text ?loc ?backtrace ?extra_remarks severity message text : _ t =
Expand Down
4 changes: 2 additions & 2 deletions src/DiagnosticData.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ type 'message t = {
(** The free-form explanation. *)
backtrace : backtrace;
(** The backtrace leading to this diagnostic. *)
extra_remarks : loctext list;
(** Additional remarks that are relevant to the main message but not part of the backtrace. *)
extra_remarks : loctext bwd;
(** Additional remarks that are relevant to the main message but not part of the backtrace. It is a backward list so that new remarks can be added to its end easily. *)
}
4 changes: 3 additions & 1 deletion src/lsp/LspServer.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Bwd

module L = Lsp.Types
module RPC = Jsonrpc
module Broadcast = Lsp.Server_notification
Expand Down Expand Up @@ -66,7 +68,7 @@ struct
let code = `String (Message.short_code diag.message) in
let source = (State.get ()).source in
let message = Diagnostic.string_of_text diag.explanation.value in
let relatedInformation = List.map (render_lsp_related_info uri) diag.extra_remarks in
let relatedInformation = Bwd.to_list @@ Bwd.map (render_lsp_related_info uri) diag.extra_remarks in
Lsp_Diagnostic.create
~range
~severity
Expand Down
8 changes: 4 additions & 4 deletions src/tty/Tty.ml
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,16 @@ struct
let explication =
let style s x = Explication.{value = x; style = s} in
let main_span = Option.to_list @@ Option.map (style Style.HighlightedPrimary) loctext.loc in
let additional_spans = List.filter_map (fun x -> Option.map (style Style.Additional) x.Span.loc) extra_remarks in
E.explicate ~block_splitting_threshold:param.block_splitting_threshold (main_span @ additional_spans)
let additional_spans = Bwd.filter_map (fun x -> Option.map (style Style.Additional) x.Span.loc) extra_remarks in
E.explicate ~block_splitting_threshold:param.block_splitting_threshold (main_span @ Bwd.to_list additional_spans)
in
let line_number_width = Int.max param.line_number_width (line_number_width explication) in
render_message ~param:{param with line_number_width} ~show_code explication loctext.value

let display_backtrace ~param backtrace =
let indentation_style = A.fg @@ A.gray 8 in
let backtrace =
Bwd.to_list @@ Bwd.map (display_message ~param ~show_code:false ~extra_remarks:[]) backtrace
Bwd.to_list @@ Bwd.map (display_message ~param ~show_code:false ~extra_remarks:Emp) backtrace
in
let backtrace =
I.vcat @@
Expand Down Expand Up @@ -309,7 +309,7 @@ struct
let traces =
SourceReader.run @@ fun () ->
Bwd.snoc
(backtrace |> Bwd.map (fun msg -> display_message ~param ~show_code:true msg ~extra_remarks:[]))
(backtrace |> Bwd.map (fun msg -> display_message ~param ~show_code:true msg ~extra_remarks:Emp))
(display_message ~param ~show_code:true explanation ~extra_remarks)
|> Bwd.to_list |> Array.of_list
in
Expand Down

0 comments on commit fe0f60f

Please sign in to comment.