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