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