1use std::collections::HashMap;
23use serde::{Deserialize, Serialize};
45use serde_json::Value;
67use url::Url;
89use crate::Range;
1011#[derive(Eq, PartialEq, Clone, Copy, Deserialize, Serialize)]
12#[serde(transparent)]
13pub struct MessageType(i32);
14lsp_enum! {
15impl MessageType {
16/// An error message.
17pub const ERROR: MessageType = MessageType(1);
18/// A warning message.
19pub const WARNING: MessageType = MessageType(2);
20/// An information message;
21pub const INFO: MessageType = MessageType(3);
22/// A log message.
23pub const LOG: MessageType = MessageType(4);
24}
25}
2627/// Window specific client capabilities.
28#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
29#[serde(rename_all = "camelCase")]
30pub 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")]
37pub work_done_progress: Option<bool>,
3839/// Capabilities specific to the showMessage request.
40 ///
41 /// @since 3.16.0
42#[serde(skip_serializing_if = "Option::is_none")]
43pub show_message: Option<ShowMessageRequestClientCapabilities>,
4445/// Client capabilities for the show document request.
46 ///
47 /// @since 3.16.0
48#[serde(skip_serializing_if = "Option::is_none")]
49pub show_document: Option<ShowDocumentClientCapabilities>,
50}
5152/// Show message request client capabilities
53#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
54#[serde(rename_all = "camelCase")]
55pub struct ShowMessageRequestClientCapabilities {
56/// Capabilities specific to the `MessageActionItem` type.
57#[serde(skip_serializing_if = "Option::is_none")]
58pub message_action_item: Option<MessageActionItemCapabilities>,
59}
6061#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
62#[serde(rename_all = "camelCase")]
63pub 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")]
68pub additional_properties_support: Option<bool>,
69}
7071#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
72#[serde(rename_all = "camelCase")]
73pub struct MessageActionItem {
74/// A short title like 'Retry', 'Open Log' etc.
75pub title: String,
7677/// 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)]
81pub properties: HashMap<String, MessageActionItemProperty>,
82}
8384#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
85#[serde(untagged)]
86pub enum MessageActionItemProperty {
87 String(String),
88 Boolean(bool),
89 Integer(i32),
90 Object(Value),
91}
9293#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
94pub struct LogMessageParams {
95/// The message type. See {@link MessageType}
96#[serde(rename = "type")]
97pub typ: MessageType,
9899/// The actual message
100pub message: String,
101}
102103#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
104pub struct ShowMessageParams {
105/// The message type. See {@link MessageType}.
106#[serde(rename = "type")]
107pub typ: MessageType,
108109/// The actual message.
110pub message: String,
111}
112113#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
114pub struct ShowMessageRequestParams {
115/// The message type. See {@link MessageType}
116#[serde(rename = "type")]
117pub typ: MessageType,
118119/// The actual message
120pub message: String,
121122/// The message action items to present.
123#[serde(skip_serializing_if = "Option::is_none")]
124pub actions: Option<Vec<MessageActionItem>>,
125}
126127/// Client capabilities for the show document request.
128#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
129#[serde(rename_all = "camelCase")]
130pub struct ShowDocumentClientCapabilities {
131/// The client has support for the show document request.
132pub support: bool,
133}
134135/// Params to show a document.
136///
137/// @since 3.16.0
138#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
139#[serde(rename_all = "camelCase")]
140pub struct ShowDocumentParams {
141/// The document uri to show.
142pub uri: Url,
143144/// 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")]
148pub external: Option<bool>,
149150/// 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")]
155pub take_focus: Option<bool>,
156157/// 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")]
162pub selection: Option<Range>,
163}
164165/// 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")]
170pub struct ShowDocumentResult {
171/// A boolean indicating if the show was successful.
172pub success: bool,
173}