lsp_types/
lib.rs

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