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.
10pub text_document: TextDocumentIdentifier,
1112#[serde(flatten)]
13pub work_done_progress_params: WorkDoneProgressParams,
1415#[serde(flatten)]
16pub partial_result_params: PartialResultParams,
17}
1819#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
20#[serde(untagged)]
21pub enum FoldingRangeProviderCapability {
22 Simple(bool),
23 FoldingProvider(FoldingProviderOptions),
24 Options(StaticTextDocumentColorProviderOptions),
25}
2627impl From<StaticTextDocumentColorProviderOptions> for FoldingRangeProviderCapability {
28fn from(from: StaticTextDocumentColorProviderOptions) -> Self {
29Self::Options(from)
30 }
31}
3233impl From<FoldingProviderOptions> for FoldingRangeProviderCapability {
34fn from(from: FoldingProviderOptions) -> Self {
35Self::FoldingProvider(from)
36 }
37}
3839impl From<bool> for FoldingRangeProviderCapability {
40fn from(from: bool) -> Self {
41Self::Simple(from)
42 }
43}
4445#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
46pub struct FoldingProviderOptions {}
4748#[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
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")]
56pub value_set: Option<Vec<FoldingRangeKind>>,
57}
5859#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
60#[serde(rename_all = "camelCase")]
61pub 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")]
67pub collapsed_text: Option<bool>,
68}
6970#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
71#[serde(rename_all = "camelCase")]
72pub 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")]
77pub dynamic_registration: Option<bool>,
7879/// 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")]
82pub range_limit: Option<u32>,
8384/// 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")]
87pub line_folding_only: Option<bool>,
8889/// Specific options for the folding range kind.
90 ///
91 /// @since 3.17.0
92#[serde(skip_serializing_if = "Option::is_none")]
93pub folding_range_kind: Option<FoldingRangeKindCapability>,
9495/// Specific options for the folding range.
96 ///
97 /// @since 3.17.0
98#[serde(skip_serializing_if = "Option::is_none")]
99pub folding_range: Option<FoldingRangeCapability>,
100}
101102/// Enum of known range kinds
103#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)]
104#[serde(rename_all = "lowercase")]
105pub enum FoldingRangeKind {
106/// Folding range for a comment
107Comment,
108/// Folding range for a imports or includes
109Imports,
110/// Folding range for a region (e.g. `#region`)
111Region,
112}
113114/// Represents a folding range.
115#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
116#[serde(rename_all = "camelCase")]
117pub struct FoldingRange {
118/// The zero-based line number from where the folded range starts.
119pub start_line: u32,
120121/// 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")]
123pub start_character: Option<u32>,
124125/// The zero-based line number where the folded range ends.
126pub end_line: u32,
127128/// 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")]
130pub end_character: Option<u32>,
131132/// 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")]
136pub kind: Option<FoldingRangeKind>,
137138/// 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")]
144pub collapsed_text: Option<String>,
145}