From 7642a1b87d37ff9ee22cbe4d6a7e57eac6331525 Mon Sep 17 00:00:00 2001 From: Vijay Ramamurthy Date: Fri, 28 Feb 2020 14:48:36 -0800 Subject: [PATCH] Update codeActionProvider type to support CodeActionOptions Summary: LSP now has the ability to tell the client upon intialization which code actions we support: see [ServerCapabilities.codeActionProvider](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize) and [CodeActionOptions](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction). This diff updates `lsp.ml` to reflect this. Relevant LSP commits: - [Adding CodeActionOptions to the `codeActionProvider` server capability](https://github.com/microsoft/language-server-protocol/commit/9ae6daabbcd1f801f186847b73e0f68d30510815) - [renaming `CodeActionOptions.providedCodeActionKinds` to `CodeActionOptions.codeActionKinds`](https://github.com/microsoft/language-server-protocol/commit/7aed39bc4b82d59ca328c43d56d85fec2ebee9b9) Reviewed By: nmote Differential Revision: D20007191 fbshipit-source-id: e5c7e5b51710eaf8c9f9b51d4d09ba2a1cec4e39 --- src/hack_forked/utils/lsp/lsp.ml | 6 +++++- src/hack_forked/utils/lsp/lsp.mli | 6 +++++- src/hack_forked/utils/lsp/lsp_fmt.ml | 14 +++++++++++++- src/lsp/flowLsp.ml | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/hack_forked/utils/lsp/lsp.ml b/src/hack_forked/utils/lsp/lsp.ml index 8835ed06af0..07e9bd3b52b 100644 --- a/src/hack_forked/utils/lsp/lsp.ml +++ b/src/hack_forked/utils/lsp/lsp.ml @@ -444,7 +444,7 @@ module Initialize = struct (* ie. document outline *) workspaceSymbolProvider: bool; (* ie. find-symbol-in-project *) - codeActionProvider: bool; + codeActionProvider: codeActionOptions; codeLensProvider: codeLensOptions option; documentFormattingProvider: bool; documentRangeFormattingProvider: bool; @@ -468,6 +468,10 @@ module Initialize = struct sighelp_triggerCharacters: string list; (* wire "triggerCharacters" *) } + and codeActionOptions = + | CodeActionBool of bool + | CodeActionOptions of { codeActionKinds: CodeActionKind.t list } + and codeLensOptions = { codelens_resolveProvider: bool (* wire "resolveProvider" *) } and documentOnTypeFormattingOptions = { diff --git a/src/hack_forked/utils/lsp/lsp.mli b/src/hack_forked/utils/lsp/lsp.mli index 7f4595a779a..ce3d4a95f19 100644 --- a/src/hack_forked/utils/lsp/lsp.mli +++ b/src/hack_forked/utils/lsp/lsp.mli @@ -281,7 +281,7 @@ module Initialize : sig documentHighlightProvider: bool; documentSymbolProvider: bool; workspaceSymbolProvider: bool; - codeActionProvider: bool; + codeActionProvider: codeActionOptions; codeLensProvider: codeLensOptions option; documentFormattingProvider: bool; documentRangeFormattingProvider: bool; @@ -301,6 +301,10 @@ module Initialize : sig and signatureHelpOptions = { sighelp_triggerCharacters: string list } + and codeActionOptions = + | CodeActionBool of bool + | CodeActionOptions of { codeActionKinds: CodeActionKind.t list } + and codeLensOptions = { codelens_resolveProvider: bool } and documentOnTypeFormattingOptions = { diff --git a/src/hack_forked/utils/lsp/lsp_fmt.ml b/src/hack_forked/utils/lsp/lsp_fmt.ml index 71450d2a051..79c5d0c6f56 100644 --- a/src/hack_forked/utils/lsp/lsp_fmt.ml +++ b/src/hack_forked/utils/lsp/lsp_fmt.ml @@ -969,7 +969,19 @@ let print_initialize (r : Initialize.result) : json = ("documentHighlightProvider", Some (JSON_Bool cap.documentHighlightProvider)); ("documentSymbolProvider", Some (JSON_Bool cap.documentSymbolProvider)); ("workspaceSymbolProvider", Some (JSON_Bool cap.workspaceSymbolProvider)); - ("codeActionProvider", Some (JSON_Bool cap.codeActionProvider)); + ( "codeActionProvider", + Some + (match cap.codeActionProvider with + | CodeActionBool b -> JSON_Bool b + | CodeActionOptions { codeActionKinds } -> + JSON_Object + [ + ( "codeActionKinds", + JSON_Array + (List.map + ~f:(fun k -> JSON_String (CodeActionKind.string_of_kind k)) + codeActionKinds) ); + ]) ); ( "codeLensProvider", Base.Option.map cap.codeLensProvider ~f:(fun codelens -> JSON_Object [("resolveProvider", JSON_Bool codelens.codelens_resolveProvider)]) diff --git a/src/lsp/flowLsp.ml b/src/lsp/flowLsp.ml index 6454afb94ae..eff2297a7ca 100644 --- a/src/lsp/flowLsp.ml +++ b/src/lsp/flowLsp.ml @@ -472,7 +472,7 @@ let send_lsp_to_server (cenv : connected_env) (metadata : LspProt.metadata) (mes (************************************************************************) let do_initialize flowconfig : Initialize.result = - let code_action_provider = FlowConfig.autofix_exports flowconfig in + let code_action_provider = Initialize.CodeActionBool (FlowConfig.autofix_exports flowconfig) in Initialize. { server_capabilities =