| 1 | /*! |
| 2 | |
| 3 | Language Server Protocol types for Rust. |
| 4 | |
| 5 | Based on: <https://microsoft.github.io/language-server-protocol/specification> |
| 6 | |
| 7 | This library uses the URL crate for parsing URIs. Note that there is |
| 8 | some confusion on the meaning of URLs vs URIs: |
| 9 | <http://stackoverflow.com/a/28865728/393898>. According to that |
| 10 | information, on the classical sense of "URLs", "URLs" are a subset of |
| 11 | URIs, But on the modern/new meaning of URLs, they are the same as |
| 12 | URIs. The important take-away aspect is that the URL crate should be |
| 13 | able to parse any URI, such as `urn:isbn:0451450523`. |
| 14 | |
| 15 | |
| 16 | */ |
| 17 | #![allow (non_upper_case_globals)] |
| 18 | #![forbid (unsafe_code)] |
| 19 | #[macro_use ] |
| 20 | extern crate bitflags; |
| 21 | |
| 22 | use std::{collections::HashMap, fmt::Debug}; |
| 23 | |
| 24 | use serde::{de, de::Error as Error_, Deserialize, Serialize}; |
| 25 | use serde_json::Value; |
| 26 | pub use url::Url; |
| 27 | |
| 28 | // Large enough to contain any enumeration name defined in this crate |
| 29 | type PascalCaseBuf = [u8; 32]; |
| 30 | const fn fmt_pascal_case_const(name: &str) -> (PascalCaseBuf, usize) { |
| 31 | let mut buf = [0; 32]; |
| 32 | let mut buf_i = 0; |
| 33 | let mut name_i = 0; |
| 34 | let name = name.as_bytes(); |
| 35 | while name_i < name.len() { |
| 36 | let first = name[name_i]; |
| 37 | name_i += 1; |
| 38 | |
| 39 | buf[buf_i] = first; |
| 40 | buf_i += 1; |
| 41 | |
| 42 | while name_i < name.len() { |
| 43 | let rest = name[name_i]; |
| 44 | name_i += 1; |
| 45 | if rest == b'_' { |
| 46 | break; |
| 47 | } |
| 48 | |
| 49 | buf[buf_i] = rest.to_ascii_lowercase(); |
| 50 | buf_i += 1; |
| 51 | } |
| 52 | } |
| 53 | (buf, buf_i) |
| 54 | } |
| 55 | |
| 56 | fn fmt_pascal_case(f: &mut std::fmt::Formatter<'_>, name: &str) -> std::fmt::Result { |
| 57 | for word: &str in name.split('_' ) { |
| 58 | let mut chars: Chars<'_> = word.chars(); |
| 59 | let first: char = chars.next().unwrap(); |
| 60 | write!(f, " {}" , first)?; |
| 61 | for rest: char in chars { |
| 62 | write!(f, " {}" , rest.to_lowercase())?; |
| 63 | } |
| 64 | } |
| 65 | Ok(()) |
| 66 | } |
| 67 | |
| 68 | macro_rules! lsp_enum { |
| 69 | (impl $typ: ident { $( $(#[$attr:meta])* pub const $name: ident : $enum_type: ty = $value: expr; )* }) => { |
| 70 | impl $typ { |
| 71 | $( |
| 72 | $(#[$attr])* |
| 73 | pub const $name: $enum_type = $value; |
| 74 | )* |
| 75 | } |
| 76 | |
| 77 | impl std::fmt::Debug for $typ { |
| 78 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 79 | match *self { |
| 80 | $( |
| 81 | Self::$name => crate::fmt_pascal_case(f, stringify!($name)), |
| 82 | )* |
| 83 | _ => write!(f, "{}({})" , stringify!($typ), self.0), |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | impl std::convert::TryFrom<&str> for $typ { |
| 89 | type Error = &'static str; |
| 90 | fn try_from(value: &str) -> Result<Self, Self::Error> { |
| 91 | match () { |
| 92 | $( |
| 93 | _ if { |
| 94 | const X: (crate::PascalCaseBuf, usize) = crate::fmt_pascal_case_const(stringify!($name)); |
| 95 | let (buf, len) = X; |
| 96 | &buf[..len] == value.as_bytes() |
| 97 | } => Ok(Self::$name), |
| 98 | )* |
| 99 | _ => Err("unknown enum variant" ), |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | pub mod error_codes; |
| 108 | pub mod notification; |
| 109 | pub mod request; |
| 110 | |
| 111 | mod call_hierarchy; |
| 112 | pub use call_hierarchy::*; |
| 113 | |
| 114 | mod code_action; |
| 115 | pub use code_action::*; |
| 116 | |
| 117 | mod code_lens; |
| 118 | pub use code_lens::*; |
| 119 | |
| 120 | mod color; |
| 121 | pub use color::*; |
| 122 | |
| 123 | mod completion; |
| 124 | pub use completion::*; |
| 125 | |
| 126 | mod document_diagnostic; |
| 127 | pub use document_diagnostic::*; |
| 128 | |
| 129 | mod document_highlight; |
| 130 | pub use document_highlight::*; |
| 131 | |
| 132 | mod document_link; |
| 133 | pub use document_link::*; |
| 134 | |
| 135 | mod document_symbols; |
| 136 | pub use document_symbols::*; |
| 137 | |
| 138 | mod file_operations; |
| 139 | pub use file_operations::*; |
| 140 | |
| 141 | mod folding_range; |
| 142 | pub use folding_range::*; |
| 143 | |
| 144 | mod formatting; |
| 145 | pub use formatting::*; |
| 146 | |
| 147 | mod hover; |
| 148 | pub use hover::*; |
| 149 | |
| 150 | mod inlay_hint; |
| 151 | pub use inlay_hint::*; |
| 152 | |
| 153 | mod inline_value; |
| 154 | pub use inline_value::*; |
| 155 | |
| 156 | #[cfg (feature = "proposed" )] |
| 157 | mod inline_completion; |
| 158 | #[cfg (feature = "proposed" )] |
| 159 | pub use inline_completion::*; |
| 160 | |
| 161 | mod moniker; |
| 162 | pub use moniker::*; |
| 163 | |
| 164 | mod progress; |
| 165 | pub use progress::*; |
| 166 | |
| 167 | mod references; |
| 168 | pub use references::*; |
| 169 | |
| 170 | mod rename; |
| 171 | pub use rename::*; |
| 172 | |
| 173 | pub mod selection_range; |
| 174 | pub use selection_range::*; |
| 175 | |
| 176 | mod semantic_tokens; |
| 177 | pub use semantic_tokens::*; |
| 178 | |
| 179 | mod signature_help; |
| 180 | pub use signature_help::*; |
| 181 | |
| 182 | mod type_hierarchy; |
| 183 | pub use type_hierarchy::*; |
| 184 | |
| 185 | mod linked_editing; |
| 186 | pub use linked_editing::*; |
| 187 | |
| 188 | mod window; |
| 189 | pub use window::*; |
| 190 | |
| 191 | mod workspace_diagnostic; |
| 192 | pub use workspace_diagnostic::*; |
| 193 | |
| 194 | mod workspace_folders; |
| 195 | pub use workspace_folders::*; |
| 196 | |
| 197 | mod workspace_symbols; |
| 198 | pub use workspace_symbols::*; |
| 199 | |
| 200 | pub mod lsif; |
| 201 | |
| 202 | mod trace; |
| 203 | pub use trace::*; |
| 204 | |
| 205 | /* ----------------- Auxiliary types ----------------- */ |
| 206 | |
| 207 | #[derive (Debug, Eq, Hash, PartialEq, Clone, Deserialize, Serialize)] |
| 208 | #[serde(untagged)] |
| 209 | pub enum NumberOrString { |
| 210 | Number(i32), |
| 211 | String(String), |
| 212 | } |
| 213 | |
| 214 | /* ----------------- Cancel support ----------------- */ |
| 215 | |
| 216 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 217 | pub struct CancelParams { |
| 218 | /// The request id to cancel. |
| 219 | pub id: NumberOrString, |
| 220 | } |
| 221 | |
| 222 | /* ----------------- Basic JSON Structures ----------------- */ |
| 223 | |
| 224 | /// The LSP any type |
| 225 | /// |
| 226 | /// @since 3.17.0 |
| 227 | pub type LSPAny = serde_json::Value; |
| 228 | |
| 229 | /// LSP object definition. |
| 230 | /// |
| 231 | /// @since 3.17.0 |
| 232 | pub type LSPObject = serde_json::Map<String, serde_json::Value>; |
| 233 | |
| 234 | /// LSP arrays. |
| 235 | /// |
| 236 | /// @since 3.17.0 |
| 237 | pub type LSPArray = Vec<serde_json::Value>; |
| 238 | |
| 239 | /// Position in a text document expressed as zero-based line and character offset. |
| 240 | /// A position is between two characters like an 'insert' cursor in a editor. |
| 241 | #[derive (Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Default, Deserialize, Serialize, Hash)] |
| 242 | pub struct Position { |
| 243 | /// Line position in a document (zero-based). |
| 244 | pub line: u32, |
| 245 | /// Character offset on a line in a document (zero-based). The meaning of this |
| 246 | /// offset is determined by the negotiated `PositionEncodingKind`. |
| 247 | /// |
| 248 | /// If the character value is greater than the line length it defaults back |
| 249 | /// to the line length. |
| 250 | pub character: u32, |
| 251 | } |
| 252 | |
| 253 | impl Position { |
| 254 | pub fn new(line: u32, character: u32) -> Position { |
| 255 | Position { line, character } |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /// A range in a text document expressed as (zero-based) start and end positions. |
| 260 | /// A range is comparable to a selection in an editor. Therefore the end position is exclusive. |
| 261 | #[derive (Debug, Eq, PartialEq, Copy, Clone, Default, Deserialize, Serialize, Hash)] |
| 262 | pub struct Range { |
| 263 | /// The range's start position. |
| 264 | pub start: Position, |
| 265 | /// The range's end position. |
| 266 | pub end: Position, |
| 267 | } |
| 268 | |
| 269 | impl Range { |
| 270 | pub fn new(start: Position, end: Position) -> Range { |
| 271 | Range { start, end } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | /// Represents a location inside a resource, such as a line inside a text file. |
| 276 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize, Hash)] |
| 277 | pub struct Location { |
| 278 | pub uri: Url, |
| 279 | pub range: Range, |
| 280 | } |
| 281 | |
| 282 | impl Location { |
| 283 | pub fn new(uri: Url, range: Range) -> Location { |
| 284 | Location { uri, range } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /// Represents a link between a source and a target location. |
| 289 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 290 | #[serde(rename_all = "camelCase" )] |
| 291 | pub struct LocationLink { |
| 292 | /// Span of the origin of this link. |
| 293 | /// |
| 294 | /// Used as the underlined span for mouse interaction. Defaults to the word range at |
| 295 | /// the mouse position. |
| 296 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 297 | pub origin_selection_range: Option<Range>, |
| 298 | |
| 299 | /// The target resource identifier of this link. |
| 300 | pub target_uri: Url, |
| 301 | |
| 302 | /// The full target range of this link. |
| 303 | pub target_range: Range, |
| 304 | |
| 305 | /// The span of this link. |
| 306 | pub target_selection_range: Range, |
| 307 | } |
| 308 | |
| 309 | /// A type indicating how positions are encoded, |
| 310 | /// specifically what column offsets mean. |
| 311 | /// |
| 312 | /// @since 3.17.0 |
| 313 | #[derive (Debug, Eq, PartialEq, Hash, PartialOrd, Clone, Deserialize, Serialize)] |
| 314 | pub struct PositionEncodingKind(std::borrow::Cow<'static, str>); |
| 315 | |
| 316 | impl PositionEncodingKind { |
| 317 | /// Character offsets count UTF-8 code units. |
| 318 | pub const UTF8: PositionEncodingKind = PositionEncodingKind::new("utf-8" ); |
| 319 | |
| 320 | /// Character offsets count UTF-16 code units. |
| 321 | /// |
| 322 | /// This is the default and must always be supported |
| 323 | /// by servers |
| 324 | pub const UTF16: PositionEncodingKind = PositionEncodingKind::new("utf-16" ); |
| 325 | |
| 326 | /// Character offsets count UTF-32 code units. |
| 327 | /// |
| 328 | /// Implementation note: these are the same as Unicode code points, |
| 329 | /// so this `PositionEncodingKind` may also be used for an |
| 330 | /// encoding-agnostic representation of character offsets. |
| 331 | pub const UTF32: PositionEncodingKind = PositionEncodingKind::new("utf-32" ); |
| 332 | |
| 333 | pub const fn new(tag: &'static str) -> Self { |
| 334 | PositionEncodingKind(std::borrow::Cow::Borrowed(tag)) |
| 335 | } |
| 336 | |
| 337 | pub fn as_str(&self) -> &str { |
| 338 | &self.0 |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | impl From<String> for PositionEncodingKind { |
| 343 | fn from(from: String) -> Self { |
| 344 | PositionEncodingKind(std::borrow::Cow::from(from)) |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | impl From<&'static str> for PositionEncodingKind { |
| 349 | fn from(from: &'static str) -> Self { |
| 350 | PositionEncodingKind::new(tag:from) |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | /// Represents a diagnostic, such as a compiler error or warning. |
| 355 | /// Diagnostic objects are only valid in the scope of a resource. |
| 356 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 357 | #[serde(rename_all = "camelCase" )] |
| 358 | pub struct Diagnostic { |
| 359 | /// The range at which the message applies. |
| 360 | pub range: Range, |
| 361 | |
| 362 | /// The diagnostic's severity. Can be omitted. If omitted it is up to the |
| 363 | /// client to interpret diagnostics as error, warning, info or hint. |
| 364 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 365 | pub severity: Option<DiagnosticSeverity>, |
| 366 | |
| 367 | /// The diagnostic's code. Can be omitted. |
| 368 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 369 | pub code: Option<NumberOrString>, |
| 370 | |
| 371 | /// An optional property to describe the error code. |
| 372 | /// |
| 373 | /// @since 3.16.0 |
| 374 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 375 | pub code_description: Option<CodeDescription>, |
| 376 | |
| 377 | /// A human-readable string describing the source of this |
| 378 | /// diagnostic, e.g. 'typescript' or 'super lint'. |
| 379 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 380 | pub source: Option<String>, |
| 381 | |
| 382 | /// The diagnostic's message. |
| 383 | pub message: String, |
| 384 | |
| 385 | /// An array of related diagnostic information, e.g. when symbol-names within |
| 386 | /// a scope collide all definitions can be marked via this property. |
| 387 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 388 | pub related_information: Option<Vec<DiagnosticRelatedInformation>>, |
| 389 | |
| 390 | /// Additional metadata about the diagnostic. |
| 391 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 392 | pub tags: Option<Vec<DiagnosticTag>>, |
| 393 | |
| 394 | /// A data entry field that is preserved between a `textDocument/publishDiagnostics` |
| 395 | /// notification and `textDocument/codeAction` request. |
| 396 | /// |
| 397 | /// @since 3.16.0 |
| 398 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 399 | pub data: Option<serde_json::Value>, |
| 400 | } |
| 401 | |
| 402 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 403 | #[serde(rename_all = "camelCase" )] |
| 404 | pub struct CodeDescription { |
| 405 | pub href: Url, |
| 406 | } |
| 407 | |
| 408 | impl Diagnostic { |
| 409 | pub fn new( |
| 410 | range: Range, |
| 411 | severity: Option<DiagnosticSeverity>, |
| 412 | code: Option<NumberOrString>, |
| 413 | source: Option<String>, |
| 414 | message: String, |
| 415 | related_information: Option<Vec<DiagnosticRelatedInformation>>, |
| 416 | tags: Option<Vec<DiagnosticTag>>, |
| 417 | ) -> Diagnostic { |
| 418 | Diagnostic { |
| 419 | range, |
| 420 | severity, |
| 421 | code, |
| 422 | source, |
| 423 | message, |
| 424 | related_information, |
| 425 | tags, |
| 426 | ..Diagnostic::default() |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | pub fn new_simple(range: Range, message: String) -> Diagnostic { |
| 431 | Self::new(range, None, None, None, message, None, None) |
| 432 | } |
| 433 | |
| 434 | pub fn new_with_code_number( |
| 435 | range: Range, |
| 436 | severity: DiagnosticSeverity, |
| 437 | code_number: i32, |
| 438 | source: Option<String>, |
| 439 | message: String, |
| 440 | ) -> Diagnostic { |
| 441 | let code = Some(NumberOrString::Number(code_number)); |
| 442 | Self::new(range, Some(severity), code, source, message, None, None) |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | /// The protocol currently supports the following diagnostic severities: |
| 447 | #[derive (Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Deserialize, Serialize)] |
| 448 | #[serde(transparent)] |
| 449 | pub struct DiagnosticSeverity(i32); |
| 450 | lsp_enum! { |
| 451 | impl DiagnosticSeverity { |
| 452 | /// Reports an error. |
| 453 | pub const ERROR: DiagnosticSeverity = DiagnosticSeverity(1); |
| 454 | /// Reports a warning. |
| 455 | pub const WARNING: DiagnosticSeverity = DiagnosticSeverity(2); |
| 456 | /// Reports an information. |
| 457 | pub const INFORMATION: DiagnosticSeverity = DiagnosticSeverity(3); |
| 458 | /// Reports a hint. |
| 459 | pub const HINT: DiagnosticSeverity = DiagnosticSeverity(4); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | /// Represents a related message and source code location for a diagnostic. This |
| 464 | /// should be used to point to code locations that cause or related to a |
| 465 | /// diagnostics, e.g when duplicating a symbol in a scope. |
| 466 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 467 | pub struct DiagnosticRelatedInformation { |
| 468 | /// The location of this related diagnostic information. |
| 469 | pub location: Location, |
| 470 | |
| 471 | /// The message of this related diagnostic information. |
| 472 | pub message: String, |
| 473 | } |
| 474 | |
| 475 | /// The diagnostic tags. |
| 476 | #[derive (Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 477 | #[serde(transparent)] |
| 478 | pub struct DiagnosticTag(i32); |
| 479 | lsp_enum! { |
| 480 | impl DiagnosticTag { |
| 481 | /// Unused or unnecessary code. |
| 482 | /// Clients are allowed to render diagnostics with this tag faded out instead of having |
| 483 | /// an error squiggle. |
| 484 | pub const UNNECESSARY: DiagnosticTag = DiagnosticTag(1); |
| 485 | |
| 486 | /// Deprecated or obsolete code. |
| 487 | /// Clients are allowed to rendered diagnostics with this tag strike through. |
| 488 | pub const DEPRECATED: DiagnosticTag = DiagnosticTag(2); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /// Represents a reference to a command. Provides a title which will be used to represent a command in the UI. |
| 493 | /// Commands are identified by a string identifier. The recommended way to handle commands is to implement |
| 494 | /// their execution on the server side if the client and server provides the corresponding capabilities. |
| 495 | /// Alternatively the tool extension code could handle the command. |
| 496 | /// The protocol currently doesn’t specify a set of well-known commands. |
| 497 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 498 | pub struct Command { |
| 499 | /// Title of the command, like `save`. |
| 500 | pub title: String, |
| 501 | /// The identifier of the actual command handler. |
| 502 | pub command: String, |
| 503 | /// Arguments that the command handler should be |
| 504 | /// invoked with. |
| 505 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 506 | pub arguments: Option<Vec<Value>>, |
| 507 | } |
| 508 | |
| 509 | impl Command { |
| 510 | pub fn new(title: String, command: String, arguments: Option<Vec<Value>>) -> Command { |
| 511 | Command { |
| 512 | title, |
| 513 | command, |
| 514 | arguments, |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | /// A textual edit applicable to a text document. |
| 520 | /// |
| 521 | /// If n `TextEdit`s are applied to a text document all text edits describe changes to the initial document version. |
| 522 | /// Execution wise text edits should applied from the bottom to the top of the text document. Overlapping text edits |
| 523 | /// are not supported. |
| 524 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 525 | #[serde(rename_all = "camelCase" )] |
| 526 | pub struct TextEdit { |
| 527 | /// The range of the text document to be manipulated. To insert |
| 528 | /// text into a document create a range where start === end. |
| 529 | pub range: Range, |
| 530 | /// The string to be inserted. For delete operations use an |
| 531 | /// empty string. |
| 532 | pub new_text: String, |
| 533 | } |
| 534 | |
| 535 | impl TextEdit { |
| 536 | pub fn new(range: Range, new_text: String) -> TextEdit { |
| 537 | TextEdit { range, new_text } |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | /// An identifier referring to a change annotation managed by a workspace |
| 542 | /// edit. |
| 543 | /// |
| 544 | /// @since 3.16.0 |
| 545 | pub type ChangeAnnotationIdentifier = String; |
| 546 | |
| 547 | /// A special text edit with an additional change annotation. |
| 548 | /// |
| 549 | /// @since 3.16.0 |
| 550 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 551 | #[serde(rename_all = "camelCase" )] |
| 552 | pub struct AnnotatedTextEdit { |
| 553 | #[serde(flatten)] |
| 554 | pub text_edit: TextEdit, |
| 555 | |
| 556 | /// The actual annotation |
| 557 | pub annotation_id: ChangeAnnotationIdentifier, |
| 558 | } |
| 559 | |
| 560 | /// Describes textual changes on a single text document. The text document is referred to as a |
| 561 | /// `OptionalVersionedTextDocumentIdentifier` to allow clients to check the text document version before an |
| 562 | /// edit is applied. A `TextDocumentEdit` describes all changes on a version Si and after they are |
| 563 | /// applied move the document to version Si+1. So the creator of a `TextDocumentEdit` doesn't need to |
| 564 | /// sort the array or do any kind of ordering. However the edits must be non overlapping. |
| 565 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 566 | #[serde(rename_all = "camelCase" )] |
| 567 | pub struct TextDocumentEdit { |
| 568 | /// The text document to change. |
| 569 | pub text_document: OptionalVersionedTextDocumentIdentifier, |
| 570 | |
| 571 | /// The edits to be applied. |
| 572 | /// |
| 573 | /// @since 3.16.0 - support for AnnotatedTextEdit. This is guarded by the |
| 574 | /// client capability `workspace.workspaceEdit.changeAnnotationSupport` |
| 575 | pub edits: Vec<OneOf<TextEdit, AnnotatedTextEdit>>, |
| 576 | } |
| 577 | |
| 578 | /// Additional information that describes document changes. |
| 579 | /// |
| 580 | /// @since 3.16.0 |
| 581 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 582 | #[serde(rename_all = "camelCase" )] |
| 583 | pub struct ChangeAnnotation { |
| 584 | /// A human-readable string describing the actual change. The string |
| 585 | /// is rendered prominent in the user interface. |
| 586 | pub label: String, |
| 587 | |
| 588 | /// A flag which indicates that user confirmation is needed |
| 589 | /// before applying the change. |
| 590 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 591 | pub needs_confirmation: Option<bool>, |
| 592 | |
| 593 | /// A human-readable string which is rendered less prominent in |
| 594 | /// the user interface. |
| 595 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 596 | pub description: Option<String>, |
| 597 | } |
| 598 | |
| 599 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 600 | #[serde(rename_all = "camelCase" )] |
| 601 | pub struct ChangeAnnotationWorkspaceEditClientCapabilities { |
| 602 | /// Whether the client groups edits with equal labels into tree nodes, |
| 603 | /// for instance all edits labelled with "Changes in Strings" would |
| 604 | /// be a tree node. |
| 605 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 606 | pub groups_on_label: Option<bool>, |
| 607 | } |
| 608 | |
| 609 | /// Options to create a file. |
| 610 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 611 | #[serde(rename_all = "camelCase" )] |
| 612 | pub struct CreateFileOptions { |
| 613 | /// Overwrite existing file. Overwrite wins over `ignoreIfExists` |
| 614 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 615 | pub overwrite: Option<bool>, |
| 616 | /// Ignore if exists. |
| 617 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 618 | pub ignore_if_exists: Option<bool>, |
| 619 | } |
| 620 | |
| 621 | /// Create file operation |
| 622 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 623 | #[serde(rename_all = "camelCase" )] |
| 624 | pub struct CreateFile { |
| 625 | /// The resource to create. |
| 626 | pub uri: Url, |
| 627 | /// Additional options |
| 628 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 629 | pub options: Option<CreateFileOptions>, |
| 630 | |
| 631 | /// An optional annotation identifier describing the operation. |
| 632 | /// |
| 633 | /// @since 3.16.0 |
| 634 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 635 | pub annotation_id: Option<ChangeAnnotationIdentifier>, |
| 636 | } |
| 637 | |
| 638 | /// Rename file options |
| 639 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 640 | #[serde(rename_all = "camelCase" )] |
| 641 | pub struct RenameFileOptions { |
| 642 | /// Overwrite target if existing. Overwrite wins over `ignoreIfExists` |
| 643 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 644 | pub overwrite: Option<bool>, |
| 645 | /// Ignores if target exists. |
| 646 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 647 | pub ignore_if_exists: Option<bool>, |
| 648 | } |
| 649 | |
| 650 | /// Rename file operation |
| 651 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 652 | #[serde(rename_all = "camelCase" )] |
| 653 | pub struct RenameFile { |
| 654 | /// The old (existing) location. |
| 655 | pub old_uri: Url, |
| 656 | /// The new location. |
| 657 | pub new_uri: Url, |
| 658 | /// Rename options. |
| 659 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 660 | pub options: Option<RenameFileOptions>, |
| 661 | |
| 662 | /// An optional annotation identifier describing the operation. |
| 663 | /// |
| 664 | /// @since 3.16.0 |
| 665 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 666 | pub annotation_id: Option<ChangeAnnotationIdentifier>, |
| 667 | } |
| 668 | |
| 669 | /// Delete file options |
| 670 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 671 | #[serde(rename_all = "camelCase" )] |
| 672 | pub struct DeleteFileOptions { |
| 673 | /// Delete the content recursively if a folder is denoted. |
| 674 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 675 | pub recursive: Option<bool>, |
| 676 | /// Ignore the operation if the file doesn't exist. |
| 677 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 678 | pub ignore_if_not_exists: Option<bool>, |
| 679 | |
| 680 | /// An optional annotation identifier describing the operation. |
| 681 | /// |
| 682 | /// @since 3.16.0 |
| 683 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 684 | pub annotation_id: Option<ChangeAnnotationIdentifier>, |
| 685 | } |
| 686 | |
| 687 | /// Delete file operation |
| 688 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 689 | #[serde(rename_all = "camelCase" )] |
| 690 | pub struct DeleteFile { |
| 691 | /// The file to delete. |
| 692 | pub uri: Url, |
| 693 | /// Delete options. |
| 694 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 695 | pub options: Option<DeleteFileOptions>, |
| 696 | } |
| 697 | |
| 698 | /// A workspace edit represents changes to many resources managed in the workspace. |
| 699 | /// The edit should either provide `changes` or `documentChanges`. |
| 700 | /// If the client can handle versioned document edits and if `documentChanges` are present, |
| 701 | /// the latter are preferred over `changes`. |
| 702 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 703 | #[serde(rename_all = "camelCase" )] |
| 704 | pub struct WorkspaceEdit { |
| 705 | /// Holds changes to existing resources. |
| 706 | #[serde(with = "url_map" )] |
| 707 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 708 | #[serde(default)] |
| 709 | pub changes: Option<HashMap<Url, Vec<TextEdit>>>, // changes?: { [uri: string]: TextEdit[]; }; |
| 710 | |
| 711 | /// Depending on the client capability `workspace.workspaceEdit.resourceOperations` document changes |
| 712 | /// are either an array of `TextDocumentEdit`s to express changes to n different text documents |
| 713 | /// where each text document edit addresses a specific version of a text document. Or it can contain |
| 714 | /// above `TextDocumentEdit`s mixed with create, rename and delete file / folder operations. |
| 715 | /// |
| 716 | /// Whether a client supports versioned document edits is expressed via |
| 717 | /// `workspace.workspaceEdit.documentChanges` client capability. |
| 718 | /// |
| 719 | /// If a client neither supports `documentChanges` nor `workspace.workspaceEdit.resourceOperations` then |
| 720 | /// only plain `TextEdit`s using the `changes` property are supported. |
| 721 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 722 | pub document_changes: Option<DocumentChanges>, |
| 723 | |
| 724 | /// A map of change annotations that can be referenced in |
| 725 | /// `AnnotatedTextEdit`s or create, rename and delete file / folder |
| 726 | /// operations. |
| 727 | /// |
| 728 | /// Whether clients honor this property depends on the client capability |
| 729 | /// `workspace.changeAnnotationSupport`. |
| 730 | /// |
| 731 | /// @since 3.16.0 |
| 732 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 733 | pub change_annotations: Option<HashMap<ChangeAnnotationIdentifier, ChangeAnnotation>>, |
| 734 | } |
| 735 | |
| 736 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 737 | #[serde(untagged)] |
| 738 | pub enum DocumentChanges { |
| 739 | Edits(Vec<TextDocumentEdit>), |
| 740 | Operations(Vec<DocumentChangeOperation>), |
| 741 | } |
| 742 | |
| 743 | // TODO: Once https://github.com/serde-rs/serde/issues/912 is solved |
| 744 | // we can remove ResourceOp and switch to the following implementation |
| 745 | // of DocumentChangeOperation: |
| 746 | // |
| 747 | // #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 748 | // #[serde(tag = "kind", rename_all="lowercase" )] |
| 749 | // pub enum DocumentChangeOperation { |
| 750 | // Create(CreateFile), |
| 751 | // Rename(RenameFile), |
| 752 | // Delete(DeleteFile), |
| 753 | // |
| 754 | // #[serde(other)] |
| 755 | // Edit(TextDocumentEdit), |
| 756 | // } |
| 757 | |
| 758 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 759 | #[serde(untagged, rename_all = "lowercase" )] |
| 760 | pub enum DocumentChangeOperation { |
| 761 | Op(ResourceOp), |
| 762 | Edit(TextDocumentEdit), |
| 763 | } |
| 764 | |
| 765 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 766 | #[serde(tag = "kind" , rename_all = "lowercase" )] |
| 767 | pub enum ResourceOp { |
| 768 | Create(CreateFile), |
| 769 | Rename(RenameFile), |
| 770 | Delete(DeleteFile), |
| 771 | } |
| 772 | |
| 773 | pub type DidChangeConfigurationClientCapabilities = DynamicRegistrationClientCapabilities; |
| 774 | |
| 775 | #[derive (Debug, Default, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 776 | #[serde(rename_all = "camelCase" )] |
| 777 | pub struct ConfigurationParams { |
| 778 | pub items: Vec<ConfigurationItem>, |
| 779 | } |
| 780 | |
| 781 | #[derive (Debug, Default, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 782 | #[serde(rename_all = "camelCase" )] |
| 783 | pub struct ConfigurationItem { |
| 784 | /// The scope to get the configuration section for. |
| 785 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 786 | pub scope_uri: Option<Url>, |
| 787 | |
| 788 | ///The configuration section asked for. |
| 789 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 790 | pub section: Option<String>, |
| 791 | } |
| 792 | |
| 793 | mod url_map { |
| 794 | use std::fmt; |
| 795 | use std::marker::PhantomData; |
| 796 | |
| 797 | use super::*; |
| 798 | |
| 799 | pub fn deserialize<'de, D, V>(deserializer: D) -> Result<Option<HashMap<Url, V>>, D::Error> |
| 800 | where |
| 801 | D: serde::Deserializer<'de>, |
| 802 | V: de::DeserializeOwned, |
| 803 | { |
| 804 | struct UrlMapVisitor<V> { |
| 805 | _marker: PhantomData<V>, |
| 806 | } |
| 807 | |
| 808 | impl<V: de::DeserializeOwned> Default for UrlMapVisitor<V> { |
| 809 | fn default() -> Self { |
| 810 | UrlMapVisitor { |
| 811 | _marker: PhantomData, |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | impl<'de, V: de::DeserializeOwned> de::Visitor<'de> for UrlMapVisitor<V> { |
| 816 | type Value = HashMap<Url, V>; |
| 817 | |
| 818 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
| 819 | formatter.write_str("map" ) |
| 820 | } |
| 821 | |
| 822 | fn visit_map<M>(self, mut visitor: M) -> Result<Self::Value, M::Error> |
| 823 | where |
| 824 | M: de::MapAccess<'de>, |
| 825 | { |
| 826 | let mut values = HashMap::with_capacity(visitor.size_hint().unwrap_or(0)); |
| 827 | |
| 828 | // While there are entries remaining in the input, add them |
| 829 | // into our map. |
| 830 | while let Some((key, value)) = visitor.next_entry::<Url, _>()? { |
| 831 | values.insert(key, value); |
| 832 | } |
| 833 | |
| 834 | Ok(values) |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | struct OptionUrlMapVisitor<V> { |
| 839 | _marker: PhantomData<V>, |
| 840 | } |
| 841 | impl<V: de::DeserializeOwned> Default for OptionUrlMapVisitor<V> { |
| 842 | fn default() -> Self { |
| 843 | OptionUrlMapVisitor { |
| 844 | _marker: PhantomData, |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | impl<'de, V: de::DeserializeOwned> de::Visitor<'de> for OptionUrlMapVisitor<V> { |
| 849 | type Value = Option<HashMap<Url, V>>; |
| 850 | |
| 851 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
| 852 | formatter.write_str("option" ) |
| 853 | } |
| 854 | |
| 855 | #[inline ] |
| 856 | fn visit_unit<E>(self) -> Result<Self::Value, E> |
| 857 | where |
| 858 | E: serde::de::Error, |
| 859 | { |
| 860 | Ok(None) |
| 861 | } |
| 862 | |
| 863 | #[inline ] |
| 864 | fn visit_none<E>(self) -> Result<Self::Value, E> |
| 865 | where |
| 866 | E: serde::de::Error, |
| 867 | { |
| 868 | Ok(None) |
| 869 | } |
| 870 | |
| 871 | #[inline ] |
| 872 | fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error> |
| 873 | where |
| 874 | D: serde::Deserializer<'de>, |
| 875 | { |
| 876 | deserializer |
| 877 | .deserialize_map(UrlMapVisitor::<V>::default()) |
| 878 | .map(Some) |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | // Instantiate our Visitor and ask the Deserializer to drive |
| 883 | // it over the input data, resulting in an instance of MyMap. |
| 884 | deserializer.deserialize_option(OptionUrlMapVisitor::default()) |
| 885 | } |
| 886 | |
| 887 | pub fn serialize<S, V>( |
| 888 | changes: &Option<HashMap<Url, V>>, |
| 889 | serializer: S, |
| 890 | ) -> Result<S::Ok, S::Error> |
| 891 | where |
| 892 | S: serde::Serializer, |
| 893 | V: serde::Serialize, |
| 894 | { |
| 895 | use serde::ser::SerializeMap; |
| 896 | |
| 897 | match *changes { |
| 898 | Some(ref changes) => { |
| 899 | let mut map = serializer.serialize_map(Some(changes.len()))?; |
| 900 | for (k, v) in changes { |
| 901 | map.serialize_entry(k.as_str(), v)?; |
| 902 | } |
| 903 | map.end() |
| 904 | } |
| 905 | None => serializer.serialize_none(), |
| 906 | } |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | impl WorkspaceEdit { |
| 911 | pub fn new(changes: HashMap<Url, Vec<TextEdit>>) -> WorkspaceEdit { |
| 912 | WorkspaceEdit { |
| 913 | changes: Some(changes), |
| 914 | document_changes: None, |
| 915 | ..Default::default() |
| 916 | } |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | /// Text documents are identified using a URI. On the protocol level, URIs are passed as strings. |
| 921 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 922 | pub struct TextDocumentIdentifier { |
| 923 | // !!!!!! Note: |
| 924 | // In the spec VersionedTextDocumentIdentifier extends TextDocumentIdentifier |
| 925 | // This modelled by "mixing-in" TextDocumentIdentifier in VersionedTextDocumentIdentifier, |
| 926 | // so any changes to this type must be effected in the sub-type as well. |
| 927 | /// The text document's URI. |
| 928 | pub uri: Url, |
| 929 | } |
| 930 | |
| 931 | impl TextDocumentIdentifier { |
| 932 | pub fn new(uri: Url) -> TextDocumentIdentifier { |
| 933 | TextDocumentIdentifier { uri } |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | /// An item to transfer a text document from the client to the server. |
| 938 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 939 | #[serde(rename_all = "camelCase" )] |
| 940 | pub struct TextDocumentItem { |
| 941 | /// The text document's URI. |
| 942 | pub uri: Url, |
| 943 | |
| 944 | /// The text document's language identifier. |
| 945 | pub language_id: String, |
| 946 | |
| 947 | /// The version number of this document (it will strictly increase after each |
| 948 | /// change, including undo/redo). |
| 949 | pub version: i32, |
| 950 | |
| 951 | /// The content of the opened text document. |
| 952 | pub text: String, |
| 953 | } |
| 954 | |
| 955 | impl TextDocumentItem { |
| 956 | pub fn new(uri: Url, language_id: String, version: i32, text: String) -> TextDocumentItem { |
| 957 | TextDocumentItem { |
| 958 | uri, |
| 959 | language_id, |
| 960 | version, |
| 961 | text, |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | /// An identifier to denote a specific version of a text document. This information usually flows from the client to the server. |
| 967 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 968 | pub struct VersionedTextDocumentIdentifier { |
| 969 | // This field was "mixed-in" from TextDocumentIdentifier |
| 970 | /// The text document's URI. |
| 971 | pub uri: Url, |
| 972 | |
| 973 | /// The version number of this document. |
| 974 | /// |
| 975 | /// The version number of a document will increase after each change, |
| 976 | /// including undo/redo. The number doesn't need to be consecutive. |
| 977 | pub version: i32, |
| 978 | } |
| 979 | |
| 980 | impl VersionedTextDocumentIdentifier { |
| 981 | pub fn new(uri: Url, version: i32) -> VersionedTextDocumentIdentifier { |
| 982 | VersionedTextDocumentIdentifier { uri, version } |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | /// An identifier which optionally denotes a specific version of a text document. This information usually flows from the server to the client |
| 987 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 988 | pub struct OptionalVersionedTextDocumentIdentifier { |
| 989 | // This field was "mixed-in" from TextDocumentIdentifier |
| 990 | /// The text document's URI. |
| 991 | pub uri: Url, |
| 992 | |
| 993 | /// The version number of this document. If an optional versioned text document |
| 994 | /// identifier is sent from the server to the client and the file is not |
| 995 | /// open in the editor (the server has not received an open notification |
| 996 | /// before) the server can send `null` to indicate that the version is |
| 997 | /// known and the content on disk is the master (as specified with document |
| 998 | /// content ownership). |
| 999 | /// |
| 1000 | /// The version number of a document will increase after each change, |
| 1001 | /// including undo/redo. The number doesn't need to be consecutive. |
| 1002 | pub version: Option<i32>, |
| 1003 | } |
| 1004 | |
| 1005 | impl OptionalVersionedTextDocumentIdentifier { |
| 1006 | pub fn new(uri: Url, version: i32) -> OptionalVersionedTextDocumentIdentifier { |
| 1007 | OptionalVersionedTextDocumentIdentifier { |
| 1008 | uri, |
| 1009 | version: Some(version), |
| 1010 | } |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | /// A parameter literal used in requests to pass a text document and a position inside that document. |
| 1015 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 1016 | #[serde(rename_all = "camelCase" )] |
| 1017 | pub struct TextDocumentPositionParams { |
| 1018 | // !!!!!! Note: |
| 1019 | // In the spec ReferenceParams extends TextDocumentPositionParams |
| 1020 | // This modelled by "mixing-in" TextDocumentPositionParams in ReferenceParams, |
| 1021 | // so any changes to this type must be effected in sub-type as well. |
| 1022 | /// The text document. |
| 1023 | pub text_document: TextDocumentIdentifier, |
| 1024 | |
| 1025 | /// The position inside the text document. |
| 1026 | pub position: Position, |
| 1027 | } |
| 1028 | |
| 1029 | impl TextDocumentPositionParams { |
| 1030 | pub fn new( |
| 1031 | text_document: TextDocumentIdentifier, |
| 1032 | position: Position, |
| 1033 | ) -> TextDocumentPositionParams { |
| 1034 | TextDocumentPositionParams { |
| 1035 | text_document, |
| 1036 | position, |
| 1037 | } |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | /// A document filter denotes a document through properties like language, schema or pattern. |
| 1042 | /// Examples are a filter that applies to TypeScript files on disk or a filter the applies to JSON |
| 1043 | /// files with name package.json: |
| 1044 | /// |
| 1045 | /// { language: 'typescript', scheme: 'file' } |
| 1046 | /// { language: 'json', pattern: '**/package.json' } |
| 1047 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 1048 | pub struct DocumentFilter { |
| 1049 | /// A language id, like `typescript`. |
| 1050 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1051 | pub language: Option<String>, |
| 1052 | |
| 1053 | /// A Uri [scheme](#Uri.scheme), like `file` or `untitled`. |
| 1054 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1055 | pub scheme: Option<String>, |
| 1056 | |
| 1057 | /// A glob pattern, like `*.{ts,js}`. |
| 1058 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1059 | pub pattern: Option<String>, |
| 1060 | } |
| 1061 | |
| 1062 | /// A document selector is the combination of one or many document filters. |
| 1063 | pub type DocumentSelector = Vec<DocumentFilter>; |
| 1064 | |
| 1065 | // ========================= Actual Protocol ========================= |
| 1066 | |
| 1067 | #[derive (Debug, PartialEq, Clone, Deserialize, Serialize, Default)] |
| 1068 | #[serde(rename_all = "camelCase" )] |
| 1069 | pub struct InitializeParams { |
| 1070 | /// The process Id of the parent process that started |
| 1071 | /// the server. Is null if the process has not been started by another process. |
| 1072 | /// If the parent process is not alive then the server should exit (see exit notification) its process. |
| 1073 | pub process_id: Option<u32>, |
| 1074 | |
| 1075 | /// The rootPath of the workspace. Is null |
| 1076 | /// if no folder is open. |
| 1077 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1078 | #[deprecated (note = "Use `root_uri` instead when possible" )] |
| 1079 | pub root_path: Option<String>, |
| 1080 | |
| 1081 | /// The rootUri of the workspace. Is null if no |
| 1082 | /// folder is open. If both `rootPath` and `rootUri` are set |
| 1083 | /// `rootUri` wins. |
| 1084 | #[serde(default)] |
| 1085 | #[deprecated (note = "Use `workspace_folders` instead when possible" )] |
| 1086 | pub root_uri: Option<Url>, |
| 1087 | |
| 1088 | /// User provided initialization options. |
| 1089 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1090 | pub initialization_options: Option<Value>, |
| 1091 | |
| 1092 | /// The capabilities provided by the client (editor or tool) |
| 1093 | pub capabilities: ClientCapabilities, |
| 1094 | |
| 1095 | /// The initial trace setting. If omitted trace is disabled ('off'). |
| 1096 | #[serde(default)] |
| 1097 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1098 | pub trace: Option<TraceValue>, |
| 1099 | |
| 1100 | /// The workspace folders configured in the client when the server starts. |
| 1101 | /// This property is only available if the client supports workspace folders. |
| 1102 | /// It can be `null` if the client supports workspace folders but none are |
| 1103 | /// configured. |
| 1104 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1105 | pub workspace_folders: Option<Vec<WorkspaceFolder>>, |
| 1106 | |
| 1107 | /// Information about the client. |
| 1108 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1109 | pub client_info: Option<ClientInfo>, |
| 1110 | |
| 1111 | /// The locale the client is currently showing the user interface |
| 1112 | /// in. This must not necessarily be the locale of the operating |
| 1113 | /// system. |
| 1114 | /// |
| 1115 | /// Uses IETF language tags as the value's syntax |
| 1116 | /// (See <https://en.wikipedia.org/wiki/IETF_language_tag>) |
| 1117 | /// |
| 1118 | /// @since 3.16.0 |
| 1119 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1120 | pub locale: Option<String>, |
| 1121 | |
| 1122 | /// The LSP server may report about initialization progress to the client |
| 1123 | /// by using the following work done token if it was passed by the client. |
| 1124 | #[serde(flatten)] |
| 1125 | pub work_done_progress_params: WorkDoneProgressParams, |
| 1126 | } |
| 1127 | |
| 1128 | #[derive (Debug, PartialEq, Clone, Deserialize, Serialize)] |
| 1129 | pub struct ClientInfo { |
| 1130 | /// The name of the client as defined by the client. |
| 1131 | pub name: String, |
| 1132 | /// The client's version as defined by the client. |
| 1133 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1134 | pub version: Option<String>, |
| 1135 | } |
| 1136 | |
| 1137 | #[derive (Debug, PartialEq, Clone, Copy, Deserialize, Serialize)] |
| 1138 | pub struct InitializedParams {} |
| 1139 | |
| 1140 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 1141 | pub struct GenericRegistrationOptions { |
| 1142 | #[serde(flatten)] |
| 1143 | pub text_document_registration_options: TextDocumentRegistrationOptions, |
| 1144 | |
| 1145 | #[serde(flatten)] |
| 1146 | pub options: GenericOptions, |
| 1147 | |
| 1148 | #[serde(flatten)] |
| 1149 | pub static_registration_options: StaticRegistrationOptions, |
| 1150 | } |
| 1151 | |
| 1152 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 1153 | pub struct GenericOptions { |
| 1154 | #[serde(flatten)] |
| 1155 | pub work_done_progress_options: WorkDoneProgressOptions, |
| 1156 | } |
| 1157 | |
| 1158 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 1159 | pub struct GenericParams { |
| 1160 | #[serde(flatten)] |
| 1161 | pub text_document_position_params: TextDocumentPositionParams, |
| 1162 | |
| 1163 | #[serde(flatten)] |
| 1164 | pub work_done_progress_params: WorkDoneProgressParams, |
| 1165 | |
| 1166 | #[serde(flatten)] |
| 1167 | pub partial_result_params: PartialResultParams, |
| 1168 | } |
| 1169 | |
| 1170 | #[derive (Debug, Eq, PartialEq, Clone, Copy, Default, Deserialize, Serialize)] |
| 1171 | #[serde(rename_all = "camelCase" )] |
| 1172 | pub struct DynamicRegistrationClientCapabilities { |
| 1173 | /// This capability supports dynamic registration. |
| 1174 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1175 | pub dynamic_registration: Option<bool>, |
| 1176 | } |
| 1177 | |
| 1178 | #[derive (Debug, Eq, PartialEq, Clone, Copy, Default, Deserialize, Serialize)] |
| 1179 | #[serde(rename_all = "camelCase" )] |
| 1180 | pub struct GotoCapability { |
| 1181 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1182 | pub dynamic_registration: Option<bool>, |
| 1183 | |
| 1184 | /// The client supports additional metadata in the form of definition links. |
| 1185 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1186 | pub link_support: Option<bool>, |
| 1187 | } |
| 1188 | |
| 1189 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1190 | #[serde(rename_all = "camelCase" )] |
| 1191 | pub struct WorkspaceEditClientCapabilities { |
| 1192 | /// The client supports versioned document changes in `WorkspaceEdit`s |
| 1193 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1194 | pub document_changes: Option<bool>, |
| 1195 | |
| 1196 | /// The resource operations the client supports. Clients should at least |
| 1197 | /// support 'create', 'rename' and 'delete' files and folders. |
| 1198 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1199 | pub resource_operations: Option<Vec<ResourceOperationKind>>, |
| 1200 | |
| 1201 | /// The failure handling strategy of a client if applying the workspace edit fails. |
| 1202 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1203 | pub failure_handling: Option<FailureHandlingKind>, |
| 1204 | |
| 1205 | /// Whether the client normalizes line endings to the client specific |
| 1206 | /// setting. |
| 1207 | /// If set to `true` the client will normalize line ending characters |
| 1208 | /// in a workspace edit to the client specific new line character(s). |
| 1209 | /// |
| 1210 | /// @since 3.16.0 |
| 1211 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1212 | pub normalizes_line_endings: Option<bool>, |
| 1213 | |
| 1214 | /// Whether the client in general supports change annotations on text edits, |
| 1215 | /// create file, rename file and delete file changes. |
| 1216 | /// |
| 1217 | /// @since 3.16.0 |
| 1218 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1219 | pub change_annotation_support: Option<ChangeAnnotationWorkspaceEditClientCapabilities>, |
| 1220 | } |
| 1221 | |
| 1222 | #[derive (Debug, Eq, PartialEq, Deserialize, Serialize, Copy, Clone)] |
| 1223 | #[serde(rename_all = "lowercase" )] |
| 1224 | pub enum ResourceOperationKind { |
| 1225 | Create, |
| 1226 | Rename, |
| 1227 | Delete, |
| 1228 | } |
| 1229 | |
| 1230 | #[derive (Debug, Eq, PartialEq, Deserialize, Serialize, Copy, Clone)] |
| 1231 | #[serde(rename_all = "camelCase" )] |
| 1232 | pub enum FailureHandlingKind { |
| 1233 | Abort, |
| 1234 | Transactional, |
| 1235 | TextOnlyTransactional, |
| 1236 | Undo, |
| 1237 | } |
| 1238 | |
| 1239 | /// A symbol kind. |
| 1240 | #[derive (Eq, PartialEq, Copy, Clone, Serialize, Deserialize)] |
| 1241 | #[serde(transparent)] |
| 1242 | pub struct SymbolKind(i32); |
| 1243 | lsp_enum! { |
| 1244 | impl SymbolKind { |
| 1245 | pub const FILE: SymbolKind = SymbolKind(1); |
| 1246 | pub const MODULE: SymbolKind = SymbolKind(2); |
| 1247 | pub const NAMESPACE: SymbolKind = SymbolKind(3); |
| 1248 | pub const PACKAGE: SymbolKind = SymbolKind(4); |
| 1249 | pub const CLASS: SymbolKind = SymbolKind(5); |
| 1250 | pub const METHOD: SymbolKind = SymbolKind(6); |
| 1251 | pub const PROPERTY: SymbolKind = SymbolKind(7); |
| 1252 | pub const FIELD: SymbolKind = SymbolKind(8); |
| 1253 | pub const CONSTRUCTOR: SymbolKind = SymbolKind(9); |
| 1254 | pub const ENUM: SymbolKind = SymbolKind(10); |
| 1255 | pub const INTERFACE: SymbolKind = SymbolKind(11); |
| 1256 | pub const FUNCTION: SymbolKind = SymbolKind(12); |
| 1257 | pub const VARIABLE: SymbolKind = SymbolKind(13); |
| 1258 | pub const CONSTANT: SymbolKind = SymbolKind(14); |
| 1259 | pub const STRING: SymbolKind = SymbolKind(15); |
| 1260 | pub const NUMBER: SymbolKind = SymbolKind(16); |
| 1261 | pub const BOOLEAN: SymbolKind = SymbolKind(17); |
| 1262 | pub const ARRAY: SymbolKind = SymbolKind(18); |
| 1263 | pub const OBJECT: SymbolKind = SymbolKind(19); |
| 1264 | pub const KEY: SymbolKind = SymbolKind(20); |
| 1265 | pub const NULL: SymbolKind = SymbolKind(21); |
| 1266 | pub const ENUM_MEMBER: SymbolKind = SymbolKind(22); |
| 1267 | pub const STRUCT: SymbolKind = SymbolKind(23); |
| 1268 | pub const EVENT: SymbolKind = SymbolKind(24); |
| 1269 | pub const OPERATOR: SymbolKind = SymbolKind(25); |
| 1270 | pub const TYPE_PARAMETER: SymbolKind = SymbolKind(26); |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | /// Specific capabilities for the `SymbolKind` in the `workspace/symbol` request. |
| 1275 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1276 | #[serde(rename_all = "camelCase" )] |
| 1277 | pub struct SymbolKindCapability { |
| 1278 | /// The symbol kind values the client supports. When this |
| 1279 | /// property exists the client also guarantees that it will |
| 1280 | /// handle values outside its set gracefully and falls back |
| 1281 | /// to a default value when unknown. |
| 1282 | /// |
| 1283 | /// If this property is not present the client only supports |
| 1284 | /// the symbol kinds from `File` to `Array` as defined in |
| 1285 | /// the initial version of the protocol. |
| 1286 | pub value_set: Option<Vec<SymbolKind>>, |
| 1287 | } |
| 1288 | |
| 1289 | /// Workspace specific client capabilities. |
| 1290 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1291 | #[serde(rename_all = "camelCase" )] |
| 1292 | pub struct WorkspaceClientCapabilities { |
| 1293 | /// The client supports applying batch edits to the workspace by supporting |
| 1294 | /// the request 'workspace/applyEdit' |
| 1295 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1296 | pub apply_edit: Option<bool>, |
| 1297 | |
| 1298 | /// Capabilities specific to `WorkspaceEdit`s |
| 1299 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1300 | pub workspace_edit: Option<WorkspaceEditClientCapabilities>, |
| 1301 | |
| 1302 | /// Capabilities specific to the `workspace/didChangeConfiguration` notification. |
| 1303 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1304 | pub did_change_configuration: Option<DidChangeConfigurationClientCapabilities>, |
| 1305 | |
| 1306 | /// Capabilities specific to the `workspace/didChangeWatchedFiles` notification. |
| 1307 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1308 | pub did_change_watched_files: Option<DidChangeWatchedFilesClientCapabilities>, |
| 1309 | |
| 1310 | /// Capabilities specific to the `workspace/symbol` request. |
| 1311 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1312 | pub symbol: Option<WorkspaceSymbolClientCapabilities>, |
| 1313 | |
| 1314 | /// Capabilities specific to the `workspace/executeCommand` request. |
| 1315 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1316 | pub execute_command: Option<ExecuteCommandClientCapabilities>, |
| 1317 | |
| 1318 | /// The client has support for workspace folders. |
| 1319 | /// |
| 1320 | /// @since 3.6.0 |
| 1321 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1322 | pub workspace_folders: Option<bool>, |
| 1323 | |
| 1324 | /// The client supports `workspace/configuration` requests. |
| 1325 | /// |
| 1326 | /// @since 3.6.0 |
| 1327 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1328 | pub configuration: Option<bool>, |
| 1329 | |
| 1330 | /// Capabilities specific to the semantic token requests scoped to the workspace. |
| 1331 | /// |
| 1332 | /// @since 3.16.0 |
| 1333 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1334 | pub semantic_tokens: Option<SemanticTokensWorkspaceClientCapabilities>, |
| 1335 | |
| 1336 | /// Capabilities specific to the code lens requests scoped to the workspace. |
| 1337 | /// |
| 1338 | /// @since 3.16.0 |
| 1339 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1340 | pub code_lens: Option<CodeLensWorkspaceClientCapabilities>, |
| 1341 | |
| 1342 | /// The client has support for file requests/notifications. |
| 1343 | /// |
| 1344 | /// @since 3.16.0 |
| 1345 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1346 | pub file_operations: Option<WorkspaceFileOperationsClientCapabilities>, |
| 1347 | |
| 1348 | /// Client workspace capabilities specific to inline values. |
| 1349 | /// |
| 1350 | /// @since 3.17.0 |
| 1351 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1352 | pub inline_value: Option<InlineValueWorkspaceClientCapabilities>, |
| 1353 | |
| 1354 | /// Client workspace capabilities specific to inlay hints. |
| 1355 | /// |
| 1356 | /// @since 3.17.0 |
| 1357 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1358 | pub inlay_hint: Option<InlayHintWorkspaceClientCapabilities>, |
| 1359 | |
| 1360 | /// Client workspace capabilities specific to diagnostics. |
| 1361 | /// since 3.17.0 |
| 1362 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1363 | pub diagnostic: Option<DiagnosticWorkspaceClientCapabilities>, |
| 1364 | } |
| 1365 | |
| 1366 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1367 | #[serde(rename_all = "camelCase" )] |
| 1368 | pub struct TextDocumentSyncClientCapabilities { |
| 1369 | /// Whether text document synchronization supports dynamic registration. |
| 1370 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1371 | pub dynamic_registration: Option<bool>, |
| 1372 | |
| 1373 | /// The client supports sending will save notifications. |
| 1374 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1375 | pub will_save: Option<bool>, |
| 1376 | |
| 1377 | /// The client supports sending a will save request and |
| 1378 | /// waits for a response providing text edits which will |
| 1379 | /// be applied to the document before it is saved. |
| 1380 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1381 | pub will_save_wait_until: Option<bool>, |
| 1382 | |
| 1383 | /// The client supports did save notifications. |
| 1384 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1385 | pub did_save: Option<bool>, |
| 1386 | } |
| 1387 | |
| 1388 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1389 | #[serde(rename_all = "camelCase" )] |
| 1390 | pub struct PublishDiagnosticsClientCapabilities { |
| 1391 | /// Whether the clients accepts diagnostics with related information. |
| 1392 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1393 | pub related_information: Option<bool>, |
| 1394 | |
| 1395 | /// Client supports the tag property to provide meta data about a diagnostic. |
| 1396 | /// Clients supporting tags have to handle unknown tags gracefully. |
| 1397 | #[serde( |
| 1398 | default, |
| 1399 | skip_serializing_if = "Option::is_none" , |
| 1400 | deserialize_with = "TagSupport::deserialize_compat" |
| 1401 | )] |
| 1402 | pub tag_support: Option<TagSupport<DiagnosticTag>>, |
| 1403 | |
| 1404 | /// Whether the client interprets the version property of the |
| 1405 | /// `textDocument/publishDiagnostics` notification's parameter. |
| 1406 | /// |
| 1407 | /// @since 3.15.0 |
| 1408 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1409 | pub version_support: Option<bool>, |
| 1410 | |
| 1411 | /// Client supports a codeDescription property |
| 1412 | /// |
| 1413 | /// @since 3.16.0 |
| 1414 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1415 | pub code_description_support: Option<bool>, |
| 1416 | |
| 1417 | /// Whether code action supports the `data` property which is |
| 1418 | /// preserved between a `textDocument/publishDiagnostics` and |
| 1419 | /// `textDocument/codeAction` request. |
| 1420 | /// |
| 1421 | /// @since 3.16.0 |
| 1422 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1423 | pub data_support: Option<bool>, |
| 1424 | } |
| 1425 | |
| 1426 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1427 | #[serde(rename_all = "camelCase" )] |
| 1428 | pub struct TagSupport<T> { |
| 1429 | /// The tags supported by the client. |
| 1430 | pub value_set: Vec<T>, |
| 1431 | } |
| 1432 | |
| 1433 | impl<T> TagSupport<T> { |
| 1434 | /// Support for deserializing a boolean tag Support, in case it's present. |
| 1435 | /// |
| 1436 | /// This is currently the case for vscode 1.41.1 |
| 1437 | fn deserialize_compat<'de, S>(serializer: S) -> Result<Option<TagSupport<T>>, S::Error> |
| 1438 | where |
| 1439 | S: serde::Deserializer<'de>, |
| 1440 | T: serde::Deserialize<'de>, |
| 1441 | { |
| 1442 | Ok( |
| 1443 | match Option::<Value>::deserialize(serializer).map_err(op:serde::de::Error::custom)? { |
| 1444 | Some(Value::Bool(false)) => None, |
| 1445 | Some(Value::Bool(true)) => Some(TagSupport { value_set: vec![] }), |
| 1446 | Some(other: Value) => { |
| 1447 | Some(TagSupport::<T>::deserialize(other).map_err(serde::de::Error::custom)?) |
| 1448 | } |
| 1449 | None => None, |
| 1450 | }, |
| 1451 | ) |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | /// Text document specific client capabilities. |
| 1456 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1457 | #[serde(rename_all = "camelCase" )] |
| 1458 | pub struct TextDocumentClientCapabilities { |
| 1459 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1460 | pub synchronization: Option<TextDocumentSyncClientCapabilities>, |
| 1461 | /// Capabilities specific to the `textDocument/completion` |
| 1462 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1463 | pub completion: Option<CompletionClientCapabilities>, |
| 1464 | |
| 1465 | /// Capabilities specific to the `textDocument/hover` |
| 1466 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1467 | pub hover: Option<HoverClientCapabilities>, |
| 1468 | |
| 1469 | /// Capabilities specific to the `textDocument/signatureHelp` |
| 1470 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1471 | pub signature_help: Option<SignatureHelpClientCapabilities>, |
| 1472 | |
| 1473 | /// Capabilities specific to the `textDocument/references` |
| 1474 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1475 | pub references: Option<ReferenceClientCapabilities>, |
| 1476 | |
| 1477 | /// Capabilities specific to the `textDocument/documentHighlight` |
| 1478 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1479 | pub document_highlight: Option<DocumentHighlightClientCapabilities>, |
| 1480 | |
| 1481 | /// Capabilities specific to the `textDocument/documentSymbol` |
| 1482 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1483 | pub document_symbol: Option<DocumentSymbolClientCapabilities>, |
| 1484 | /// Capabilities specific to the `textDocument/formatting` |
| 1485 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1486 | pub formatting: Option<DocumentFormattingClientCapabilities>, |
| 1487 | |
| 1488 | /// Capabilities specific to the `textDocument/rangeFormatting` |
| 1489 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1490 | pub range_formatting: Option<DocumentRangeFormattingClientCapabilities>, |
| 1491 | |
| 1492 | /// Capabilities specific to the `textDocument/onTypeFormatting` |
| 1493 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1494 | pub on_type_formatting: Option<DocumentOnTypeFormattingClientCapabilities>, |
| 1495 | |
| 1496 | /// Capabilities specific to the `textDocument/declaration` |
| 1497 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1498 | pub declaration: Option<GotoCapability>, |
| 1499 | |
| 1500 | /// Capabilities specific to the `textDocument/definition` |
| 1501 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1502 | pub definition: Option<GotoCapability>, |
| 1503 | |
| 1504 | /// Capabilities specific to the `textDocument/typeDefinition` |
| 1505 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1506 | pub type_definition: Option<GotoCapability>, |
| 1507 | |
| 1508 | /// Capabilities specific to the `textDocument/implementation` |
| 1509 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1510 | pub implementation: Option<GotoCapability>, |
| 1511 | |
| 1512 | /// Capabilities specific to the `textDocument/codeAction` |
| 1513 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1514 | pub code_action: Option<CodeActionClientCapabilities>, |
| 1515 | |
| 1516 | /// Capabilities specific to the `textDocument/codeLens` |
| 1517 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1518 | pub code_lens: Option<CodeLensClientCapabilities>, |
| 1519 | |
| 1520 | /// Capabilities specific to the `textDocument/documentLink` |
| 1521 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1522 | pub document_link: Option<DocumentLinkClientCapabilities>, |
| 1523 | |
| 1524 | /// Capabilities specific to the `textDocument/documentColor` and the |
| 1525 | /// `textDocument/colorPresentation` request. |
| 1526 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1527 | pub color_provider: Option<DocumentColorClientCapabilities>, |
| 1528 | |
| 1529 | /// Capabilities specific to the `textDocument/rename` |
| 1530 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1531 | pub rename: Option<RenameClientCapabilities>, |
| 1532 | |
| 1533 | /// Capabilities specific to `textDocument/publishDiagnostics`. |
| 1534 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1535 | pub publish_diagnostics: Option<PublishDiagnosticsClientCapabilities>, |
| 1536 | |
| 1537 | /// Capabilities specific to `textDocument/foldingRange` requests. |
| 1538 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1539 | pub folding_range: Option<FoldingRangeClientCapabilities>, |
| 1540 | |
| 1541 | /// Capabilities specific to the `textDocument/selectionRange` request. |
| 1542 | /// |
| 1543 | /// @since 3.15.0 |
| 1544 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1545 | pub selection_range: Option<SelectionRangeClientCapabilities>, |
| 1546 | |
| 1547 | /// Capabilities specific to `textDocument/linkedEditingRange` requests. |
| 1548 | /// |
| 1549 | /// @since 3.16.0 |
| 1550 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1551 | pub linked_editing_range: Option<LinkedEditingRangeClientCapabilities>, |
| 1552 | |
| 1553 | /// Capabilities specific to the various call hierarchy requests. |
| 1554 | /// |
| 1555 | /// @since 3.16.0 |
| 1556 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1557 | pub call_hierarchy: Option<CallHierarchyClientCapabilities>, |
| 1558 | |
| 1559 | /// Capabilities specific to the `textDocument/semanticTokens/*` requests. |
| 1560 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1561 | pub semantic_tokens: Option<SemanticTokensClientCapabilities>, |
| 1562 | |
| 1563 | /// Capabilities specific to the `textDocument/moniker` request. |
| 1564 | /// |
| 1565 | /// @since 3.16.0 |
| 1566 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1567 | pub moniker: Option<MonikerClientCapabilities>, |
| 1568 | |
| 1569 | /// Capabilities specific to the various type hierarchy requests. |
| 1570 | /// |
| 1571 | /// @since 3.17.0 |
| 1572 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1573 | pub type_hierarchy: Option<TypeHierarchyClientCapabilities>, |
| 1574 | |
| 1575 | /// Capabilities specific to the `textDocument/inlineValue` request. |
| 1576 | /// |
| 1577 | /// @since 3.17.0 |
| 1578 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1579 | pub inline_value: Option<InlineValueClientCapabilities>, |
| 1580 | |
| 1581 | /// Capabilities specific to the `textDocument/inlayHint` request. |
| 1582 | /// |
| 1583 | /// @since 3.17.0 |
| 1584 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1585 | pub inlay_hint: Option<InlayHintClientCapabilities>, |
| 1586 | |
| 1587 | /// Capabilities specific to the diagnostic pull model. |
| 1588 | /// |
| 1589 | /// @since 3.17.0 |
| 1590 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1591 | pub diagnostic: Option<DiagnosticClientCapabilities>, |
| 1592 | |
| 1593 | /// Capabilities specific to the `textDocument/inlineCompletion` request. |
| 1594 | /// |
| 1595 | /// @since 3.18.0 |
| 1596 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1597 | #[cfg (feature = "proposed" )] |
| 1598 | pub inline_completion: Option<InlineCompletionClientCapabilities>, |
| 1599 | } |
| 1600 | |
| 1601 | /// Where ClientCapabilities are currently empty: |
| 1602 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1603 | #[serde(rename_all = "camelCase" )] |
| 1604 | pub struct ClientCapabilities { |
| 1605 | /// Workspace specific client capabilities. |
| 1606 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1607 | pub workspace: Option<WorkspaceClientCapabilities>, |
| 1608 | |
| 1609 | /// Text document specific client capabilities. |
| 1610 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1611 | pub text_document: Option<TextDocumentClientCapabilities>, |
| 1612 | |
| 1613 | /// Window specific client capabilities. |
| 1614 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1615 | pub window: Option<WindowClientCapabilities>, |
| 1616 | |
| 1617 | /// General client capabilities. |
| 1618 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1619 | pub general: Option<GeneralClientCapabilities>, |
| 1620 | |
| 1621 | /// Unofficial UT8-offsets extension. |
| 1622 | /// |
| 1623 | /// See https://clangd.llvm.org/extensions.html#utf-8-offsets. |
| 1624 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1625 | #[cfg (feature = "proposed" )] |
| 1626 | pub offset_encoding: Option<Vec<String>>, |
| 1627 | |
| 1628 | /// Experimental client capabilities. |
| 1629 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1630 | pub experimental: Option<Value>, |
| 1631 | } |
| 1632 | |
| 1633 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1634 | #[serde(rename_all = "camelCase" )] |
| 1635 | pub struct GeneralClientCapabilities { |
| 1636 | /// Client capabilities specific to regular expressions. |
| 1637 | /// |
| 1638 | /// @since 3.16.0 |
| 1639 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1640 | pub regular_expressions: Option<RegularExpressionsClientCapabilities>, |
| 1641 | |
| 1642 | /// Client capabilities specific to the client's markdown parser. |
| 1643 | /// |
| 1644 | /// @since 3.16.0 |
| 1645 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1646 | pub markdown: Option<MarkdownClientCapabilities>, |
| 1647 | |
| 1648 | /// Client capability that signals how the client handles stale requests (e.g. a request for |
| 1649 | /// which the client will not process the response anymore since the information is outdated). |
| 1650 | /// |
| 1651 | /// @since 3.17.0 |
| 1652 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1653 | pub stale_request_support: Option<StaleRequestSupportClientCapabilities>, |
| 1654 | |
| 1655 | /// The position encodings supported by the client. Client and server |
| 1656 | /// have to agree on the same position encoding to ensure that offsets |
| 1657 | /// (e.g. character position in a line) are interpreted the same on both |
| 1658 | /// side. |
| 1659 | /// |
| 1660 | /// To keep the protocol backwards compatible the following applies: if |
| 1661 | /// the value 'utf-16' is missing from the array of position encodings |
| 1662 | /// servers can assume that the client supports UTF-16. UTF-16 is |
| 1663 | /// therefore a mandatory encoding. |
| 1664 | /// |
| 1665 | /// If omitted it defaults to ['utf-16']. |
| 1666 | /// |
| 1667 | /// Implementation considerations: since the conversion from one encoding |
| 1668 | /// into another requires the content of the file / line the conversion |
| 1669 | /// is best done where the file is read which is usually on the server |
| 1670 | /// side. |
| 1671 | /// |
| 1672 | /// @since 3.17.0 |
| 1673 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1674 | pub position_encodings: Option<Vec<PositionEncodingKind>>, |
| 1675 | } |
| 1676 | |
| 1677 | /// Client capability that signals how the client |
| 1678 | /// handles stale requests (e.g. a request |
| 1679 | /// for which the client will not process the response |
| 1680 | /// anymore since the information is outdated). |
| 1681 | /// |
| 1682 | /// @since 3.17.0 |
| 1683 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1684 | #[serde(rename_all = "camelCase" )] |
| 1685 | pub struct StaleRequestSupportClientCapabilities { |
| 1686 | /// The client will actively cancel the request. |
| 1687 | pub cancel: bool, |
| 1688 | |
| 1689 | /// The list of requests for which the client |
| 1690 | /// will retry the request if it receives a |
| 1691 | /// response with error code `ContentModified`` |
| 1692 | pub retry_on_content_modified: Vec<String>, |
| 1693 | } |
| 1694 | |
| 1695 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1696 | #[serde(rename_all = "camelCase" )] |
| 1697 | pub struct RegularExpressionsClientCapabilities { |
| 1698 | /// The engine's name. |
| 1699 | pub engine: String, |
| 1700 | |
| 1701 | /// The engine's version |
| 1702 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1703 | pub version: Option<String>, |
| 1704 | } |
| 1705 | |
| 1706 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1707 | #[serde(rename_all = "camelCase" )] |
| 1708 | pub struct MarkdownClientCapabilities { |
| 1709 | /// The name of the parser. |
| 1710 | pub parser: String, |
| 1711 | |
| 1712 | /// The version of the parser. |
| 1713 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1714 | pub version: Option<String>, |
| 1715 | |
| 1716 | /// A list of HTML tags that the client allows / supports in |
| 1717 | /// Markdown. |
| 1718 | /// |
| 1719 | /// @since 3.17.0 |
| 1720 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1721 | pub allowed_tags: Option<Vec<String>>, |
| 1722 | } |
| 1723 | |
| 1724 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1725 | #[serde(rename_all = "camelCase" )] |
| 1726 | pub struct InitializeResult { |
| 1727 | /// The capabilities the language server provides. |
| 1728 | pub capabilities: ServerCapabilities, |
| 1729 | |
| 1730 | /// Information about the server. |
| 1731 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1732 | pub server_info: Option<ServerInfo>, |
| 1733 | |
| 1734 | /// Unofficial UT8-offsets extension. |
| 1735 | /// |
| 1736 | /// See https://clangd.llvm.org/extensions.html#utf-8-offsets. |
| 1737 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1738 | #[cfg (feature = "proposed" )] |
| 1739 | pub offset_encoding: Option<String>, |
| 1740 | } |
| 1741 | |
| 1742 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1743 | pub struct ServerInfo { |
| 1744 | /// The name of the server as defined by the server. |
| 1745 | pub name: String, |
| 1746 | /// The servers's version as defined by the server. |
| 1747 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1748 | pub version: Option<String>, |
| 1749 | } |
| 1750 | |
| 1751 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1752 | pub struct InitializeError { |
| 1753 | /// Indicates whether the client execute the following retry logic: |
| 1754 | /// |
| 1755 | /// - (1) show the message provided by the ResponseError to the user |
| 1756 | /// - (2) user selects retry or cancel |
| 1757 | /// - (3) if user selected retry the initialize method is sent again. |
| 1758 | pub retry: bool, |
| 1759 | } |
| 1760 | |
| 1761 | // The server can signal the following capabilities: |
| 1762 | |
| 1763 | /// Defines how the host (editor) should sync document changes to the language server. |
| 1764 | #[derive (Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] |
| 1765 | #[serde(transparent)] |
| 1766 | pub struct TextDocumentSyncKind(i32); |
| 1767 | lsp_enum! { |
| 1768 | impl TextDocumentSyncKind { |
| 1769 | /// Documents should not be synced at all. |
| 1770 | pub const NONE: TextDocumentSyncKind = TextDocumentSyncKind(0); |
| 1771 | |
| 1772 | /// Documents are synced by always sending the full content of the document. |
| 1773 | pub const FULL: TextDocumentSyncKind = TextDocumentSyncKind(1); |
| 1774 | |
| 1775 | /// Documents are synced by sending the full content on open. After that only |
| 1776 | /// incremental updates to the document are sent. |
| 1777 | pub const INCREMENTAL: TextDocumentSyncKind = TextDocumentSyncKind(2); |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | pub type ExecuteCommandClientCapabilities = DynamicRegistrationClientCapabilities; |
| 1782 | |
| 1783 | /// Execute command options. |
| 1784 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1785 | pub struct ExecuteCommandOptions { |
| 1786 | /// The commands to be executed on the server |
| 1787 | pub commands: Vec<String>, |
| 1788 | |
| 1789 | #[serde(flatten)] |
| 1790 | pub work_done_progress_options: WorkDoneProgressOptions, |
| 1791 | } |
| 1792 | |
| 1793 | /// Save options. |
| 1794 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1795 | #[serde(rename_all = "camelCase" )] |
| 1796 | pub struct SaveOptions { |
| 1797 | /// The client is supposed to include the content on save. |
| 1798 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1799 | pub include_text: Option<bool>, |
| 1800 | } |
| 1801 | |
| 1802 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 1803 | #[serde(untagged)] |
| 1804 | pub enum TextDocumentSyncSaveOptions { |
| 1805 | Supported(bool), |
| 1806 | SaveOptions(SaveOptions), |
| 1807 | } |
| 1808 | |
| 1809 | impl From<SaveOptions> for TextDocumentSyncSaveOptions { |
| 1810 | fn from(from: SaveOptions) -> Self { |
| 1811 | Self::SaveOptions(from) |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | impl From<bool> for TextDocumentSyncSaveOptions { |
| 1816 | fn from(from: bool) -> Self { |
| 1817 | Self::Supported(from) |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1822 | #[serde(rename_all = "camelCase" )] |
| 1823 | pub struct TextDocumentSyncOptions { |
| 1824 | /// Open and close notifications are sent to the server. |
| 1825 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1826 | pub open_close: Option<bool>, |
| 1827 | |
| 1828 | /// Change notifications are sent to the server. See TextDocumentSyncKind.None, TextDocumentSyncKind.Full |
| 1829 | /// and TextDocumentSyncKindIncremental. |
| 1830 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1831 | pub change: Option<TextDocumentSyncKind>, |
| 1832 | |
| 1833 | /// Will save notifications are sent to the server. |
| 1834 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1835 | pub will_save: Option<bool>, |
| 1836 | |
| 1837 | /// Will save wait until requests are sent to the server. |
| 1838 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1839 | pub will_save_wait_until: Option<bool>, |
| 1840 | |
| 1841 | /// Save notifications are sent to the server. |
| 1842 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1843 | pub save: Option<TextDocumentSyncSaveOptions>, |
| 1844 | } |
| 1845 | |
| 1846 | #[derive (Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Deserialize, Serialize)] |
| 1847 | #[serde(untagged)] |
| 1848 | pub enum OneOf<A, B> { |
| 1849 | Left(A), |
| 1850 | Right(B), |
| 1851 | } |
| 1852 | |
| 1853 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 1854 | #[serde(untagged)] |
| 1855 | pub enum TextDocumentSyncCapability { |
| 1856 | Kind(TextDocumentSyncKind), |
| 1857 | Options(TextDocumentSyncOptions), |
| 1858 | } |
| 1859 | |
| 1860 | impl From<TextDocumentSyncOptions> for TextDocumentSyncCapability { |
| 1861 | fn from(from: TextDocumentSyncOptions) -> Self { |
| 1862 | Self::Options(from) |
| 1863 | } |
| 1864 | } |
| 1865 | |
| 1866 | impl From<TextDocumentSyncKind> for TextDocumentSyncCapability { |
| 1867 | fn from(from: TextDocumentSyncKind) -> Self { |
| 1868 | Self::Kind(from) |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 1873 | #[serde(untagged)] |
| 1874 | pub enum ImplementationProviderCapability { |
| 1875 | Simple(bool), |
| 1876 | Options(StaticTextDocumentRegistrationOptions), |
| 1877 | } |
| 1878 | |
| 1879 | impl From<StaticTextDocumentRegistrationOptions> for ImplementationProviderCapability { |
| 1880 | fn from(from: StaticTextDocumentRegistrationOptions) -> Self { |
| 1881 | Self::Options(from) |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | impl From<bool> for ImplementationProviderCapability { |
| 1886 | fn from(from: bool) -> Self { |
| 1887 | Self::Simple(from) |
| 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 1892 | #[serde(untagged)] |
| 1893 | pub enum TypeDefinitionProviderCapability { |
| 1894 | Simple(bool), |
| 1895 | Options(StaticTextDocumentRegistrationOptions), |
| 1896 | } |
| 1897 | |
| 1898 | impl From<StaticTextDocumentRegistrationOptions> for TypeDefinitionProviderCapability { |
| 1899 | fn from(from: StaticTextDocumentRegistrationOptions) -> Self { |
| 1900 | Self::Options(from) |
| 1901 | } |
| 1902 | } |
| 1903 | |
| 1904 | impl From<bool> for TypeDefinitionProviderCapability { |
| 1905 | fn from(from: bool) -> Self { |
| 1906 | Self::Simple(from) |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 1911 | #[serde(rename_all = "camelCase" )] |
| 1912 | pub struct ServerCapabilities { |
| 1913 | /// The position encoding the server picked from the encodings offered |
| 1914 | /// by the client via the client capability `general.positionEncodings`. |
| 1915 | /// |
| 1916 | /// If the client didn't provide any position encodings the only valid |
| 1917 | /// value that a server can return is 'utf-16'. |
| 1918 | /// |
| 1919 | /// If omitted it defaults to 'utf-16'. |
| 1920 | /// |
| 1921 | /// @since 3.17.0 |
| 1922 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1923 | pub position_encoding: Option<PositionEncodingKind>, |
| 1924 | |
| 1925 | /// Defines how text documents are synced. |
| 1926 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1927 | pub text_document_sync: Option<TextDocumentSyncCapability>, |
| 1928 | |
| 1929 | /// Capabilities specific to `textDocument/selectionRange` requests. |
| 1930 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1931 | pub selection_range_provider: Option<SelectionRangeProviderCapability>, |
| 1932 | |
| 1933 | /// The server provides hover support. |
| 1934 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1935 | pub hover_provider: Option<HoverProviderCapability>, |
| 1936 | |
| 1937 | /// The server provides completion support. |
| 1938 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1939 | pub completion_provider: Option<CompletionOptions>, |
| 1940 | |
| 1941 | /// The server provides signature help support. |
| 1942 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1943 | pub signature_help_provider: Option<SignatureHelpOptions>, |
| 1944 | |
| 1945 | /// The server provides goto definition support. |
| 1946 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1947 | pub definition_provider: Option<OneOf<bool, DefinitionOptions>>, |
| 1948 | |
| 1949 | /// The server provides goto type definition support. |
| 1950 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1951 | pub type_definition_provider: Option<TypeDefinitionProviderCapability>, |
| 1952 | |
| 1953 | /// The server provides goto implementation support. |
| 1954 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1955 | pub implementation_provider: Option<ImplementationProviderCapability>, |
| 1956 | |
| 1957 | /// The server provides find references support. |
| 1958 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1959 | pub references_provider: Option<OneOf<bool, ReferencesOptions>>, |
| 1960 | |
| 1961 | /// The server provides document highlight support. |
| 1962 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1963 | pub document_highlight_provider: Option<OneOf<bool, DocumentHighlightOptions>>, |
| 1964 | |
| 1965 | /// The server provides document symbol support. |
| 1966 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1967 | pub document_symbol_provider: Option<OneOf<bool, DocumentSymbolOptions>>, |
| 1968 | |
| 1969 | /// The server provides workspace symbol support. |
| 1970 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1971 | pub workspace_symbol_provider: Option<OneOf<bool, WorkspaceSymbolOptions>>, |
| 1972 | |
| 1973 | /// The server provides code actions. |
| 1974 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1975 | pub code_action_provider: Option<CodeActionProviderCapability>, |
| 1976 | |
| 1977 | /// The server provides code lens. |
| 1978 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1979 | pub code_lens_provider: Option<CodeLensOptions>, |
| 1980 | |
| 1981 | /// The server provides document formatting. |
| 1982 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1983 | pub document_formatting_provider: Option<OneOf<bool, DocumentFormattingOptions>>, |
| 1984 | |
| 1985 | /// The server provides document range formatting. |
| 1986 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1987 | pub document_range_formatting_provider: Option<OneOf<bool, DocumentRangeFormattingOptions>>, |
| 1988 | |
| 1989 | /// The server provides document formatting on typing. |
| 1990 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1991 | pub document_on_type_formatting_provider: Option<DocumentOnTypeFormattingOptions>, |
| 1992 | |
| 1993 | /// The server provides rename support. |
| 1994 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1995 | pub rename_provider: Option<OneOf<bool, RenameOptions>>, |
| 1996 | |
| 1997 | /// The server provides document link support. |
| 1998 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 1999 | pub document_link_provider: Option<DocumentLinkOptions>, |
| 2000 | |
| 2001 | /// The server provides color provider support. |
| 2002 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2003 | pub color_provider: Option<ColorProviderCapability>, |
| 2004 | |
| 2005 | /// The server provides folding provider support. |
| 2006 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2007 | pub folding_range_provider: Option<FoldingRangeProviderCapability>, |
| 2008 | |
| 2009 | /// The server provides go to declaration support. |
| 2010 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2011 | pub declaration_provider: Option<DeclarationCapability>, |
| 2012 | |
| 2013 | /// The server provides execute command support. |
| 2014 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2015 | pub execute_command_provider: Option<ExecuteCommandOptions>, |
| 2016 | |
| 2017 | /// Workspace specific server capabilities |
| 2018 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2019 | pub workspace: Option<WorkspaceServerCapabilities>, |
| 2020 | |
| 2021 | /// Call hierarchy provider capabilities. |
| 2022 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2023 | pub call_hierarchy_provider: Option<CallHierarchyServerCapability>, |
| 2024 | |
| 2025 | /// Semantic tokens server capabilities. |
| 2026 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2027 | pub semantic_tokens_provider: Option<SemanticTokensServerCapabilities>, |
| 2028 | |
| 2029 | /// Whether server provides moniker support. |
| 2030 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2031 | pub moniker_provider: Option<OneOf<bool, MonikerServerCapabilities>>, |
| 2032 | |
| 2033 | /// The server provides linked editing range support. |
| 2034 | /// |
| 2035 | /// @since 3.16.0 |
| 2036 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2037 | pub linked_editing_range_provider: Option<LinkedEditingRangeServerCapabilities>, |
| 2038 | |
| 2039 | /// The server provides inline values. |
| 2040 | /// |
| 2041 | /// @since 3.17.0 |
| 2042 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2043 | pub inline_value_provider: Option<OneOf<bool, InlineValueServerCapabilities>>, |
| 2044 | |
| 2045 | /// The server provides inlay hints. |
| 2046 | /// |
| 2047 | /// @since 3.17.0 |
| 2048 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2049 | pub inlay_hint_provider: Option<OneOf<bool, InlayHintServerCapabilities>>, |
| 2050 | |
| 2051 | /// The server has support for pull model diagnostics. |
| 2052 | /// |
| 2053 | /// @since 3.17.0 |
| 2054 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2055 | pub diagnostic_provider: Option<DiagnosticServerCapabilities>, |
| 2056 | |
| 2057 | /// The server provides inline completions. |
| 2058 | /// |
| 2059 | /// @since 3.18.0 |
| 2060 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2061 | #[cfg (feature = "proposed" )] |
| 2062 | pub inline_completion_provider: Option<OneOf<bool, InlineCompletionOptions>>, |
| 2063 | |
| 2064 | /// Experimental server capabilities. |
| 2065 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2066 | pub experimental: Option<Value>, |
| 2067 | } |
| 2068 | |
| 2069 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 2070 | #[serde(rename_all = "camelCase" )] |
| 2071 | pub struct WorkspaceServerCapabilities { |
| 2072 | /// The server supports workspace folder. |
| 2073 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2074 | pub workspace_folders: Option<WorkspaceFoldersServerCapabilities>, |
| 2075 | |
| 2076 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2077 | pub file_operations: Option<WorkspaceFileOperationsServerCapabilities>, |
| 2078 | } |
| 2079 | |
| 2080 | /// General parameters to to register for a capability. |
| 2081 | #[derive (Debug, PartialEq, Clone, Deserialize, Serialize)] |
| 2082 | #[serde(rename_all = "camelCase" )] |
| 2083 | pub struct Registration { |
| 2084 | /// The id used to register the request. The id can be used to deregister |
| 2085 | /// the request again. |
| 2086 | pub id: String, |
| 2087 | |
| 2088 | /// The method / capability to register for. |
| 2089 | pub method: String, |
| 2090 | |
| 2091 | /// Options necessary for the registration. |
| 2092 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2093 | pub register_options: Option<Value>, |
| 2094 | } |
| 2095 | |
| 2096 | #[derive (Debug, PartialEq, Clone, Deserialize, Serialize)] |
| 2097 | pub struct RegistrationParams { |
| 2098 | pub registrations: Vec<Registration>, |
| 2099 | } |
| 2100 | |
| 2101 | /// Since most of the registration options require to specify a document selector there is a base |
| 2102 | /// interface that can be used. |
| 2103 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 2104 | #[serde(rename_all = "camelCase" )] |
| 2105 | pub struct TextDocumentRegistrationOptions { |
| 2106 | /// A document selector to identify the scope of the registration. If set to null |
| 2107 | /// the document selector provided on the client side will be used. |
| 2108 | pub document_selector: Option<DocumentSelector>, |
| 2109 | } |
| 2110 | |
| 2111 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2112 | #[serde(untagged)] |
| 2113 | pub enum DeclarationCapability { |
| 2114 | Simple(bool), |
| 2115 | RegistrationOptions(DeclarationRegistrationOptions), |
| 2116 | Options(DeclarationOptions), |
| 2117 | } |
| 2118 | |
| 2119 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2120 | #[serde(rename_all = "camelCase" )] |
| 2121 | pub struct DeclarationRegistrationOptions { |
| 2122 | #[serde(flatten)] |
| 2123 | pub declaration_options: DeclarationOptions, |
| 2124 | |
| 2125 | #[serde(flatten)] |
| 2126 | pub text_document_registration_options: TextDocumentRegistrationOptions, |
| 2127 | |
| 2128 | #[serde(flatten)] |
| 2129 | pub static_registration_options: StaticRegistrationOptions, |
| 2130 | } |
| 2131 | |
| 2132 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2133 | #[serde(rename_all = "camelCase" )] |
| 2134 | pub struct DeclarationOptions { |
| 2135 | #[serde(flatten)] |
| 2136 | pub work_done_progress_options: WorkDoneProgressOptions, |
| 2137 | } |
| 2138 | |
| 2139 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 2140 | #[serde(rename_all = "camelCase" )] |
| 2141 | pub struct StaticRegistrationOptions { |
| 2142 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2143 | pub id: Option<String>, |
| 2144 | } |
| 2145 | |
| 2146 | #[derive (Debug, Default, Eq, PartialEq, Clone, Deserialize, Serialize, Copy)] |
| 2147 | #[serde(rename_all = "camelCase" )] |
| 2148 | pub struct WorkDoneProgressOptions { |
| 2149 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2150 | pub work_done_progress: Option<bool>, |
| 2151 | } |
| 2152 | |
| 2153 | #[derive (Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 2154 | #[serde(rename_all = "camelCase" )] |
| 2155 | pub struct DocumentFormattingOptions { |
| 2156 | #[serde(flatten)] |
| 2157 | pub work_done_progress_options: WorkDoneProgressOptions, |
| 2158 | } |
| 2159 | |
| 2160 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2161 | #[serde(rename_all = "camelCase" )] |
| 2162 | pub struct DocumentRangeFormattingOptions { |
| 2163 | #[serde(flatten)] |
| 2164 | pub work_done_progress_options: WorkDoneProgressOptions, |
| 2165 | } |
| 2166 | |
| 2167 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2168 | #[serde(rename_all = "camelCase" )] |
| 2169 | pub struct DefinitionOptions { |
| 2170 | #[serde(flatten)] |
| 2171 | pub work_done_progress_options: WorkDoneProgressOptions, |
| 2172 | } |
| 2173 | |
| 2174 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2175 | #[serde(rename_all = "camelCase" )] |
| 2176 | pub struct DocumentSymbolOptions { |
| 2177 | /// A human-readable string that is shown when multiple outlines trees are |
| 2178 | /// shown for the same document. |
| 2179 | /// |
| 2180 | /// @since 3.16.0 |
| 2181 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2182 | pub label: Option<String>, |
| 2183 | |
| 2184 | #[serde(flatten)] |
| 2185 | pub work_done_progress_options: WorkDoneProgressOptions, |
| 2186 | } |
| 2187 | |
| 2188 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2189 | #[serde(rename_all = "camelCase" )] |
| 2190 | pub struct ReferencesOptions { |
| 2191 | #[serde(flatten)] |
| 2192 | pub work_done_progress_options: WorkDoneProgressOptions, |
| 2193 | } |
| 2194 | |
| 2195 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2196 | #[serde(rename_all = "camelCase" )] |
| 2197 | pub struct DocumentHighlightOptions { |
| 2198 | #[serde(flatten)] |
| 2199 | pub work_done_progress_options: WorkDoneProgressOptions, |
| 2200 | } |
| 2201 | |
| 2202 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2203 | #[serde(rename_all = "camelCase" )] |
| 2204 | pub struct WorkspaceSymbolOptions { |
| 2205 | #[serde(flatten)] |
| 2206 | pub work_done_progress_options: WorkDoneProgressOptions, |
| 2207 | |
| 2208 | /// The server provides support to resolve additional |
| 2209 | /// information for a workspace symbol. |
| 2210 | /// |
| 2211 | /// @since 3.17.0 |
| 2212 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2213 | pub resolve_provider: Option<bool>, |
| 2214 | } |
| 2215 | |
| 2216 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2217 | #[serde(rename_all = "camelCase" )] |
| 2218 | pub struct StaticTextDocumentRegistrationOptions { |
| 2219 | /// A document selector to identify the scope of the registration. If set to null |
| 2220 | /// the document selector provided on the client side will be used. |
| 2221 | pub document_selector: Option<DocumentSelector>, |
| 2222 | |
| 2223 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2224 | pub id: Option<String>, |
| 2225 | } |
| 2226 | |
| 2227 | /// General parameters to unregister a capability. |
| 2228 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2229 | pub struct Unregistration { |
| 2230 | /// The id used to unregister the request or notification. Usually an id |
| 2231 | /// provided during the register request. |
| 2232 | pub id: String, |
| 2233 | |
| 2234 | /// The method / capability to unregister for. |
| 2235 | pub method: String, |
| 2236 | } |
| 2237 | |
| 2238 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2239 | pub struct UnregistrationParams { |
| 2240 | pub unregisterations: Vec<Unregistration>, |
| 2241 | } |
| 2242 | |
| 2243 | #[derive (Debug, PartialEq, Clone, Deserialize, Serialize)] |
| 2244 | pub struct DidChangeConfigurationParams { |
| 2245 | /// The actual changed settings |
| 2246 | pub settings: Value, |
| 2247 | } |
| 2248 | |
| 2249 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2250 | #[serde(rename_all = "camelCase" )] |
| 2251 | pub struct DidOpenTextDocumentParams { |
| 2252 | /// The document that was opened. |
| 2253 | pub text_document: TextDocumentItem, |
| 2254 | } |
| 2255 | |
| 2256 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2257 | #[serde(rename_all = "camelCase" )] |
| 2258 | pub struct DidChangeTextDocumentParams { |
| 2259 | /// The document that did change. The version number points |
| 2260 | /// to the version after all provided content changes have |
| 2261 | /// been applied. |
| 2262 | pub text_document: VersionedTextDocumentIdentifier, |
| 2263 | /// The actual content changes. |
| 2264 | pub content_changes: Vec<TextDocumentContentChangeEvent>, |
| 2265 | } |
| 2266 | |
| 2267 | /// An event describing a change to a text document. If range and rangeLength are omitted |
| 2268 | /// the new text is considered to be the full content of the document. |
| 2269 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2270 | #[serde(rename_all = "camelCase" )] |
| 2271 | pub struct TextDocumentContentChangeEvent { |
| 2272 | /// The range of the document that changed. |
| 2273 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2274 | pub range: Option<Range>, |
| 2275 | |
| 2276 | /// The length of the range that got replaced. |
| 2277 | /// |
| 2278 | /// Deprecated: Use range instead |
| 2279 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2280 | pub range_length: Option<u32>, |
| 2281 | |
| 2282 | /// The new text of the document. |
| 2283 | pub text: String, |
| 2284 | } |
| 2285 | |
| 2286 | /// Describe options to be used when registering for text document change events. |
| 2287 | /// |
| 2288 | /// Extends TextDocumentRegistrationOptions |
| 2289 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2290 | #[serde(rename_all = "camelCase" )] |
| 2291 | pub struct TextDocumentChangeRegistrationOptions { |
| 2292 | /// A document selector to identify the scope of the registration. If set to null |
| 2293 | /// the document selector provided on the client side will be used. |
| 2294 | pub document_selector: Option<DocumentSelector>, |
| 2295 | |
| 2296 | /// How documents are synced to the server. See TextDocumentSyncKind.Full |
| 2297 | /// and TextDocumentSyncKindIncremental. |
| 2298 | pub sync_kind: i32, |
| 2299 | } |
| 2300 | |
| 2301 | /// The parameters send in a will save text document notification. |
| 2302 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2303 | #[serde(rename_all = "camelCase" )] |
| 2304 | pub struct WillSaveTextDocumentParams { |
| 2305 | /// The document that will be saved. |
| 2306 | pub text_document: TextDocumentIdentifier, |
| 2307 | |
| 2308 | /// The 'TextDocumentSaveReason'. |
| 2309 | pub reason: TextDocumentSaveReason, |
| 2310 | } |
| 2311 | |
| 2312 | /// Represents reasons why a text document is saved. |
| 2313 | #[derive (Copy, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2314 | #[serde(transparent)] |
| 2315 | pub struct TextDocumentSaveReason(i32); |
| 2316 | lsp_enum! { |
| 2317 | impl TextDocumentSaveReason { |
| 2318 | /// Manually triggered, e.g. by the user pressing save, by starting debugging, |
| 2319 | /// or by an API call. |
| 2320 | pub const MANUAL: TextDocumentSaveReason = TextDocumentSaveReason(1); |
| 2321 | |
| 2322 | /// Automatic after a delay. |
| 2323 | pub const AFTER_DELAY: TextDocumentSaveReason = TextDocumentSaveReason(2); |
| 2324 | |
| 2325 | /// When the editor lost focus. |
| 2326 | pub const FOCUS_OUT: TextDocumentSaveReason = TextDocumentSaveReason(3); |
| 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2331 | #[serde(rename_all = "camelCase" )] |
| 2332 | pub struct DidCloseTextDocumentParams { |
| 2333 | /// The document that was closed. |
| 2334 | pub text_document: TextDocumentIdentifier, |
| 2335 | } |
| 2336 | |
| 2337 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2338 | #[serde(rename_all = "camelCase" )] |
| 2339 | pub struct DidSaveTextDocumentParams { |
| 2340 | /// The document that was saved. |
| 2341 | pub text_document: TextDocumentIdentifier, |
| 2342 | |
| 2343 | /// Optional the content when saved. Depends on the includeText value |
| 2344 | /// when the save notification was requested. |
| 2345 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2346 | pub text: Option<String>, |
| 2347 | } |
| 2348 | |
| 2349 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2350 | #[serde(rename_all = "camelCase" )] |
| 2351 | pub struct TextDocumentSaveRegistrationOptions { |
| 2352 | /// The client is supposed to include the content on save. |
| 2353 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2354 | pub include_text: Option<bool>, |
| 2355 | |
| 2356 | #[serde(flatten)] |
| 2357 | pub text_document_registration_options: TextDocumentRegistrationOptions, |
| 2358 | } |
| 2359 | |
| 2360 | #[derive (Debug, Eq, PartialEq, Clone, Copy, Default, Deserialize, Serialize)] |
| 2361 | #[serde(rename_all = "camelCase" )] |
| 2362 | pub struct DidChangeWatchedFilesClientCapabilities { |
| 2363 | /// Did change watched files notification supports dynamic registration. |
| 2364 | /// Please note that the current protocol doesn't support static |
| 2365 | /// configuration for file changes from the server side. |
| 2366 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2367 | pub dynamic_registration: Option<bool>, |
| 2368 | |
| 2369 | /// Whether the client has support for relative patterns |
| 2370 | /// or not. |
| 2371 | /// |
| 2372 | /// @since 3.17.0 |
| 2373 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2374 | pub relative_pattern_support: Option<bool>, |
| 2375 | } |
| 2376 | |
| 2377 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2378 | pub struct DidChangeWatchedFilesParams { |
| 2379 | /// The actual file events. |
| 2380 | pub changes: Vec<FileEvent>, |
| 2381 | } |
| 2382 | |
| 2383 | /// The file event type. |
| 2384 | #[derive (Eq, PartialEq, Hash, Copy, Clone, Deserialize, Serialize)] |
| 2385 | #[serde(transparent)] |
| 2386 | pub struct FileChangeType(i32); |
| 2387 | lsp_enum! { |
| 2388 | impl FileChangeType { |
| 2389 | /// The file got created. |
| 2390 | pub const CREATED: FileChangeType = FileChangeType(1); |
| 2391 | |
| 2392 | /// The file got changed. |
| 2393 | pub const CHANGED: FileChangeType = FileChangeType(2); |
| 2394 | |
| 2395 | /// The file got deleted. |
| 2396 | pub const DELETED: FileChangeType = FileChangeType(3); |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | /// An event describing a file change. |
| 2401 | #[derive (Debug, Eq, Hash, PartialEq, Clone, Deserialize, Serialize)] |
| 2402 | pub struct FileEvent { |
| 2403 | /// The file's URI. |
| 2404 | pub uri: Url, |
| 2405 | |
| 2406 | /// The change type. |
| 2407 | #[serde(rename = "type" )] |
| 2408 | pub typ: FileChangeType, |
| 2409 | } |
| 2410 | |
| 2411 | impl FileEvent { |
| 2412 | pub fn new(uri: Url, typ: FileChangeType) -> FileEvent { |
| 2413 | FileEvent { uri, typ } |
| 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | /// Describe options to be used when registered for text document change events. |
| 2418 | #[derive (Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Deserialize, Serialize)] |
| 2419 | pub struct DidChangeWatchedFilesRegistrationOptions { |
| 2420 | /// The watchers to register. |
| 2421 | pub watchers: Vec<FileSystemWatcher>, |
| 2422 | } |
| 2423 | |
| 2424 | #[derive (Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Deserialize, Serialize)] |
| 2425 | #[serde(rename_all = "camelCase" )] |
| 2426 | pub struct FileSystemWatcher { |
| 2427 | /// The glob pattern to watch. See {@link GlobPattern glob pattern} |
| 2428 | /// for more detail. |
| 2429 | /// |
| 2430 | /// @since 3.17.0 support for relative patterns. |
| 2431 | pub glob_pattern: GlobPattern, |
| 2432 | |
| 2433 | /// The kind of events of interest. If omitted it defaults to WatchKind.Create | |
| 2434 | /// WatchKind.Change | WatchKind.Delete which is 7. |
| 2435 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2436 | pub kind: Option<WatchKind>, |
| 2437 | } |
| 2438 | |
| 2439 | /// The glob pattern. Either a string pattern or a relative pattern. |
| 2440 | /// |
| 2441 | /// @since 3.17.0 |
| 2442 | #[derive (Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Deserialize, Serialize)] |
| 2443 | #[serde(untagged)] |
| 2444 | pub enum GlobPattern { |
| 2445 | String(Pattern), |
| 2446 | Relative(RelativePattern), |
| 2447 | } |
| 2448 | |
| 2449 | impl From<Pattern> for GlobPattern { |
| 2450 | #[inline ] |
| 2451 | fn from(from: Pattern) -> Self { |
| 2452 | Self::String(from) |
| 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | impl From<RelativePattern> for GlobPattern { |
| 2457 | #[inline ] |
| 2458 | fn from(from: RelativePattern) -> Self { |
| 2459 | Self::Relative(from) |
| 2460 | } |
| 2461 | } |
| 2462 | |
| 2463 | /// A relative pattern is a helper to construct glob patterns that are matched |
| 2464 | /// relatively to a base URI. The common value for a `baseUri` is a workspace |
| 2465 | /// folder root, but it can be another absolute URI as well. |
| 2466 | /// |
| 2467 | /// @since 3.17.0 |
| 2468 | #[derive (Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Deserialize, Serialize)] |
| 2469 | #[serde(rename_all = "camelCase" )] |
| 2470 | pub struct RelativePattern { |
| 2471 | /// A workspace folder or a base URI to which this pattern will be matched |
| 2472 | /// against relatively. |
| 2473 | pub base_uri: OneOf<WorkspaceFolder, Url>, |
| 2474 | |
| 2475 | /// The actual glob pattern. |
| 2476 | pub pattern: Pattern, |
| 2477 | } |
| 2478 | |
| 2479 | /// The glob pattern to watch relative to the base path. Glob patterns can have |
| 2480 | /// the following syntax: |
| 2481 | /// - `*` to match one or more characters in a path segment |
| 2482 | /// - `?` to match on one character in a path segment |
| 2483 | /// - `**` to match any number of path segments, including none |
| 2484 | /// - `{}` to group conditions (e.g. `**/*.{ts,js}` matches all TypeScript |
| 2485 | /// and JavaScript files) |
| 2486 | /// - `[]` to declare a range of characters to match in a path segment |
| 2487 | /// (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …) |
| 2488 | /// - `[!...]` to negate a range of characters to match in a path segment |
| 2489 | /// (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, |
| 2490 | /// but not `example.0`) |
| 2491 | /// |
| 2492 | /// @since 3.17.0 |
| 2493 | pub type Pattern = String; |
| 2494 | |
| 2495 | bitflags! { |
| 2496 | pub struct WatchKind: u8 { |
| 2497 | /// Interested in create events. |
| 2498 | const Create = 1; |
| 2499 | /// Interested in change events |
| 2500 | const Change = 2; |
| 2501 | /// Interested in delete events |
| 2502 | const Delete = 4; |
| 2503 | } |
| 2504 | } |
| 2505 | |
| 2506 | impl<'de> serde::Deserialize<'de> for WatchKind { |
| 2507 | fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| 2508 | where |
| 2509 | D: serde::Deserializer<'de>, |
| 2510 | { |
| 2511 | let i: u8 = u8::deserialize(deserializer)?; |
| 2512 | WatchKind::from_bits(i).ok_or_else(|| { |
| 2513 | D::Error::invalid_value(unexp:de::Unexpected::Unsigned(u64::from(i)), &"Unknown flag" ) |
| 2514 | }) |
| 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | impl serde::Serialize for WatchKind { |
| 2519 | fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
| 2520 | where |
| 2521 | S: serde::Serializer, |
| 2522 | { |
| 2523 | serializer.serialize_u8(self.bits()) |
| 2524 | } |
| 2525 | } |
| 2526 | |
| 2527 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2528 | pub struct PublishDiagnosticsParams { |
| 2529 | /// The URI for which diagnostic information is reported. |
| 2530 | pub uri: Url, |
| 2531 | |
| 2532 | /// An array of diagnostic information items. |
| 2533 | pub diagnostics: Vec<Diagnostic>, |
| 2534 | |
| 2535 | /// Optional the version number of the document the diagnostics are published for. |
| 2536 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2537 | pub version: Option<i32>, |
| 2538 | } |
| 2539 | |
| 2540 | impl PublishDiagnosticsParams { |
| 2541 | pub fn new( |
| 2542 | uri: Url, |
| 2543 | diagnostics: Vec<Diagnostic>, |
| 2544 | version: Option<i32>, |
| 2545 | ) -> PublishDiagnosticsParams { |
| 2546 | PublishDiagnosticsParams { |
| 2547 | uri, |
| 2548 | diagnostics, |
| 2549 | version, |
| 2550 | } |
| 2551 | } |
| 2552 | } |
| 2553 | |
| 2554 | #[derive (Debug, Eq, PartialEq, Deserialize, Serialize, Clone)] |
| 2555 | #[serde(untagged)] |
| 2556 | pub enum Documentation { |
| 2557 | String(String), |
| 2558 | MarkupContent(MarkupContent), |
| 2559 | } |
| 2560 | |
| 2561 | /// MarkedString can be used to render human readable text. It is either a |
| 2562 | /// markdown string or a code-block that provides a language and a code snippet. |
| 2563 | /// The language identifier is semantically equal to the optional language |
| 2564 | /// identifier in fenced code blocks in GitHub issues. |
| 2565 | /// |
| 2566 | /// The pair of a language and a value is an equivalent to markdown: |
| 2567 | /// |
| 2568 | /// ```${language} |
| 2569 | /// ${value} |
| 2570 | /// ``` |
| 2571 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2572 | #[serde(untagged)] |
| 2573 | pub enum MarkedString { |
| 2574 | String(String), |
| 2575 | LanguageString(LanguageString), |
| 2576 | } |
| 2577 | |
| 2578 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2579 | pub struct LanguageString { |
| 2580 | pub language: String, |
| 2581 | pub value: String, |
| 2582 | } |
| 2583 | |
| 2584 | impl MarkedString { |
| 2585 | pub fn from_markdown(markdown: String) -> MarkedString { |
| 2586 | MarkedString::String(markdown) |
| 2587 | } |
| 2588 | |
| 2589 | pub fn from_language_code(language: String, code_block: String) -> MarkedString { |
| 2590 | MarkedString::LanguageString(LanguageString { |
| 2591 | language, |
| 2592 | value: code_block, |
| 2593 | }) |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2598 | #[serde(rename_all = "camelCase" )] |
| 2599 | pub struct GotoDefinitionParams { |
| 2600 | #[serde(flatten)] |
| 2601 | pub text_document_position_params: TextDocumentPositionParams, |
| 2602 | |
| 2603 | #[serde(flatten)] |
| 2604 | pub work_done_progress_params: WorkDoneProgressParams, |
| 2605 | |
| 2606 | #[serde(flatten)] |
| 2607 | pub partial_result_params: PartialResultParams, |
| 2608 | } |
| 2609 | |
| 2610 | /// GotoDefinition response can be single location, or multiple Locations or a link. |
| 2611 | #[derive (Debug, PartialEq, Serialize, Deserialize, Clone)] |
| 2612 | #[serde(untagged)] |
| 2613 | pub enum GotoDefinitionResponse { |
| 2614 | Scalar(Location), |
| 2615 | Array(Vec<Location>), |
| 2616 | Link(Vec<LocationLink>), |
| 2617 | } |
| 2618 | |
| 2619 | impl From<Location> for GotoDefinitionResponse { |
| 2620 | fn from(location: Location) -> Self { |
| 2621 | GotoDefinitionResponse::Scalar(location) |
| 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | impl From<Vec<Location>> for GotoDefinitionResponse { |
| 2626 | fn from(locations: Vec<Location>) -> Self { |
| 2627 | GotoDefinitionResponse::Array(locations) |
| 2628 | } |
| 2629 | } |
| 2630 | |
| 2631 | impl From<Vec<LocationLink>> for GotoDefinitionResponse { |
| 2632 | fn from(locations: Vec<LocationLink>) -> Self { |
| 2633 | GotoDefinitionResponse::Link(locations) |
| 2634 | } |
| 2635 | } |
| 2636 | |
| 2637 | #[derive (Debug, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 2638 | pub struct ExecuteCommandParams { |
| 2639 | /// The identifier of the actual command handler. |
| 2640 | pub command: String, |
| 2641 | /// Arguments that the command should be invoked with. |
| 2642 | #[serde(default)] |
| 2643 | pub arguments: Vec<Value>, |
| 2644 | |
| 2645 | #[serde(flatten)] |
| 2646 | pub work_done_progress_params: WorkDoneProgressParams, |
| 2647 | } |
| 2648 | |
| 2649 | /// Execute command registration options. |
| 2650 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2651 | pub struct ExecuteCommandRegistrationOptions { |
| 2652 | /// The commands to be executed on the server |
| 2653 | pub commands: Vec<String>, |
| 2654 | |
| 2655 | #[serde(flatten)] |
| 2656 | pub execute_command_options: ExecuteCommandOptions, |
| 2657 | } |
| 2658 | |
| 2659 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2660 | #[serde(rename_all = "camelCase" )] |
| 2661 | pub struct ApplyWorkspaceEditParams { |
| 2662 | /// An optional label of the workspace edit. This label is |
| 2663 | /// presented in the user interface for example on an undo |
| 2664 | /// stack to undo the workspace edit. |
| 2665 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2666 | pub label: Option<String>, |
| 2667 | |
| 2668 | /// The edits to apply. |
| 2669 | pub edit: WorkspaceEdit, |
| 2670 | } |
| 2671 | |
| 2672 | #[derive (Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2673 | #[serde(rename_all = "camelCase" )] |
| 2674 | pub struct ApplyWorkspaceEditResponse { |
| 2675 | /// Indicates whether the edit was applied or not. |
| 2676 | pub applied: bool, |
| 2677 | |
| 2678 | /// An optional textual description for why the edit was not applied. |
| 2679 | /// This may be used may be used by the server for diagnostic |
| 2680 | /// logging or to provide a suitable error for a request that |
| 2681 | /// triggered the edit |
| 2682 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2683 | pub failure_reason: Option<String>, |
| 2684 | |
| 2685 | /// Depending on the client's failure handling strategy `failedChange` might |
| 2686 | /// contain the index of the change that failed. This property is only available |
| 2687 | /// if the client signals a `failureHandlingStrategy` in its client capabilities. |
| 2688 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2689 | pub failed_change: Option<u32>, |
| 2690 | } |
| 2691 | |
| 2692 | /// Describes the content type that a client supports in various |
| 2693 | /// result literals like `Hover`, `ParameterInfo` or `CompletionItem`. |
| 2694 | /// |
| 2695 | /// Please note that `MarkupKinds` must not start with a `$`. This kinds |
| 2696 | /// are reserved for internal usage. |
| 2697 | #[derive (Debug, Eq, PartialEq, Deserialize, Serialize, Clone)] |
| 2698 | #[serde(rename_all = "lowercase" )] |
| 2699 | pub enum MarkupKind { |
| 2700 | /// Plain text is supported as a content format |
| 2701 | PlainText, |
| 2702 | /// Markdown is supported as a content format |
| 2703 | Markdown, |
| 2704 | } |
| 2705 | |
| 2706 | /// A `MarkupContent` literal represents a string value which content can be represented in different formats. |
| 2707 | /// Currently `plaintext` and `markdown` are supported formats. A `MarkupContent` is usually used in |
| 2708 | /// documentation properties of result literals like `CompletionItem` or `SignatureInformation`. |
| 2709 | /// If the format is `markdown` the content should follow the [GitHub Flavored Markdown Specification](https://github.github.com/gfm/). |
| 2710 | /// |
| 2711 | /// Here is an example how such a string can be constructed using JavaScript / TypeScript: |
| 2712 | /// |
| 2713 | /// ```ignore |
| 2714 | /// let markdown: MarkupContent = { |
| 2715 | /// kind: MarkupKind::Markdown, |
| 2716 | /// value: [ |
| 2717 | /// "# Header" , |
| 2718 | /// "Some text" , |
| 2719 | /// "```typescript", |
| 2720 | /// "someCode();", |
| 2721 | /// "```" |
| 2722 | /// ] |
| 2723 | /// .join("\n"), |
| 2724 | /// }; |
| 2725 | /// ``` |
| 2726 | /// |
| 2727 | /// Please *Note* that clients might sanitize the return markdown. A client could decide to |
| 2728 | /// remove HTML from the markdown to avoid script execution. |
| 2729 | #[derive (Debug, Eq, PartialEq, Deserialize, Serialize, Clone)] |
| 2730 | pub struct MarkupContent { |
| 2731 | pub kind: MarkupKind, |
| 2732 | pub value: String, |
| 2733 | } |
| 2734 | |
| 2735 | /// A parameter literal used to pass a partial result token. |
| 2736 | #[derive (Debug, Eq, PartialEq, Default, Deserialize, Serialize, Clone)] |
| 2737 | #[serde(rename_all = "camelCase" )] |
| 2738 | pub struct PartialResultParams { |
| 2739 | #[serde(skip_serializing_if = "Option::is_none" )] |
| 2740 | pub partial_result_token: Option<ProgressToken>, |
| 2741 | } |
| 2742 | |
| 2743 | /// Symbol tags are extra annotations that tweak the rendering of a symbol. |
| 2744 | /// |
| 2745 | /// @since 3.16.0 |
| 2746 | #[derive (Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 2747 | #[serde(transparent)] |
| 2748 | pub struct SymbolTag(i32); |
| 2749 | lsp_enum! { |
| 2750 | impl SymbolTag { |
| 2751 | /// Render a symbol as obsolete, usually using a strike-out. |
| 2752 | pub const DEPRECATED: SymbolTag = SymbolTag(1); |
| 2753 | } |
| 2754 | } |
| 2755 | |
| 2756 | #[cfg (test)] |
| 2757 | mod tests { |
| 2758 | use serde::{Deserialize, Serialize}; |
| 2759 | |
| 2760 | use super::*; |
| 2761 | |
| 2762 | pub(crate) fn test_serialization<SER>(ms: &SER, expected: &str) |
| 2763 | where |
| 2764 | SER: Serialize + for<'de> Deserialize<'de> + PartialEq + std::fmt::Debug, |
| 2765 | { |
| 2766 | let json_str = serde_json::to_string(ms).unwrap(); |
| 2767 | assert_eq!(&json_str, expected); |
| 2768 | let deserialized: SER = serde_json::from_str(&json_str).unwrap(); |
| 2769 | assert_eq!(&deserialized, ms); |
| 2770 | } |
| 2771 | |
| 2772 | pub(crate) fn test_deserialization<T>(json: &str, expected: &T) |
| 2773 | where |
| 2774 | T: for<'de> Deserialize<'de> + PartialEq + std::fmt::Debug, |
| 2775 | { |
| 2776 | let value = serde_json::from_str::<T>(json).unwrap(); |
| 2777 | assert_eq!(&value, expected); |
| 2778 | } |
| 2779 | |
| 2780 | #[test ] |
| 2781 | fn one_of() { |
| 2782 | test_serialization(&OneOf::<bool, ()>::Left(true), r#"true"# ); |
| 2783 | test_serialization(&OneOf::<String, ()>::Left("abcd" .into()), r#""abcd""# ); |
| 2784 | test_serialization( |
| 2785 | &OneOf::<String, WorkDoneProgressOptions>::Right(WorkDoneProgressOptions { |
| 2786 | work_done_progress: Some(false), |
| 2787 | }), |
| 2788 | r#"{"workDoneProgress":false}"# , |
| 2789 | ); |
| 2790 | } |
| 2791 | |
| 2792 | #[test ] |
| 2793 | fn number_or_string() { |
| 2794 | test_serialization(&NumberOrString::Number(123), r#"123"# ); |
| 2795 | |
| 2796 | test_serialization(&NumberOrString::String("abcd" .into()), r#""abcd""# ); |
| 2797 | } |
| 2798 | |
| 2799 | #[test ] |
| 2800 | fn marked_string() { |
| 2801 | test_serialization(&MarkedString::from_markdown("xxx" .into()), r#""xxx""# ); |
| 2802 | |
| 2803 | test_serialization( |
| 2804 | &MarkedString::from_language_code("lang" .into(), "code" .into()), |
| 2805 | r#"{"language":"lang","value":"code"}"# , |
| 2806 | ); |
| 2807 | } |
| 2808 | |
| 2809 | #[test ] |
| 2810 | fn language_string() { |
| 2811 | test_serialization( |
| 2812 | &LanguageString { |
| 2813 | language: "LL" .into(), |
| 2814 | value: "VV" .into(), |
| 2815 | }, |
| 2816 | r#"{"language":"LL","value":"VV"}"# , |
| 2817 | ); |
| 2818 | } |
| 2819 | |
| 2820 | #[test ] |
| 2821 | fn workspace_edit() { |
| 2822 | test_serialization( |
| 2823 | &WorkspaceEdit { |
| 2824 | changes: Some(vec![].into_iter().collect()), |
| 2825 | document_changes: None, |
| 2826 | ..Default::default() |
| 2827 | }, |
| 2828 | r#"{"changes":{}}"# , |
| 2829 | ); |
| 2830 | |
| 2831 | test_serialization( |
| 2832 | &WorkspaceEdit { |
| 2833 | changes: None, |
| 2834 | document_changes: None, |
| 2835 | ..Default::default() |
| 2836 | }, |
| 2837 | r#"{}"# , |
| 2838 | ); |
| 2839 | |
| 2840 | test_serialization( |
| 2841 | &WorkspaceEdit { |
| 2842 | changes: Some( |
| 2843 | vec![(Url::parse("file://test" ).unwrap(), vec![])] |
| 2844 | .into_iter() |
| 2845 | .collect(), |
| 2846 | ), |
| 2847 | document_changes: None, |
| 2848 | ..Default::default() |
| 2849 | }, |
| 2850 | r#"{"changes":{"file://test/":[]}}"# , |
| 2851 | ); |
| 2852 | } |
| 2853 | |
| 2854 | #[test ] |
| 2855 | fn root_uri_can_be_missing() { |
| 2856 | serde_json::from_str::<InitializeParams>(r#"{ "capabilities": {} }"# ).unwrap(); |
| 2857 | } |
| 2858 | |
| 2859 | #[test ] |
| 2860 | fn test_watch_kind() { |
| 2861 | test_serialization(&WatchKind::Create, "1" ); |
| 2862 | test_serialization(&(WatchKind::Create | WatchKind::Change), "3" ); |
| 2863 | test_serialization( |
| 2864 | &(WatchKind::Create | WatchKind::Change | WatchKind::Delete), |
| 2865 | "7" , |
| 2866 | ); |
| 2867 | } |
| 2868 | |
| 2869 | #[test ] |
| 2870 | fn test_resource_operation_kind() { |
| 2871 | test_serialization( |
| 2872 | &vec![ |
| 2873 | ResourceOperationKind::Create, |
| 2874 | ResourceOperationKind::Rename, |
| 2875 | ResourceOperationKind::Delete, |
| 2876 | ], |
| 2877 | r#"["create","rename","delete"]"# , |
| 2878 | ); |
| 2879 | } |
| 2880 | } |
| 2881 | |