use super::*;
use serde::{de::DeserializeOwned, Serialize};
pub trait Notification {
type Params: DeserializeOwned + Serialize;
const METHOD: &'static str;
}
#[macro_export]
macro_rules! lsp_notification {
("$/cancelRequest") => {
$crate::notification::Cancel
};
("initialized") => {
$crate::notification::Initialized
};
("exit") => {
$crate::notification::Exit
};
("window/showMessage") => {
$crate::notification::ShowMessage
};
("window/logMessage") => {
$crate::notification::LogMessage
};
("window/workDoneProgress/cancel") => {
$crate::notification::WorkDoneProgressCancel
};
("telemetry/event") => {
$crate::notification::TelemetryEvent
};
("textDocument/didOpen") => {
$crate::notification::DidOpenTextDocument
};
("textDocument/didChange") => {
$crate::notification::DidChangeTextDocument
};
("textDocument/willSave") => {
$crate::notification::WillSaveTextDocument
};
("textDocument/didSave") => {
$crate::notification::DidSaveTextDocument
};
("textDocument/didClose") => {
$crate::notification::DidCloseTextDocument
};
("textDocument/publishDiagnostics") => {
$crate::notification::PublishDiagnostics
};
("workspace/didChangeConfiguration") => {
$crate::notification::DidChangeConfiguration
};
("workspace/didChangeWatchedFiles") => {
$crate::notification::DidChangeWatchedFiles
};
("workspace/didChangeWorkspaceFolders") => {
$crate::notification::DidChangeWorkspaceFolders
};
("$/progress") => {
$crate::notification::Progress
};
("workspace/didCreateFiles") => {
$crate::notification::DidCreateFiles
};
("workspace/didRenameFiles") => {
$crate::notification::DidRenameFiles
};
("workspace/didDeleteFiles") => {
$crate::notification::DidDeleteFiles
};
}
#[derive(Debug)]
pub enum Cancel {}
impl Notification for Cancel {
type Params = CancelParams;
const METHOD: &'static str = "$/cancelRequest";
}
#[derive(Debug)]
pub enum Initialized {}
impl Notification for Initialized {
type Params = InitializedParams;
const METHOD: &'static str = "initialized";
}
#[derive(Debug)]
pub enum Exit {}
impl Notification for Exit {
type Params = ();
const METHOD: &'static str = "exit";
}
#[derive(Debug)]
pub enum ShowMessage {}
impl Notification for ShowMessage {
type Params = ShowMessageParams;
const METHOD: &'static str = "window/showMessage";
}
#[derive(Debug)]
pub enum LogMessage {}
impl Notification for LogMessage {
type Params = LogMessageParams;
const METHOD: &'static str = "window/logMessage";
}
#[derive(Debug)]
pub enum TelemetryEvent {}
impl Notification for TelemetryEvent {
type Params = serde_json::Value;
const METHOD: &'static str = "telemetry/event";
}
#[derive(Debug)]
pub enum DidChangeConfiguration {}
impl Notification for DidChangeConfiguration {
type Params = DidChangeConfigurationParams;
const METHOD: &'static str = "workspace/didChangeConfiguration";
}
#[derive(Debug)]
pub enum DidOpenTextDocument {}
impl Notification for DidOpenTextDocument {
type Params = DidOpenTextDocumentParams;
const METHOD: &'static str = "textDocument/didOpen";
}
#[derive(Debug)]
pub enum DidChangeTextDocument {}
impl Notification for DidChangeTextDocument {
type Params = DidChangeTextDocumentParams;
const METHOD: &'static str = "textDocument/didChange";
}
#[derive(Debug)]
pub enum WillSaveTextDocument {}
impl Notification for WillSaveTextDocument {
type Params = WillSaveTextDocumentParams;
const METHOD: &'static str = "textDocument/willSave";
}
#[derive(Debug)]
pub enum DidCloseTextDocument {}
impl Notification for DidCloseTextDocument {
type Params = DidCloseTextDocumentParams;
const METHOD: &'static str = "textDocument/didClose";
}
#[derive(Debug)]
pub enum DidSaveTextDocument {}
impl Notification for DidSaveTextDocument {
type Params = DidSaveTextDocumentParams;
const METHOD: &'static str = "textDocument/didSave";
}
#[derive(Debug)]
pub enum DidChangeWatchedFiles {}
impl Notification for DidChangeWatchedFiles {
type Params = DidChangeWatchedFilesParams;
const METHOD: &'static str = "workspace/didChangeWatchedFiles";
}
#[derive(Debug)]
pub enum DidChangeWorkspaceFolders {}
impl Notification for DidChangeWorkspaceFolders {
type Params = DidChangeWorkspaceFoldersParams;
const METHOD: &'static str = "workspace/didChangeWorkspaceFolders";
}
#[derive(Debug)]
pub enum PublishDiagnostics {}
impl Notification for PublishDiagnostics {
type Params = PublishDiagnosticsParams;
const METHOD: &'static str = "textDocument/publishDiagnostics";
}
#[derive(Debug)]
pub enum Progress {}
impl Notification for Progress {
type Params = ProgressParams;
const METHOD: &'static str = "$/progress";
}
#[derive(Debug)]
pub enum WorkDoneProgressCancel {}
impl Notification for WorkDoneProgressCancel {
type Params = WorkDoneProgressCancelParams;
const METHOD: &'static str = "window/workDoneProgress/cancel";
}
#[derive(Debug)]
pub enum DidCreateFiles {}
impl Notification for DidCreateFiles {
type Params = CreateFilesParams;
const METHOD: &'static str = "workspace/didCreateFiles";
}
#[derive(Debug)]
pub enum DidRenameFiles {}
impl Notification for DidRenameFiles {
type Params = RenameFilesParams;
const METHOD: &'static str = "workspace/didRenameFiles";
}
#[derive(Debug)]
pub enum DidDeleteFiles {}
impl Notification for DidDeleteFiles {
type Params = DeleteFilesParams;
const METHOD: &'static str = "workspace/didDeleteFiles";
}
#[cfg(test)]
mod test {
use super::*;
fn fake_call<N>()
where
N: Notification,
N::Params: serde::Serialize,
{
}
macro_rules! check_macro {
($name:tt) => {
assert_eq!(<lsp_notification!($name) as Notification>::METHOD, $name);
fake_call::<lsp_notification!($name)>();
};
}
#[test]
fn check_macro_definitions() {
check_macro!("$/cancelRequest");
check_macro!("$/progress");
check_macro!("initialized");
check_macro!("exit");
check_macro!("window/showMessage");
check_macro!("window/logMessage");
check_macro!("window/workDoneProgress/cancel");
check_macro!("telemetry/event");
check_macro!("textDocument/didOpen");
check_macro!("textDocument/didChange");
check_macro!("textDocument/willSave");
check_macro!("textDocument/didSave");
check_macro!("textDocument/didClose");
check_macro!("textDocument/publishDiagnostics");
check_macro!("workspace/didChangeConfiguration");
check_macro!("workspace/didChangeWatchedFiles");
check_macro!("workspace/didChangeWorkspaceFolders");
check_macro!("workspace/didCreateFiles");
check_macro!("workspace/didRenameFiles");
check_macro!("workspace/didDeleteFiles");
}
#[test]
#[cfg(feature = "proposed")]
fn check_proposed_macro_definitions() {}
}