languageserver_types/
notification.rs1use super::*;
2
3pub trait Notification {
4 type Params;
5 const METHOD: &'static str;
6}
7
8#[macro_export]
9macro_rules! lsp_notification {
10 ("$/cancelRequest") => {
11 $crate::notification::Cancel
12 };
13 ("initialized") => {
14 $crate::notification::Initialized
15 };
16 ("exit") => {
17 $crate::notification::Exit
18 };
19
20 ("window/showMessage") => {
21 $crate::notification::ShowMessage
22 };
23 ("window/logMessage") => {
24 $crate::notification::LogMessage
25 };
26
27 ("telemetry/event") => {
28 $crate::notification::TelemetryEvent
29 };
30
31 ("textDocument/didOpen") => {
32 $crate::notification::DidOpenTextDocument
33 };
34 ("textDocument/didChange") => {
35 $crate::notification::DidChangeTextDocument
36 };
37 ("textDocument/willSave") => {
38 $crate::notification::WillSaveTextDocument
39 };
40 ("textDocument/willSaveWaitUntil") => {
41 $crate::notification::WillSaveWaitUntil
42 };
43 ("textDocument/didSave") => {
44 $crate::notification::DidSaveTextDocument
45 };
46 ("textDocument/didClose") => {
47 $crate::notification::DidCloseTextDocument
48 };
49 ("textDocument/publishDiagnostics") => {
50 $crate::notification::PublishDiagnostics
51 };
52
53 ("workspace/didChangeConfiguration") => {
54 $crate::notification::DidChangeConfiguration
55 };
56 ("workspace/didChangeWatchedFiles") => {
57 $crate::notification::DidChangeWatchedFiles
58 };
59 ("workspace/didChangeWorkspaceFolders") => {
60 $crate::notification::DidChangeWorkspaceFolders
61 };
62}
63
64#[derive(Debug)]
71pub enum Cancel {}
72
73impl Notification for Cancel {
74 type Params = CancelParams;
75 const METHOD: &'static str = "$/cancelRequest";
76}
77
78#[derive(Debug)]
83pub enum Initialized {}
84
85impl Notification for Initialized {
86 type Params = InitializedParams;
87 const METHOD: &'static str = "initialized";
88}
89
90#[derive(Debug)]
96pub enum Exit {}
97
98impl Notification for Exit {
99 type Params = ();
100 const METHOD: &'static str = "exit";
101}
102
103#[derive(Debug)]
108pub enum ShowMessage {}
109
110impl Notification for ShowMessage {
111 type Params = ShowMessageParams;
112 const METHOD: &'static str = "window/showMessage";
113}
114
115#[derive(Debug)]
119pub enum LogMessage {}
120
121impl Notification for LogMessage {
122 type Params = LogMessageParams;
123 const METHOD: &'static str = "window/logMessage";
124}
125
126#[derive(Debug)]
130pub enum TelemetryEvent {}
131
132impl Notification for TelemetryEvent {
133 type Params = serde_json::Value;
134 const METHOD: &'static str = "telemetry/event";
135}
136
137#[derive(Debug)]
141pub enum DidChangeConfiguration {}
142
143impl Notification for DidChangeConfiguration {
144 type Params = DidChangeConfigurationParams;
145 const METHOD: &'static str = "workspace/didChangeConfiguration";
146}
147
148#[derive(Debug)]
154pub enum DidOpenTextDocument {}
155
156impl Notification for DidOpenTextDocument {
157 type Params = DidOpenTextDocumentParams;
158 const METHOD: &'static str = "textDocument/didOpen";
159}
160
161#[derive(Debug)]
166pub enum DidChangeTextDocument {}
167
168impl Notification for DidChangeTextDocument {
169 type Params = DidChangeTextDocumentParams;
170 const METHOD: &'static str = "textDocument/didChange";
171}
172
173#[derive(Debug)]
176pub enum WillSaveTextDocument {}
177
178impl Notification for WillSaveTextDocument {
179 type Params = WillSaveTextDocumentParams;
180 const METHOD: &'static str = "textDocument/willSave";
181}
182
183#[derive(Debug)]
189pub enum WillSaveWaitUntil {}
190
191impl Notification for WillSaveWaitUntil {
192 type Params = WillSaveTextDocumentParams;
193 const METHOD: &'static str = "textDocument/willSaveWaitUntil";
194}
195
196#[derive(Debug)]
202pub enum DidCloseTextDocument {}
203
204impl Notification for DidCloseTextDocument {
205 type Params = DidCloseTextDocumentParams;
206 const METHOD: &'static str = "textDocument/didClose";
207}
208
209#[derive(Debug)]
213pub enum DidSaveTextDocument {}
214
215impl Notification for DidSaveTextDocument {
216 type Params = DidSaveTextDocumentParams;
217 const METHOD: &'static str = "textDocument/didSave";
218}
219
220#[derive(Debug)]
225pub enum DidChangeWatchedFiles {}
226
227impl Notification for DidChangeWatchedFiles {
228 type Params = DidChangeWatchedFilesParams;
229 const METHOD: &'static str = "workspace/didChangeWatchedFiles";
230}
231
232#[derive(Debug)]
237pub enum DidChangeWorkspaceFolders {}
238
239impl Notification for DidChangeWorkspaceFolders {
240 type Params = DidChangeWorkspaceFoldersParams;
241 const METHOD: &'static str = "workspace/didChangeWorkspaceFolders";
242}
243
244#[derive(Debug)]
248pub enum PublishDiagnostics {}
249
250impl Notification for PublishDiagnostics {
251 type Params = PublishDiagnosticsParams;
252 const METHOD: &'static str = "textDocument/publishDiagnostics";
253}
254
255#[cfg(test)]
256mod test {
257 use super::*;
258
259 fn fake_call<N>()
260 where
261 N: Notification,
262 N::Params: serde::Serialize,
263 {
264 }
265
266 macro_rules! check_macro {
267 ($name:tt) => {
268 assert_eq!(<lsp_notification!($name) as Notification>::METHOD, $name);
270 fake_call::<lsp_notification!($name)>();
272 };
273 }
274
275 #[test]
276 fn check_macro_definitions() {
277 check_macro!("$/cancelRequest");
278 check_macro!("initialized");
279 check_macro!("exit");
280 check_macro!("window/showMessage");
281 check_macro!("window/logMessage");
282 check_macro!("telemetry/event");
283 check_macro!("textDocument/didOpen");
284 check_macro!("textDocument/didChange");
285 check_macro!("textDocument/willSave");
286 check_macro!("textDocument/willSaveWaitUntil");
287 check_macro!("textDocument/didSave");
288 check_macro!("textDocument/didClose");
289 check_macro!("textDocument/publishDiagnostics");
290 check_macro!("workspace/didChangeConfiguration");
291 check_macro!("workspace/didChangeWatchedFiles");
292 check_macro!("workspace/didChangeWorkspaceFolders");
293 }
294}