lsp_types/
notification.rs

1use 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/// The base protocol now offers support for request cancellation. To cancel a request,
98/// a notification message with the following properties is sent:
99///
100/// A request that got canceled still needs to return from the server and send a response back.
101/// It can not be left open / hanging. This is in line with the JSON RPC protocol that requires
102/// that every request sends a response back. In addition it allows for returning partial results on cancel.
103#[derive(Debug)]
104pub enum Cancel {}
105
106impl Notification for Cancel {
107    type Params = CancelParams;
108    const METHOD: &'static str = "$/cancelRequest";
109}
110
111/// A notification that should be used by the client to modify the trace
112/// setting of the server.
113#[derive(Debug)]
114pub enum SetTrace {}
115
116impl Notification for SetTrace {
117    type Params = SetTraceParams;
118    const METHOD: &'static str = "$/setTrace";
119}
120
121/// A notification to log the trace of the server’s execution.
122/// The amount and content of these notifications depends on the current trace configuration.
123///
124/// `LogTrace` should be used for systematic trace reporting. For single debugging messages,
125/// the server should send `LogMessage` notifications.
126#[derive(Debug)]
127pub enum LogTrace {}
128
129impl Notification for LogTrace {
130    type Params = LogTraceParams;
131    const METHOD: &'static str = "$/logTrace";
132}
133
134/// The initialized notification is sent from the client to the server after the client received
135/// the result of the initialize request but before the client is sending any other request or
136/// notification to the server. The server can use the initialized notification for example to
137/// dynamically register capabilities.
138#[derive(Debug)]
139pub enum Initialized {}
140
141impl Notification for Initialized {
142    type Params = InitializedParams;
143    const METHOD: &'static str = "initialized";
144}
145
146/// A notification to ask the server to exit its process.
147/// The server should exit with success code 0 if the shutdown request has been received before;
148/// otherwise with error code 1.
149#[derive(Debug)]
150pub enum Exit {}
151
152impl Notification for Exit {
153    type Params = ();
154    const METHOD: &'static str = "exit";
155}
156
157/// The show message notification is sent from a server to a client to ask the client to display a particular message
158/// in the user interface.
159#[derive(Debug)]
160pub enum ShowMessage {}
161
162impl Notification for ShowMessage {
163    type Params = ShowMessageParams;
164    const METHOD: &'static str = "window/showMessage";
165}
166
167/// The log message notification is sent from the server to the client to ask the client to log a particular message.
168#[derive(Debug)]
169pub enum LogMessage {}
170
171impl Notification for LogMessage {
172    type Params = LogMessageParams;
173    const METHOD: &'static str = "window/logMessage";
174}
175
176/// The telemetry notification is sent from the server to the client to ask the client to log a telemetry event.
177/// The protocol doesn't specify the payload since no interpretation of the data happens in the protocol. Most clients even don't handle
178/// the event directly but forward them to the extensions owning the corresponding server issuing the event.
179#[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/// A notification sent from the client to the server to signal the change of configuration settings.
188#[derive(Debug)]
189pub enum DidChangeConfiguration {}
190
191impl Notification for DidChangeConfiguration {
192    type Params = DidChangeConfigurationParams;
193    const METHOD: &'static str = "workspace/didChangeConfiguration";
194}
195
196/// The document open notification is sent from the client to the server to signal newly opened text documents.
197/// The document's truth is now managed by the client and the server must not try to read the document's truth
198/// using the document's uri.
199#[derive(Debug)]
200pub enum DidOpenTextDocument {}
201
202impl Notification for DidOpenTextDocument {
203    type Params = DidOpenTextDocumentParams;
204    const METHOD: &'static str = "textDocument/didOpen";
205}
206
207/// The document change notification is sent from the client to the server to signal changes to a text document.
208/// In 2.0 the shape of the params has changed to include proper version numbers and language ids.
209#[derive(Debug)]
210pub enum DidChangeTextDocument {}
211
212impl Notification for DidChangeTextDocument {
213    type Params = DidChangeTextDocumentParams;
214    const METHOD: &'static str = "textDocument/didChange";
215}
216
217/// The document will save notification is sent from the client to the server before the document
218/// is actually saved.
219#[derive(Debug)]
220pub enum WillSaveTextDocument {}
221
222impl Notification for WillSaveTextDocument {
223    type Params = WillSaveTextDocumentParams;
224    const METHOD: &'static str = "textDocument/willSave";
225}
226
227/// The document close notification is sent from the client to the server when the document got closed in the client.
228/// The document's truth now exists where the document's uri points to (e.g. if the document's uri is a file uri
229/// the truth now exists on disk).
230#[derive(Debug)]
231pub enum DidCloseTextDocument {}
232
233impl Notification for DidCloseTextDocument {
234    type Params = DidCloseTextDocumentParams;
235    const METHOD: &'static str = "textDocument/didClose";
236}
237
238/// The document save notification is sent from the client to the server when the document was saved in the client.
239#[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/// The watched files notification is sent from the client to the server when the client detects changes to files and folders
276/// watched by the language client (note although the name suggest that only file events are sent it is about file system events which include folders as well).
277/// It is recommended that servers register for these file system events using the registration mechanism.
278/// In former implementations clients pushed file events without the server actively asking for it.
279#[derive(Debug)]
280pub enum DidChangeWatchedFiles {}
281
282impl Notification for DidChangeWatchedFiles {
283    type Params = DidChangeWatchedFilesParams;
284    const METHOD: &'static str = "workspace/didChangeWatchedFiles";
285}
286
287/// The workspace/didChangeWorkspaceFolders notification is sent from the client to the server to inform the server
288/// about workspace folder configuration changes
289#[derive(Debug)]
290pub enum DidChangeWorkspaceFolders {}
291
292impl Notification for DidChangeWorkspaceFolders {
293    type Params = DidChangeWorkspaceFoldersParams;
294    const METHOD: &'static str = "workspace/didChangeWorkspaceFolders";
295}
296
297/// Diagnostics notification are sent from the server to the client to signal results of validation runs.
298#[derive(Debug)]
299pub enum PublishDiagnostics {}
300
301impl Notification for PublishDiagnostics {
302    type Params = PublishDiagnosticsParams;
303    const METHOD: &'static str = "textDocument/publishDiagnostics";
304}
305
306/// The progress notification is sent from the server to the client to ask
307/// the client to indicate progress.
308#[derive(Debug)]
309pub enum Progress {}
310
311impl Notification for Progress {
312    type Params = ProgressParams;
313    const METHOD: &'static str = "$/progress";
314}
315
316/// The `window/workDoneProgress/cancel` notification is sent from the client
317/// to the server to cancel a progress initiated on the server side using the `window/workDoneProgress/create`.
318#[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/// The did create files notification is sent from the client to the server when files were created from within the client.
327#[derive(Debug)]
328pub enum DidCreateFiles {}
329
330impl Notification for DidCreateFiles {
331    type Params = CreateFilesParams;
332    const METHOD: &'static str = "workspace/didCreateFiles";
333}
334
335/// The did rename files notification is sent from the client to the server when files were renamed from within the client.
336#[derive(Debug)]
337pub enum DidRenameFiles {}
338
339impl Notification for DidRenameFiles {
340    type Params = RenameFilesParams;
341    const METHOD: &'static str = "workspace/didRenameFiles";
342}
343
344/// The did delete files notification is sent from the client to the server when files were deleted from within the client.
345#[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            // check whether the macro name matches the method
367            assert_eq!(<lsp_notification!($name) as Notification>::METHOD, $name);
368            // test whether type checking passes for each component
369            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}