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 19 #[macro_use] 20 extern crate bitflags; 21 22 use serde::{Serialize, Deserialize}; 23 use serde_json; 24 use serde_repr::{Serialize_repr, Deserialize_repr}; 25 26 pub use url::Url; 27 28 use std::collections::HashMap; 29 30 use serde::de; 31 use serde::de::Error as Error_; 32 use serde_json::Value; 33 34 pub mod notification; 35 pub mod request; 36 37 /* ----------------- Auxiliary types ----------------- */ 38 39 #[derive(Debug, Eq, Hash, PartialEq, Clone, Deserialize, Serialize)] 40 #[serde(untagged)] 41 pub enum NumberOrString { 42 Number(u64), 43 String(String), 44 } 45 46 /* ----------------- Cancel support ----------------- */ 47 48 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 49 pub struct CancelParams { 50 /// The request id to cancel. 51 pub id: NumberOrString, 52 } 53 54 /* ----------------- Basic JSON Structures ----------------- */ 55 56 /// Position in a text document expressed as zero-based line and character offset. 57 /// A position is between two characters like an 'insert' cursor in a editor. 58 #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Default, Deserialize, Serialize)] 59 pub struct Position { 60 /// Line position in a document (zero-based). 61 pub line: u64, 62 /// Character offset on a line in a document (zero-based). 63 pub character: u64, 64 } 65 66 impl Position { new(line: u64, character: u64) -> Position67 pub fn new(line: u64, character: u64) -> Position { 68 Position { 69 line, 70 character, 71 } 72 } 73 } 74 75 /// A range in a text document expressed as (zero-based) start and end positions. 76 /// A range is comparable to a selection in an editor. Therefore the end position is exclusive. 77 #[derive(Debug, Eq, PartialEq, Copy, Clone, Default, Deserialize, Serialize)] 78 pub struct Range { 79 /// The range's start position. 80 pub start: Position, 81 /// The range's end position. 82 pub end: Position, 83 } 84 85 impl Range { new(start: Position, end: Position) -> Range86 pub fn new(start: Position, end: Position) -> Range { 87 Range { 88 start, 89 end, 90 } 91 } 92 } 93 94 /// Represents a location inside a resource, such as a line inside a text file. 95 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 96 pub struct Location { 97 pub uri: Url, 98 pub range: Range, 99 } 100 101 impl Location { new(uri: Url, range: Range) -> Location102 pub fn new(uri: Url, range: Range) -> Location { 103 Location { 104 uri, 105 range, 106 } 107 } 108 } 109 110 /// Represents a link between a source and a target location. 111 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 112 #[serde(rename_all = "camelCase")] 113 pub struct LocationLink { 114 /// Span of the origin of this link. 115 /// 116 /// Used as the underlined span for mouse interaction. Defaults to the word range at 117 /// the mouse position. 118 #[serde(skip_serializing_if = "Option::is_none")] 119 pub origin_selection_range: Option<Range>, 120 121 /// The target resource identifier of this link. 122 pub target_uri: Url, 123 124 /// The full target range of this link. 125 pub target_range: Range, 126 127 /// The span of this link. 128 pub target_selection_range: Range, 129 } 130 131 /// Represents a diagnostic, such as a compiler error or warning. 132 /// Diagnostic objects are only valid in the scope of a resource. 133 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 134 #[serde(rename_all = "camelCase")] 135 pub struct Diagnostic { 136 /// The range at which the message applies. 137 pub range: Range, 138 139 /// The diagnostic's severity. Can be omitted. If omitted it is up to the 140 /// client to interpret diagnostics as error, warning, info or hint. 141 #[serde(skip_serializing_if = "Option::is_none")] 142 pub severity: Option<DiagnosticSeverity>, 143 144 /// The diagnostic's code. Can be omitted. 145 #[serde(skip_serializing_if = "Option::is_none")] 146 pub code: Option<NumberOrString>, 147 // code?: number | string; 148 /// A human-readable string describing the source of this 149 /// diagnostic, e.g. 'typescript' or 'super lint'. 150 #[serde(skip_serializing_if = "Option::is_none")] 151 pub source: Option<String>, 152 153 /// The diagnostic's message. 154 pub message: String, 155 156 /// An array of related diagnostic information, e.g. when symbol-names within 157 /// a scope collide all definitions can be marked via this property. 158 #[serde(skip_serializing_if = "Option::is_none")] 159 pub related_information: Option<Vec<DiagnosticRelatedInformation>>, 160 } 161 162 impl Diagnostic { new( range: Range, severity: Option<DiagnosticSeverity>, code: Option<NumberOrString>, source: Option<String>, message: String, related_information: Option<Vec<DiagnosticRelatedInformation>>, ) -> Diagnostic163 pub fn new( 164 range: Range, 165 severity: Option<DiagnosticSeverity>, 166 code: Option<NumberOrString>, 167 source: Option<String>, 168 message: String, 169 related_information: Option<Vec<DiagnosticRelatedInformation>>, 170 ) -> Diagnostic { 171 Diagnostic { 172 range, 173 severity, 174 code, 175 source, 176 message, 177 related_information, 178 } 179 } 180 new_simple(range: Range, message: String) -> Diagnostic181 pub fn new_simple(range: Range, message: String) -> Diagnostic { 182 Self::new(range, None, None, None, message, None) 183 } 184 new_with_code_number( range: Range, severity: DiagnosticSeverity, code_number: u64, source: Option<String>, message: String, ) -> Diagnostic185 pub fn new_with_code_number( 186 range: Range, 187 severity: DiagnosticSeverity, 188 code_number: u64, 189 source: Option<String>, 190 message: String, 191 ) -> Diagnostic { 192 let code = Some(NumberOrString::Number(code_number)); 193 Self::new(range, Some(severity), code, source, message, None) 194 } 195 } 196 197 /// The protocol currently supports the following diagnostic severities: 198 #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Copy)] 199 pub enum DiagnosticSeverity { 200 /// Reports an error. 201 Error = 1, 202 /// Reports a warning. 203 Warning = 2, 204 /// Reports an information. 205 Information = 3, 206 /// Reports a hint. 207 Hint = 4, 208 } 209 210 /// Represents a related message and source code location for a diagnostic. This 211 /// should be used to point to code locations that cause or related to a 212 /// diagnostics, e.g when duplicating a symbol in a scope. 213 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 214 pub struct DiagnosticRelatedInformation { 215 /// The location of this related diagnostic information. 216 pub location: Location, 217 218 /// The message of this related diagnostic information. 219 pub message: String, 220 } 221 222 impl<'de> serde::Deserialize<'de> for DiagnosticSeverity { deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de>,223 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 224 where 225 D: serde::Deserializer<'de>, 226 { 227 Ok(match u8::deserialize(deserializer)? { 228 1 => DiagnosticSeverity::Error, 229 2 => DiagnosticSeverity::Warning, 230 3 => DiagnosticSeverity::Information, 231 4 => DiagnosticSeverity::Hint, 232 i => { 233 return Err(D::Error::invalid_value( 234 de::Unexpected::Unsigned(u64::from(i)), 235 &"value of 1, 2, 3 or 4", 236 )); 237 } 238 }) 239 } 240 } 241 242 impl serde::Serialize for DiagnosticSeverity { serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer,243 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 244 where 245 S: serde::Serializer, 246 { 247 serializer.serialize_u8(*self as u8) 248 } 249 } 250 251 /** 252 Represents a reference to a command. Provides a title which will be used to represent a command in the UI. 253 Commands are identitifed using a string identifier and the protocol currently doesn't specify a set of 254 well known commands. So executing a command requires some tool extension code. 255 */ 256 #[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)] 257 pub struct Command { 258 /// Title of the command, like `save`. 259 pub title: String, 260 /// The identifier of the actual command handler. 261 pub command: String, 262 /// Arguments that the command handler should be 263 /// invoked with. 264 #[serde(skip_serializing_if = "Option::is_none")] 265 pub arguments: Option<Vec<Value>>, 266 } 267 268 impl Command { new(title: String, command: String, arguments: Option<Vec<Value>>) -> Command269 pub fn new(title: String, command: String, arguments: Option<Vec<Value>>) -> Command { 270 Command { 271 title, 272 command, 273 arguments, 274 } 275 } 276 } 277 278 /// A textual edit applicable to a text document. 279 /// 280 /// If n `TextEdit`s are applied to a text document all text edits describe changes to the initial document version. 281 /// Execution wise text edits should applied from the bottom to the top of the text document. Overlapping text edits 282 /// are not supported. 283 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 284 #[serde(rename_all = "camelCase")] 285 pub struct TextEdit { 286 /// The range of the text document to be manipulated. To insert 287 /// text into a document create a range where start === end. 288 pub range: Range, 289 /// The string to be inserted. For delete operations use an 290 /// empty string. 291 pub new_text: String, 292 } 293 294 impl TextEdit { new(range: Range, new_text: String) -> TextEdit295 pub fn new(range: Range, new_text: String) -> TextEdit { 296 TextEdit { 297 range, 298 new_text, 299 } 300 } 301 } 302 303 /** 304 Describes textual changes on a single text document. The text document is referred to as a 305 `VersionedTextDocumentIdentifier` to allow clients to check the text document version before an 306 edit is applied. A `TextDocumentEdit` describes all changes on a version Si and after they are 307 applied move the document to version Si+1. So the creator of a `TextDocumentEdit` doesn't need to 308 sort the array or do any kind of ordering. However the edits must be non overlapping. 309 */ 310 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 311 #[serde(rename_all = "camelCase")] 312 pub struct TextDocumentEdit { 313 /** 314 * The text document to change. 315 */ 316 pub text_document: VersionedTextDocumentIdentifier, 317 318 /** 319 * The edits to be applied. 320 */ 321 pub edits: Vec<TextEdit>, 322 } 323 324 /** 325 * Options to create a file. 326 */ 327 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 328 #[serde(rename_all = "camelCase")] 329 pub struct CreateFileOptions { 330 /** 331 * Overwrite existing file. Overwrite wins over `ignoreIfExists` 332 */ 333 #[serde(skip_serializing_if = "Option::is_none")] 334 pub overwrite: Option<bool>, 335 /** 336 * Ignore if exists. 337 */ 338 #[serde(skip_serializing_if = "Option::is_none")] 339 pub ignore_if_exists: Option<bool>, 340 } 341 342 /** 343 * Create file operation 344 */ 345 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 346 #[serde(rename_all = "camelCase")] 347 pub struct CreateFile { 348 /** 349 * The resource to create. 350 */ 351 pub uri: Url, 352 /** 353 * Additional options 354 */ 355 #[serde(skip_serializing_if = "Option::is_none")] 356 pub options: Option<CreateFileOptions>, 357 } 358 359 /** 360 * Rename file options 361 */ 362 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 363 #[serde(rename_all = "camelCase")] 364 pub struct RenameFileOptions { 365 /** 366 * Overwrite target if existing. Overwrite wins over `ignoreIfExists` 367 */ 368 #[serde(skip_serializing_if = "Option::is_none")] 369 pub overwrite: Option<bool>, 370 /** 371 * Ignores if target exists. 372 */ 373 #[serde(skip_serializing_if = "Option::is_none")] 374 pub ignore_if_exists: Option<bool>, 375 } 376 377 /** 378 * Rename file operation 379 */ 380 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 381 #[serde(rename_all = "camelCase")] 382 pub struct RenameFile { 383 /** 384 * The old (existing) location. 385 */ 386 pub old_uri: Url, 387 /** 388 * The new location. 389 */ 390 pub new_uri: Url, 391 /** 392 * Rename options. 393 */ 394 #[serde(skip_serializing_if = "Option::is_none")] 395 pub options: Option<RenameFileOptions>, 396 } 397 398 /** 399 * Delete file options 400 */ 401 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 402 #[serde(rename_all = "camelCase")] 403 pub struct DeleteFileOptions { 404 /** 405 * Delete the content recursively if a folder is denoted. 406 */ 407 #[serde(skip_serializing_if = "Option::is_none")] 408 pub recursive: Option<bool>, 409 /** 410 * Ignore the operation if the file doesn't exist. 411 */ 412 #[serde(skip_serializing_if = "Option::is_none")] 413 pub ignore_if_not_exists: Option<bool>, 414 } 415 416 /** 417 * Delete file operation 418 */ 419 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 420 #[serde(rename_all = "camelCase")] 421 pub struct DeleteFile { 422 /** 423 * The file to delete. 424 */ 425 pub uri: Url, 426 /** 427 * Delete options. 428 */ 429 #[serde(skip_serializing_if = "Option::is_none")] 430 pub options: Option<DeleteFileOptions>, 431 } 432 433 /// A workspace edit represents changes to many resources managed in the workspace. 434 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 435 #[serde(rename_all = "camelCase")] 436 pub struct WorkspaceEdit { 437 /// Holds changes to existing resources. 438 #[serde(with = "url_map")] 439 #[serde(skip_serializing_if = "Option::is_none")] 440 #[serde(default)] 441 pub changes: Option<HashMap<Url, Vec<TextEdit>>>, // changes?: { [uri: string]: TextEdit[]; }; 442 443 /** 444 * Depending on the client capability `workspace.workspaceEdit.resourceOperations` document changes 445 * are either an array of `TextDocumentEdit`s to express changes to n different text documents 446 * where each text document edit addresses a specific version of a text document. Or it can contain 447 * above `TextDocumentEdit`s mixed with create, rename and delete file / folder operations. 448 * 449 * Whether a client supports versioned document edits is expressed via 450 * `workspace.workspaceEdit.documentChanges` client capability. 451 * 452 * If a client neither supports `documentChanges` nor `workspace.workspaceEdit.resourceOperations` then 453 * only plain `TextEdit`s using the `changes` property are supported. 454 */ 455 #[serde(skip_serializing_if = "Option::is_none")] 456 pub document_changes: Option<DocumentChanges>, 457 } 458 459 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 460 #[serde(untagged)] 461 pub enum DocumentChanges { 462 Edits(Vec<TextDocumentEdit>), 463 Operations(Vec<DocumentChangeOperation>), 464 } 465 466 // TODO: Once https://github.com/serde-rs/serde/issues/912 is solved 467 // we can remove ResourceOp and switch to the following implementation 468 // of DocumentChangeOperation: 469 // 470 // #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 471 // #[serde(tag = "kind", rename_all="lowercase" )] 472 // pub enum DocumentChangeOperation { 473 // Create(CreateFile), 474 // Rename(RenameFile), 475 // Delete(DeleteFile), 476 // 477 // #[serde(other)] 478 // Edit(TextDocumentEdit), 479 // } 480 481 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 482 #[serde(untagged, rename_all = "lowercase")] 483 pub enum DocumentChangeOperation { 484 Op(ResourceOp), 485 Edit(TextDocumentEdit), 486 } 487 488 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 489 #[serde(tag = "kind", rename_all = "lowercase")] 490 pub enum ResourceOp { 491 Create(CreateFile), 492 Rename(RenameFile), 493 Delete(DeleteFile), 494 } 495 496 #[derive(Debug, Default, Eq, PartialEq, Clone, Deserialize, Serialize)] 497 #[serde(rename_all = "camelCase")] 498 pub struct ConfigurationParams { 499 pub items: Vec<ConfigurationItem>, 500 } 501 502 #[derive(Debug, Default, Eq, PartialEq, Clone, Deserialize, Serialize)] 503 #[serde(rename_all = "camelCase")] 504 pub struct ConfigurationItem { 505 /// The scope to get the configuration section for. 506 #[serde(skip_serializing_if = "Option::is_none")] 507 pub scope_uri: Option<String>, 508 509 ///The configuration section asked for. 510 #[serde(skip_serializing_if = "Option::is_none")] 511 pub section: Option<String>, 512 } 513 514 mod url_map { 515 use super::*; 516 517 use std::fmt; 518 deserialize<'de, D>( deserializer: D, ) -> Result<Option<HashMap<Url, Vec<TextEdit>>>, D::Error> where D: serde::Deserializer<'de>,519 pub fn deserialize<'de, D>( 520 deserializer: D, 521 ) -> Result<Option<HashMap<Url, Vec<TextEdit>>>, D::Error> 522 where 523 D: serde::Deserializer<'de>, 524 { 525 struct UrlMapVisitor; 526 impl<'de> de::Visitor<'de> for UrlMapVisitor { 527 type Value = HashMap<Url, Vec<TextEdit>>; 528 529 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 530 formatter.write_str("map") 531 } 532 533 fn visit_map<M>(self, mut visitor: M) -> Result<Self::Value, M::Error> 534 where 535 M: de::MapAccess<'de>, 536 { 537 let mut values = HashMap::with_capacity(visitor.size_hint().unwrap_or(0)); 538 539 // While there are entries remaining in the input, add them 540 // into our map. 541 while let Some((key, value)) = visitor.next_entry::<Url, _>()? { 542 values.insert(key, value); 543 } 544 545 Ok(values) 546 } 547 } 548 549 struct OptionUrlMapVisitor; 550 impl<'de> de::Visitor<'de> for OptionUrlMapVisitor { 551 type Value = Option<HashMap<Url, Vec<TextEdit>>>; 552 553 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 554 formatter.write_str("option") 555 } 556 557 #[inline] 558 fn visit_unit<E>(self) -> Result<Self::Value, E> 559 where 560 E: serde::de::Error, 561 { 562 Ok(None) 563 } 564 565 #[inline] 566 fn visit_none<E>(self) -> Result<Self::Value, E> 567 where 568 E: serde::de::Error, 569 { 570 Ok(None) 571 } 572 573 #[inline] 574 fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error> 575 where 576 D: serde::Deserializer<'de>, 577 { 578 deserializer.deserialize_map(UrlMapVisitor).map(Some) 579 } 580 } 581 582 // Instantiate our Visitor and ask the Deserializer to drive 583 // it over the input data, resulting in an instance of MyMap. 584 deserializer.deserialize_option(OptionUrlMapVisitor) 585 } 586 serialize<S>( changes: &Option<HashMap<Url, Vec<TextEdit>>>, serializer: S, ) -> Result<S::Ok, S::Error> where S: serde::Serializer,587 pub fn serialize<S>( 588 changes: &Option<HashMap<Url, Vec<TextEdit>>>, 589 serializer: S, 590 ) -> Result<S::Ok, S::Error> 591 where 592 S: serde::Serializer, 593 { 594 use serde::ser::SerializeMap; 595 596 match *changes { 597 Some(ref changes) => { 598 let mut map = serializer.serialize_map(Some(changes.len()))?; 599 for (k, v) in changes { 600 map.serialize_entry(k.as_str(), v)?; 601 } 602 map.end() 603 } 604 None => serializer.serialize_none(), 605 } 606 } 607 } 608 609 impl WorkspaceEdit { new(changes: HashMap<Url, Vec<TextEdit>>) -> WorkspaceEdit610 pub fn new(changes: HashMap<Url, Vec<TextEdit>>) -> WorkspaceEdit { 611 WorkspaceEdit { 612 changes: Some(changes), 613 document_changes: None, 614 } 615 } 616 } 617 618 /// Text documents are identified using a URI. On the protocol level, URIs are passed as strings. 619 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 620 pub struct TextDocumentIdentifier { 621 // !!!!!! Note: 622 // In the spec VersionedTextDocumentIdentifier extends TextDocumentIdentifier 623 // This modelled by "mixing-in" TextDocumentIdentifier in VersionedTextDocumentIdentifier, 624 // so any changes to this type must be effected in the sub-type as well. 625 /// The text document's URI. 626 pub uri: Url, 627 } 628 629 impl TextDocumentIdentifier { new(uri: Url) -> TextDocumentIdentifier630 pub fn new(uri: Url) -> TextDocumentIdentifier { 631 TextDocumentIdentifier { uri } 632 } 633 } 634 635 /// An item to transfer a text document from the client to the server. 636 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 637 #[serde(rename_all = "camelCase")] 638 pub struct TextDocumentItem { 639 /// The text document's URI. 640 pub uri: Url, 641 642 /// The text document's language identifier. 643 pub language_id: String, 644 645 /// The version number of this document (it will strictly increase after each 646 /// change, including undo/redo). 647 pub version: u64, 648 649 /// The content of the opened text document. 650 pub text: String, 651 } 652 653 impl TextDocumentItem { new(uri: Url, language_id: String, version: u64, text: String) -> TextDocumentItem654 pub fn new(uri: Url, language_id: String, version: u64, text: String) -> TextDocumentItem { 655 TextDocumentItem { 656 uri, 657 language_id, 658 version, 659 text, 660 } 661 } 662 } 663 664 /// An identifier to denote a specific version of a text document. 665 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 666 pub struct VersionedTextDocumentIdentifier { 667 // This field was "mixed-in" from TextDocumentIdentifier 668 /// The text document's URI. 669 pub uri: Url, 670 671 /// The version number of this document. 672 pub version: Option<u64>, 673 } 674 675 impl VersionedTextDocumentIdentifier { new(uri: Url, version: u64) -> VersionedTextDocumentIdentifier676 pub fn new(uri: Url, version: u64) -> VersionedTextDocumentIdentifier { 677 VersionedTextDocumentIdentifier { 678 uri, 679 version: Some(version), 680 } 681 } 682 } 683 684 /// A parameter literal used in requests to pass a text document and a position inside that document. 685 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 686 #[serde(rename_all = "camelCase")] 687 pub struct TextDocumentPositionParams { 688 // !!!!!! Note: 689 // In the spec ReferenceParams extends TextDocumentPositionParams 690 // This modelled by "mixing-in" TextDocumentPositionParams in ReferenceParams, 691 // so any changes to this type must be effected in sub-type as well. 692 /// The text document. 693 pub text_document: TextDocumentIdentifier, 694 695 /// The position inside the text document. 696 pub position: Position, 697 } 698 699 impl TextDocumentPositionParams { new( text_document: TextDocumentIdentifier, position: Position, ) -> TextDocumentPositionParams700 pub fn new( 701 text_document: TextDocumentIdentifier, 702 position: Position, 703 ) -> TextDocumentPositionParams { 704 TextDocumentPositionParams { 705 text_document, 706 position, 707 } 708 } 709 } 710 711 /// A document filter denotes a document through properties like language, schema or pattern. 712 /// Examples are a filter that applies to TypeScript files on disk or a filter the applies to JSON 713 /// files with name package.json: 714 /// 715 /// { language: 'typescript', scheme: 'file' } 716 /// { language: 'json', pattern: '**/package.json' } 717 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 718 pub struct DocumentFilter { 719 /** 720 * A language id, like `typescript`. 721 */ 722 #[serde(skip_serializing_if = "Option::is_none")] 723 pub language: Option<String>, 724 725 /** 726 * A Uri [scheme](#Uri.scheme), like `file` or `untitled`. 727 */ 728 #[serde(skip_serializing_if = "Option::is_none")] 729 pub scheme: Option<String>, 730 731 /** 732 * A glob pattern, like `*.{ts,js}`. 733 */ 734 #[serde(skip_serializing_if = "Option::is_none")] 735 pub pattern: Option<String>, 736 } 737 738 /// A document selector is the combination of one or many document filters. 739 pub type DocumentSelector = Vec<DocumentFilter>; 740 741 // ========================= Actual Protocol ========================= 742 743 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 744 #[serde(rename_all = "camelCase")] 745 pub struct InitializeParams { 746 /// The process Id of the parent process that started 747 /// the server. Is null if the process has not been started by another process. 748 /// If the parent process is not alive then the server should exit (see exit notification) its process. 749 pub process_id: Option<u64>, 750 751 /// The rootPath of the workspace. Is null 752 /// if no folder is open. 753 #[serde(skip_serializing_if = "Option::is_none")] 754 pub root_path: Option<String>, 755 756 /// The rootUri of the workspace. Is null if no 757 /// folder is open. If both `rootPath` and `rootUri` are set 758 /// `rootUri` wins. 759 #[serde(default)] 760 pub root_uri: Option<Url>, 761 762 /// User provided initialization options. 763 #[serde(skip_serializing_if = "Option::is_none")] 764 pub initialization_options: Option<Value>, 765 766 /// The capabilities provided by the client (editor) 767 pub capabilities: ClientCapabilities, 768 769 /// The initial trace setting. If omitted trace is disabled ('off'). 770 #[serde(default)] 771 #[serde(skip_serializing_if = "Option::is_none")] 772 pub trace: Option<TraceOption>, 773 774 /// The workspace folders configured in the client when the server starts. 775 /// This property is only available if the client supports workspace folders. 776 /// It can be `null` if the client supports workspace folders but none are 777 /// configured. 778 #[serde(skip_serializing_if = "Option::is_none")] 779 pub workspace_folders: Option<Vec<WorkspaceFolder>>, 780 } 781 782 #[derive(Debug, PartialEq, Clone, Copy, Deserialize, Serialize)] 783 pub struct InitializedParams {} 784 785 #[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] 786 pub enum TraceOption { 787 #[serde(rename = "off")] 788 Off, 789 #[serde(rename = "messages")] 790 Messages, 791 #[serde(rename = "verbose")] 792 Verbose, 793 } 794 795 impl Default for TraceOption { default() -> TraceOption796 fn default() -> TraceOption { 797 TraceOption::Off 798 } 799 } 800 801 #[derive(Debug, Eq, PartialEq, Clone, Copy, Default, Deserialize, Serialize)] 802 #[serde(rename_all = "camelCase")] 803 pub struct GenericCapability { 804 /** 805 * This capability supports dynamic registration. 806 */ 807 #[serde(skip_serializing_if = "Option::is_none")] 808 pub dynamic_registration: Option<bool>, 809 } 810 811 #[derive(Debug, Eq, PartialEq, Clone, Copy, Default, Deserialize, Serialize)] 812 #[serde(rename_all = "camelCase")] 813 pub struct GotoCapability { 814 #[serde(skip_serializing_if = "Option::is_none")] 815 pub dynamic_registration: Option<bool>, 816 817 /// The client supports additional metadata in the form of definition links. 818 pub link_support: Option<bool>, 819 } 820 821 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 822 #[serde(rename_all = "camelCase")] 823 pub struct WorkspaceEditCapability { 824 /** 825 * The client supports versioned document changes in `WorkspaceEdit`s 826 */ 827 #[serde(skip_serializing_if = "Option::is_none")] 828 pub document_changes: Option<bool>, 829 830 /** 831 * The resource operations the client supports. Clients should at least 832 * support 'create', 'rename' and 'delete' files and folders. 833 */ 834 #[serde(skip_serializing_if = "Option::is_none")] 835 pub resource_operations: Option<Vec<ResourceOperationKind>>, 836 837 /** 838 * The failure handling strategy of a client if applying the workspace edit 839 * failes. 840 */ 841 #[serde(skip_serializing_if = "Option::is_none")] 842 pub failure_handling: Option<FailureHandlingKind>, 843 } 844 845 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 846 #[serde(rename_all = "camelCase")] 847 pub struct WorkspaceCapability { 848 /// The server supports workspace folder. 849 #[serde(skip_serializing_if = "Option::is_none")] 850 pub workspace_folders: Option<WorkspaceFolderCapability>, 851 } 852 853 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 854 #[serde(rename_all = "camelCase")] 855 pub struct WorkspaceFolderCapability { 856 #[serde(skip_serializing_if = "Option::is_none")] 857 pub supported: Option<bool>, 858 859 #[serde(skip_serializing_if = "Option::is_none")] 860 pub change_notifications: Option<WorkspaceFolderCapabilityChangeNotifications>, 861 } 862 863 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 864 #[serde(untagged)] 865 pub enum WorkspaceFolderCapabilityChangeNotifications { 866 Bool(bool), 867 Id(String), 868 } 869 870 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 871 #[serde(rename_all = "camelCase")] 872 pub struct WorkspaceFolder { 873 /// The associated URI for this workspace folder. 874 pub uri: Url, 875 /// The name of the workspace folder. Defaults to the uri's basename. 876 pub name: String, 877 } 878 879 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 880 #[serde(rename_all = "camelCase")] 881 pub struct DidChangeWorkspaceFoldersParams { 882 /** 883 * The actual workspace folder change event. 884 */ 885 pub event: WorkspaceFoldersChangeEvent, 886 } 887 888 /** 889 * The workspace folder change event. 890 */ 891 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 892 #[serde(rename_all = "camelCase")] 893 pub struct WorkspaceFoldersChangeEvent { 894 /** 895 * The array of added workspace folders 896 */ 897 pub added: Vec<WorkspaceFolder>, 898 899 /** 900 * The array of the removed workspace folders 901 */ 902 pub removed: Vec<WorkspaceFolder>, 903 } 904 905 #[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Copy, Clone)] 906 #[serde(rename_all = "lowercase")] 907 pub enum ResourceOperationKind { 908 Create, 909 Rename, 910 Delete, 911 } 912 913 #[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Copy, Clone)] 914 #[serde(rename_all = "camelCase")] 915 pub enum FailureHandlingKind { 916 Abort, 917 Transactional, 918 TextOnlyTransactional, 919 Undo, 920 } 921 922 /** 923 * Specific capabilities for the `SymbolKind` in the `workspace/symbol` request. 924 */ 925 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 926 #[serde(rename_all = "camelCase")] 927 pub struct SymbolKindCapability { 928 /** 929 * The symbol kind values the client supports. When this 930 * property exists the client also guarantees that it will 931 * handle values outside its set gracefully and falls back 932 * to a default value when unknown. 933 * 934 * If this property is not present the client only supports 935 * the symbol kinds from `File` to `Array` as defined in 936 * the initial version of the protocol. 937 */ 938 pub value_set: Option<Vec<SymbolKind>>, 939 } 940 941 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 942 #[serde(rename_all = "camelCase")] 943 pub struct SymbolCapability { 944 /** 945 * This capability supports dynamic registration. 946 */ 947 #[serde(skip_serializing_if = "Option::is_none")] 948 pub dynamic_registration: Option<bool>, 949 950 /** 951 * Specific capabilities for the `SymbolKind` in the `workspace/symbol` request. 952 */ 953 #[serde(skip_serializing_if = "Option::is_none")] 954 pub symbol_kind: Option<SymbolKindCapability>, 955 } 956 957 /** 958 * Workspace specific client capabilities. 959 */ 960 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 961 #[serde(rename_all = "camelCase")] 962 pub struct WorkspaceClientCapabilities { 963 /** 964 * The client supports applying batch edits to the workspace by supporting 965 * the request 'workspace/applyEdit' 966 */ 967 #[serde(skip_serializing_if = "Option::is_none")] 968 pub apply_edit: Option<bool>, 969 970 /** 971 * Capabilities specific to `WorkspaceEdit`s 972 */ 973 #[serde(skip_serializing_if = "Option::is_none")] 974 pub workspace_edit: Option<WorkspaceEditCapability>, 975 976 /** 977 * Capabilities specific to the `workspace/didChangeConfiguration` notification. 978 */ 979 #[serde(skip_serializing_if = "Option::is_none")] 980 pub did_change_configuration: Option<GenericCapability>, 981 982 /** 983 * Capabilities specific to the `workspace/didChangeWatchedFiles` notification. 984 */ 985 #[serde(skip_serializing_if = "Option::is_none")] 986 pub did_change_watched_files: Option<GenericCapability>, 987 988 /** 989 * Capabilities specific to the `workspace/symbol` request. 990 */ 991 #[serde(skip_serializing_if = "Option::is_none")] 992 pub symbol: Option<SymbolCapability>, 993 994 /** 995 * Capabilities specific to the `workspace/executeCommand` request. 996 */ 997 #[serde(skip_serializing_if = "Option::is_none")] 998 pub execute_command: Option<GenericCapability>, 999 1000 /** 1001 * The client has support for workspace folders. 1002 */ 1003 #[serde(skip_serializing_if = "Option::is_none")] 1004 pub workspace_folders: Option<bool>, 1005 1006 /** 1007 * The client supports `workspace/configuration` requests. 1008 */ 1009 #[serde(skip_serializing_if = "Option::is_none")] 1010 pub configuration: Option<bool>, 1011 } 1012 1013 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1014 #[serde(rename_all = "camelCase")] 1015 pub struct SynchronizationCapability { 1016 /** 1017 * Whether text document synchronization supports dynamic registration. 1018 */ 1019 #[serde(skip_serializing_if = "Option::is_none")] 1020 pub dynamic_registration: Option<bool>, 1021 1022 /** 1023 * The client supports sending will save notifications. 1024 */ 1025 #[serde(skip_serializing_if = "Option::is_none")] 1026 pub will_save: Option<bool>, 1027 1028 /** 1029 * The client supports sending a will save request and 1030 * waits for a response providing text edits which will 1031 * be applied to the document before it is saved. 1032 */ 1033 #[serde(skip_serializing_if = "Option::is_none")] 1034 pub will_save_wait_until: Option<bool>, 1035 1036 /** 1037 * The client supports did save notifications. 1038 */ 1039 #[serde(skip_serializing_if = "Option::is_none")] 1040 pub did_save: Option<bool>, 1041 } 1042 1043 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1044 #[serde(rename_all = "camelCase")] 1045 pub struct CompletionItemCapability { 1046 /** 1047 * Client supports snippets as insert text. 1048 * 1049 * A snippet can define tab stops and placeholders with `$1`, `$2` 1050 * and `${3:foo}`. `$0` defines the final tab stop, it defaults to 1051 * the end of the snippet. Placeholders with equal identifiers are linked, 1052 * that is typing in one will update others too. 1053 */ 1054 #[serde(skip_serializing_if = "Option::is_none")] 1055 pub snippet_support: Option<bool>, 1056 1057 /** 1058 * Client supports commit characters on a completion item. 1059 */ 1060 #[serde(skip_serializing_if = "Option::is_none")] 1061 pub commit_characters_support: Option<bool>, 1062 1063 /** 1064 * Client supports the follow content formats for the documentation 1065 * property. The order describes the preferred format of the client. 1066 */ 1067 #[serde(skip_serializing_if = "Option::is_none")] 1068 pub documentation_format: Option<Vec<MarkupKind>>, 1069 1070 /** 1071 * Client supports the deprecated property on a completion item. 1072 */ 1073 #[serde(skip_serializing_if = "Option::is_none")] 1074 pub deprecated_support: Option<bool>, 1075 1076 /** 1077 * Client supports the preselect property on a completion item. 1078 */ 1079 #[serde(skip_serializing_if = "Option::is_none")] 1080 pub preselect_support: Option<bool>, 1081 } 1082 1083 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1084 #[serde(rename_all = "camelCase")] 1085 pub struct CompletionItemKindCapability { 1086 /** 1087 * The completion item kind values the client supports. When this 1088 * property exists the client also guarantees that it will 1089 * handle values outside its set gracefully and falls back 1090 * to a default value when unknown. 1091 * 1092 * If this property is not present the client only supports 1093 * the completion items kinds from `Text` to `Reference` as defined in 1094 * the initial version of the protocol. 1095 */ 1096 #[serde(skip_serializing_if = "Option::is_none")] 1097 pub value_set: Option<Vec<CompletionItemKind>>, 1098 } 1099 1100 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1101 #[serde(rename_all = "camelCase")] 1102 pub struct HoverCapability { 1103 /** 1104 * Whether completion supports dynamic registration. 1105 */ 1106 #[serde(skip_serializing_if = "Option::is_none")] 1107 pub dynamic_registration: Option<bool>, 1108 1109 /** 1110 * Client supports the follow content formats for the content 1111 * property. The order describes the preferred format of the client. 1112 */ 1113 #[serde(skip_serializing_if = "Option::is_none")] 1114 pub content_format: Option<Vec<MarkupKind>>, 1115 } 1116 1117 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1118 #[serde(rename_all = "camelCase")] 1119 pub struct CompletionCapability { 1120 /** 1121 * Whether completion supports dynamic registration. 1122 */ 1123 #[serde(skip_serializing_if = "Option::is_none")] 1124 pub dynamic_registration: Option<bool>, 1125 1126 /** 1127 * The client supports the following `CompletionItem` specific 1128 * capabilities. 1129 */ 1130 #[serde(skip_serializing_if = "Option::is_none")] 1131 pub completion_item: Option<CompletionItemCapability>, 1132 1133 #[serde(skip_serializing_if = "Option::is_none")] 1134 pub completion_item_kind: Option<CompletionItemKindCapability>, 1135 1136 /** 1137 * The client supports to send additional context information for a 1138 * `textDocument/completion` requestion. 1139 */ 1140 #[serde(skip_serializing_if = "Option::is_none")] 1141 pub context_support: Option<bool>, 1142 } 1143 1144 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1145 #[serde(rename_all = "camelCase")] 1146 pub struct SignatureInformationSettings { 1147 /** 1148 * Client supports the follow content formats for the documentation 1149 * property. The order describes the preferred format of the client. 1150 */ 1151 #[serde(skip_serializing_if = "Option::is_none")] 1152 pub documentation_format: Option<Vec<MarkupKind>>, 1153 1154 #[serde(skip_serializing_if = "Option::is_none")] 1155 pub parameter_information: Option<ParameterInformationSettings>, 1156 } 1157 1158 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1159 #[serde(rename_all = "camelCase")] 1160 pub struct ParameterInformationSettings { 1161 /** 1162 * The client supports processing label offsets instead of a 1163 * simple label string. 1164 */ 1165 #[serde(skip_serializing_if = "Option::is_none")] 1166 pub label_offset_support: Option<bool>, 1167 } 1168 1169 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1170 #[serde(rename_all = "camelCase")] 1171 pub struct SignatureHelpCapability { 1172 /** 1173 * Whether completion supports dynamic registration. 1174 */ 1175 #[serde(skip_serializing_if = "Option::is_none")] 1176 pub dynamic_registration: Option<bool>, 1177 1178 /** 1179 * The client supports the following `SignatureInformation` 1180 * specific properties. 1181 */ 1182 #[serde(skip_serializing_if = "Option::is_none")] 1183 pub signature_information: Option<SignatureInformationSettings>, 1184 } 1185 1186 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1187 #[serde(rename_all = "camelCase")] 1188 pub struct PublishDiagnosticsCapability { 1189 /** 1190 * Whether the clients accepts diagnostics with related information. 1191 */ 1192 #[serde(skip_serializing_if = "Option::is_none")] 1193 pub related_information: Option<bool>, 1194 } 1195 1196 /** 1197 * Text document specific client capabilities. 1198 */ 1199 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1200 #[serde(rename_all = "camelCase")] 1201 pub struct TextDocumentClientCapabilities { 1202 #[serde(skip_serializing_if = "Option::is_none")] 1203 pub synchronization: Option<SynchronizationCapability>, 1204 /** 1205 * Capabilities specific to the `textDocument/completion` 1206 */ 1207 #[serde(skip_serializing_if = "Option::is_none")] 1208 pub completion: Option<CompletionCapability>, 1209 1210 /** 1211 * Capabilities specific to the `textDocument/hover` 1212 */ 1213 #[serde(skip_serializing_if = "Option::is_none")] 1214 pub hover: Option<HoverCapability>, 1215 1216 /** 1217 * Capabilities specific to the `textDocument/signatureHelp` 1218 */ 1219 #[serde(skip_serializing_if = "Option::is_none")] 1220 pub signature_help: Option<SignatureHelpCapability>, 1221 1222 /** 1223 * Capabilities specific to the `textDocument/references` 1224 */ 1225 #[serde(skip_serializing_if = "Option::is_none")] 1226 pub references: Option<GenericCapability>, 1227 1228 /** 1229 * Capabilities specific to the `textDocument/documentHighlight` 1230 */ 1231 #[serde(skip_serializing_if = "Option::is_none")] 1232 pub document_highlight: Option<GenericCapability>, 1233 1234 /** 1235 * Capabilities specific to the `textDocument/documentSymbol` 1236 */ 1237 #[serde(skip_serializing_if = "Option::is_none")] 1238 pub document_symbol: Option<DocumentSymbolCapability>, 1239 /** 1240 * Capabilities specific to the `textDocument/formatting` 1241 */ 1242 #[serde(skip_serializing_if = "Option::is_none")] 1243 pub formatting: Option<GenericCapability>, 1244 1245 /** 1246 * Capabilities specific to the `textDocument/rangeFormatting` 1247 */ 1248 #[serde(skip_serializing_if = "Option::is_none")] 1249 pub range_formatting: Option<GenericCapability>, 1250 1251 /** 1252 * Capabilities specific to the `textDocument/onTypeFormatting` 1253 */ 1254 #[serde(skip_serializing_if = "Option::is_none")] 1255 pub on_type_formatting: Option<GenericCapability>, 1256 1257 /** 1258 * Capabilities specific to the `textDocument/declaration` 1259 */ 1260 #[serde(skip_serializing_if = "Option::is_none")] 1261 pub declaration: Option<GotoCapability>, 1262 1263 /** 1264 * Capabilities specific to the `textDocument/definition` 1265 */ 1266 #[serde(skip_serializing_if = "Option::is_none")] 1267 pub definition: Option<GotoCapability>, 1268 1269 /** 1270 * Capabilities specific to the `textDocument/typeDefinition` 1271 */ 1272 #[serde(skip_serializing_if = "Option::is_none")] 1273 pub type_definition: Option<GotoCapability>, 1274 1275 /** 1276 * Capabilities specific to the `textDocument/implementation` 1277 */ 1278 #[serde(skip_serializing_if = "Option::is_none")] 1279 pub implementation: Option<GotoCapability>, 1280 1281 /** 1282 * Capabilities specific to the `textDocument/codeAction` 1283 */ 1284 #[serde(skip_serializing_if = "Option::is_none")] 1285 pub code_action: Option<CodeActionCapability>, 1286 1287 /** 1288 * Capabilities specific to the `textDocument/codeLens` 1289 */ 1290 #[serde(skip_serializing_if = "Option::is_none")] 1291 pub code_lens: Option<GenericCapability>, 1292 1293 /** 1294 * Capabilities specific to the `textDocument/documentLink` 1295 */ 1296 #[serde(skip_serializing_if = "Option::is_none")] 1297 pub document_link: Option<GenericCapability>, 1298 1299 /** 1300 * Capabilities specific to the `textDocument/documentColor` and the 1301 * `textDocument/colorPresentation` request. 1302 */ 1303 pub color_provider: Option<GenericCapability>, 1304 1305 /** 1306 * Capabilities specific to the `textDocument/rename` 1307 */ 1308 #[serde(skip_serializing_if = "Option::is_none")] 1309 pub rename: Option<RenameCapability>, 1310 1311 /** 1312 * Capabilities specific to `textDocument/publishDiagnostics`. 1313 */ 1314 #[serde(skip_serializing_if = "Option::is_none")] 1315 pub publish_diagnostics: Option<PublishDiagnosticsCapability>, 1316 1317 /** 1318 * Capabilities specific to `textDocument/foldingRange` requests. 1319 */ 1320 #[serde(skip_serializing_if = "Option::is_none")] 1321 pub folding_range: Option<FoldingRangeCapability>, 1322 } 1323 1324 /** 1325 * Window specific client capabilities. 1326 */ 1327 #[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)] 1328 #[serde(rename_all = "camelCase")] 1329 pub struct WindowClientCapabilities { 1330 /** 1331 * Whether `window/progress` server notifications are supported. 1332 */ 1333 #[cfg(feature = "proposed")] 1334 pub progress: Option<bool>, 1335 } 1336 1337 /** 1338 * Where ClientCapabilities are currently empty: 1339 */ 1340 #[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)] 1341 #[serde(rename_all = "camelCase")] 1342 pub struct ClientCapabilities { 1343 /** 1344 * Workspace specific client capabilities. 1345 */ 1346 #[serde(skip_serializing_if = "Option::is_none")] 1347 pub workspace: Option<WorkspaceClientCapabilities>, 1348 1349 /** 1350 * Text document specific client capabilities. 1351 */ 1352 #[serde(skip_serializing_if = "Option::is_none")] 1353 pub text_document: Option<TextDocumentClientCapabilities>, 1354 1355 /** 1356 * Window specific client capabilities. 1357 */ 1358 #[serde(skip_serializing_if = "Option::is_none")] 1359 pub window: Option<WindowClientCapabilities>, 1360 1361 /** 1362 * Experimental client capabilities. 1363 */ 1364 #[serde(skip_serializing_if = "Option::is_none")] 1365 pub experimental: Option<Value>, 1366 } 1367 1368 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1369 pub struct InitializeResult { 1370 /// The capabilities the language server provides. 1371 pub capabilities: ServerCapabilities, 1372 } 1373 1374 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1375 pub struct InitializeError { 1376 /// Indicates whether the client should retry to send the 1377 /// initilize request after showing the message provided 1378 /// in the ResponseError. 1379 pub retry: bool, 1380 } 1381 1382 // The server can signal the following capabilities: 1383 1384 /// Defines how the host (editor) should sync document changes to the language server. 1385 #[derive(Debug, Eq, PartialEq, Clone, Copy)] 1386 pub enum TextDocumentSyncKind { 1387 /// Documents should not be synced at all. 1388 None = 0, 1389 1390 /// Documents are synced by always sending the full content of the document. 1391 Full = 1, 1392 1393 /// Documents are synced by sending the full content on open. After that only 1394 /// incremental updates to the document are sent. 1395 Incremental = 2, 1396 } 1397 1398 impl<'de> serde::Deserialize<'de> for TextDocumentSyncKind { deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de>,1399 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 1400 where 1401 D: serde::Deserializer<'de>, 1402 { 1403 Ok(match u8::deserialize(deserializer)? { 1404 0 => TextDocumentSyncKind::None, 1405 1 => TextDocumentSyncKind::Full, 1406 2 => TextDocumentSyncKind::Incremental, 1407 i => { 1408 return Err(D::Error::invalid_value( 1409 de::Unexpected::Unsigned(u64::from(i)), 1410 &"value between 0 and 2 (inclusive)", 1411 )); 1412 } 1413 }) 1414 } 1415 } 1416 1417 impl serde::Serialize for TextDocumentSyncKind { serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer,1418 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 1419 where 1420 S: serde::Serializer, 1421 { 1422 serializer.serialize_u8(*self as u8) 1423 } 1424 } 1425 1426 /// Completion options. 1427 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1428 #[serde(rename_all = "camelCase")] 1429 pub struct CompletionOptions { 1430 /// The server provides support to resolve additional information for a completion item. 1431 #[serde(skip_serializing_if = "Option::is_none")] 1432 pub resolve_provider: Option<bool>, 1433 1434 /// The characters that trigger completion automatically. 1435 #[serde(skip_serializing_if = "Option::is_none")] 1436 pub trigger_characters: Option<Vec<String>>, 1437 } 1438 1439 /// Signature help options. 1440 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1441 #[serde(rename_all = "camelCase")] 1442 pub struct SignatureHelpOptions { 1443 /// The characters that trigger signature help automatically. 1444 #[serde(skip_serializing_if = "Option::is_none")] 1445 pub trigger_characters: Option<Vec<String>>, 1446 } 1447 1448 /// Code Lens options. 1449 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1450 #[serde(rename_all = "camelCase")] 1451 pub struct CodeLensOptions { 1452 /// Code lens has a resolve provider as well. 1453 #[serde(skip_serializing_if = "Option::is_none")] 1454 pub resolve_provider: Option<bool>, 1455 } 1456 1457 /// Format document on type options 1458 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1459 #[serde(rename_all = "camelCase")] 1460 pub struct DocumentOnTypeFormattingOptions { 1461 /// A character on which formatting should be triggered, like `}`. 1462 pub first_trigger_character: String, 1463 1464 /// More trigger characters. 1465 #[serde(skip_serializing_if = "Option::is_none")] 1466 pub more_trigger_character: Option<Vec<String>>, 1467 } 1468 1469 /// Execute command options. 1470 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1471 pub struct ExecuteCommandOptions { 1472 /// The commands to be executed on the server 1473 pub commands: Vec<String>, 1474 } 1475 1476 /** 1477 * Save options. 1478 */ 1479 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1480 #[serde(rename_all = "camelCase")] 1481 pub struct SaveOptions { 1482 /** 1483 * The client is supposed to include the content on save. 1484 */ 1485 #[serde(skip_serializing_if = "Option::is_none")] 1486 pub include_text: Option<bool>, 1487 } 1488 1489 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1490 #[serde(rename_all = "camelCase")] 1491 pub struct TextDocumentSyncOptions { 1492 /** 1493 * Open and close notifications are sent to the server. 1494 */ 1495 #[serde(skip_serializing_if = "Option::is_none")] 1496 pub open_close: Option<bool>, 1497 1498 /** 1499 * Change notifications are sent to the server. See TextDocumentSyncKind.None, TextDocumentSyncKind.Full 1500 * and TextDocumentSyncKindIncremental. 1501 */ 1502 #[serde(skip_serializing_if = "Option::is_none")] 1503 pub change: Option<TextDocumentSyncKind>, 1504 1505 /** 1506 * Will save notifications are sent to the server. 1507 */ 1508 #[serde(skip_serializing_if = "Option::is_none")] 1509 pub will_save: Option<bool>, 1510 1511 /** 1512 * Will save wait until requests are sent to the server. 1513 */ 1514 #[serde(skip_serializing_if = "Option::is_none")] 1515 pub will_save_wait_until: Option<bool>, 1516 1517 /** 1518 * Save notifications are sent to the server. 1519 */ 1520 #[serde(skip_serializing_if = "Option::is_none")] 1521 pub save: Option<SaveOptions>, 1522 } 1523 1524 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1525 #[serde(untagged)] 1526 pub enum TextDocumentSyncCapability { 1527 Kind(TextDocumentSyncKind), 1528 Options(TextDocumentSyncOptions), 1529 } 1530 1531 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1532 #[serde(untagged)] 1533 pub enum ImplementationProviderCapability { 1534 Simple(bool), 1535 Options(StaticTextDocumentRegistrationOptions), 1536 } 1537 1538 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1539 #[serde(untagged)] 1540 pub enum TypeDefinitionProviderCapability { 1541 Simple(bool), 1542 Options(StaticTextDocumentRegistrationOptions), 1543 } 1544 1545 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1546 #[serde(untagged)] 1547 pub enum ColorProviderCapability { 1548 Simple(bool), 1549 ColorProvider(ColorProviderOptions), 1550 Options(StaticTextDocumentColorProviderOptions), 1551 } 1552 1553 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1554 #[serde(untagged)] 1555 pub enum CodeActionProviderCapability { 1556 Simple(bool), 1557 Options(CodeActionOptions), 1558 } 1559 1560 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1561 #[serde(rename_all = "camelCase")] 1562 pub struct CodeActionCapability { 1563 /// 1564 /// This capability supports dynamic registration. 1565 /// 1566 #[serde(skip_serializing_if = "Option::is_none")] 1567 pub dynamic_registration: Option<bool>, 1568 1569 /// The client support code action literals as a valid 1570 /// response of the `textDocument/codeAction` request. 1571 #[serde(skip_serializing_if = "Option::is_none")] 1572 pub code_action_literal_support: Option<CodeActionLiteralSupport>, 1573 } 1574 1575 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1576 #[serde(rename_all = "camelCase")] 1577 pub struct CodeActionLiteralSupport { 1578 /// The code action kind is support with the following value set. 1579 pub code_action_kind: CodeActionKindLiteralSupport, 1580 } 1581 1582 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1583 #[serde(rename_all = "camelCase")] 1584 pub struct CodeActionKindLiteralSupport { 1585 /// The code action kind values the client supports. When this 1586 /// property exists the client also guarantees that it will 1587 /// handle values outside its set gracefully and falls back 1588 /// to a default value when unknown. 1589 pub value_set: Vec<String>, 1590 } 1591 1592 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 1593 #[serde(rename_all = "camelCase")] 1594 pub struct ServerCapabilities { 1595 /// Defines how text documents are synced. 1596 #[serde(skip_serializing_if = "Option::is_none")] 1597 pub text_document_sync: Option<TextDocumentSyncCapability>, 1598 1599 /// Capabilities specific to `textDocument/selectionRange` requests. 1600 #[serde(skip_serializing_if = "Option::is_none")] 1601 #[cfg(feature = "proposed")] 1602 pub selection_range_provider: Option<GenericCapability>, 1603 1604 /// The server provides hover support. 1605 #[serde(skip_serializing_if = "Option::is_none")] 1606 pub hover_provider: Option<bool>, 1607 1608 /// The server provides completion support. 1609 #[serde(skip_serializing_if = "Option::is_none")] 1610 pub completion_provider: Option<CompletionOptions>, 1611 1612 /// The server provides signature help support. 1613 #[serde(skip_serializing_if = "Option::is_none")] 1614 pub signature_help_provider: Option<SignatureHelpOptions>, 1615 1616 /// The server provides goto definition support. 1617 #[serde(skip_serializing_if = "Option::is_none")] 1618 pub definition_provider: Option<bool>, 1619 1620 /// The server provides goto type definition support. 1621 #[serde(skip_serializing_if = "Option::is_none")] 1622 pub type_definition_provider: Option<TypeDefinitionProviderCapability>, 1623 1624 /// the server provides goto implementation support. 1625 #[serde(skip_serializing_if = "Option::is_none")] 1626 pub implementation_provider: Option<ImplementationProviderCapability>, 1627 1628 /// The server provides find references support. 1629 #[serde(skip_serializing_if = "Option::is_none")] 1630 pub references_provider: Option<bool>, 1631 1632 /// The server provides document highlight support. 1633 #[serde(skip_serializing_if = "Option::is_none")] 1634 pub document_highlight_provider: Option<bool>, 1635 1636 /// The server provides document symbol support. 1637 #[serde(skip_serializing_if = "Option::is_none")] 1638 pub document_symbol_provider: Option<bool>, 1639 1640 /// The server provides workspace symbol support. 1641 #[serde(skip_serializing_if = "Option::is_none")] 1642 pub workspace_symbol_provider: Option<bool>, 1643 1644 /// The server provides code actions. 1645 #[serde(skip_serializing_if = "Option::is_none")] 1646 pub code_action_provider: Option<CodeActionProviderCapability>, 1647 1648 /// The server provides code lens. 1649 #[serde(skip_serializing_if = "Option::is_none")] 1650 pub code_lens_provider: Option<CodeLensOptions>, 1651 1652 /// The server provides document formatting. 1653 #[serde(skip_serializing_if = "Option::is_none")] 1654 pub document_formatting_provider: Option<bool>, 1655 1656 /// The server provides document range formatting. 1657 #[serde(skip_serializing_if = "Option::is_none")] 1658 pub document_range_formatting_provider: Option<bool>, 1659 1660 /// The server provides document formatting on typing. 1661 #[serde(skip_serializing_if = "Option::is_none")] 1662 pub document_on_type_formatting_provider: Option<DocumentOnTypeFormattingOptions>, 1663 1664 /// The server provides rename support. 1665 #[serde(skip_serializing_if = "Option::is_none")] 1666 pub rename_provider: Option<RenameProviderCapability>, 1667 1668 /// The server provides color provider support. 1669 #[serde(skip_serializing_if = "Option::is_none")] 1670 pub color_provider: Option<ColorProviderCapability>, 1671 1672 /// The server provides folding provider support. 1673 #[serde(skip_serializing_if = "Option::is_none")] 1674 pub folding_range_provider: Option<FoldingRangeProviderCapability>, 1675 1676 /// The server provides execute command support. 1677 #[serde(skip_serializing_if = "Option::is_none")] 1678 pub execute_command_provider: Option<ExecuteCommandOptions>, 1679 1680 /// Workspace specific server capabilities 1681 #[serde(skip_serializing_if = "Option::is_none")] 1682 pub workspace: Option<WorkspaceCapability>, 1683 } 1684 1685 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1686 pub struct ShowMessageParams { 1687 /// The message type. See {@link MessageType}. 1688 #[serde(rename = "type")] 1689 pub typ: MessageType, 1690 1691 /// The actual message. 1692 pub message: String, 1693 } 1694 1695 #[derive(Debug, Eq, PartialEq, Clone, Copy)] 1696 pub enum MessageType { 1697 /// An error message. 1698 Error = 1, 1699 /// A warning message. 1700 Warning = 2, 1701 /// An information message. 1702 Info = 3, 1703 /// A log message. 1704 Log = 4, 1705 } 1706 1707 impl<'de> serde::Deserialize<'de> for MessageType { deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de>,1708 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 1709 where 1710 D: serde::Deserializer<'de>, 1711 { 1712 Ok(match u8::deserialize(deserializer)? { 1713 1 => MessageType::Error, 1714 2 => MessageType::Warning, 1715 3 => MessageType::Info, 1716 4 => MessageType::Log, 1717 i => { 1718 return Err(D::Error::invalid_value( 1719 de::Unexpected::Unsigned(u64::from(i)), 1720 &"value of 1, 2, 3 or 4", 1721 )); 1722 } 1723 }) 1724 } 1725 } 1726 1727 impl serde::Serialize for MessageType { serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer,1728 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 1729 where 1730 S: serde::Serializer, 1731 { 1732 serializer.serialize_u8(*self as u8) 1733 } 1734 } 1735 1736 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1737 pub struct ShowMessageRequestParams { 1738 /// The message type. See {@link MessageType} 1739 #[serde(rename = "type")] 1740 pub typ: MessageType, 1741 1742 /// The actual message 1743 pub message: String, 1744 1745 /// The message action items to present. 1746 #[serde(skip_serializing_if = "Option::is_none")] 1747 pub actions: Option<Vec<MessageActionItem>>, 1748 } 1749 1750 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1751 pub struct MessageActionItem { 1752 /// A short title like 'Retry', 'Open Log' etc. 1753 pub title: String, 1754 } 1755 1756 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1757 pub struct LogMessageParams { 1758 /// The message type. See {@link MessageType} 1759 #[serde(rename = "type")] 1760 pub typ: MessageType, 1761 1762 /// The actual message 1763 pub message: String, 1764 } 1765 1766 /** 1767 * General parameters to to register for a capability. 1768 */ 1769 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 1770 #[serde(rename_all = "camelCase")] 1771 pub struct Registration { 1772 /** 1773 * The id used to register the request. The id can be used to deregister 1774 * the request again. 1775 */ 1776 pub id: String, 1777 1778 /** 1779 * The method / capability to register for. 1780 */ 1781 pub method: String, 1782 1783 /** 1784 * Options necessary for the registration. 1785 */ 1786 #[serde(skip_serializing_if = "Option::is_none")] 1787 pub register_options: Option<Value>, 1788 } 1789 1790 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 1791 pub struct RegistrationParams { 1792 pub registrations: Vec<Registration>, 1793 } 1794 1795 /// Since most of the registration options require to specify a document selector there is a base 1796 /// interface that can be used. 1797 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1798 #[serde(rename_all = "camelCase")] 1799 pub struct TextDocumentRegistrationOptions { 1800 /** 1801 * A document selector to identify the scope of the registration. If set to null 1802 * the document selector provided on the client side will be used. 1803 */ 1804 pub document_selector: Option<DocumentSelector>, 1805 } 1806 1807 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1808 #[serde(rename_all = "camelCase")] 1809 pub struct StaticRegistrationOptions { 1810 #[serde(skip_serializing_if = "Option::is_none")] 1811 pub id: Option<String>, 1812 } 1813 1814 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1815 #[serde(rename_all = "camelCase")] 1816 pub struct StaticTextDocumentRegistrationOptions { 1817 /** 1818 * A document selector to identify the scope of the registration. If set to null 1819 * the document selector provided on the client side will be used. 1820 */ 1821 pub document_selector: Option<DocumentSelector>, 1822 1823 #[serde(skip_serializing_if = "Option::is_none")] 1824 pub id: Option<String>, 1825 } 1826 1827 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1828 #[serde(rename_all = "camelCase")] 1829 pub struct ColorProviderOptions {} 1830 1831 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1832 #[serde(rename_all = "camelCase")] 1833 pub struct StaticTextDocumentColorProviderOptions { 1834 /** 1835 * A document selector to identify the scope of the registration. If set to null 1836 * the document selector provided on the client side will be used. 1837 */ 1838 pub document_selector: Option<DocumentSelector>, 1839 1840 #[serde(skip_serializing_if = "Option::is_none")] 1841 pub id: Option<String>, 1842 } 1843 1844 /** 1845 * General parameters to unregister a capability. 1846 */ 1847 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1848 pub struct Unregistration { 1849 /** 1850 * The id used to unregister the request or notification. Usually an id 1851 * provided during the register request. 1852 */ 1853 pub id: String, 1854 1855 /** 1856 * The method / capability to unregister for. 1857 */ 1858 pub method: String, 1859 } 1860 1861 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1862 pub struct UnregistrationParams { 1863 pub unregisterations: Vec<Unregistration>, 1864 } 1865 1866 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 1867 pub struct DidChangeConfigurationParams { 1868 /// The actual changed settings 1869 pub settings: Value, 1870 } 1871 1872 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1873 #[serde(rename_all = "camelCase")] 1874 pub struct DidOpenTextDocumentParams { 1875 /// The document that was opened. 1876 pub text_document: TextDocumentItem, 1877 } 1878 1879 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1880 #[serde(rename_all = "camelCase")] 1881 pub struct DidChangeTextDocumentParams { 1882 /// The document that did change. The version number points 1883 /// to the version after all provided content changes have 1884 /// been applied. 1885 pub text_document: VersionedTextDocumentIdentifier, 1886 /// The actual content changes. 1887 pub content_changes: Vec<TextDocumentContentChangeEvent>, 1888 } 1889 1890 /// An event describing a change to a text document. If range and rangeLength are omitted 1891 /// the new text is considered to be the full content of the document. 1892 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1893 #[serde(rename_all = "camelCase")] 1894 pub struct TextDocumentContentChangeEvent { 1895 /// The range of the document that changed. 1896 #[serde(skip_serializing_if = "Option::is_none")] 1897 pub range: Option<Range>, 1898 1899 /// The length of the range that got replaced. 1900 /// NOTE: seems redundant, see: <https://github.com/Microsoft/language-server-protocol/issues/9> 1901 #[serde(skip_serializing_if = "Option::is_none")] 1902 pub range_length: Option<u64>, 1903 1904 /// The new text of the document. 1905 pub text: String, 1906 } 1907 1908 /** 1909 * Descibe options to be used when registered for text document change events. 1910 * 1911 * Extends TextDocumentRegistrationOptions 1912 */ 1913 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1914 #[serde(rename_all = "camelCase")] 1915 pub struct TextDocumentChangeRegistrationOptions { 1916 /** 1917 * A document selector to identify the scope of the registration. If set to null 1918 * the document selector provided on the client side will be used. 1919 */ 1920 pub document_selector: Option<DocumentSelector>, 1921 1922 /** 1923 * How documents are synced to the server. See TextDocumentSyncKind.Full 1924 * and TextDocumentSyncKindIncremental. 1925 */ 1926 pub sync_kind: i32, 1927 } 1928 1929 /** 1930 * The parameters send in a will save text document notification. 1931 */ 1932 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1933 #[serde(rename_all = "camelCase")] 1934 pub struct WillSaveTextDocumentParams { 1935 /** 1936 * The document that will be saved. 1937 */ 1938 pub text_document: TextDocumentIdentifier, 1939 1940 /** 1941 * The 'TextDocumentSaveReason'. 1942 */ 1943 pub reason: TextDocumentSaveReason, 1944 } 1945 1946 /** 1947 * Represents reasons why a text document is saved. 1948 */ 1949 #[derive(Copy, Debug, Eq, PartialEq, Clone)] 1950 pub enum TextDocumentSaveReason { 1951 /** 1952 * Manually triggered, e.g. by the user pressing save, by starting debugging, 1953 * or by an API call. 1954 */ 1955 Manual = 1, 1956 1957 /** 1958 * Automatic after a delay. 1959 */ 1960 AfterDelay = 2, 1961 1962 /** 1963 * When the editor lost focus. 1964 */ 1965 FocusOut = 3, 1966 } 1967 1968 impl<'de> serde::Deserialize<'de> for TextDocumentSaveReason { deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de>,1969 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 1970 where 1971 D: serde::Deserializer<'de>, 1972 { 1973 Ok(match u8::deserialize(deserializer)? { 1974 1 => TextDocumentSaveReason::Manual, 1975 2 => TextDocumentSaveReason::AfterDelay, 1976 3 => TextDocumentSaveReason::FocusOut, 1977 i => { 1978 return Err(D::Error::invalid_value( 1979 de::Unexpected::Unsigned(u64::from(i)), 1980 &"value of 1, 2 or 3", 1981 )) 1982 } 1983 }) 1984 } 1985 } 1986 1987 impl serde::Serialize for TextDocumentSaveReason { serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer,1988 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 1989 where 1990 S: serde::Serializer, 1991 { 1992 serializer.serialize_u8(*self as u8) 1993 } 1994 } 1995 1996 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 1997 #[serde(rename_all = "camelCase")] 1998 pub struct DidCloseTextDocumentParams { 1999 /// The document that was closed. 2000 pub text_document: TextDocumentIdentifier, 2001 } 2002 2003 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2004 #[serde(rename_all = "camelCase")] 2005 pub struct DidSaveTextDocumentParams { 2006 /// The document that was saved. 2007 pub text_document: TextDocumentIdentifier, 2008 } 2009 2010 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2011 pub struct DidChangeWatchedFilesParams { 2012 /// The actual file events. 2013 pub changes: Vec<FileEvent>, 2014 } 2015 2016 /// The file event type. 2017 #[derive(Debug, Eq, PartialEq, Copy, Clone)] 2018 pub enum FileChangeType { 2019 /// The file got created. 2020 Created = 1, 2021 2022 /// The file got changed. 2023 Changed = 2, 2024 2025 /// The file got deleted. 2026 Deleted = 3, 2027 } 2028 2029 impl<'de> serde::Deserialize<'de> for FileChangeType { deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de>,2030 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 2031 where 2032 D: serde::Deserializer<'de>, 2033 { 2034 Ok(match u8::deserialize(deserializer)? { 2035 1 => FileChangeType::Created, 2036 2 => FileChangeType::Changed, 2037 3 => FileChangeType::Deleted, 2038 i => { 2039 return Err(D::Error::invalid_value( 2040 de::Unexpected::Unsigned(u64::from(i)), 2041 &"value of 1, 2 or 3", 2042 )) 2043 } 2044 }) 2045 } 2046 } 2047 2048 impl serde::Serialize for FileChangeType { serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer,2049 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 2050 where 2051 S: serde::Serializer, 2052 { 2053 serializer.serialize_u8(*self as u8) 2054 } 2055 } 2056 2057 /// An event describing a file change. 2058 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2059 pub struct FileEvent { 2060 /// The file's URI. 2061 pub uri: Url, 2062 2063 /// The change type. 2064 #[serde(rename = "type")] 2065 pub typ: FileChangeType, 2066 } 2067 2068 impl FileEvent { new(uri: Url, typ: FileChangeType) -> FileEvent2069 pub fn new(uri: Url, typ: FileChangeType) -> FileEvent { 2070 FileEvent { uri, typ } 2071 } 2072 } 2073 2074 /// Describe options to be used when registered for text document change events. 2075 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Deserialize, Serialize)] 2076 pub struct DidChangeWatchedFilesRegistrationOptions { 2077 /// The watchers to register. 2078 pub watchers: Vec<FileSystemWatcher>, 2079 } 2080 2081 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Deserialize, Serialize)] 2082 #[serde(rename_all = "camelCase")] 2083 pub struct FileSystemWatcher { 2084 /// The glob pattern to watch 2085 pub glob_pattern: String, 2086 2087 /// The kind of events of interest. If omitted it defaults to WatchKind.Create | 2088 /// WatchKind.Change | WatchKind.Delete which is 7. 2089 #[serde(skip_serializing_if = "Option::is_none")] 2090 pub kind: Option<WatchKind>, 2091 } 2092 2093 bitflags! { 2094 pub struct WatchKind: u8 { 2095 /// Interested in create events. 2096 const Create = 1; 2097 /// Interested in change events 2098 const Change = 2; 2099 /// Interested in delete events 2100 const Delete = 4; 2101 } 2102 } 2103 2104 impl<'de> serde::Deserialize<'de> for WatchKind { deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de>,2105 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 2106 where 2107 D: serde::Deserializer<'de>, 2108 { 2109 let i = u8::deserialize(deserializer)?; 2110 WatchKind::from_bits(i).ok_or_else(|| { 2111 D::Error::invalid_value(de::Unexpected::Unsigned(u64::from(i)), &"Unknown flag") 2112 }) 2113 } 2114 } 2115 2116 impl serde::Serialize for WatchKind { serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer,2117 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 2118 where 2119 S: serde::Serializer, 2120 { 2121 serializer.serialize_u8(self.bits()) 2122 } 2123 } 2124 2125 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2126 pub struct PublishDiagnosticsParams { 2127 /// The URI for which diagnostic information is reported. 2128 pub uri: Url, 2129 2130 /// An array of diagnostic information items. 2131 pub diagnostics: Vec<Diagnostic>, 2132 } 2133 2134 impl PublishDiagnosticsParams { new(uri: Url, diagnostics: Vec<Diagnostic>) -> PublishDiagnosticsParams2135 pub fn new(uri: Url, diagnostics: Vec<Diagnostic>) -> PublishDiagnosticsParams { 2136 PublishDiagnosticsParams { 2137 uri, 2138 diagnostics, 2139 } 2140 } 2141 } 2142 2143 #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] 2144 #[serde(untagged)] 2145 pub enum CompletionResponse { 2146 Array(Vec<CompletionItem>), 2147 List(CompletionList), 2148 } 2149 2150 impl From<Vec<CompletionItem>> for CompletionResponse { from(items: Vec<CompletionItem>) -> Self2151 fn from(items: Vec<CompletionItem>) -> Self { 2152 CompletionResponse::Array(items) 2153 } 2154 } 2155 2156 impl From<CompletionList> for CompletionResponse { from(list: CompletionList) -> Self2157 fn from(list: CompletionList) -> Self { 2158 CompletionResponse::List(list) 2159 } 2160 } 2161 2162 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 2163 #[serde(rename_all = "camelCase")] 2164 pub struct CompletionParams { 2165 2166 // This field was "mixed-in" from TextDocumentPositionParams 2167 #[serde(flatten)] 2168 pub text_document_position: TextDocumentPositionParams, 2169 2170 // CompletionParams properties: 2171 #[serde(skip_serializing_if = "Option::is_none")] 2172 pub context: Option<CompletionContext>, 2173 } 2174 2175 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 2176 #[serde(rename_all = "camelCase")] 2177 pub struct CompletionContext { 2178 /** 2179 * How the completion was triggered. 2180 */ 2181 pub trigger_kind: CompletionTriggerKind, 2182 2183 /** 2184 * The trigger character (a single character) that has trigger code complete. 2185 * Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter` 2186 */ 2187 #[serde(skip_serializing_if = "Option::is_none")] 2188 pub trigger_character: Option<String>, 2189 } 2190 2191 /// How a completion was triggered. 2192 #[derive(Debug, PartialEq, Clone, Copy, Deserialize_repr, Serialize_repr)] 2193 #[repr(u8)] 2194 pub enum CompletionTriggerKind { 2195 Invoked = 1, 2196 TriggerCharacter = 2, 2197 TriggerForIncompleteCompletions = 3, 2198 } 2199 2200 /// Represents a collection of [completion items](#CompletionItem) to be presented 2201 /// in the editor. 2202 #[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)] 2203 #[serde(rename_all = "camelCase")] 2204 pub struct CompletionList { 2205 /// This list it not complete. Further typing should result in recomputing 2206 /// this list. 2207 pub is_incomplete: bool, 2208 2209 /// The completion items. 2210 pub items: Vec<CompletionItem>, 2211 } 2212 2213 #[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)] 2214 #[serde(untagged)] 2215 pub enum Documentation { 2216 String(String), 2217 MarkupContent(MarkupContent), 2218 } 2219 2220 #[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)] 2221 #[serde(rename_all = "camelCase")] 2222 pub struct CompletionItem { 2223 /// The label of this completion item. By default 2224 /// also the text that is inserted when selecting 2225 /// this completion. 2226 pub label: String, 2227 2228 /// The kind of this completion item. Based of the kind 2229 /// an icon is chosen by the editor. 2230 #[serde(skip_serializing_if = "Option::is_none")] 2231 pub kind: Option<CompletionItemKind>, 2232 2233 /// A human-readable string with additional information 2234 /// about this item, like type or symbol information. 2235 #[serde(skip_serializing_if = "Option::is_none")] 2236 pub detail: Option<String>, 2237 2238 /// A human-readable string that represents a doc-comment. 2239 #[serde(skip_serializing_if = "Option::is_none")] 2240 pub documentation: Option<Documentation>, 2241 2242 /// Indicates if this item is deprecated. 2243 #[serde(skip_serializing_if = "Option::is_none")] 2244 pub deprecated: Option<bool>, 2245 2246 /// Select this item when showing. 2247 #[serde(skip_serializing_if = "Option::is_none")] 2248 pub preselect: Option<bool>, 2249 2250 /// A string that shoud be used when comparing this item 2251 /// with other items. When `falsy` the label is used. 2252 #[serde(skip_serializing_if = "Option::is_none")] 2253 pub sort_text: Option<String>, 2254 2255 /// A string that should be used when filtering a set of 2256 /// completion items. When `falsy` the label is used. 2257 #[serde(skip_serializing_if = "Option::is_none")] 2258 pub filter_text: Option<String>, 2259 2260 /// A string that should be inserted a document when selecting 2261 /// this completion. When `falsy` the label is used. 2262 #[serde(skip_serializing_if = "Option::is_none")] 2263 pub insert_text: Option<String>, 2264 2265 /// The format of the insert text. The format applies to both the `insertText` property 2266 /// and the `newText` property of a provided `textEdit`. 2267 #[serde(skip_serializing_if = "Option::is_none")] 2268 pub insert_text_format: Option<InsertTextFormat>, 2269 2270 /// An edit which is applied to a document when selecting 2271 /// this completion. When an edit is provided the value of 2272 /// insertText is ignored. 2273 #[serde(skip_serializing_if = "Option::is_none")] 2274 pub text_edit: Option<TextEdit>, 2275 2276 /// An optional array of additional text edits that are applied when 2277 /// selecting this completion. Edits must not overlap with the main edit 2278 /// nor with themselves. 2279 #[serde(skip_serializing_if = "Option::is_none")] 2280 pub additional_text_edits: Option<Vec<TextEdit>>, 2281 2282 /// An optional command that is executed *after* inserting this completion. *Note* that 2283 /// additional modifications to the current document should be described with the 2284 /// additionalTextEdits-property. 2285 #[serde(skip_serializing_if = "Option::is_none")] 2286 pub command: Option<Command>, 2287 2288 /// An data entry field that is preserved on a completion item between 2289 /// a completion and a completion resolve request. 2290 #[serde(skip_serializing_if = "Option::is_none")] 2291 pub data: Option<Value>, 2292 } 2293 2294 impl CompletionItem { 2295 /// Create a CompletionItem with the minimum possible info (label and detail). new_simple(label: String, detail: String) -> CompletionItem2296 pub fn new_simple(label: String, detail: String) -> CompletionItem { 2297 CompletionItem { 2298 label, 2299 detail: Some(detail), 2300 ..Self::default() 2301 } 2302 } 2303 } 2304 2305 /// The kind of a completion entry. 2306 #[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize_repr, Deserialize_repr)] 2307 #[repr(u8)] 2308 pub enum CompletionItemKind { 2309 Text = 1, 2310 Method = 2, 2311 Function = 3, 2312 Constructor = 4, 2313 Field = 5, 2314 Variable = 6, 2315 Class = 7, 2316 Interface = 8, 2317 Module = 9, 2318 Property = 10, 2319 Unit = 11, 2320 Value = 12, 2321 Enum = 13, 2322 Keyword = 14, 2323 Snippet = 15, 2324 Color = 16, 2325 File = 17, 2326 Reference = 18, 2327 Folder = 19, 2328 EnumMember = 20, 2329 Constant = 21, 2330 Struct = 22, 2331 Event = 23, 2332 Operator = 24, 2333 TypeParameter = 25, 2334 } 2335 2336 /// Defines how to interpret the insert text in a completion item 2337 #[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize_repr, Deserialize_repr)] 2338 #[repr(u8)] 2339 pub enum InsertTextFormat { 2340 PlainText = 1, 2341 Snippet = 2, 2342 } 2343 2344 /// The result of a hover request. 2345 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2346 pub struct Hover { 2347 /// The hover's content 2348 pub contents: HoverContents, 2349 /// An optional range is a range inside a text document 2350 /// that is used to visualize a hover, e.g. by changing the background color. 2351 #[serde(skip_serializing_if = "Option::is_none")] 2352 pub range: Option<Range>, 2353 } 2354 2355 /** 2356 * Hover contents could be single entry or multiple entries. 2357 */ 2358 #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)] 2359 #[serde(untagged)] 2360 pub enum HoverContents { 2361 Scalar(MarkedString), 2362 Array(Vec<MarkedString>), 2363 Markup(MarkupContent), 2364 } 2365 2366 /** 2367 The marked string is rendered: 2368 - as markdown if it is represented as a string 2369 - as code block of the given langauge if it is represented as a pair of a language and a value 2370 2371 The pair of a language and a value is an equivalent to markdown: 2372 ```${language} 2373 ${value} 2374 ``` 2375 */ 2376 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2377 #[serde(untagged)] 2378 pub enum MarkedString { 2379 String(String), 2380 LanguageString(LanguageString), 2381 } 2382 2383 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2384 pub struct LanguageString { 2385 pub language: String, 2386 pub value: String, 2387 } 2388 2389 impl MarkedString { from_markdown(markdown: String) -> MarkedString2390 pub fn from_markdown(markdown: String) -> MarkedString { 2391 MarkedString::String(markdown) 2392 } 2393 from_language_code(language: String, code_block: String) -> MarkedString2394 pub fn from_language_code(language: String, code_block: String) -> MarkedString { 2395 MarkedString::LanguageString(LanguageString { 2396 language, 2397 value: code_block, 2398 }) 2399 } 2400 } 2401 2402 /// Signature help represents the signature of something 2403 /// callable. There can be multiple signature but only one 2404 /// active and only one active parameter. 2405 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2406 #[serde(rename_all = "camelCase")] 2407 pub struct SignatureHelp { 2408 /// One or more signatures. 2409 pub signatures: Vec<SignatureInformation>, 2410 2411 /// The active signature. 2412 #[serde(skip_serializing_if = "Option::is_none")] 2413 pub active_signature: Option<i64>, 2414 2415 /// The active parameter of the active signature. 2416 #[serde(skip_serializing_if = "Option::is_none")] 2417 pub active_parameter: Option<i64>, 2418 } 2419 2420 /// Represents the signature of something callable. A signature 2421 /// can have a label, like a function-name, a doc-comment, and 2422 /// a set of parameters. 2423 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2424 pub struct SignatureInformation { 2425 /// The label of this signature. Will be shown in 2426 /// the UI. 2427 pub label: String, 2428 2429 /// The human-readable doc-comment of this signature. Will be shown 2430 /// in the UI but can be omitted. 2431 #[serde(skip_serializing_if = "Option::is_none")] 2432 pub documentation: Option<Documentation>, 2433 2434 /// The parameters of this signature. 2435 #[serde(skip_serializing_if = "Option::is_none")] 2436 pub parameters: Option<Vec<ParameterInformation>>, 2437 } 2438 2439 /// Represents a parameter of a callable-signature. A parameter can 2440 /// have a label and a doc-comment. 2441 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2442 pub struct ParameterInformation { 2443 /// The label of this parameter information. 2444 /// 2445 /// Either a string or an inclusive start and exclusive end offsets within its containing 2446 /// signature label. (see SignatureInformation.label). *Note*: A label of type string must be 2447 /// a substring of its containing signature label. 2448 pub label: ParameterLabel, 2449 2450 /// The human-readable doc-comment of this parameter. Will be shown 2451 /// in the UI but can be omitted. 2452 #[serde(skip_serializing_if = "Option::is_none")] 2453 pub documentation: Option<Documentation>, 2454 } 2455 2456 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2457 #[serde(untagged)] 2458 pub enum ParameterLabel { 2459 Simple(String), 2460 LabelOffsets([u64; 2]), 2461 } 2462 2463 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2464 #[serde(rename_all = "camelCase")] 2465 pub struct ReferenceParams { 2466 // Text Document and Position fields 2467 #[serde(flatten)] 2468 pub text_document_position: TextDocumentPositionParams, 2469 2470 // ReferenceParams properties: 2471 pub context: ReferenceContext, 2472 } 2473 2474 #[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] 2475 #[serde(rename_all = "camelCase")] 2476 pub struct ReferenceContext { 2477 /// Include the declaration of the current symbol. 2478 pub include_declaration: bool, 2479 } 2480 2481 /// A document highlight is a range inside a text document which deserves 2482 /// special attention. Usually a document highlight is visualized by changing 2483 /// the background color of its range. 2484 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2485 pub struct DocumentHighlight { 2486 /// The range this highlight applies to. 2487 pub range: Range, 2488 2489 /// The highlight kind, default is DocumentHighlightKind.Text. 2490 #[serde(skip_serializing_if = "Option::is_none")] 2491 pub kind: Option<DocumentHighlightKind>, 2492 } 2493 2494 /// A document highlight kind. 2495 #[derive(Debug, Eq, PartialEq, Copy, Clone)] 2496 pub enum DocumentHighlightKind { 2497 /// A textual occurrance. 2498 Text = 1, 2499 2500 /// Read-access of a symbol, like reading a variable. 2501 Read = 2, 2502 2503 /// Write-access of a symbol, like writing to a variable. 2504 Write = 3, 2505 } 2506 2507 impl<'de> serde::Deserialize<'de> for DocumentHighlightKind { deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de>,2508 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 2509 where 2510 D: serde::Deserializer<'de>, 2511 { 2512 Ok(match u8::deserialize(deserializer)? { 2513 1 => DocumentHighlightKind::Text, 2514 2 => DocumentHighlightKind::Read, 2515 3 => DocumentHighlightKind::Write, 2516 i => { 2517 return Err(D::Error::invalid_value( 2518 de::Unexpected::Unsigned(u64::from(i)), 2519 &"1, 2, or 3", 2520 )) 2521 } 2522 }) 2523 } 2524 } 2525 2526 impl serde::Serialize for DocumentHighlightKind { serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer,2527 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 2528 where 2529 S: serde::Serializer, 2530 { 2531 serializer.serialize_u8(*self as u8) 2532 } 2533 } 2534 2535 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 2536 #[serde(rename_all = "camelCase")] 2537 pub struct DocumentSymbolCapability { 2538 /// This capability supports dynamic registration. 2539 #[serde(skip_serializing_if = "Option::is_none")] 2540 pub dynamic_registration: Option<bool>, 2541 2542 /// Specific capabilities for the `SymbolKind`. 2543 #[serde(skip_serializing_if = "Option::is_none")] 2544 pub symbol_kind: Option<SymbolKindCapability>, 2545 2546 /// The client support hierarchical document symbols. 2547 #[serde(skip_serializing_if = "Option::is_none")] 2548 pub hierarchical_document_symbol_support: Option<bool>, 2549 } 2550 2551 #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] 2552 #[serde(untagged)] 2553 pub enum DocumentSymbolResponse { 2554 Flat(Vec<SymbolInformation>), 2555 Nested(Vec<DocumentSymbol>), 2556 } 2557 2558 impl From<Vec<SymbolInformation>> for DocumentSymbolResponse { from(info: Vec<SymbolInformation>) -> Self2559 fn from(info: Vec<SymbolInformation>) -> Self { 2560 DocumentSymbolResponse::Flat(info) 2561 } 2562 } 2563 2564 impl From<Vec<DocumentSymbol>> for DocumentSymbolResponse { from(symbols: Vec<DocumentSymbol>) -> Self2565 fn from(symbols: Vec<DocumentSymbol>) -> Self { 2566 DocumentSymbolResponse::Nested(symbols) 2567 } 2568 } 2569 2570 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2571 #[serde(rename_all = "camelCase")] 2572 pub struct DocumentSymbolParams { 2573 /// The text document. 2574 pub text_document: TextDocumentIdentifier, 2575 } 2576 2577 /// Represents programming constructs like variables, classes, interfaces etc. 2578 /// that appear in a document. Document symbols can be hierarchical and they have two ranges: 2579 /// one that encloses its definition and one that points to its most interesting range, 2580 /// e.g. the range of an identifier. 2581 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2582 #[serde(rename_all = "camelCase")] 2583 pub struct DocumentSymbol { 2584 /// The name of this symbol. 2585 pub name: String, 2586 /// More detail for this symbol, e.g the signature of a function. If not provided the 2587 /// name is used. 2588 #[serde(skip_serializing_if = "Option::is_none")] 2589 pub detail: Option<String>, 2590 /// The kind of this symbol. 2591 pub kind: SymbolKind, 2592 /// Indicates if this symbol is deprecated. 2593 #[serde(skip_serializing_if = "Option::is_none")] 2594 pub deprecated: Option<bool>, 2595 /// The range enclosing this symbol not including leading/trailing whitespace but everything else 2596 /// like comments. This information is typically used to determine if the the clients cursor is 2597 /// inside the symbol to reveal in the symbol in the UI. 2598 pub range: Range, 2599 /// The range that should be selected and revealed when this symbol is being picked, e.g the name of a function. 2600 /// Must be contained by the the `range`. 2601 pub selection_range: Range, 2602 /// Children of this symbol, e.g. properties of a class. 2603 #[serde(skip_serializing_if = "Option::is_none")] 2604 pub children: Option<Vec<DocumentSymbol>>, 2605 } 2606 2607 /// Represents information about programming constructs like variables, classes, 2608 /// interfaces etc. 2609 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2610 #[serde(rename_all = "camelCase")] 2611 pub struct SymbolInformation { 2612 /// The name of this symbol. 2613 pub name: String, 2614 2615 /// The kind of this symbol. 2616 pub kind: SymbolKind, 2617 2618 /// Indicates if this symbol is deprecated. 2619 #[serde(skip_serializing_if = "Option::is_none")] 2620 pub deprecated: Option<bool>, 2621 2622 /// The location of this symbol. 2623 pub location: Location, 2624 2625 /// The name of the symbol containing this symbol. 2626 #[serde(skip_serializing_if = "Option::is_none")] 2627 pub container_name: Option<String>, 2628 } 2629 2630 /// A symbol kind. 2631 #[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize_repr, Deserialize_repr)] 2632 #[repr(u8)] 2633 pub enum SymbolKind { 2634 File = 1, 2635 Module = 2, 2636 Namespace = 3, 2637 Package = 4, 2638 Class = 5, 2639 Method = 6, 2640 Property = 7, 2641 Field = 8, 2642 Constructor = 9, 2643 Enum = 10, 2644 Interface = 11, 2645 Function = 12, 2646 Variable = 13, 2647 Constant = 14, 2648 String = 15, 2649 Number = 16, 2650 Boolean = 17, 2651 Array = 18, 2652 Object = 19, 2653 Key = 20, 2654 Null = 21, 2655 EnumMember = 22, 2656 Struct = 23, 2657 Event = 24, 2658 Operator = 25, 2659 TypeParameter = 26, 2660 2661 // Capturing all unknown enums by this lib. 2662 Unknown = 255, 2663 } 2664 2665 /// The parameters of a Workspace Symbol Request. 2666 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2667 pub struct WorkspaceSymbolParams { 2668 /// A non-empty query string 2669 pub query: String, 2670 } 2671 2672 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 2673 pub struct ExecuteCommandParams { 2674 /** 2675 * The identifier of the actual command handler. 2676 */ 2677 pub command: String, 2678 /** 2679 * Arguments that the command should be invoked with. 2680 */ 2681 #[serde(default)] 2682 pub arguments: Vec<Value>, 2683 } 2684 2685 /** 2686 * Execute command registration options. 2687 */ 2688 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2689 pub struct ExecuteCommandRegistrationOptions { 2690 /** 2691 * The commands to be executed on the server 2692 */ 2693 pub commands: Vec<String>, 2694 } 2695 2696 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2697 pub struct ApplyWorkspaceEditParams { 2698 /** 2699 * The edits to apply. 2700 */ 2701 pub edit: WorkspaceEdit, 2702 } 2703 2704 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2705 pub struct ApplyWorkspaceEditResponse { 2706 /** 2707 * Indicates whether the edit was applied or not. 2708 */ 2709 pub applied: bool, 2710 } 2711 2712 /// Params for the CodeActionRequest 2713 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2714 #[serde(rename_all = "camelCase")] 2715 pub struct CodeActionParams { 2716 /// The document in which the command was invoked. 2717 pub text_document: TextDocumentIdentifier, 2718 2719 /// The range for which the command was invoked. 2720 pub range: Range, 2721 2722 /// Context carrying additional information. 2723 pub context: CodeActionContext, 2724 } 2725 2726 /// response for CodeActionRequest 2727 pub type CodeActionResponse = Vec<CodeActionOrCommand>; 2728 2729 #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 2730 #[serde(untagged)] 2731 pub enum CodeActionOrCommand { 2732 Command(Command), 2733 CodeAction(CodeAction), 2734 } 2735 2736 impl From<Command> for CodeActionOrCommand { from(comand: Command) -> Self2737 fn from(comand: Command) -> Self { 2738 CodeActionOrCommand::Command(comand) 2739 } 2740 } 2741 2742 impl From<CodeAction> for CodeActionOrCommand { from(action: CodeAction) -> Self2743 fn from(action: CodeAction) -> Self { 2744 CodeActionOrCommand::CodeAction(action) 2745 } 2746 } 2747 2748 /** 2749 * A set of predefined code action kinds 2750 */ 2751 pub mod code_action_kind { 2752 2753 /** 2754 * Base kind for quickfix actions: 'quickfix' 2755 */ 2756 pub const QUICKFIX: &str = "quickfix"; 2757 2758 /** 2759 * Base kind for refactoring actions: 'refactor' 2760 */ 2761 pub const REFACTOR: &str = "refactor"; 2762 2763 /** 2764 * Base kind for refactoring extraction actions: 'refactor.extract' 2765 * 2766 * Example extract actions: 2767 * 2768 * - Extract method 2769 * - Extract function 2770 * - Extract variable 2771 * - Extract interface from class 2772 * - ... 2773 */ 2774 pub const REFACTOR_EXTRACT: &str = "refactor.extract"; 2775 2776 /** 2777 * Base kind for refactoring inline actions: 'refactor.inline' 2778 * 2779 * Example inline actions: 2780 * 2781 * - Inline function 2782 * - Inline variable 2783 * - Inline constant 2784 * - ... 2785 */ 2786 pub const REFACTOR_INLINE: &str = "refactor.inline"; 2787 2788 /** 2789 * Base kind for refactoring rewrite actions: 'refactor.rewrite' 2790 * 2791 * Example rewrite actions: 2792 * 2793 * - Convert JavaScript function to class 2794 * - Add or remove parameter 2795 * - Encapsulate field 2796 * - Make method static 2797 * - Move method to base class 2798 * - ... 2799 */ 2800 pub const REFACTOR_REWRITE: &str = "refactor.rewrite"; 2801 2802 /** 2803 * Base kind for source actions: `source` 2804 * 2805 * Source code actions apply to the entire file. 2806 */ 2807 pub const SOURCE: &str = "source"; 2808 2809 /** 2810 * Base kind for an organize imports source action: `source.organizeImports` 2811 */ 2812 pub const SOURCE_ORGANIZE_IMPORTS: &str = "source.organizeImports"; 2813 } 2814 2815 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 2816 pub struct CodeAction { 2817 /// A short, human-readable, title for this code action. 2818 pub title: String, 2819 2820 /// The kind of the code action. 2821 /// Used to filter code actions. 2822 #[serde(skip_serializing_if = "Option::is_none")] 2823 pub kind: Option<String>, 2824 2825 /// The diagnostics that this code action resolves. 2826 #[serde(skip_serializing_if = "Option::is_none")] 2827 pub diagnostics: Option<Vec<Diagnostic>>, 2828 2829 /// The workspace edit this code action performs. 2830 #[serde(skip_serializing_if = "Option::is_none")] 2831 pub edit: Option<WorkspaceEdit>, 2832 2833 /// A command this code action executes. If a code action 2834 /// provides an edit and a command, first the edit is 2835 /// executed and then the command. 2836 #[serde(skip_serializing_if = "Option::is_none")] 2837 pub command: Option<Command>, 2838 } 2839 2840 /// Contains additional diagnostic information about the context in which 2841 /// a code action is run. 2842 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2843 pub struct CodeActionContext { 2844 /// An array of diagnostics. 2845 pub diagnostics: Vec<Diagnostic>, 2846 2847 /// Requested kind of actions to return. 2848 /// 2849 /// Actions not of this kind are filtered out by the client before being shown. So servers 2850 /// can omit computing them. 2851 #[serde(skip_serializing_if = "Option::is_none")] 2852 pub only: Option<Vec<String>>, 2853 } 2854 2855 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2856 #[serde(rename_all = "camelCase")] 2857 pub struct CodeActionOptions { 2858 /** 2859 * CodeActionKinds that this server may return. 2860 * 2861 * The list of kinds may be generic, such as `CodeActionKind.Refactor`, or the server 2862 * may list out every specific kind they provide. 2863 */ 2864 #[serde(skip_serializing_if = "Option::is_none")] 2865 pub code_action_kinds: Option<Vec<String>>, 2866 } 2867 2868 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2869 #[serde(rename_all = "camelCase")] 2870 pub struct CodeLensParams { 2871 /// The document to request code lens for. 2872 pub text_document: TextDocumentIdentifier, 2873 } 2874 2875 /// A code lens represents a command that should be shown along with 2876 /// source text, like the number of references, a way to run tests, etc. 2877 /// 2878 /// A code lens is _unresolved_ when no command is associated to it. For performance 2879 /// reasons the creation of a code lens and resolving should be done in two stages. 2880 #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 2881 pub struct CodeLens { 2882 /// The range in which this code lens is valid. Should only span a single line. 2883 pub range: Range, 2884 2885 /// The command this code lens represents. 2886 #[serde(skip_serializing_if = "Option::is_none")] 2887 pub command: Option<Command>, 2888 2889 /// A data entry field that is preserved on a code lens item between 2890 /// a code lens and a code lens resolve request. 2891 #[serde(skip_serializing_if = "Option::is_none")] 2892 pub data: Option<Value>, 2893 } 2894 2895 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2896 #[serde(rename_all = "camelCase")] 2897 pub struct DocumentLinkParams { 2898 /** 2899 * The document to provide document links for. 2900 */ 2901 pub text_document: TextDocumentIdentifier, 2902 } 2903 2904 /** 2905 * A document link is a range in a text document that links to an internal or external resource, like another 2906 * text document or a web site. 2907 */ 2908 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2909 pub struct DocumentLink { 2910 /** 2911 * The range this link applies to. 2912 */ 2913 pub range: Range, 2914 /** 2915 * The uri this link points to. 2916 */ 2917 pub target: Url, 2918 } 2919 2920 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 2921 #[serde(rename_all = "camelCase")] 2922 pub struct DocumentFormattingParams { 2923 /// The document to format. 2924 pub text_document: TextDocumentIdentifier, 2925 2926 /// The format options. 2927 pub options: FormattingOptions, 2928 } 2929 2930 /// Value-object describing what options formatting should use. 2931 #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] 2932 #[serde(rename_all = "camelCase")] 2933 pub struct FormattingOptions { 2934 /// Size of a tab in spaces. 2935 pub tab_size: u64, 2936 2937 /// Prefer spaces over tabs. 2938 pub insert_spaces: bool, 2939 2940 /// Signature for further properties. 2941 #[serde(flatten)] 2942 pub properties: HashMap<String, FormattingProperty>, 2943 } 2944 2945 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 2946 #[serde(untagged)] 2947 pub enum FormattingProperty { 2948 Bool(bool), 2949 Number(f64), 2950 String(String), 2951 } 2952 2953 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 2954 #[serde(rename_all = "camelCase")] 2955 pub struct DocumentRangeFormattingParams { 2956 /// The document to format. 2957 pub text_document: TextDocumentIdentifier, 2958 2959 /// The range to format 2960 pub range: Range, 2961 2962 /// The format options 2963 pub options: FormattingOptions, 2964 } 2965 2966 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 2967 #[serde(rename_all = "camelCase")] 2968 pub struct DocumentOnTypeFormattingParams { 2969 /// Text Document and Position fields. 2970 #[serde(flatten)] 2971 pub text_document_position: TextDocumentPositionParams, 2972 2973 /// The character that has been typed. 2974 pub ch: String, 2975 2976 /// The format options. 2977 pub options: FormattingOptions, 2978 } 2979 2980 /// Extends TextDocumentRegistrationOptions 2981 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 2982 #[serde(rename_all = "camelCase")] 2983 pub struct DocumentOnTypeFormattingRegistrationOptions { 2984 /** 2985 * A document selector to identify the scope of the registration. If set to null 2986 * the document selector provided on the client side will be used. 2987 */ 2988 pub document_selector: Option<DocumentSelector>, 2989 2990 /** 2991 * A character on which formatting should be triggered, like `}`. 2992 */ 2993 pub first_trigger_character: String, 2994 2995 /** 2996 * More trigger characters. 2997 */ 2998 #[serde(skip_serializing_if = "Option::is_none")] 2999 pub more_trigger_character: Option<Vec<String>>, 3000 } 3001 3002 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 3003 #[serde(rename_all = "camelCase")] 3004 pub struct RenameParams { 3005 /// Text Document and Position fields 3006 #[serde(flatten)] 3007 pub text_document_position: TextDocumentPositionParams, 3008 3009 /// The new name of the symbol. If the given name is not valid the 3010 /// request must return a [ResponseError](#ResponseError) with an 3011 /// appropriate message set. 3012 pub new_name: String, 3013 } 3014 3015 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 3016 #[serde(untagged)] 3017 pub enum RenameProviderCapability { 3018 Simple(bool), 3019 Options(RenameOptions), 3020 } 3021 3022 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 3023 #[serde(rename_all = "camelCase")] 3024 pub struct RenameOptions { 3025 /// Renames should be checked and tested before being executed. 3026 #[serde(skip_serializing_if = "Option::is_none")] 3027 pub prepare_provider: Option<bool>, 3028 } 3029 3030 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 3031 #[serde(rename_all = "camelCase")] 3032 pub struct RenameCapability { 3033 /// Whether rename supports dynamic registration. 3034 #[serde(skip_serializing_if = "Option::is_none")] 3035 pub dynamic_registration: Option<bool>, 3036 3037 /// Client supports testing for validity of rename operations before execution. 3038 #[serde(skip_serializing_if = "Option::is_none")] 3039 pub prepare_support: Option<bool>, 3040 } 3041 3042 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 3043 #[serde(untagged)] 3044 pub enum PrepareRenameResponse { 3045 Range(Range), 3046 RangeWithPlaceholder { range: Range, placeholder: String }, 3047 } 3048 3049 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 3050 #[serde(rename_all = "camelCase")] 3051 pub struct DocumentColorParams { 3052 /// The text document 3053 pub text_document: TextDocumentIdentifier, 3054 } 3055 3056 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 3057 #[serde(rename_all = "camelCase")] 3058 pub struct ColorInformation { 3059 /** 3060 * The range in the document where this color appears. 3061 */ 3062 pub range: Range, 3063 /** 3064 * The actual color value for this color range. 3065 */ 3066 pub color: Color, 3067 } 3068 3069 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 3070 #[serde(rename_all = "camelCase")] 3071 pub struct Color { 3072 /** 3073 * The red component of this color in the range [0-1]. 3074 */ 3075 pub red: f64, 3076 /** 3077 * The green component of this color in the range [0-1]. 3078 */ 3079 pub green: f64, 3080 /** 3081 * The blue component of this color in the range [0-1]. 3082 */ 3083 pub blue: f64, 3084 /** 3085 * The alpha component of this color in the range [0-1]. 3086 */ 3087 pub alpha: f64, 3088 } 3089 3090 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] 3091 #[serde(rename_all = "camelCase")] 3092 pub struct ColorPresentationParams { 3093 /** 3094 * The text document. 3095 */ 3096 pub text_document: TextDocumentIdentifier, 3097 3098 /** 3099 * The color information to request presentations for. 3100 */ 3101 pub color: Color, 3102 3103 /** 3104 * The range where the color would be inserted. Serves as a context. 3105 */ 3106 pub range: Range, 3107 } 3108 3109 #[derive(Debug, PartialEq, Eq, Deserialize, Serialize, Default, Clone)] 3110 #[serde(rename_all = "camelCase")] 3111 pub struct ColorPresentation { 3112 /** 3113 * The label of this color presentation. It will be shown on the color 3114 * picker header. By default this is also the text that is inserted when selecting 3115 * this color presentation. 3116 */ 3117 pub label: String, 3118 3119 /** 3120 * An [edit](#TextEdit) which is applied to a document when selecting 3121 * this presentation for the color. When `falsy` the [label](#ColorPresentation.label) 3122 * is used. 3123 */ 3124 #[serde(skip_serializing_if = "Option::is_none")] 3125 pub text_edit: Option<TextEdit>, 3126 3127 /** 3128 * An optional array of additional [text edits](#TextEdit) that are applied when 3129 * selecting this color presentation. Edits must not overlap with the main [edit](#ColorPresentation.textEdit) nor with themselves. 3130 */ 3131 #[serde(skip_serializing_if = "Option::is_none")] 3132 pub additional_text_edits: Option<Vec<TextEdit>>, 3133 } 3134 3135 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 3136 #[serde(rename_all = "camelCase")] 3137 pub struct FoldingRangeParams { 3138 /// The text document. 3139 pub text_document: TextDocumentIdentifier, 3140 } 3141 3142 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 3143 #[serde(untagged)] 3144 pub enum FoldingRangeProviderCapability { 3145 Simple(bool), 3146 FoldingProvider(FoldingProviderOptions), 3147 Options(StaticTextDocumentColorProviderOptions), 3148 } 3149 3150 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 3151 pub struct FoldingProviderOptions {} 3152 3153 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 3154 #[serde(rename_all = "camelCase")] 3155 pub struct FoldingRangeCapability { 3156 /** 3157 * Whether implementation supports dynamic registration for folding range providers. If this is set to `true` 3158 * the client supports the new `(FoldingRangeProviderOptions & TextDocumentRegistrationOptions & StaticRegistrationOptions)` 3159 * return value for the corresponding server capability as well. 3160 */ 3161 #[serde(skip_serializing_if = "Option::is_none")] 3162 pub dynamic_registration: Option<bool>, 3163 3164 /** 3165 * The maximum number of folding ranges that the client prefers to receive per document. The value serves as a 3166 * hint, servers are free to follow the limit. 3167 */ 3168 #[serde(skip_serializing_if = "Option::is_none")] 3169 pub range_limit: Option<u64>, 3170 /** 3171 * If set, the client signals that it only supports folding complete lines. If set, client will 3172 * ignore specified `startCharacter` and `endCharacter` properties in a FoldingRange. 3173 */ 3174 #[serde(skip_serializing_if = "Option::is_none")] 3175 pub line_folding_only: Option<bool>, 3176 } 3177 3178 /** 3179 * Represents a folding range. 3180 */ 3181 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 3182 #[serde(rename_all = "camelCase")] 3183 pub struct FoldingRange { 3184 /** 3185 * The zero-based line number from where the folded range starts. 3186 */ 3187 pub start_line: u64, 3188 3189 /** 3190 * The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line. 3191 */ 3192 #[serde(skip_serializing_if = "Option::is_none")] 3193 pub start_character: Option<u64>, 3194 3195 /** 3196 * The zero-based line number where the folded range ends. 3197 */ 3198 pub end_line: u64, 3199 3200 /** 3201 * The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line. 3202 */ 3203 #[serde(skip_serializing_if = "Option::is_none")] 3204 pub end_character: Option<u64>, 3205 3206 /** 3207 * Describes the kind of the folding range such as `comment' or 'region'. The kind 3208 * is used to categorize folding ranges and used by commands like 'Fold all comments'. See 3209 * [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds. 3210 */ 3211 #[serde(skip_serializing_if = "Option::is_none")] 3212 pub kind: Option<FoldingRangeKind>, 3213 } 3214 3215 /// A parameter literal used in selection range requests. 3216 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 3217 #[serde(rename_all = "camelCase")] 3218 #[cfg(feature = "proposed")] 3219 pub struct SelectionRangeParams { 3220 /// The text document. 3221 pub text_document: TextDocumentIdentifier, 3222 /// The positions inside the text document. 3223 pub positions: Vec<Position>, 3224 } 3225 3226 /// Represents a selection range. 3227 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] 3228 #[serde(rename_all = "camelCase")] 3229 #[cfg(feature = "proposed")] 3230 pub struct SelectionRange { 3231 /// Range of the selection. 3232 pub range: Range, 3233 /// The parent selection range containing this range. 3234 pub parent: Option<Box<SelectionRange>>, 3235 } 3236 3237 /** 3238 * Enum of known range kinds 3239 */ 3240 #[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)] 3241 #[serde(rename_all = "lowercase")] 3242 pub enum FoldingRangeKind { 3243 /// Folding range for a comment 3244 Comment, 3245 /// Folding range for a imports or includes 3246 Imports, 3247 /// Folding range for a region (e.g. `#region`) 3248 Region, 3249 } 3250 3251 /** 3252 * Describes the content type that a client supports in various 3253 * result literals like `Hover`, `ParameterInfo` or `CompletionItem`. 3254 * 3255 * Please note that `MarkupKinds` must not start with a `$`. This kinds 3256 * are reserved for internal usage. 3257 */ 3258 #[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)] 3259 #[serde(rename_all = "lowercase")] 3260 pub enum MarkupKind { 3261 /// Plain text is supported as a content format 3262 PlainText, 3263 /// Markdown is supported as a content format 3264 Markdown, 3265 } 3266 3267 /** 3268 * A `MarkupContent` literal represents a string value which content is interpreted base on its 3269 * kind flag. Currently the protocol supports `plaintext` and `markdown` as markup kinds. 3270 * 3271 * If the kind is `markdown` then the value can contain fenced code blocks like in GitHub issues. 3272 * See <https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting> 3273 * 3274 * Here is an example how such a string can be constructed using JavaScript / TypeScript: 3275 * ```ts 3276 * let markdown: MarkdownContent = { 3277 * kind: MarkupKind.Markdown, 3278 * value: [ 3279 * '# Header', 3280 * 'Some text', 3281 * '```typescript', 3282 * 'someCode();', 3283 * '```' 3284 * ].join('\n') 3285 * }; 3286 * ``` 3287 * 3288 * *Please Note* that clients might sanitize the return markdown. A client could decide to 3289 * remove HTML from the markdown to avoid script execution. 3290 */ 3291 #[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)] 3292 pub struct MarkupContent { 3293 pub kind: MarkupKind, 3294 pub value: String, 3295 } 3296 3297 #[cfg(feature = "proposed")] 3298 /// The progress notification is sent from the server to the client to ask 3299 /// the client to indicate progress. 3300 #[derive(Debug, PartialEq, Deserialize, Serialize, Clone)] 3301 pub struct ProgressParams { 3302 /// A unique identifier to associate multiple progress notifications 3303 /// with the same progress. 3304 pub id: String, 3305 3306 /// Mandatory title of the progress operation. Used to briefly inform 3307 /// about the kind of operation being performed. 3308 /// Examples: "Indexing" or "Linking dependencies". 3309 pub title: String, 3310 3311 /// Optional, more detailed associated progress message. Contains 3312 /// complementary information to the `title`. 3313 /// Examples: "3/25 files", "project/src/module2", "node_modules/some_dep". 3314 /// If unset, the previous progress message (if any) is still valid. 3315 pub message: Option<String>, 3316 3317 /// Optional progress percentage to display (value 100 is considered 100%). 3318 /// If unset, the previous progress percentage (if any) is still valid. 3319 pub percentage: Option<f64>, 3320 3321 /// Set to true on the final progress update. 3322 /// No more progress notifications with the same ID should be sent. 3323 pub done: Option<bool>, 3324 } 3325 3326 #[cfg(test)] 3327 mod tests { 3328 use super::*; 3329 use serde::{Deserialize, Serialize}; 3330 test_serialization<SER>(ms: &SER, expected: &str) where SER: Serialize + for<'de> Deserialize<'de> + PartialEq + std::fmt::Debug,3331 fn test_serialization<SER>(ms: &SER, expected: &str) 3332 where 3333 SER: Serialize + for<'de> Deserialize<'de> + PartialEq + std::fmt::Debug, 3334 { 3335 let json_str = serde_json::to_string(ms).unwrap(); 3336 assert_eq!(&json_str, expected); 3337 let deserialized: SER = serde_json::from_str(&json_str).unwrap(); 3338 assert_eq!(&deserialized, ms); 3339 } 3340 3341 #[test] number_or_string()3342 fn number_or_string() { 3343 test_serialization(&NumberOrString::Number(123), r#"123"#); 3344 3345 test_serialization(&NumberOrString::String("abcd".into()), r#""abcd""#); 3346 } 3347 3348 #[test] marked_string()3349 fn marked_string() { 3350 test_serialization(&MarkedString::from_markdown("xxx".into()), r#""xxx""#); 3351 3352 test_serialization( 3353 &MarkedString::from_language_code("lang".into(), "code".into()), 3354 r#"{"language":"lang","value":"code"}"#, 3355 ); 3356 } 3357 3358 #[test] language_string()3359 fn language_string() { 3360 test_serialization( 3361 &LanguageString { 3362 language: "LL".into(), 3363 value: "VV".into(), 3364 }, 3365 r#"{"language":"LL","value":"VV"}"#, 3366 ); 3367 } 3368 3369 #[test] workspace_edit()3370 fn workspace_edit() { 3371 test_serialization( 3372 &WorkspaceEdit { 3373 changes: Some(vec![].into_iter().collect()), 3374 document_changes: None, 3375 }, 3376 r#"{"changes":{}}"#, 3377 ); 3378 3379 test_serialization( 3380 &WorkspaceEdit { 3381 changes: None, 3382 document_changes: None, 3383 }, 3384 r#"{}"#, 3385 ); 3386 3387 test_serialization( 3388 &WorkspaceEdit { 3389 changes: Some( 3390 vec![(Url::parse("file://test").unwrap(), vec![])] 3391 .into_iter() 3392 .collect(), 3393 ), 3394 document_changes: None, 3395 }, 3396 r#"{"changes":{"file://test/":[]}}"#, 3397 ); 3398 } 3399 3400 #[test] formatting_options()3401 fn formatting_options() { 3402 test_serialization( 3403 &FormattingOptions { 3404 tab_size: 123, 3405 insert_spaces: true, 3406 properties: HashMap::new(), 3407 }, 3408 r#"{"tabSize":123,"insertSpaces":true}"#, 3409 ); 3410 3411 test_serialization( 3412 &FormattingOptions { 3413 tab_size: 123, 3414 insert_spaces: true, 3415 properties: vec![("prop".to_string(), FormattingProperty::Number(1.0))] 3416 .into_iter() 3417 .collect(), 3418 }, 3419 r#"{"tabSize":123,"insertSpaces":true,"prop":1.0}"#, 3420 ); 3421 } 3422 3423 #[test] root_uri_can_be_missing()3424 fn root_uri_can_be_missing() { 3425 serde_json::from_str::<InitializeParams>(r#"{ "capabilities": {} }"#).unwrap(); 3426 } 3427 3428 #[test] test_watch_kind()3429 fn test_watch_kind() { 3430 test_serialization(&WatchKind::Create, "1"); 3431 test_serialization(&(WatchKind::Create | WatchKind::Change), "3"); 3432 test_serialization( 3433 &(WatchKind::Create | WatchKind::Change | WatchKind::Delete), 3434 "7", 3435 ); 3436 } 3437 3438 #[test] test_resource_operation_kind()3439 fn test_resource_operation_kind() { 3440 test_serialization( 3441 &vec![ 3442 ResourceOperationKind::Create, 3443 ResourceOperationKind::Rename, 3444 ResourceOperationKind::Delete, 3445 ], 3446 r#"["create","rename","delete"]"#, 3447 ); 3448 } 3449 3450 #[test] test_code_action_response()3451 fn test_code_action_response() { 3452 test_serialization( 3453 &vec![ 3454 CodeActionOrCommand::Command(Command { 3455 title: "title".to_string(), 3456 command: "command".to_string(), 3457 arguments: None, 3458 }), 3459 CodeActionOrCommand::CodeAction(CodeAction { 3460 title: "title".to_string(), 3461 kind: Some(code_action_kind::QUICKFIX.to_owned()), 3462 command: None, 3463 diagnostics: None, 3464 edit: None, 3465 }), 3466 ], 3467 r#"[{"title":"title","command":"command"},{"title":"title","kind":"quickfix"}]"#, 3468 ) 3469 } 3470 } 3471