lsp_types/
notification.rs1use super::*;
2
3use serde::{de::DeserializeOwned, Serialize};
4
5pub trait Notification {
6 type Params: DeserializeOwned + Serialize + Send + Sync + 'static;
7 const METHOD: &'static str;
8}
9
10#[macro_export]
11macro_rules! lsp_notification {
12 ("$/cancelRequest") => {
13 $crate::notification::Cancel
14 };
15 ("$/setTrace") => {
16 $crate::notification::SetTrace
17 };
18 ("$/logTrace") => {
19 $crate::notification::LogTrace
20 };
21 ("initialized") => {
22 $crate::notification::Initialized
23 };
24 ("exit") => {
25 $crate::notification::Exit
26 };
27
28 ("window/showMessage") => {
29 $crate::notification::ShowMessage
30 };
31 ("window/logMessage") => {
32 $crate::notification::LogMessage
33 };
34 ("window/workDoneProgress/cancel") => {
35 $crate::notification::WorkDoneProgressCancel
36 };
37
38 ("telemetry/event") => {
39 $crate::notification::TelemetryEvent
40 };
41
42 ("textDocument/didOpen") => {
43 $crate::notification::DidOpenTextDocument
44 };
45 ("textDocument/didChange") => {
46 $crate::notification::DidChangeTextDocument
47 };
48 ("textDocument/willSave") => {
49 $crate::notification::WillSaveTextDocument
50 };
51 ("textDocument/didSave") => {
52 $crate::notification::DidSaveTextDocument
53 };
54 ("textDocument/didClose") => {
55 $crate::notification::DidCloseTextDocument
56 };
57 ("textDocument/publishDiagnostics") => {
58 $crate::notification::PublishDiagnostics
59 };
60
61 ("notebookDocument/didOpen") => {
62 $crate::notification::DidOpenNotebookDocument
63 };
64 ("notebookDocument/didChange") => {
65 $crate::notification::DidChangeNotebookDocument
66 };
67 ("notebookDocument/didSave") => {
68 $crate::notification::DidSaveNotebookDocument
69 };
70 ("notebookDocument/didClose") => {
71 $crate::notification::DidCloseNotebookDocument
72 };
73
74 ("workspace/didChangeConfiguration") => {
75 $crate::notification::DidChangeConfiguration
76 };
77 ("workspace/didChangeWatchedFiles") => {
78 $crate::notification::DidChangeWatchedFiles
79 };
80 ("workspace/didChangeWorkspaceFolders") => {
81 $crate::notification::DidChangeWorkspaceFolders
82 };
83 ("$/progress") => {
84 $crate::notification::Progress
85 };
86 ("workspace/didCreateFiles") => {
87 $crate::notification::DidCreateFiles
88 };
89 ("workspace/didRenameFiles") => {
90 $crate::notification::DidRenameFiles
91 };
92 ("workspace/didDeleteFiles") => {
93 $crate::notification::DidDeleteFiles
94 };
95}
96
97#[derive(Debug)]
104pub enum Cancel {}
105
106impl Notification for Cancel {
107 type Params = CancelParams;
108 const METHOD: &'static str = "$/cancelRequest";
109}
110
111#[derive(Debug)]
114pub enum SetTrace {}
115
116impl Notification for SetTrace {
117 type Params = SetTraceParams;
118 const METHOD: &'static str = "$/setTrace";
119}
120
121#[derive(Debug)]
127pub enum LogTrace {}
128
129impl Notification for LogTrace {
130 type Params = LogTraceParams;
131 const METHOD: &'static str = "$/logTrace";
132}
133
134#[derive(Debug)]
139pub enum Initialized {}
140
141impl Notification for Initialized {
142 type Params = InitializedParams;
143 const METHOD: &'static str = "initialized";
144}
145
146#[derive(Debug)]
150pub enum Exit {}
151
152impl Notification for Exit {
153 type Params = ();
154 const METHOD: &'static str = "exit";
155}
156
157#[derive(Debug)]
160pub enum ShowMessage {}
161
162impl Notification for ShowMessage {
163 type Params = ShowMessageParams;
164 const METHOD: &'static str = "window/showMessage";
165}
166
167#[derive(Debug)]
169pub enum LogMessage {}
170
171impl Notification for LogMessage {
172 type Params = LogMessageParams;
173 const METHOD: &'static str = "window/logMessage";
174}
175
176#[derive(Debug)]
180pub enum TelemetryEvent {}
181
182impl Notification for TelemetryEvent {
183 type Params = OneOf<LSPObject, LSPArray>;
184 const METHOD: &'static str = "telemetry/event";
185}
186
187#[derive(Debug)]
189pub enum DidChangeConfiguration {}
190
191impl Notification for DidChangeConfiguration {
192 type Params = DidChangeConfigurationParams;
193 const METHOD: &'static str = "workspace/didChangeConfiguration";
194}
195
196#[derive(Debug)]
200pub enum DidOpenTextDocument {}
201
202impl Notification for DidOpenTextDocument {
203 type Params = DidOpenTextDocumentParams;
204 const METHOD: &'static str = "textDocument/didOpen";
205}
206
207#[derive(Debug)]
210pub enum DidChangeTextDocument {}
211
212impl Notification for DidChangeTextDocument {
213 type Params = DidChangeTextDocumentParams;
214 const METHOD: &'static str = "textDocument/didChange";
215}
216
217#[derive(Debug)]
220pub enum WillSaveTextDocument {}
221
222impl Notification for WillSaveTextDocument {
223 type Params = WillSaveTextDocumentParams;
224 const METHOD: &'static str = "textDocument/willSave";
225}
226
227#[derive(Debug)]
231pub enum DidCloseTextDocument {}
232
233impl Notification for DidCloseTextDocument {
234 type Params = DidCloseTextDocumentParams;
235 const METHOD: &'static str = "textDocument/didClose";
236}
237
238#[derive(Debug)]
240pub enum DidSaveTextDocument {}
241
242impl Notification for DidSaveTextDocument {
243 type Params = DidSaveTextDocumentParams;
244 const METHOD: &'static str = "textDocument/didSave";
245}
246
247#[derive(Debug)]
248pub enum DidOpenNotebookDocument {}
249impl Notification for DidOpenNotebookDocument {
250 type Params = DidOpenNotebookDocumentParams;
251 const METHOD: &'static str = "notebookDocument/didOpen";
252}
253
254#[derive(Debug)]
255pub enum DidChangeNotebookDocument {}
256impl Notification for DidChangeNotebookDocument {
257 type Params = DidChangeNotebookDocumentParams;
258 const METHOD: &'static str = "notebookDocument/didChange";
259}
260
261#[derive(Debug)]
262pub enum DidSaveNotebookDocument {}
263impl Notification for DidSaveNotebookDocument {
264 type Params = DidSaveNotebookDocumentParams;
265 const METHOD: &'static str = "notebookDocument/didSave";
266}
267
268#[derive(Debug)]
269pub enum DidCloseNotebookDocument {}
270impl Notification for DidCloseNotebookDocument {
271 type Params = DidCloseNotebookDocumentParams;
272 const METHOD: &'static str = "notebookDocument/didClose";
273}
274
275#[derive(Debug)]
280pub enum DidChangeWatchedFiles {}
281
282impl Notification for DidChangeWatchedFiles {
283 type Params = DidChangeWatchedFilesParams;
284 const METHOD: &'static str = "workspace/didChangeWatchedFiles";
285}
286
287#[derive(Debug)]
290pub enum DidChangeWorkspaceFolders {}
291
292impl Notification for DidChangeWorkspaceFolders {
293 type Params = DidChangeWorkspaceFoldersParams;
294 const METHOD: &'static str = "workspace/didChangeWorkspaceFolders";
295}
296
297#[derive(Debug)]
299pub enum PublishDiagnostics {}
300
301impl Notification for PublishDiagnostics {
302 type Params = PublishDiagnosticsParams;
303 const METHOD: &'static str = "textDocument/publishDiagnostics";
304}
305
306#[derive(Debug)]
309pub enum Progress {}
310
311impl Notification for Progress {
312 type Params = ProgressParams;
313 const METHOD: &'static str = "$/progress";
314}
315
316#[derive(Debug)]
319pub enum WorkDoneProgressCancel {}
320
321impl Notification for WorkDoneProgressCancel {
322 type Params = WorkDoneProgressCancelParams;
323 const METHOD: &'static str = "window/workDoneProgress/cancel";
324}
325
326#[derive(Debug)]
328pub enum DidCreateFiles {}
329
330impl Notification for DidCreateFiles {
331 type Params = CreateFilesParams;
332 const METHOD: &'static str = "workspace/didCreateFiles";
333}
334
335#[derive(Debug)]
337pub enum DidRenameFiles {}
338
339impl Notification for DidRenameFiles {
340 type Params = RenameFilesParams;
341 const METHOD: &'static str = "workspace/didRenameFiles";
342}
343
344#[derive(Debug)]
346pub enum DidDeleteFiles {}
347
348impl Notification for DidDeleteFiles {
349 type Params = DeleteFilesParams;
350 const METHOD: &'static str = "workspace/didDeleteFiles";
351}
352
353#[cfg(test)]
354mod test {
355 use super::*;
356
357 fn fake_call<N>()
358 where
359 N: Notification,
360 N::Params: serde::Serialize,
361 {
362 }
363
364 macro_rules! check_macro {
365 ($name:tt) => {
366 assert_eq!(<lsp_notification!($name) as Notification>::METHOD, $name);
368 fake_call::<lsp_notification!($name)>();
370 };
371 }
372
373 #[test]
374 fn check_macro_definitions() {
375 check_macro!("$/cancelRequest");
376 check_macro!("$/progress");
377 check_macro!("$/logTrace");
378 check_macro!("$/setTrace");
379 check_macro!("initialized");
380 check_macro!("exit");
381 check_macro!("window/showMessage");
382 check_macro!("window/logMessage");
383 check_macro!("window/workDoneProgress/cancel");
384 check_macro!("telemetry/event");
385 check_macro!("textDocument/didOpen");
386 check_macro!("textDocument/didChange");
387 check_macro!("textDocument/willSave");
388 check_macro!("textDocument/didSave");
389 check_macro!("textDocument/didClose");
390 check_macro!("textDocument/publishDiagnostics");
391 check_macro!("workspace/didChangeConfiguration");
392 check_macro!("workspace/didChangeWatchedFiles");
393 check_macro!("workspace/didChangeWorkspaceFolders");
394 check_macro!("workspace/didCreateFiles");
395 check_macro!("workspace/didRenameFiles");
396 check_macro!("workspace/didDeleteFiles");
397 }
398
399 #[test]
400 #[cfg(feature = "proposed")]
401 fn check_proposed_macro_definitions() {}
402}