Debian Codegraph @

helix-lsp-types/src/lib.rs

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