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