1 | use std::collections::HashMap; |
2 | |
3 | use serde::{Deserialize, Serialize}; |
4 | |
5 | use serde_json::Value; |
6 | |
7 | use url::Url; |
8 | |
9 | use crate::Range; |
10 | |
11 | #[derive (Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] |
12 | #[serde(transparent)] |
13 | pub struct MessageType(i32); |
14 | lsp_enum! { |
15 | impl MessageType { |
16 | /// An error message. |
17 | pub const ERROR: MessageType = MessageType(1); |
18 | /// A warning message. |
19 | pub const WARNING: MessageType = MessageType(2); |
20 | /// An information message; |
21 | pub const INFO: MessageType = MessageType(3); |
22 | /// A log message. |
23 | pub const LOG: MessageType = MessageType(4); |
24 | } |
25 | } |
26 | |
27 | /// Window specific client capabilities. |
28 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
29 | #[serde(rename_all = "camelCase" )] |
30 | pub struct WindowClientCapabilities { |
31 | /// Whether client supports handling progress notifications. If set |
32 | /// servers are allowed to report in `workDoneProgress` property in the |
33 | /// request specific server capabilities. |
34 | /// |
35 | /// @since 3.15.0 |
36 | #[serde(skip_serializing_if = "Option::is_none" )] |
37 | pub work_done_progress: Option<bool>, |
38 | |
39 | /// Capabilities specific to the showMessage request. |
40 | /// |
41 | /// @since 3.16.0 |
42 | #[serde(skip_serializing_if = "Option::is_none" )] |
43 | pub show_message: Option<ShowMessageRequestClientCapabilities>, |
44 | |
45 | /// Client capabilities for the show document request. |
46 | /// |
47 | /// @since 3.16.0 |
48 | #[serde(skip_serializing_if = "Option::is_none" )] |
49 | pub show_document: Option<ShowDocumentClientCapabilities>, |
50 | } |
51 | |
52 | /// Show message request client capabilities |
53 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
54 | #[serde(rename_all = "camelCase" )] |
55 | pub struct ShowMessageRequestClientCapabilities { |
56 | /// Capabilities specific to the `MessageActionItem` type. |
57 | #[serde(skip_serializing_if = "Option::is_none" )] |
58 | pub message_action_item: Option<MessageActionItemCapabilities>, |
59 | } |
60 | |
61 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
62 | #[serde(rename_all = "camelCase" )] |
63 | pub struct MessageActionItemCapabilities { |
64 | /// Whether the client supports additional attributes which |
65 | /// are preserved and send back to the server in the |
66 | /// request's response. |
67 | #[serde(skip_serializing_if = "Option::is_none" )] |
68 | pub additional_properties_support: Option<bool>, |
69 | } |
70 | |
71 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
72 | #[serde(rename_all = "camelCase" )] |
73 | pub struct MessageActionItem { |
74 | /// A short title like 'Retry', 'Open Log' etc. |
75 | pub title: String, |
76 | |
77 | /// Additional attributes that the client preserves and |
78 | /// sends back to the server. This depends on the client |
79 | /// capability window.messageActionItem.additionalPropertiesSupport |
80 | #[serde(flatten)] |
81 | pub properties: HashMap<String, MessageActionItemProperty>, |
82 | } |
83 | |
84 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
85 | #[serde(untagged)] |
86 | pub enum MessageActionItemProperty { |
87 | String(String), |
88 | Boolean(bool), |
89 | Integer(i32), |
90 | Object(Value), |
91 | } |
92 | |
93 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
94 | pub struct LogMessageParams { |
95 | /// The message type. See {@link MessageType} |
96 | #[serde(rename = "type" )] |
97 | pub typ: MessageType, |
98 | |
99 | /// The actual message |
100 | pub message: String, |
101 | } |
102 | |
103 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
104 | pub struct ShowMessageParams { |
105 | /// The message type. See {@link MessageType}. |
106 | #[serde(rename = "type" )] |
107 | pub typ: MessageType, |
108 | |
109 | /// The actual message. |
110 | pub message: String, |
111 | } |
112 | |
113 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
114 | pub struct ShowMessageRequestParams { |
115 | /// The message type. See {@link MessageType} |
116 | #[serde(rename = "type" )] |
117 | pub typ: MessageType, |
118 | |
119 | /// The actual message |
120 | pub message: String, |
121 | |
122 | /// The message action items to present. |
123 | #[serde(skip_serializing_if = "Option::is_none" )] |
124 | pub actions: Option<Vec<MessageActionItem>>, |
125 | } |
126 | |
127 | /// Client capabilities for the show document request. |
128 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
129 | #[serde(rename_all = "camelCase" )] |
130 | pub struct ShowDocumentClientCapabilities { |
131 | /// The client has support for the show document request. |
132 | pub support: bool, |
133 | } |
134 | |
135 | /// Params to show a document. |
136 | /// |
137 | /// @since 3.16.0 |
138 | #[derive (Debug, PartialEq, Clone, Deserialize, Serialize)] |
139 | #[serde(rename_all = "camelCase" )] |
140 | pub struct ShowDocumentParams { |
141 | /// The document uri to show. |
142 | pub uri: Url, |
143 | |
144 | /// Indicates to show the resource in an external program. |
145 | /// To show for example `https://code.visualstudio.com/` |
146 | /// in the default WEB browser set `external` to `true`. |
147 | #[serde(skip_serializing_if = "Option::is_none" )] |
148 | pub external: Option<bool>, |
149 | |
150 | /// An optional property to indicate whether the editor |
151 | /// showing the document should take focus or not. |
152 | /// Clients might ignore this property if an external |
153 | /// program in started. |
154 | #[serde(skip_serializing_if = "Option::is_none" )] |
155 | pub take_focus: Option<bool>, |
156 | |
157 | /// An optional selection range if the document is a text |
158 | /// document. Clients might ignore the property if an |
159 | /// external program is started or the file is not a text |
160 | /// file. |
161 | #[serde(skip_serializing_if = "Option::is_none" )] |
162 | pub selection: Option<Range>, |
163 | } |
164 | |
165 | /// The result of an show document request. |
166 | /// |
167 | /// @since 3.16.0 |
168 | #[derive (Debug, PartialEq, Clone, Deserialize, Serialize)] |
169 | #[serde(rename_all = "camelCase" )] |
170 | pub struct ShowDocumentResult { |
171 | /// A boolean indicating if the show was successful. |
172 | pub success: bool, |
173 | } |
174 | |