| 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 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 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 |
|
| 99 |
|
| 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 |
n. |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 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 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 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 |
|
| 134 |
|
| 135 |
|
| 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 |
|
| 145 |
|
| 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 |
|
| 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 |
|
| 164 |
|
| 165 |
|
| 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 |
|
| 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 |
|
| 184 |
|
| 185 |
|
| 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 |
|
| 195 |
|
| 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 |
|
| 205 |
|
| 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 |
|
| 215 |
|
| 216 |
|
| 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 |
|
| 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 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 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 |
|
| 247 |
|
| 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 |
|
| 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 |
|
| 266 |
|
| 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 |
|
| 276 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 326 |
assert_eq!(<lsp_notification!($name) as Notification>::METHOD, $name); |
| 327 |
|
| 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 |
} |