From d4a1cb61c630aef1cf6825187d3ffa96ee18b674 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 9 Jun 2023 16:23:21 +0100 Subject: [PATCH] feature(lsp): add InlayHint client request Signed-off-by: Rudi Grinberg --- lsp/src/client_request.ml | 10 ++++++++++ lsp/src/client_request.mli | 1 + ocaml-lsp-server/src/ocaml_lsp_server.ml | 1 + 3 files changed, 12 insertions(+) diff --git a/lsp/src/client_request.ml b/lsp/src/client_request.ml index b72a454b8..d101d2a04 100644 --- a/lsp/src/client_request.ml +++ b/lsp/src/client_request.ml @@ -20,6 +20,7 @@ type _ t = option t | TextDocumentCodeLens : CodeLensParams.t -> CodeLens.t list t + | InlayHint : InlayHintParams.t -> InlayHint.t list option t | TextDocumentCodeLensResolve : CodeLens.t -> CodeLens.t t | TextDocumentPrepareCallHierarchy : CallHierarchyPrepareParams.t @@ -201,6 +202,8 @@ let yojson_of_result (type a) (req : a t) (result : a) = | WillRenameFiles _, result -> Json.Option.yojson_of_t WorkspaceEdit.yojson_of_t result | ExecuteCommand _, result -> result + | InlayHint _, result -> + Json.Option.yojson_of_t (Json.To.list InlayHint.yojson_of_t) result | UnknownRequest _, resp -> resp type packed = E : 'r t -> packed @@ -240,6 +243,9 @@ let of_jsonrpc (r : Jsonrpc.Request.t) = | "textDocument/codeLens" -> let+ params = parse CodeLensParams.t_of_yojson in E (TextDocumentCodeLens params) + | "textDocument/inlayHint" -> + let+ params = parse InlayHintParams.t_of_yojson in + E (InlayHint params) | "textDocument/prepareCallHierarchy" -> let+ params = parse CallHierarchyPrepareParams.t_of_yojson in E (TextDocumentPrepareCallHierarchy params) @@ -387,6 +393,7 @@ let method_ (type a) (t : a t) = | WillRenameFiles _ -> "workspace/willRenameFiles" | TextDocumentMoniker _ -> "textDocument/moniker" | WillSaveWaitUntilTextDocument _ -> "textDocument/willSaveWaitUntil" + | InlayHint _ -> "textDocument/inlayHint" | UnknownRequest { meth; _ } -> meth let params = @@ -455,6 +462,7 @@ let params = | TextDocumentCodeLensResolve params -> ret (CodeLens.yojson_of_t params) | WillSaveWaitUntilTextDocument params -> ret (WillSaveTextDocumentParams.yojson_of_t params) + | InlayHint params -> ret (InlayHintParams.yojson_of_t params) | UnknownRequest { params; _ } -> params let to_jsonrpc_request t ~id = @@ -549,6 +557,7 @@ let response_of_json (type a) (t : a t) (json : Json.t) : a = | WillCreateFiles _ -> option_of_yojson WorkspaceEdit.t_of_yojson json | WillDeleteFiles _ -> option_of_yojson WorkspaceEdit.t_of_yojson json | WillRenameFiles _ -> option_of_yojson WorkspaceEdit.t_of_yojson json + | InlayHint _ -> option_of_yojson (list_of_yojson InlayHint.t_of_yojson) json | UnknownRequest _ -> json let text_document (type a) (t : a t) f : TextDocumentIdentifier.t option = @@ -592,6 +601,7 @@ let text_document (type a) (t : a t) f : TextDocumentIdentifier.t option = | SemanticTokensDelta r -> Some r.textDocument | SemanticTokensRange r -> Some r.textDocument | LinkedEditingRange r -> Some r.textDocument + | InlayHint r -> Some r.textDocument | CallHierarchyIncomingCalls _ -> None | CallHierarchyOutgoingCalls _ -> None | WillCreateFiles _ -> None diff --git a/lsp/src/client_request.mli b/lsp/src/client_request.mli index 0f8f02b5a..4dd1d5b23 100644 --- a/lsp/src/client_request.mli +++ b/lsp/src/client_request.mli @@ -20,6 +20,7 @@ type _ t = option t | TextDocumentCodeLens : CodeLensParams.t -> CodeLens.t list t + | InlayHint : InlayHintParams.t -> InlayHint.t list option t | TextDocumentCodeLensResolve : CodeLens.t -> CodeLens.t t | TextDocumentPrepareCallHierarchy : CallHierarchyPrepareParams.t diff --git a/ocaml-lsp-server/src/ocaml_lsp_server.ml b/ocaml-lsp-server/src/ocaml_lsp_server.ml index 3eb6937ed..4ac3c050d 100644 --- a/ocaml-lsp-server/src/ocaml_lsp_server.ml +++ b/ocaml-lsp-server/src/ocaml_lsp_server.ml @@ -595,6 +595,7 @@ let on_request : Compl.resolve doc ci resolve Document.Merlin.doc_comment ~markdown)) () | CodeAction params -> Code_actions.compute server params + | InlayHint _ -> now None | TextDocumentColor _ -> now [] | TextDocumentColorPresentation _ -> now [] | TextDocumentHover req ->