diff --git a/CHANGES.md b/CHANGES.md index c1b8cb413..6cedd13a7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,10 @@ ## Fixes +- Respect codeActionLiteralSupport capability (#1046) + - Fix a document syncing issue when utf-16 is the position encoding (#1004) + - Disable "Type-annotate" action for code that is already annotated. ([#1037](https://github.com/ocaml/ocaml-lsp/pull/1037)), fixes [#1036](https://github.com/ocaml/ocaml-lsp/issues/1036) diff --git a/ocaml-lsp-server/src/ocaml_lsp_server.ml b/ocaml-lsp-server/src/ocaml_lsp_server.ml index 2e6fe4b5d..9e65259ef 100644 --- a/ocaml-lsp-server/src/ocaml_lsp_server.ml +++ b/ocaml-lsp-server/src/ocaml_lsp_server.ml @@ -30,21 +30,24 @@ let view_metrics server = let initialize_info (client_capabilities : ClientCapabilities.t) : InitializeResult.t = let codeActionProvider = - let codeActionKinds = - Action_inferred_intf.kind :: Action_destruct.kind - :: List.map - ~f:(fun (c : Code_action.t) -> c.kind) - [ Action_type_annotate.t - ; Action_remove_type_annotation.t - ; Action_construct.t - ; Action_refactor_open.unqualify - ; Action_refactor_open.qualify - ; Action_add_rec.t - ; Action_inline.t - ] - |> List.sort_uniq ~compare:Poly.compare - in - `CodeActionOptions (CodeActionOptions.create ~codeActionKinds ()) + match client_capabilities.textDocument with + | Some { codeAction = Some { codeActionLiteralSupport = Some _; _ }; _ } -> + let codeActionKinds = + Action_inferred_intf.kind :: Action_destruct.kind + :: List.map + ~f:(fun (c : Code_action.t) -> c.kind) + [ Action_type_annotate.t + ; Action_remove_type_annotation.t + ; Action_construct.t + ; Action_refactor_open.unqualify + ; Action_refactor_open.qualify + ; Action_add_rec.t + ; Action_inline.t + ] + |> List.sort_uniq ~compare:Poly.compare + in + `CodeActionOptions (CodeActionOptions.create ~codeActionKinds ()) + | _ -> `Bool true in let textDocumentSync = `TextDocumentSyncOptions diff --git a/ocaml-lsp-server/test/e2e-new/start_stop.ml b/ocaml-lsp-server/test/e2e-new/start_stop.ml index 005c7f9fc..03f6fb237 100644 --- a/ocaml-lsp-server/test/e2e-new/start_stop.ml +++ b/ocaml-lsp-server/test/e2e-new/start_stop.ml @@ -16,7 +16,20 @@ let%expect_test "start/stop" = in WindowClientCapabilities.create ~showDocument () in - ClientCapabilities.create ~window () + let textDocument = + let codeAction = + let codeActionLiteralSupport = + let codeActionKind = + CodeActionClientCapabilities.create_codeActionKind ~valueSet:[] + in + CodeActionClientCapabilities.create_codeActionLiteralSupport + ~codeActionKind + in + CodeActionClientCapabilities.create ~codeActionLiteralSupport () + in + TextDocumentClientCapabilities.create ~codeAction () + in + ClientCapabilities.create ~window ~textDocument () in Client.start client (InitializeParams.create ~capabilities ()) in