1 | use super::*; |
2 | |
3 | use serde::{de::DeserializeOwned, Serialize}; |
4 | |
5 | pub trait Notification { |
6 | type Params: DeserializeOwned + Serialize + Send + Sync + 'static; |
7 | const METHOD: &'static str; |
8 | } |
9 | |
10 | #[macro_export ] |
11 | macro_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 | ("workspace/didChangeConfiguration" ) => { |
62 | $crate::notification::DidChangeConfiguration |
63 | }; |
64 | ("workspace/didChangeWatchedFiles" ) => { |
65 | $crate::notification::DidChangeWatchedFiles |
66 | }; |
67 | ("workspace/didChangeWorkspaceFolders" ) => { |
68 | $crate::notification::DidChangeWorkspaceFolders |
69 | }; |
70 | ("$/progress" ) => { |
71 | $crate::notification::Progress |
72 | }; |
73 | ("workspace/didCreateFiles" ) => { |
74 | $crate::notification::DidCreateFiles |
75 | }; |
76 | ("workspace/didRenameFiles" ) => { |
77 | $crate::notification::DidRenameFiles |
78 | }; |
79 | ("workspace/didDeleteFiles" ) => { |
80 | $crate::notification::DidDeleteFiles |
81 | }; |
82 | } |
83 | |
84 | /// The base protocol now offers support for request cancellation. To cancel a request, |
85 | /// a notification message with the following properties is sent: |
86 | /// |
87 | /// A request that got canceled still needs to return from the server and send a response back. |
88 | /// It can not be left open / hanging. This is in line with the JSON RPC protocol that requires |
89 | /// that every request sends a response back. In addition it allows for returning partial results on cancel. |
90 | #[derive (Debug)] |
91 | pub enum Cancel {} |
92 | |
93 | impl Notification for Cancel { |
94 | type Params = CancelParams; |
95 | const METHOD: &'static str = "$/cancelRequest" ; |
96 | } |
97 | |
98 | /// A notification that should be used by the client to modify the trace |
99 | /// setting of the server. |
100 | #[derive (Debug)] |
101 | pub enum SetTrace {} |
102 | |
103 | impl Notification for SetTrace { |
104 | type Params = SetTraceParams; |
105 | const METHOD: &'static str = "$/setTrace" ; |
106 | } |
107 | |
108 | /// A notification to log the trace of the server’s execution. |
109 | /// The amount and content of these notifications depends on the current trace configuration. |
110 | /// |
111 | /// `LogTrace` should be used for systematic trace reporting. For single debugging messages, |
112 | /// the server should send `LogMessage` notifications. |
113 | #[derive (Debug)] |
114 | pub enum LogTrace {} |
115 | |
116 | impl Notification for LogTrace { |
117 | type Params = LogTraceParams; |
118 | const METHOD: &'static str = "$/logTrace" ; |
119 | } |
120 | |
121 | /// The initialized notification is sent from the client to the server after the client received |
122 | /// the result of the initialize request but before the client is sending any other request or |
123 | /// notification to the server. The server can use the initialized notification for example to |
124 | /// dynamically register capabilities. |
125 | #[derive (Debug)] |
126 | pub enum Initialized {} |
127 | |
128 | impl Notification for Initialized { |
129 | type Params = InitializedParams; |
130 | const METHOD: &'static str = "initialized" ; |
131 | } |
132 | |
133 | /// A notification to ask the server to exit its process. |
134 | /// The server should exit with success code 0 if the shutdown request has been received before; |
135 | /// otherwise with error code 1. |
136 | #[derive (Debug)] |
137 | pub enum Exit {} |
138 | |
139 | impl Notification for Exit { |
140 | type Params = (); |
141 | const METHOD: &'static str = "exit" ; |
142 | } |
143 | |
144 | /// The show message notification is sent from a server to a client to ask the client to display a particular message |
145 | /// in the user interface. |
146 | #[derive (Debug)] |
147 | pub enum ShowMessage {} |
148 | |
149 | impl Notification for ShowMessage { |
150 | type Params = ShowMessageParams; |
151 | const METHOD: &'static str = "window/showMessage" ; |
152 | } |
153 | |
154 | /// The log message notification is sent from the server to the client to ask the client to log a particular message. |
155 | #[derive (Debug)] |
156 | pub enum LogMessage {} |
157 | |
158 | impl Notification for LogMessage { |
159 | type Params = LogMessageParams; |
160 | const METHOD: &'static str = "window/logMessage" ; |
161 | } |
162 | |
163 | /// The telemetry notification is sent from the server to the client to ask the client to log a telemetry event. |
164 | /// The protocol doesn't specify the payload since no interpretation of the data happens in the protocol. Most clients even don't handle |
165 | /// the event directly but forward them to the extensions owning the corresponding server issuing the event. |
166 | #[derive (Debug)] |
167 | pub enum TelemetryEvent {} |
168 | |
169 | impl Notification for TelemetryEvent { |
170 | type Params = OneOf<LSPObject, LSPArray>; |
171 | const METHOD: &'static str = "telemetry/event" ; |
172 | } |
173 | |
174 | /// A notification sent from the client to the server to signal the change of configuration settings. |
175 | #[derive (Debug)] |
176 | pub enum DidChangeConfiguration {} |
177 | |
178 | impl Notification for DidChangeConfiguration { |
179 | type Params = DidChangeConfigurationParams; |
180 | const METHOD: &'static str = "workspace/didChangeConfiguration" ; |
181 | } |
182 | |
183 | /// The document open notification is sent from the client to the server to signal newly opened text documents. |
184 | /// The document's truth is now managed by the client and the server must not try to read the document's truth |
185 | /// using the document's uri. |
186 | #[derive (Debug)] |
187 | pub enum DidOpenTextDocument {} |
188 | |
189 | impl Notification for DidOpenTextDocument { |
190 | type Params = DidOpenTextDocumentParams; |
191 | const METHOD: &'static str = "textDocument/didOpen" ; |
192 | } |
193 | |
194 | /// The document change notification is sent from the client to the server to signal changes to a text document. |
195 | /// In 2.0 the shape of the params has changed to include proper version numbers and language ids. |
196 | #[derive (Debug)] |
197 | pub enum DidChangeTextDocument {} |
198 | |
199 | impl Notification for DidChangeTextDocument { |
200 | type Params = DidChangeTextDocumentParams; |
201 | const METHOD: &'static str = "textDocument/didChange" ; |
202 | } |
203 | |
204 | /// The document will save notification is sent from the client to the server before the document |
205 | /// is actually saved. |
206 | #[derive (Debug)] |
207 | pub enum WillSaveTextDocument {} |
208 | |
209 | impl Notification for WillSaveTextDocument { |
210 | type Params = WillSaveTextDocumentParams; |
211 | const METHOD: &'static str = "textDocument/willSave" ; |
212 | } |
213 | |
214 | /// The document close notification is sent from the client to the server when the document got closed in the client. |
215 | /// The document's truth now exists where the document's uri points to (e.g. if the document's uri is a file uri |
216 | /// the truth now exists on disk). |
217 | #[derive (Debug)] |
218 | pub enum DidCloseTextDocument {} |
219 | |
220 | impl Notification for DidCloseTextDocument { |
221 | type Params = DidCloseTextDocumentParams; |
222 | const METHOD: &'static str = "textDocument/didClose" ; |
223 | } |
224 | |
225 | /// The document save notification is sent from the client to the server when the document was saved in the client. |
226 | #[derive (Debug)] |
227 | pub enum DidSaveTextDocument {} |
228 | |
229 | impl Notification for DidSaveTextDocument { |
230 | type Params = DidSaveTextDocumentParams; |
231 | const METHOD: &'static str = "textDocument/didSave" ; |
232 | } |
233 | |
234 | /// The watched files notification is sent from the client to the server when the client detects changes to files and folders |
235 | /// 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). |
236 | /// It is recommended that servers register for these file system events using the registration mechanism. |
237 | /// In former implementations clients pushed file events without the server actively asking for it. |
238 | #[derive (Debug)] |
239 | pub enum DidChangeWatchedFiles {} |
240 | |
241 | impl Notification for DidChangeWatchedFiles { |
242 | type Params = DidChangeWatchedFilesParams; |
243 | const METHOD: &'static str = "workspace/didChangeWatchedFiles" ; |
244 | } |
245 | |
246 | /// The workspace/didChangeWorkspaceFolders notification is sent from the client to the server to inform the server |
247 | /// about workspace folder configuration changes |
248 | #[derive (Debug)] |
249 | pub enum DidChangeWorkspaceFolders {} |
250 | |
251 | impl Notification for DidChangeWorkspaceFolders { |
252 | type Params = DidChangeWorkspaceFoldersParams; |
253 | const METHOD: &'static str = "workspace/didChangeWorkspaceFolders" ; |
254 | } |
255 | |
256 | /// Diagnostics notification are sent from the server to the client to signal results of validation runs. |
257 | #[derive (Debug)] |
258 | pub enum PublishDiagnostics {} |
259 | |
260 | impl Notification for PublishDiagnostics { |
261 | type Params = PublishDiagnosticsParams; |
262 | const METHOD: &'static str = "textDocument/publishDiagnostics" ; |
263 | } |
264 | |
265 | /// The progress notification is sent from the server to the client to ask |
266 | /// the client to indicate progress. |
267 | #[derive (Debug)] |
268 | pub enum Progress {} |
269 | |
270 | impl Notification for Progress { |
271 | type Params = ProgressParams; |
272 | const METHOD: &'static str = "$/progress" ; |
273 | } |
274 | |
275 | /// The `window/workDoneProgress/cancel` notification is sent from the client |
276 | /// to the server to cancel a progress initiated on the server side using the `window/workDoneProgress/create`. |
277 | #[derive (Debug)] |
278 | pub enum WorkDoneProgressCancel {} |
279 | |
280 | impl Notification for WorkDoneProgressCancel { |
281 | type Params = WorkDoneProgressCancelParams; |
282 | const METHOD: &'static str = "window/workDoneProgress/cancel" ; |
283 | } |
284 | |
285 | /// The did create files notification is sent from the client to the server when files were created from within the client. |
286 | #[derive (Debug)] |
287 | pub enum DidCreateFiles {} |
288 | |
289 | impl Notification for DidCreateFiles { |
290 | type Params = CreateFilesParams; |
291 | const METHOD: &'static str = "workspace/didCreateFiles" ; |
292 | } |
293 | |
294 | /// The did rename files notification is sent from the client to the server when files were renamed from within the client. |
295 | #[derive (Debug)] |
296 | pub enum DidRenameFiles {} |
297 | |
298 | impl Notification for DidRenameFiles { |
299 | type Params = RenameFilesParams; |
300 | const METHOD: &'static str = "workspace/didRenameFiles" ; |
301 | } |
302 | |
303 | /// The did delete files notification is sent from the client to the server when files were deleted from within the client. |
304 | #[derive (Debug)] |
305 | pub enum DidDeleteFiles {} |
306 | |
307 | impl Notification for DidDeleteFiles { |
308 | type Params = DeleteFilesParams; |
309 | const METHOD: &'static str = "workspace/didDeleteFiles" ; |
310 | } |
311 | |
312 | #[cfg (test)] |
313 | mod test { |
314 | use super::*; |
315 | |
316 | fn fake_call<N>() |
317 | where |
318 | N: Notification, |
319 | N::Params: serde::Serialize, |
320 | { |
321 | } |
322 | |
323 | macro_rules! check_macro { |
324 | ($name:tt) => { |
325 | // check whether the macro name matches the method |
326 | assert_eq!(<lsp_notification!($name) as Notification>::METHOD, $name); |
327 | // test whether type checking passes for each component |
328 | fake_call::<lsp_notification!($name)>(); |
329 | }; |
330 | } |
331 | |
332 | #[test ] |
333 | fn check_macro_definitions() { |
334 | check_macro!("$/cancelRequest" ); |
335 | check_macro!("$/progress" ); |
336 | check_macro!("$/logTrace" ); |
337 | check_macro!("$/setTrace" ); |
338 | check_macro!("initialized" ); |
339 | check_macro!("exit" ); |
340 | check_macro!("window/showMessage" ); |
341 | check_macro!("window/logMessage" ); |
342 | check_macro!("window/workDoneProgress/cancel" ); |
343 | check_macro!("telemetry/event" ); |
344 | check_macro!("textDocument/didOpen" ); |
345 | check_macro!("textDocument/didChange" ); |
346 | check_macro!("textDocument/willSave" ); |
347 | check_macro!("textDocument/didSave" ); |
348 | check_macro!("textDocument/didClose" ); |
349 | check_macro!("textDocument/publishDiagnostics" ); |
350 | check_macro!("workspace/didChangeConfiguration" ); |
351 | check_macro!("workspace/didChangeWatchedFiles" ); |
352 | check_macro!("workspace/didChangeWorkspaceFolders" ); |
353 | check_macro!("workspace/didCreateFiles" ); |
354 | check_macro!("workspace/didRenameFiles" ); |
355 | check_macro!("workspace/didDeleteFiles" ); |
356 | } |
357 | |
358 | #[test ] |
359 | #[cfg (feature = "proposed" )] |
360 | fn check_proposed_macro_definitions() {} |
361 | } |
362 | |