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 { from(from: StaticTextDocumentColorProviderOptions) -> Self28 fn from(from: StaticTextDocumentColorProviderOptions) -> Self { 29 Self::Options(from) 30 } 31 } 32 33 impl From<FoldingProviderOptions> for FoldingRangeProviderCapability { from(from: FoldingProviderOptions) -> Self34 fn from(from: FoldingProviderOptions) -> Self { 35 Self::FoldingProvider(from) 36 } 37 } 38 39 impl From<bool> for FoldingRangeProviderCapability { from(from: bool) -> Self40 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 FoldingRangeClientCapabilities { 51 /// Whether implementation supports dynamic registration for folding range providers. If this is set to `true` 52 /// the client supports the new `(FoldingRangeProviderOptions & TextDocumentRegistrationOptions & StaticRegistrationOptions)` 53 /// return value for the corresponding server capability as well. 54 #[serde(skip_serializing_if = "Option::is_none")] 55 pub dynamic_registration: Option<bool>, 56 57 /// The maximum number of folding ranges that the client prefers to receive per document. The value serves as a 58 /// hint, servers are free to follow the limit. 59 #[serde(skip_serializing_if = "Option::is_none")] 60 pub range_limit: Option<u32>, 61 /// If set, the client signals that it only supports folding complete lines. If set, client will 62 /// ignore specified `startCharacter` and `endCharacter` properties in a FoldingRange. 63 #[serde(skip_serializing_if = "Option::is_none")] 64 pub line_folding_only: Option<bool>, 65 } 66 67 /// Enum of known range kinds 68 #[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)] 69 #[serde(rename_all = "lowercase")] 70 pub enum FoldingRangeKind { 71 /// Folding range for a comment 72 Comment, 73 /// Folding range for a imports or includes 74 Imports, 75 /// Folding range for a region (e.g. `#region`) 76 Region, 77 } 78 79 /// Represents a folding range. 80 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 81 #[serde(rename_all = "camelCase")] 82 pub struct FoldingRange { 83 /// The zero-based line number from where the folded range starts. 84 pub start_line: u32, 85 86 /// The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line. 87 #[serde(skip_serializing_if = "Option::is_none")] 88 pub start_character: Option<u32>, 89 90 /// The zero-based line number where the folded range ends. 91 pub end_line: u32, 92 93 /// The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line. 94 #[serde(skip_serializing_if = "Option::is_none")] 95 pub end_character: Option<u32>, 96 97 /// Describes the kind of the folding range such as `comment' or 'region'. The kind 98 /// is used to categorize folding ranges and used by commands like 'Fold all comments'. See 99 /// [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds. 100 #[serde(skip_serializing_if = "Option::is_none")] 101 pub kind: Option<FoldingRangeKind>, 102 } 103