lsp_types/
color.rs

1use crate::{
2    DocumentSelector, DynamicRegistrationClientCapabilities, PartialResultParams, Range,
3    TextDocumentIdentifier, TextEdit, WorkDoneProgressParams,
4};
5use serde::{Deserialize, Serialize};
6
7pub type DocumentColorClientCapabilities = DynamicRegistrationClientCapabilities;
8
9#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
10#[serde(rename_all = "camelCase")]
11pub struct ColorProviderOptions {}
12
13#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
14#[serde(rename_all = "camelCase")]
15pub struct StaticTextDocumentColorProviderOptions {
16    /// A document selector to identify the scope of the registration. If set to null
17    /// the document selector provided on the client side will be used.
18    pub document_selector: Option<DocumentSelector>,
19
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub id: Option<String>,
22}
23
24#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
25#[serde(untagged)]
26pub enum ColorProviderCapability {
27    Simple(bool),
28    ColorProvider(ColorProviderOptions),
29    Options(StaticTextDocumentColorProviderOptions),
30}
31
32impl From<ColorProviderOptions> for ColorProviderCapability {
33    fn from(from: ColorProviderOptions) -> Self {
34        Self::ColorProvider(from)
35    }
36}
37
38impl From<StaticTextDocumentColorProviderOptions> for ColorProviderCapability {
39    fn from(from: StaticTextDocumentColorProviderOptions) -> Self {
40        Self::Options(from)
41    }
42}
43
44impl From<bool> for ColorProviderCapability {
45    fn from(from: bool) -> Self {
46        Self::Simple(from)
47    }
48}
49
50#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
51#[serde(rename_all = "camelCase")]
52pub struct DocumentColorParams {
53    /// The text document
54    pub text_document: TextDocumentIdentifier,
55
56    #[serde(flatten)]
57    pub work_done_progress_params: WorkDoneProgressParams,
58
59    #[serde(flatten)]
60    pub partial_result_params: PartialResultParams,
61}
62
63#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
64#[serde(rename_all = "camelCase")]
65pub struct ColorInformation {
66    /// The range in the document where this color appears.
67    pub range: Range,
68    /// The actual color value for this color range.
69    pub color: Color,
70}
71
72#[derive(Debug, PartialEq, Clone, Deserialize, Serialize, Copy)]
73#[serde(rename_all = "camelCase")]
74pub struct Color {
75    /// The red component of this color in the range [0-1].
76    pub red: f32,
77    /// The green component of this color in the range [0-1].
78    pub green: f32,
79    /// The blue component of this color in the range [0-1].
80    pub blue: f32,
81    /// The alpha component of this color in the range [0-1].
82    pub alpha: f32,
83}
84
85#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
86#[serde(rename_all = "camelCase")]
87pub struct ColorPresentationParams {
88    /// The text document.
89    pub text_document: TextDocumentIdentifier,
90
91    /// The color information to request presentations for.
92    pub color: Color,
93
94    /// The range where the color would be inserted. Serves as a context.
95    pub range: Range,
96
97    #[serde(flatten)]
98    pub work_done_progress_params: WorkDoneProgressParams,
99
100    #[serde(flatten)]
101    pub partial_result_params: PartialResultParams,
102}
103
104#[derive(Debug, PartialEq, Eq, Deserialize, Serialize, Default, Clone)]
105#[serde(rename_all = "camelCase")]
106pub struct ColorPresentation {
107    /// The label of this color presentation. It will be shown on the color
108    /// picker header. By default this is also the text that is inserted when selecting
109    /// this color presentation.
110    pub label: String,
111
112    /// An [edit](#TextEdit) which is applied to a document when selecting
113    /// this presentation for the color.  When `falsy` the [label](#ColorPresentation.label)
114    /// is used.
115    #[serde(skip_serializing_if = "Option::is_none")]
116    pub text_edit: Option<TextEdit>,
117
118    /// An optional array of additional [text edits](#TextEdit) that are applied when
119    /// selecting this color presentation. Edits must not overlap with the main [edit](#ColorPresentation.textEdit) nor with themselves.
120    #[serde(skip_serializing_if = "Option::is_none")]
121    pub additional_text_edits: Option<Vec<TextEdit>>,
122}