Skip to content

Commit

Permalink
Update codeActionProvider type to support CodeActionOptions
Browse files Browse the repository at this point in the history
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](microsoft/language-server-protocol@9ae6daa)
- [renaming `CodeActionOptions.providedCodeActionKinds` to `CodeActionOptions.codeActionKinds`](microsoft/language-server-protocol@7aed39b)

Reviewed By: nmote

Differential Revision: D20007191

fbshipit-source-id: e5c7e5b51710eaf8c9f9b51d4d09ba2a1cec4e39
  • Loading branch information
Vijay Ramamurthy authored and facebook-github-bot committed Feb 28, 2020
1 parent 922c145 commit 7642a1b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/hack_forked/utils/lsp/lsp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = {
Expand Down
6 changes: 5 additions & 1 deletion src/hack_forked/utils/lsp/lsp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ module Initialize : sig
documentHighlightProvider: bool;
documentSymbolProvider: bool;
workspaceSymbolProvider: bool;
codeActionProvider: bool;
codeActionProvider: codeActionOptions;
codeLensProvider: codeLensOptions option;
documentFormattingProvider: bool;
documentRangeFormattingProvider: bool;
Expand All @@ -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 = {
Expand Down
14 changes: 13 additions & 1 deletion src/hack_forked/utils/lsp/lsp_fmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/flowLsp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 7642a1b

Please sign in to comment.