Skip to content

Commit

Permalink
[flow][detailed-error] Use detailedErrorRendering config from client …
Browse files Browse the repository at this point in the history
…init options

Reviewed By: panagosg7

Differential Revision: D58106022

fbshipit-source-id: 36808008a0309b71c2f3d75ce2a603b2d644a19e
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Jun 4, 2024
1 parent 950c5f7 commit d4226f6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/hack_forked/utils/lsp/lsp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,10 @@ module Initialize = struct
| Messages
| Verbose

and initializationOptions = { liveSyntaxErrors: bool }
and initializationOptions = {
liveSyntaxErrors: bool;
detailedErrorRendering: bool option;
}

and client_capabilities = {
workspace: workspaceClientCapabilities;
Expand Down
5 changes: 4 additions & 1 deletion src/hack_forked/utils/lsp/lsp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ module Initialize : sig
| Messages
| Verbose

and initializationOptions = { liveSyntaxErrors: bool }
and initializationOptions = {
liveSyntaxErrors: bool;
detailedErrorRendering: bool option;
}

and client_capabilities = {
workspace: workspaceClientCapabilities;
Expand Down
12 changes: 11 additions & 1 deletion src/hack_forked/utils/lsp/lsp_fmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,17 @@ let parse_initialize (params : json option) : Initialize.params =
| Some "verbose" -> Verbose
| _ -> Off
and parse_initializationOptions json =
{ liveSyntaxErrors = Jget.bool_d json "liveSyntaxErrors" ~default:true }
{
liveSyntaxErrors = Jget.bool_d json "liveSyntaxErrors" ~default:true;
detailedErrorRendering =
(match Jget.bool_opt json "detailedErrorRendering" with
| Some b -> Some b
| None ->
(match Jget.string_opt json "detailedErrorRendering" with
| Some "true" -> Some true
| Some "false" -> Some false
| _ -> None));
}
and parse_capabilities json =
{
workspace = Jget.obj_opt json "workspace" |> parse_workspace;
Expand Down
6 changes: 5 additions & 1 deletion src/server/command_handler/commandHandler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1191,9 +1191,13 @@ let linked_editing_range ~options ~env ~profiling ~params ~client =
)

let vscode_detailed_diagnostics ~options client =
let client_config = Persistent_connection.client_config client in
let lsp_initialize_params = Persistent_connection.lsp_initialize_params client in
Persistent_connection.Client_config.detailed_error_rendering_merge_with_options
~flowconfig_enabled:(Options.vscode_detailed_diagnostics options)
(Persistent_connection.client_config client)
~client_init_options_enabled:
Lsp.Initialize.(lsp_initialize_params.initializationOptions.detailedErrorRendering)
client_config

let rank_autoimports_by_usage ~options client =
let client_config = Persistent_connection.client_config client in
Expand Down
6 changes: 4 additions & 2 deletions src/server/persistent_connection/persistent_connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ module Client_config = struct
let detailed_error_rendering { detailed_error_rendering; _ } = detailed_error_rendering

let detailed_error_rendering_merge_with_options
~flowconfig_enabled { detailed_error_rendering; _ } =
~flowconfig_enabled ~client_init_options_enabled { detailed_error_rendering; _ } =
match detailed_error_rendering with
| Default -> flowconfig_enabled
| Default -> Base.Option.value client_init_options_enabled ~default:flowconfig_enabled
| True -> true
| False -> false

Expand Down Expand Up @@ -116,6 +116,8 @@ let send_errors =
let vscode_detailed_diagnostics =
Client_config.detailed_error_rendering_merge_with_options
~flowconfig_enabled:flowconfig_vscode_detailed_diagnostics
~client_init_options_enabled:
Lsp.Initialize.(client.lsp_initialize_params.initializationOptions.detailedErrorRendering)
client.client_config
in
let diagnostics =
Expand Down
3 changes: 2 additions & 1 deletion src/server/persistent_connection/persistent_connection.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module Client_config : sig

val detailed_error_rendering : t -> client_toggle

val detailed_error_rendering_merge_with_options : flowconfig_enabled:bool -> t -> bool
val detailed_error_rendering_merge_with_options :
flowconfig_enabled:bool -> client_init_options_enabled:bool option -> t -> bool

val rank_autoimports_by_usage : t -> client_toggle

Expand Down

0 comments on commit d4226f6

Please sign in to comment.