Skip to main content

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