1use serde::{Deserialize, Serialize};
2
3use crate::{
4 MarkedString, MarkupContent, MarkupKind, Range, TextDocumentPositionParams,
5 TextDocumentRegistrationOptions, WorkDoneProgressOptions, WorkDoneProgressParams,
6};
7
8#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct HoverClientCapabilities {
11 /// Whether completion supports dynamic registration.
12 #[serde(skip_serializing_if = "Option::is_none")]
13 pub dynamic_registration: Option<bool>,
14
15 /// Client supports the follow content formats for the content
16 /// property. The order describes the preferred format of the client.
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub content_format: Option<Vec<MarkupKind>>,
19}
20
21/// Hover options.
22#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
23#[serde(rename_all = "camelCase")]
24pub struct HoverOptions {
25 #[serde(flatten)]
26 pub work_done_progress_options: WorkDoneProgressOptions,
27}
28
29#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
30#[serde(rename_all = "camelCase")]
31pub struct HoverRegistrationOptions {
32 #[serde(flatten)]
33 pub text_document_registration_options: TextDocumentRegistrationOptions,
34
35 #[serde(flatten)]
36 pub hover_options: HoverOptions,
37}
38
39#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
40#[serde(untagged)]
41pub enum HoverProviderCapability {
42 Simple(bool),
43 Options(HoverOptions),
44}
45
46impl From<HoverOptions> for HoverProviderCapability {
47 fn from(from: HoverOptions) -> Self {
48 Self::Options(from)
49 }
50}
51
52impl From<bool> for HoverProviderCapability {
53 fn from(from: bool) -> Self {
54 Self::Simple(from)
55 }
56}
57
58#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
59#[serde(rename_all = "camelCase")]
60pub struct HoverParams {
61 #[serde(flatten)]
62 pub text_document_position_params: TextDocumentPositionParams,
63
64 #[serde(flatten)]
65 pub work_done_progress_params: WorkDoneProgressParams,
66}
67
68/// The result of a hover request.
69#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
70pub struct Hover {
71 /// The hover's content
72 pub contents: HoverContents,
73 /// An optional range is a range inside a text document
74 /// that is used to visualize a hover, e.g. by changing the background color.
75 #[serde(skip_serializing_if = "Option::is_none")]
76 pub range: Option<Range>,
77}
78
79/// Hover contents could be single entry or multiple entries.
80#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum HoverContents {
83 Scalar(MarkedString),
84 Array(Vec<MarkedString>),
85 Markup(MarkupContent),
86}
87