Skip to content

Commit

Permalink
LSP: improvements to textDocuments/hover (ocaml#926)
Browse files Browse the repository at this point in the history
* Use MarkupContent in LSP hover response
* Add tests for LSP hover formatting
* Cleanup LSP hover
  • Loading branch information
andreypopp authored Feb 28, 2019
2 parents 3887e32 + 4e7264f commit 3de7f1b
Showing 1 changed file with 11 additions and 30 deletions.
41 changes: 11 additions & 30 deletions lsp/src/lsp/protocol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,6 @@ module Command = struct
} [@@deriving yojson]
end

module MarkedString = struct

type code = {
language : string;
value : string;
} [@@deriving yojson { strict = false }]

(* markedString can be used to render human readable text. It is either a
* markdown string or a code-block that provides a language and a code snippet.
* Note that markdown strings will be sanitized by the client - including
* escaping html *)
type t =
| MarkedString of string
| MarkedCode of code

let to_yojson = function
| MarkedString v -> `String v
| MarkedCode code -> code_to_yojson code

let of_yojson = function
| `String v -> Ok (MarkedString v)
| json ->
begin match code_of_yojson json with
| Ok code -> Ok (MarkedCode code)
| Error err -> Error err
end
end

module MarkupKind = struct
type t =
| Plaintext
Expand All @@ -72,6 +44,13 @@ module MarkupKind = struct
| _ -> Error "invalid contentFormat"
end

module MarkupContent = struct
type t = {
value: string;
kind: MarkupKind.t;
} [@@deriving yojson { strict = false }]
end

module Location = struct
type t = {
uri: Uri.t;
Expand Down Expand Up @@ -422,12 +401,14 @@ end

(* Hover request, method="textDocument/hover" *)
module Hover = struct
type params = TextDocumentPositionParams.t [@@deriving yojson { strict = false }]
type params =
TextDocumentPositionParams.t
[@@deriving yojson { strict = false }]

and result = hoverResult option [@default None]

and hoverResult = {
contents: MarkedString.t list; (* wire: either a single one or an array *)
contents: MarkupContent.t;
range: range option [@default None];
}
end
Expand Down

0 comments on commit 3de7f1b

Please sign in to comment.