sync_lsp/window/show_message.rs
1//! impls for the `window/showMessage` notification
2//!
3//! # Usage
4//! The main difference between [`Connection::show_message`] and [`Connection::log_message`] is
5//! that this notification will shown as some kind of popup to the user, whereas
6//! [`Connection::log_message`] will only be logged to the console.
7
8use serde::Serialize;
9use crate::{Connection, TypeProvider};
10use crate::connection::RpcConnection;
11
12use super::MessageType;
13
14#[derive(Default)]
15pub(super) struct ShowMessage;
16
17#[derive(Serialize)]
18struct ShowMessageParams {
19 #[serde(rename = "type")]
20 r#type: MessageType,
21 message: String,
22}
23
24impl<T: TypeProvider> Connection<T> {
25
26 /// This notification may be used to [show a message](self) to the user.
27 ///
28 /// # Arguments
29 /// * `r#type` - The type of message to show.
30 /// * `message` - The message to show.
31
32 pub fn show_message(&mut self, r#type: MessageType, message: String) {
33 self.notify(
34 ShowMessage::METHOD,
35 ShowMessageParams {
36 r#type,
37 message
38 }
39 );
40 }
41}
42
43impl ShowMessage {
44 const METHOD: &'static str = "window/showMessage";
45}