| 1 | use crate::{ |
| 2 | PartialResultParams, StaticTextDocumentColorProviderOptions, TextDocumentIdentifier, |
| 3 | WorkDoneProgressParams, |
| 4 | }; |
| 5 | use serde::{Deserialize, Serialize}; |
| 6 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 7 | #[serde(rename_all = "camelCase" )] |
| 8 | pub struct FoldingRangeParams { |
| 9 | /// The text document. |
| 10 | pub text_document: TextDocumentIdentifier, |
| 11 | |
| 12 | #[serde(flatten)] |
| 13 | pub work_done_progress_params: WorkDoneProgressParams, |
| 14 | |
| 15 | #[serde(flatten)] |
| 16 | pub partial_result_params: PartialResultParams, |
| 17 | } |
| 18 | |
| 19 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 20 | #[serde(untagged)] |
| 21 | pub enum FoldingRangeProviderCapability { |
| 22 | Simple(bool), |
| 23 | FoldingProvider(FoldingProviderOptions), |
| 24 | Options(StaticTextDocumentColorProviderOptions), |
| 25 | } |
| 26 | |
| 27 | impl From<StaticTextDocumentColorProviderOptions> for FoldingRangeProviderCapability { |
| 28 | fn from(from: StaticTextDocumentColorProviderOptions) -> Self { |
| 29 | Self::Options(from) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | impl From<FoldingProviderOptions> for FoldingRangeProviderCapability { |
| 34 | fn from(from: FoldingProviderOptions) -> Self { |
| 35 | Self::FoldingProvider(from) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | impl From<bool> for FoldingRangeProviderCapability { |
| 40 | fn from(from: bool) -> Self { |
| 41 | Self::Simple(from) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 46 | pub struct FoldingProviderOptions {} |
| 47 | |
| 48 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 49 | #[serde(rename_all = "camelCase" )] |
| 50 | pub struct FoldingRangeKindCapability { |
| 51 | /// The folding range kind values the client supports. When this |
| 52 | /// property exists the client also guarantees that it will |
| 53 | /// handle values outside its set gracefully and falls back |
| 54 | /// to a default value when unknown. |
| 55 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 56 | pub value_set: Option<Vec<FoldingRangeKind>>, |
| 57 | } |
| 58 | |
| 59 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 60 | #[serde(rename_all = "camelCase" )] |
| 61 | pub struct FoldingRangeCapability { |
| 62 | /// If set, the client signals that it supports setting collapsedText on |
| 63 | /// folding ranges to display custom labels instead of the default text. |
| 64 | /// |
| 65 | /// @since 3.17.0 |
| 66 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 67 | pub collapsed_text: Option<bool>, |
| 68 | } |
| 69 | |
| 70 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 71 | #[serde(rename_all = "camelCase" )] |
| 72 | pub struct FoldingRangeClientCapabilities { |
| 73 | /// Whether implementation supports dynamic registration for folding range providers. If this is set to `true` |
| 74 | /// the client supports the new `(FoldingRangeProviderOptions & TextDocumentRegistrationOptions & StaticRegistrationOptions)` |
| 75 | /// return value for the corresponding server capability as well. |
| 76 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 77 | pub dynamic_registration: Option<bool>, |
| 78 | |
| 79 | /// The maximum number of folding ranges that the client prefers to receive per document. The value serves as a |
| 80 | /// hint, servers are free to follow the limit. |
| 81 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 82 | pub range_limit: Option<u32>, |
| 83 | |
| 84 | /// If set, the client signals that it only supports folding complete lines. If set, client will |
| 85 | /// ignore specified `startCharacter` and `endCharacter` properties in a FoldingRange. |
| 86 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 87 | pub line_folding_only: Option<bool>, |
| 88 | |
| 89 | /// Specific options for the folding range kind. |
| 90 | /// |
| 91 | /// @since 3.17.0 |
| 92 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 93 | pub folding_range_kind: Option<FoldingRangeKindCapability>, |
| 94 | |
| 95 | /// Specific options for the folding range. |
| 96 | /// |
| 97 | /// @since 3.17.0 |
| 98 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 99 | pub folding_range: Option<FoldingRangeCapability>, |
| 100 | } |
| 101 | |
| 102 | /// Enum of known range kinds |
| 103 | #[derive (Debug, Eq, PartialEq, Deserialize, Serialize, Clone)] |
| 104 | #[serde(rename_all = "lowercase" )] |
| 105 | pub enum FoldingRangeKind { |
| 106 | /// Folding range for a comment |
| 107 | Comment, |
| 108 | /// Folding range for a imports or includes |
| 109 | Imports, |
| 110 | /// Folding range for a region (e.g. `#region`) |
| 111 | Region, |
| 112 | } |
| 113 | |
| 114 | /// Represents a folding range. |
| 115 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 116 | #[serde(rename_all = "camelCase" )] |
| 117 | pub struct FoldingRange { |
| 118 | /// The zero-based line number from where the folded range starts. |
| 119 | pub start_line: u32, |
| 120 | |
| 121 | /// The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line. |
| 122 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 123 | pub start_character: Option<u32>, |
| 124 | |
| 125 | /// The zero-based line number where the folded range ends. |
| 126 | pub end_line: u32, |
| 127 | |
| 128 | /// The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line. |
| 129 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 130 | pub end_character: Option<u32>, |
| 131 | |
| 132 | /// Describes the kind of the folding range such as `comment' or 'region'. The kind |
| 133 | /// is used to categorize folding ranges and used by commands like 'Fold all comments'. See |
| 134 | /// [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds. |
| 135 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 136 | pub kind: Option<FoldingRangeKind>, |
| 137 | |
| 138 | /// The text that the client should show when the specified range is |
| 139 | /// collapsed. If not defined or not supported by the client, a default |
| 140 | /// will be chosen by the client. |
| 141 | /// |
| 142 | /// @since 3.17.0 |
| 143 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 144 | pub collapsed_text: Option<String>, |
| 145 | } |
| 146 | |