Skip to main content

ls_types/
lib.rs

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