ls_types/
folding_range.rs

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