Skip to content

Commit

Permalink
[flow][lsp] No-op when given null json as configuration change update
Browse files Browse the repository at this point in the history
Summary:
Similar to the logic [here](https://github.com/facebook/flow/blob/cf97273874d14dec2f0a5b6cb144793a2dcabbd6/src/lsp/flowLsp.ml#L1984-L1985), we need to special case null, otherwise we might just randomly overriding previously configured client back to default, when we decide to pull new configuration from client.

I think it is one of the reason why the client override of the detailed error feature doesn't work quite reliably, which is not that surprising, given that these client overrides are never exercised a lot by end users.

Changelog: [internal]

Reviewed By: panagosg7

Differential Revision: D58071178

fbshipit-source-id: 8abc663b1a0dbf511a5ca63c6af9e0eb846b1011
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Jun 4, 2024
1 parent d22d9ca commit 950c5f7
Showing 1 changed file with 43 additions and 37 deletions.
80 changes: 43 additions & 37 deletions src/server/command_handler/commandHandler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2173,43 +2173,49 @@ let handle_persistent_did_change_configuration_notification ~params ~metadata ~c
let open Hh_json_helpers in
let open Persistent_connection in
let { Lsp.DidChangeConfiguration.settings } = params in
let client_config = client_config client in
let json = Some settings in
let client_config =
match Jget.val_opt json "detailedErrorRendering" with
| Some (Hh_json.JSON_String "true")
| Some (Hh_json.JSON_Bool true) ->
{ client_config with Client_config.detailed_error_rendering = Client_config.True }
| Some (Hh_json.JSON_String "false")
| Some (Hh_json.JSON_Bool false) ->
{ client_config with Client_config.detailed_error_rendering = Client_config.False }
| Some _
| None ->
{ client_config with Client_config.detailed_error_rendering = Client_config.Default }
in
let suggest = Jget.obj_opt json "suggest" in
let client_config =
match Jget.bool_opt suggest "autoImports" with
| Some suggest_autoimports -> { client_config with Client_config.suggest_autoimports }
| None -> client_config
in
let client_config =
match Jget.val_opt suggest "rankAutoimportsByUsage" with
| Some (Hh_json.JSON_String "true")
| Some (Hh_json.JSON_Bool true) ->
{ client_config with Client_config.rank_autoimports_by_usage = Client_config.True }
| Some (Hh_json.JSON_String "false")
| Some (Hh_json.JSON_Bool false) ->
{ client_config with Client_config.rank_autoimports_by_usage = Client_config.False }
| Some _
| None ->
{ client_config with Client_config.rank_autoimports_by_usage = Client_config.Default }
in
let client_config =
let show_suggest_ranking_info = Jget.bool_d suggest "showRankingInfo" ~default:false in
{ client_config with Client_config.show_suggest_ranking_info }
in
client_did_change_configuration client client_config;
(match settings with
| Hh_json.JSON_Null ->
(* a null notification means we should pull the configs we care about.
* In this case, we should not update the client config will all the defaults. *)
()
| _ ->
let client_config = client_config client in
let json = Some settings in
let client_config =
match Jget.val_opt json "detailedErrorRendering" with
| Some (Hh_json.JSON_String "true")
| Some (Hh_json.JSON_Bool true) ->
{ client_config with Client_config.detailed_error_rendering = Client_config.True }
| Some (Hh_json.JSON_String "false")
| Some (Hh_json.JSON_Bool false) ->
{ client_config with Client_config.detailed_error_rendering = Client_config.False }
| Some _
| None ->
{ client_config with Client_config.detailed_error_rendering = Client_config.Default }
in
let suggest = Jget.obj_opt json "suggest" in
let client_config =
match Jget.bool_opt suggest "autoImports" with
| Some suggest_autoimports -> { client_config with Client_config.suggest_autoimports }
| None -> client_config
in
let client_config =
match Jget.val_opt suggest "rankAutoimportsByUsage" with
| Some (Hh_json.JSON_String "true")
| Some (Hh_json.JSON_Bool true) ->
{ client_config with Client_config.rank_autoimports_by_usage = Client_config.True }
| Some (Hh_json.JSON_String "false")
| Some (Hh_json.JSON_Bool false) ->
{ client_config with Client_config.rank_autoimports_by_usage = Client_config.False }
| Some _
| None ->
{ client_config with Client_config.rank_autoimports_by_usage = Client_config.Default }
in
let client_config =
let show_suggest_ranking_info = Jget.bool_d suggest "showRankingInfo" ~default:false in
{ client_config with Client_config.show_suggest_ranking_info }
in
client_did_change_configuration client client_config);
(LspProt.LspFromServer None, metadata)

let handle_persistent_get_def
Expand Down

0 comments on commit 950c5f7

Please sign in to comment.