Skip to content

Commit

Permalink
Descriptive titles for "did you mean?" quickfixes
Browse files Browse the repository at this point in the history
Summary: We used to title all quickfixes "Apply suggestion", but this is insufficiently specific when the user has to choose from multiple different quickfixes. This diff updates the quickfix title message to say "Replace <old property name> with <new property name>"

Reviewed By: nmote

Differential Revision: D20633648

fbshipit-source-id: 2f5314f246c1368ae7b7098a476fefe33883976a
  • Loading branch information
Vijay Ramamurthy authored and facebook-github-bot committed Mar 30, 2020
1 parent 598b7bc commit 45d8ae2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions newtests/lsp/code-action/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default suite(
'textDocument/codeAction',
JSON.stringify([
{
title: 'Apply suggestion',
title: 'Replace `faceboy` with `facebook`',
kind: 'quickfix',
diagnostics: [
{
Expand Down Expand Up @@ -133,7 +133,7 @@ export default suite(
command: {
title: '',
command: 'log:<PLACEHOLDER_PROJECT_URL>',
arguments: ['Apply suggestion'],
arguments: ['Replace `faceboy` with `facebook`'],
},
},
]),
Expand Down Expand Up @@ -189,7 +189,7 @@ export default suite(
'textDocument/codeAction',
JSON.stringify([
{
title: 'Apply suggestion',
title: 'Replace `Foobat` with `Foobar`',
kind: 'quickfix',
diagnostics: [
{
Expand Down Expand Up @@ -234,7 +234,7 @@ export default suite(
command: {
title: '',
command: 'log:<PLACEHOLDER_PROJECT_URL>',
arguments: ['Apply suggestion'],
arguments: ['Replace `Foobat` with `Foobar`'],
},
},
]),
Expand Down
16 changes: 10 additions & 6 deletions src/services/type_info/type_info_service.ml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ let code_actions_at_loc ~reader ~options ~env ~profiling ~params ~file_key ~file
else
[]
in
let create_suggestion loc suggestion =
let create_suggestion loc ~original ~suggestion =
let title = Printf.sprintf "Replace %s with `%s`" original suggestion in
let error_range = Flow_lsp_conversions.loc_to_lsp_range loc in
let relevant_diagnostics =
context.CodeActionRequest.diagnostics
Expand All @@ -178,7 +179,7 @@ let code_actions_at_loc ~reader ~options ~env ~profiling ~params ~file_key ~file
CodeAction.Action
CodeAction.
{
title = "Apply suggestion";
title;
kind = CodeActionKind.quickfix;
diagnostics = relevant_diagnostics;
action =
Expand All @@ -188,7 +189,7 @@ let code_actions_at_loc ~reader ~options ~env ~profiling ~params ~file_key ~file
(* https://github.com/microsoft/language-server-protocol/issues/933 *)
Command.title = "";
command = Command.Command "log";
arguments = [Hh_json.JSON_String "Apply suggestion"];
arguments = [Hh_json.JSON_String title];
} );
}
in
Expand All @@ -201,11 +202,14 @@ let code_actions_at_loc ~reader ~options ~env ~profiling ~params ~file_key ~file
with
| Error_message.EEnumInvalidMemberAccess { reason; suggestion = Some suggestion; _ } ->
let loc = Reason.loc_of_reason reason in
create_suggestion loc suggestion :: actions
let original = reason |> Reason.desc_of_reason |> Reason.string_of_desc in
create_suggestion loc ~original ~suggestion :: actions
| error_message ->
(match error_message |> Error_message.friendly_message_of_msg with
| Error_message.PropMissing { loc; suggestion = Some suggestion; _ } ->
create_suggestion loc suggestion :: actions
| Error_message.PropMissing
{ loc; suggestion = Some suggestion; prop = Some prop_name; _ } ->
let original = Printf.sprintf "`%s`" prop_name in
create_suggestion loc ~original ~suggestion :: actions
| _ -> actions))
errors
[]
Expand Down

0 comments on commit 45d8ae2

Please sign in to comment.