Skip to content

Commit

Permalink
New constructor to add quickfixes when evaluating Reasons_callback.ts
Browse files Browse the repository at this point in the history
Summary: There are use cases where we want to add a `Pos.t Quickfix.t` when we have a `Reasons_callback.t` in hand. Currently, those use cases are stashing the quickfix in the `Secondary.t` error to which the callback is applied. This is not the intended use of secondary errors so we add a combinator which allows modification of the callback to contain the quickfixes

Reviewed By: mheiber

Differential Revision: D45947487

fbshipit-source-id: 061dfbfba42559b226f7e05123685079bd8493a1
  • Loading branch information
Michael Thomas authored and facebook-github-bot committed May 17, 2023
1 parent 82435a4 commit 36060c3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions hphp/hack/src/typing/typing_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,7 @@ and Reasons_callback : sig
| Incoming_reasons of t * op
| With_code of t * Error_code.t
| With_reasons of t * Pos_or_decl.t Message.t list Lazy.t
| Add_quickfixes of t * Pos.t Quickfix.t list
| Add_reason of t * op * Pos_or_decl.t Message.t Lazy.t
| From_on_error of
((?code:int ->
Expand Down Expand Up @@ -2254,6 +2255,8 @@ and Reasons_callback : sig

val with_reasons : t -> reasons:Pos_or_decl.t Message.t list Lazy.t -> t

val add_quickfixes : t -> Pos.t Quickfix.t list -> t

val prepend_reason : t -> reason:Pos_or_decl.t Message.t Lazy.t -> t

val append_reason : t -> reason:Pos_or_decl.t Message.t Lazy.t -> t
Expand Down Expand Up @@ -2347,6 +2350,7 @@ end = struct
| Incoming_reasons of t * op
| With_code of t * Error_code.t
| With_reasons of t * Pos_or_decl.t Message.t list Lazy.t
| Add_quickfixes of t * Pos.t Quickfix.t list
| Add_reason of t * op * Pos_or_decl.t Message.t Lazy.t
| From_on_error of
((?code:int ->
Expand All @@ -2371,6 +2375,7 @@ end = struct
| Incoming_reasons (t, _)
| With_code (t, _)
| With_reasons (t, _)
| Add_quickfixes (t, _)
| Add_reason (t, _, _)
| Prepend_on_apply (t, _)
| Drop_reasons_on_apply t ->
Expand All @@ -2396,6 +2401,8 @@ end = struct

let with_reasons t ~reasons = With_reasons (t, reasons)

let add_quickfixes t qfxs = Add_quickfixes (t, qfxs)

let prepend_reason t ~reason = Add_reason (t, Prepend, reason)

let append_reason t ~reason = Add_reason (t, Append, reason)
Expand Down
6 changes: 6 additions & 0 deletions hphp/hack/src/typing/typing_error.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,7 @@ and Reasons_callback : sig
| Incoming_reasons of t * op
| With_code of t * Error_code.t
| With_reasons of t * Pos_or_decl.t Message.t list Lazy.t
| Add_quickfixes of t * Pos.t Quickfix.t list
| Add_reason of t * op * Pos_or_decl.t Message.t Lazy.t
| From_on_error of
((?code:int ->
Expand Down Expand Up @@ -1767,6 +1768,11 @@ and Reasons_callback : sig
*)
val with_reasons : t -> reasons:Pos_or_decl.t Message.t list Lazy.t -> t

(** Add a `quickfix` to the `User_error.t` generated when the callback is
applied
*)
val add_quickfixes : t -> Pos.t Quickfix.t list -> t

(** Add the `reason` to the start of current list of reasons *)
val prepend_reason : t -> reason:Pos_or_decl.t Message.t Lazy.t -> t

Expand Down
11 changes: 11 additions & 0 deletions hphp/hack/src/typing/typing_error_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6066,6 +6066,17 @@ end = struct
aux err st
| With_reasons (err, reasons) ->
aux err Error_state.{ st with reasons_opt = Some reasons }
| Add_quickfixes (err, qfxs) ->
aux
err
Error_state.
{
st with
quickfixes_opt =
Option.first_some
(Option.map ~f:(List.append qfxs) st.quickfixes_opt)
(Some qfxs);
}
| Add_reason (err, op, reason) -> aux_reason_op op err reason st
| Retain (t, comp) -> aux_retain t comp st
| Incoming_reasons (err, op) ->
Expand Down

0 comments on commit 36060c3

Please sign in to comment.