| 1 | use crate::{ |
| 2 | Command, LSPAny, Location, MarkupContent, Position, Range, StaticRegistrationOptions, |
| 3 | TextDocumentIdentifier, TextDocumentRegistrationOptions, TextEdit, WorkDoneProgressOptions, |
| 4 | WorkDoneProgressParams, |
| 5 | }; |
| 6 | use serde::{Deserialize, Serialize}; |
| 7 | |
| 8 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 9 | #[serde(rename_all = "camelCase" )] |
| 10 | #[serde(untagged)] |
| 11 | pub enum InlayHintServerCapabilities { |
| 12 | Options(InlayHintOptions), |
| 13 | RegistrationOptions(InlayHintRegistrationOptions), |
| 14 | } |
| 15 | |
| 16 | /// Inlay hint client capabilities. |
| 17 | /// |
| 18 | /// @since 3.17.0 |
| 19 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 20 | #[serde(rename_all = "camelCase" )] |
| 21 | pub struct InlayHintClientCapabilities { |
| 22 | /// Whether inlay hints support dynamic registration. |
| 23 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 24 | pub dynamic_registration: Option<bool>, |
| 25 | |
| 26 | /// Indicates which properties a client can resolve lazily on a inlay |
| 27 | /// hint. |
| 28 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 29 | pub resolve_support: Option<InlayHintResolveClientCapabilities>, |
| 30 | } |
| 31 | |
| 32 | /// Inlay hint options used during static registration. |
| 33 | /// |
| 34 | /// @since 3.17.0 |
| 35 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 36 | #[serde(rename_all = "camelCase" )] |
| 37 | pub struct InlayHintOptions { |
| 38 | #[serde(flatten)] |
| 39 | pub work_done_progress_options: WorkDoneProgressOptions, |
| 40 | |
| 41 | /// The server provides support to resolve additional |
| 42 | /// information for an inlay hint item. |
| 43 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 44 | pub resolve_provider: Option<bool>, |
| 45 | } |
| 46 | |
| 47 | /// Inlay hint options used during static or dynamic registration. |
| 48 | /// |
| 49 | /// @since 3.17.0 |
| 50 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 51 | #[serde(rename_all = "camelCase" )] |
| 52 | pub struct InlayHintRegistrationOptions { |
| 53 | #[serde(flatten)] |
| 54 | pub inlay_hint_options: InlayHintOptions, |
| 55 | |
| 56 | #[serde(flatten)] |
| 57 | pub text_document_registration_options: TextDocumentRegistrationOptions, |
| 58 | |
| 59 | #[serde(flatten)] |
| 60 | pub static_registration_options: StaticRegistrationOptions, |
| 61 | } |
| 62 | |
| 63 | /// A parameter literal used in inlay hint requests. |
| 64 | /// |
| 65 | /// @since 3.17.0 |
| 66 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 67 | #[serde(rename_all = "camelCase" )] |
| 68 | pub struct InlayHintParams { |
| 69 | #[serde(flatten)] |
| 70 | pub work_done_progress_params: WorkDoneProgressParams, |
| 71 | |
| 72 | /// The text document. |
| 73 | pub text_document: TextDocumentIdentifier, |
| 74 | |
| 75 | /// The visible document range for which inlay hints should be computed. |
| 76 | pub range: Range, |
| 77 | } |
| 78 | |
| 79 | /// Inlay hint information. |
| 80 | /// |
| 81 | /// @since 3.17.0 |
| 82 | #[derive (Debug, Clone, Deserialize, Serialize)] |
| 83 | #[serde(rename_all = "camelCase" )] |
| 84 | pub struct InlayHint { |
| 85 | /// The position of this hint. |
| 86 | pub position: Position, |
| 87 | |
| 88 | /// The label of this hint. A human readable string or an array of |
| 89 | /// InlayHintLabelPart label parts. |
| 90 | /// |
| 91 | /// *Note* that neither the string nor the label part can be empty. |
| 92 | pub label: InlayHintLabel, |
| 93 | |
| 94 | /// The kind of this hint. Can be omitted in which case the client |
| 95 | /// should fall back to a reasonable default. |
| 96 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 97 | pub kind: Option<InlayHintKind>, |
| 98 | |
| 99 | /// Optional text edits that are performed when accepting this inlay hint. |
| 100 | /// |
| 101 | /// *Note* that edits are expected to change the document so that the inlay |
| 102 | /// hint (or its nearest variant) is now part of the document and the inlay |
| 103 | /// hint itself is now obsolete. |
| 104 | /// |
| 105 | /// Depending on the client capability `inlayHint.resolveSupport` clients |
| 106 | /// might resolve this property late using the resolve request. |
| 107 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 108 | pub text_edits: Option<Vec<TextEdit>>, |
| 109 | |
| 110 | /// The tooltip text when you hover over this item. |
| 111 | /// |
| 112 | /// Depending on the client capability `inlayHint.resolveSupport` clients |
| 113 | /// might resolve this property late using the resolve request. |
| 114 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 115 | pub tooltip: Option<InlayHintTooltip>, |
| 116 | |
| 117 | /// Render padding before the hint. |
| 118 | /// |
| 119 | /// Note: Padding should use the editor's background color, not the |
| 120 | /// background color of the hint itself. That means padding can be used |
| 121 | /// to visually align/separate an inlay hint. |
| 122 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 123 | pub padding_left: Option<bool>, |
| 124 | |
| 125 | /// Render padding after the hint. |
| 126 | /// |
| 127 | /// Note: Padding should use the editor's background color, not the |
| 128 | /// background color of the hint itself. That means padding can be used |
| 129 | /// to visually align/separate an inlay hint. |
| 130 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 131 | pub padding_right: Option<bool>, |
| 132 | |
| 133 | /// A data entry field that is preserved on a inlay hint between |
| 134 | /// a `textDocument/inlayHint` and a `inlayHint/resolve` request. |
| 135 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 136 | pub data: Option<LSPAny>, |
| 137 | } |
| 138 | |
| 139 | #[derive (Debug, Clone, Deserialize, Serialize)] |
| 140 | #[serde(untagged)] |
| 141 | pub enum InlayHintLabel { |
| 142 | String(String), |
| 143 | LabelParts(Vec<InlayHintLabelPart>), |
| 144 | } |
| 145 | |
| 146 | impl From<String> for InlayHintLabel { |
| 147 | #[inline ] |
| 148 | fn from(from: String) -> Self { |
| 149 | Self::String(from) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | impl From<Vec<InlayHintLabelPart>> for InlayHintLabel { |
| 154 | #[inline ] |
| 155 | fn from(from: Vec<InlayHintLabelPart>) -> Self { |
| 156 | Self::LabelParts(from) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | #[derive (Debug, Clone, Deserialize, Serialize)] |
| 161 | #[serde(untagged)] |
| 162 | pub enum InlayHintTooltip { |
| 163 | String(String), |
| 164 | MarkupContent(MarkupContent), |
| 165 | } |
| 166 | |
| 167 | impl From<String> for InlayHintTooltip { |
| 168 | #[inline ] |
| 169 | fn from(from: String) -> Self { |
| 170 | Self::String(from) |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | impl From<MarkupContent> for InlayHintTooltip { |
| 175 | #[inline ] |
| 176 | fn from(from: MarkupContent) -> Self { |
| 177 | Self::MarkupContent(from) |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | /// An inlay hint label part allows for interactive and composite labels |
| 182 | /// of inlay hints. |
| 183 | #[derive (Debug, Clone, Default, Deserialize, Serialize)] |
| 184 | #[serde(rename_all = "camelCase" )] |
| 185 | pub struct InlayHintLabelPart { |
| 186 | /// The value of this label part. |
| 187 | pub value: String, |
| 188 | |
| 189 | /// The tooltip text when you hover over this label part. Depending on |
| 190 | /// the client capability `inlayHint.resolveSupport` clients might resolve |
| 191 | /// this property late using the resolve request. |
| 192 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 193 | pub tooltip: Option<InlayHintLabelPartTooltip>, |
| 194 | |
| 195 | /// An optional source code location that represents this |
| 196 | /// label part. |
| 197 | /// |
| 198 | /// The editor will use this location for the hover and for code navigation |
| 199 | /// features: This part will become a clickable link that resolves to the |
| 200 | /// definition of the symbol at the given location (not necessarily the |
| 201 | /// location itself), it shows the hover that shows at the given location, |
| 202 | /// and it shows a context menu with further code navigation commands. |
| 203 | /// |
| 204 | /// Depending on the client capability `inlayHint.resolveSupport` clients |
| 205 | /// might resolve this property late using the resolve request. |
| 206 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 207 | pub location: Option<Location>, |
| 208 | |
| 209 | /// An optional command for this label part. |
| 210 | /// |
| 211 | /// Depending on the client capability `inlayHint.resolveSupport` clients |
| 212 | /// might resolve this property late using the resolve request. |
| 213 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 214 | pub command: Option<Command>, |
| 215 | } |
| 216 | |
| 217 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 218 | #[serde(untagged)] |
| 219 | pub enum InlayHintLabelPartTooltip { |
| 220 | String(String), |
| 221 | MarkupContent(MarkupContent), |
| 222 | } |
| 223 | |
| 224 | impl From<String> for InlayHintLabelPartTooltip { |
| 225 | #[inline ] |
| 226 | fn from(from: String) -> Self { |
| 227 | Self::String(from) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | impl From<MarkupContent> for InlayHintLabelPartTooltip { |
| 232 | #[inline ] |
| 233 | fn from(from: MarkupContent) -> Self { |
| 234 | Self::MarkupContent(from) |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /// Inlay hint kinds. |
| 239 | /// |
| 240 | /// @since 3.17.0 |
| 241 | #[derive (Eq, PartialEq, Copy, Clone, Serialize, Deserialize)] |
| 242 | #[serde(transparent)] |
| 243 | pub struct InlayHintKind(i32); |
| 244 | lsp_enum! { |
| 245 | impl InlayHintKind { |
| 246 | /// An inlay hint that for a type annotation. |
| 247 | pub const TYPE: InlayHintKind = InlayHintKind(1); |
| 248 | |
| 249 | /// An inlay hint that is for a parameter. |
| 250 | pub const PARAMETER: InlayHintKind = InlayHintKind(2); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /// Inlay hint client capabilities. |
| 255 | /// |
| 256 | /// @since 3.17.0 |
| 257 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 258 | #[serde(rename_all = "camelCase" )] |
| 259 | pub struct InlayHintResolveClientCapabilities { |
| 260 | /// The properties that a client can resolve lazily. |
| 261 | pub properties: Vec<String>, |
| 262 | } |
| 263 | |
| 264 | /// Client workspace capabilities specific to inlay hints. |
| 265 | /// |
| 266 | /// @since 3.17.0 |
| 267 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 268 | #[serde(rename_all = "camelCase" )] |
| 269 | pub struct InlayHintWorkspaceClientCapabilities { |
| 270 | /// Whether the client implementation supports a refresh request sent from |
| 271 | /// the server to the client. |
| 272 | /// |
| 273 | /// Note that this event is global and will force the client to refresh all |
| 274 | /// inlay hints currently shown. It should be used with absolute care and |
| 275 | /// is useful for situation where a server for example detects a project wide |
| 276 | /// change that requires such a calculation. |
| 277 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 278 | pub refresh_support: Option<bool>, |
| 279 | } |
| 280 | |
| 281 | // TODO(sno2): add tests once stabilized |
| 282 | |