languageserver_types/
lib.rs

1/*!
2
3Language Server Protocol types for Rust.
4
5Based on: <https://microsoft.github.io/language-server-protocol/specification>
6
7This library uses the URL crate for parsing URIs.  Note that there is
8some confusion on the meaning of URLs vs URIs:
9<http://stackoverflow.com/a/28865728/393898>.  According to that
10information, on the classical sense of "URLs", "URLs" are a subset of
11URIs, But on the modern/new meaning of URLs, they are the same as
12URIs.  The important take-away aspect is that the URL crate should be
13able to parse any URI, such as `urn:isbn:0451450523`.
14
15
16*/
17#![allow(non_upper_case_globals)]
18
19#[macro_use]
20extern crate bitflags;
21#[macro_use]
22extern crate num_derive;
23extern crate num_traits;
24extern crate serde;
25#[macro_use]
26extern crate serde_derive;
27extern crate serde_json;
28
29extern crate url;
30extern crate url_serde;
31
32pub use url::Url;
33
34use std::collections::HashMap;
35
36use num_traits::FromPrimitive;
37use serde::de;
38use serde::de::Error as Error_;
39use serde_json::Value;
40
41pub mod notification;
42pub mod request;
43
44/* ----------------- Auxiliary types ----------------- */
45
46#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
47#[serde(untagged)]
48pub enum NumberOrString {
49    Number(u64),
50    String(String),
51}
52
53/* ----------------- Cancel support ----------------- */
54
55#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
56pub struct CancelParams {
57    /// The request id to cancel.
58    pub id: NumberOrString,
59}
60
61/* ----------------- Basic JSON Structures ----------------- */
62
63/// Position in a text document expressed as zero-based line and character offset.
64/// A position is between two characters like an 'insert' cursor in a editor.
65#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Default, Deserialize, Serialize)]
66pub struct Position {
67    /// Line position in a document (zero-based).
68    pub line: u64,
69    /// Character offset on a line in a document (zero-based).
70    pub character: u64,
71}
72
73impl Position {
74    pub fn new(line: u64, character: u64) -> Position {
75        Position {
76            line: line,
77            character: character,
78        }
79    }
80}
81
82/// A range in a text document expressed as (zero-based) start and end positions.
83/// A range is comparable to a selection in an editor. Therefore the end position is exclusive.
84#[derive(Debug, Eq, PartialEq, Copy, Clone, Default, Deserialize, Serialize)]
85pub struct Range {
86    /// The range's start position.
87    pub start: Position,
88    /// The range's end position.
89    pub end: Position,
90}
91
92impl Range {
93    pub fn new(start: Position, end: Position) -> Range {
94        Range {
95            start: start,
96            end: end,
97        }
98    }
99}
100
101/// Represents a location inside a resource, such as a line inside a text file.
102#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
103pub struct Location {
104    #[serde(with = "url_serde")]
105    pub uri: Url,
106    pub range: Range,
107}
108
109impl Location {
110    pub fn new(uri: Url, range: Range) -> Location {
111        Location {
112            uri: uri,
113            range: range,
114        }
115    }
116}
117
118/// Represents a link between a source and a target location.
119#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
120#[serde(rename_all = "camelCase")]
121pub struct LocationLink {
122    /// Span of the origin of this link.
123    ///
124    ///  Used as the underlined span for mouse interaction. Defaults to the word range at
125    ///  the mouse position.
126    #[serde(skip_serializing_if = "Option::is_none")]
127    pub origin_selection_range: Option<Range>,
128
129    /// The target resource identifier of this link.
130    #[serde(with = "url_serde")]
131    pub target_uri: Url,
132
133    /// The full target range of this link.
134    pub target_range: Range,
135
136    /// The span of this link.
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub target_selection_range: Option<Range>
139}
140
141/// Represents a diagnostic, such as a compiler error or warning.
142/// Diagnostic objects are only valid in the scope of a resource.
143#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
144#[serde(rename_all = "camelCase")]
145pub struct Diagnostic {
146    /// The range at which the message applies.
147    pub range: Range,
148
149    /// The diagnostic's severity. Can be omitted. If omitted it is up to the
150    /// client to interpret diagnostics as error, warning, info or hint.
151    #[serde(skip_serializing_if = "Option::is_none")]
152    pub severity: Option<DiagnosticSeverity>,
153
154    /// The diagnostic's code. Can be omitted.
155    #[serde(skip_serializing_if = "Option::is_none")]
156    pub code: Option<NumberOrString>,
157    //    code?: number | string;
158    /// A human-readable string describing the source of this
159    /// diagnostic, e.g. 'typescript' or 'super lint'.
160    #[serde(skip_serializing_if = "Option::is_none")]
161    pub source: Option<String>,
162
163    /// The diagnostic's message.
164    pub message: String,
165
166    /// An array of related diagnostic information, e.g. when symbol-names within
167    /// a scope collide all definitions can be marked via this property.
168    #[serde(skip_serializing_if = "Option::is_none")]
169    pub related_information: Option<Vec<DiagnosticRelatedInformation>>,
170}
171
172impl Diagnostic {
173    pub fn new(
174        range: Range,
175        severity: Option<DiagnosticSeverity>,
176        code: Option<NumberOrString>,
177        source: Option<String>,
178        message: String,
179        related_information: Option<Vec<DiagnosticRelatedInformation>>,
180    ) -> Diagnostic {
181        Diagnostic {
182            range,
183            severity,
184            code,
185            source,
186            message,
187            related_information,
188        }
189    }
190
191    pub fn new_simple(range: Range, message: String) -> Diagnostic {
192        Self::new(range, None, None, None, message, None)
193    }
194
195    pub fn new_with_code_number(
196        range: Range,
197        severity: DiagnosticSeverity,
198        code_number: u64,
199        source: Option<String>,
200        message: String,
201    ) -> Diagnostic {
202        let code = Some(NumberOrString::Number(code_number));
203        Self::new(range, Some(severity), code, source, message, None)
204    }
205}
206
207/// The protocol currently supports the following diagnostic severities:
208#[derive(Debug, Eq, PartialEq, Clone, Copy)]
209pub enum DiagnosticSeverity {
210    /// Reports an error.
211    Error = 1,
212    /// Reports a warning.
213    Warning = 2,
214    /// Reports an information.
215    Information = 3,
216    /// Reports a hint.
217    Hint = 4,
218}
219
220/// Represents a related message and source code location for a diagnostic. This
221/// should be used to point to code locations that cause or related to a
222/// diagnostics, e.g when duplicating a symbol in a scope.
223#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
224pub struct DiagnosticRelatedInformation {
225    /// The location of this related diagnostic information.
226    pub location: Location,
227
228    /// The message of this related diagnostic information.
229    pub message: String,
230}
231
232impl<'de> serde::Deserialize<'de> for DiagnosticSeverity {
233    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
234    where
235        D: serde::Deserializer<'de>,
236    {
237        Ok(match try!(u8::deserialize(deserializer)) {
238            1 => DiagnosticSeverity::Error,
239            2 => DiagnosticSeverity::Warning,
240            3 => DiagnosticSeverity::Information,
241            4 => DiagnosticSeverity::Hint,
242            i => {
243                return Err(D::Error::invalid_value(
244                    de::Unexpected::Unsigned(i as u64),
245                    &"value of 1, 2, 3 or 4",
246                ));
247            }
248        })
249    }
250}
251
252impl serde::Serialize for DiagnosticSeverity {
253    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
254    where
255        S: serde::Serializer,
256    {
257        serializer.serialize_u8(*self as u8)
258    }
259}
260
261/**
262 Represents a reference to a command. Provides a title which will be used to represent a command in the UI.
263 Commands are identitifed using a string identifier and the protocol currently doesn't specify a set of
264 well known commands. So executing a command requires some tool extension code.
265*/
266#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
267pub struct Command {
268    /// Title of the command, like `save`.
269    pub title: String,
270    /// The identifier of the actual command handler.
271    pub command: String,
272    /// Arguments that the command handler should be
273    /// invoked with.
274    #[serde(skip_serializing_if = "Option::is_none")]
275    pub arguments: Option<Vec<Value>>,
276}
277
278impl Command {
279    pub fn new(title: String, command: String, arguments: Option<Vec<Value>>) -> Command {
280        Command {
281            title: title,
282            command: command,
283            arguments: arguments,
284        }
285    }
286}
287
288/// A textual edit applicable to a text document.
289///
290/// If n `TextEdit`s are applied to a text document all text edits describe changes to the initial document version.
291/// Execution wise text edits should applied from the bottom to the top of the text document. Overlapping text edits
292/// are not supported.
293#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
294#[serde(rename_all = "camelCase")]
295pub struct TextEdit {
296    /// The range of the text document to be manipulated. To insert
297    /// text into a document create a range where start === end.
298    pub range: Range,
299    /// The string to be inserted. For delete operations use an
300    /// empty string.
301    pub new_text: String,
302}
303
304impl TextEdit {
305    pub fn new(range: Range, new_text: String) -> TextEdit {
306        TextEdit {
307            range: range,
308            new_text: new_text,
309        }
310    }
311}
312
313/**
314  Describes textual changes on a single text document. The text document is referred to as a
315  `VersionedTextDocumentIdentifier` to allow clients to check the text document version before an
316  edit is applied. A `TextDocumentEdit` describes all changes on a version Si and after they are
317  applied move the document to version Si+1. So the creator of a `TextDocumentEdit` doesn't need to
318  sort the array or do any kind of ordering. However the edits must be non overlapping.
319  */
320#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
321#[serde(rename_all = "camelCase")]
322pub struct TextDocumentEdit {
323    /**
324     * The text document to change.
325     */
326    pub text_document: VersionedTextDocumentIdentifier,
327
328    /**
329     * The edits to be applied.
330     */
331    pub edits: Vec<TextEdit>,
332}
333
334/**
335 * Options to create a file.
336 */
337#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
338#[serde(rename_all = "camelCase")]
339pub struct CreateFileOptions {
340    /**
341     * Overwrite existing file. Overwrite wins over `ignoreIfExists`
342     */
343    #[serde(skip_serializing_if = "Option::is_none")]
344    pub overwrite: Option<bool>,
345    /**
346     * Ignore if exists.
347     */
348    #[serde(skip_serializing_if = "Option::is_none")]
349    pub ignore_if_exists: Option<bool>,
350}
351
352/**
353 * Create file operation
354 */
355#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
356#[serde(rename_all = "camelCase")]
357pub struct CreateFile {
358    /**
359     * The resource to create.
360     */
361    #[serde(with = "url_serde")]
362    pub uri: Url,
363    /**
364     * Additional options
365     */
366    #[serde(skip_serializing_if = "Option::is_none")]
367    pub options: Option<CreateFileOptions>,
368}
369
370/**
371 * Rename file options
372 */
373#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
374#[serde(rename_all = "camelCase")]
375pub struct RenameFileOptions {
376    /**
377     * Overwrite target if existing. Overwrite wins over `ignoreIfExists`
378     */
379    #[serde(skip_serializing_if = "Option::is_none")]
380    pub overwrite: Option<bool>,
381    /**
382     * Ignores if target exists.
383     */
384    #[serde(skip_serializing_if = "Option::is_none")]
385    pub ignore_if_exists: Option<bool>,
386}
387
388/**
389 * Rename file operation
390 */
391#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
392#[serde(rename_all = "camelCase")]
393pub struct RenameFile {
394    /**
395     * The old (existing) location.
396     */
397    #[serde(with = "url_serde")]
398    pub old_uri: Url,
399    /**
400     * The new location.
401     */
402    #[serde(with = "url_serde")]
403    pub new_uri: Url,
404    /**
405     * Rename options.
406     */
407    #[serde(skip_serializing_if = "Option::is_none")]
408    pub options: Option<RenameFileOptions>,
409}
410
411/**
412 * Delete file options
413 */
414#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
415#[serde(rename_all = "camelCase")]
416pub struct DeleteFileOptions {
417    /**
418     * Delete the content recursively if a folder is denoted.
419     */
420    #[serde(skip_serializing_if = "Option::is_none")]
421    pub recursive: Option<bool>,
422    /**
423     * Ignore the operation if the file doesn't exist.
424     */
425    #[serde(skip_serializing_if = "Option::is_none")]
426    pub ignore_if_not_exists: Option<bool>,
427}
428
429/**
430 * Delete file operation
431 */
432#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
433#[serde(rename_all = "camelCase")]
434pub struct DeleteFile {
435    /**
436     * The file to delete.
437     */
438    #[serde(with = "url_serde")]
439    pub uri: Url,
440    /**
441     * Delete options.
442     */
443    #[serde(skip_serializing_if = "Option::is_none")]
444    pub options: Option<DeleteFileOptions>,
445}
446
447/// A workspace edit represents changes to many resources managed in the workspace.
448#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
449#[serde(rename_all = "camelCase")]
450pub struct WorkspaceEdit {
451    /// Holds changes to existing resources.
452    #[serde(with = "url_map")]
453    #[serde(skip_serializing_if = "Option::is_none")]
454    #[serde(default)]
455    pub changes: Option<HashMap<Url, Vec<TextEdit>>>, //    changes?: { [uri: string]: TextEdit[]; };
456
457    /**
458     * Depending on the client capability `workspace.workspaceEdit.resourceOperations` document changes
459     * are either an array of `TextDocumentEdit`s to express changes to n different text documents
460     * where each text document edit addresses a specific version of a text document. Or it can contain
461     * above `TextDocumentEdit`s mixed with create, rename and delete file / folder operations.
462     *
463     * Whether a client supports versioned document edits is expressed via
464     * `workspace.workspaceEdit.documentChanges` client capability.
465     *
466     * If a client neither supports `documentChanges` nor `workspace.workspaceEdit.resourceOperations` then
467     * only plain `TextEdit`s using the `changes` property are supported.
468     */
469    #[serde(skip_serializing_if = "Option::is_none")]
470    pub document_changes: Option<DocumentChanges>,
471}
472
473#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
474#[serde(untagged)]
475pub enum DocumentChanges {
476    Edits(Vec<TextDocumentEdit>),
477    Operations(Vec<DocumentChangeOperation>),
478}
479
480// TODO: Once https://github.com/serde-rs/serde/issues/912 is solved
481// we can remove ResourceOp and switch to the following implementation
482// of DocumentChangeOperation:
483//
484// #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
485// #[serde(tag = "kind", rename_all="lowercase" )]
486// pub enum DocumentChangeOperation {
487//     Create(CreateFile),
488//     Rename(RenameFile),
489//     Delete(DeleteFile),
490//
491//     #[serde(other)]
492//     Edit(TextDocumentEdit),
493// }
494
495#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
496#[serde(untagged, rename_all = "lowercase")]
497pub enum DocumentChangeOperation {
498    Op(ResourceOp),
499    Edit(TextDocumentEdit),
500}
501
502#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
503#[serde(tag = "kind", rename_all = "lowercase")]
504pub enum ResourceOp {
505    Create(CreateFile),
506    Rename(RenameFile),
507    Delete(DeleteFile),
508}
509
510mod url_map {
511    use super::*;
512
513    use std::fmt;
514
515    pub fn deserialize<'de, D>(
516        deserializer: D,
517    ) -> Result<Option<HashMap<Url, Vec<TextEdit>>>, D::Error>
518    where
519        D: serde::Deserializer<'de>,
520    {
521        struct UrlMapVisitor;
522        impl<'de> de::Visitor<'de> for UrlMapVisitor {
523            type Value = HashMap<Url, Vec<TextEdit>>;
524
525            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
526                formatter.write_str("map")
527            }
528
529            fn visit_map<M>(self, mut visitor: M) -> Result<Self::Value, M::Error>
530            where
531                M: de::MapAccess<'de>,
532            {
533                let mut values = HashMap::with_capacity(visitor.size_hint().unwrap_or(0));
534
535                // While there are entries remaining in the input, add them
536                // into our map.
537                while let Some((key, value)) = visitor.next_entry::<url_serde::De<Url>, _>()? {
538                    values.insert(key.into_inner(), value);
539                }
540
541                Ok(values)
542            }
543        }
544
545        struct OptionUrlMapVisitor;
546        impl<'de> de::Visitor<'de> for OptionUrlMapVisitor {
547            type Value = Option<HashMap<Url, Vec<TextEdit>>>;
548
549            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
550                formatter.write_str("option")
551            }
552
553            #[inline]
554            fn visit_unit<E>(self) -> Result<Self::Value, E>
555            where
556                E: serde::de::Error,
557            {
558                Ok(None)
559            }
560
561            #[inline]
562            fn visit_none<E>(self) -> Result<Self::Value, E>
563            where
564                E: serde::de::Error,
565            {
566                Ok(None)
567            }
568
569            #[inline]
570            fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
571            where
572                D: serde::Deserializer<'de>,
573            {
574                deserializer.deserialize_map(UrlMapVisitor).map(Some)
575            }
576        }
577
578        // Instantiate our Visitor and ask the Deserializer to drive
579        // it over the input data, resulting in an instance of MyMap.
580        deserializer.deserialize_option(OptionUrlMapVisitor)
581    }
582
583    pub fn serialize<S>(
584        changes: &Option<HashMap<Url, Vec<TextEdit>>>,
585        serializer: S,
586    ) -> Result<S::Ok, S::Error>
587    where
588        S: serde::Serializer,
589    {
590        use serde::ser::SerializeMap;
591
592        match *changes {
593            Some(ref changes) => {
594                let mut map = serializer.serialize_map(Some(changes.len()))?;
595                for (k, v) in changes {
596                    map.serialize_entry(k.as_str(), v)?;
597                }
598                map.end()
599            }
600            None => serializer.serialize_none(),
601        }
602    }
603}
604
605impl WorkspaceEdit {
606    pub fn new(changes: HashMap<Url, Vec<TextEdit>>) -> WorkspaceEdit {
607        WorkspaceEdit {
608            changes: Some(changes),
609            document_changes: None,
610        }
611    }
612}
613
614/// Text documents are identified using a URI. On the protocol level, URIs are passed as strings.
615#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
616pub struct TextDocumentIdentifier {
617    // !!!!!! Note:
618    // In the spec VersionedTextDocumentIdentifier extends TextDocumentIdentifier
619    // This modelled by "mixing-in" TextDocumentIdentifier in VersionedTextDocumentIdentifier,
620    // so any changes to this type must be effected in the sub-type as well.
621    /// The text document's URI.
622    #[serde(with = "url_serde")]
623    pub uri: Url,
624}
625
626impl TextDocumentIdentifier {
627    pub fn new(uri: Url) -> TextDocumentIdentifier {
628        TextDocumentIdentifier { uri: uri }
629    }
630}
631
632/// An item to transfer a text document from the client to the server.
633#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
634#[serde(rename_all = "camelCase")]
635pub struct TextDocumentItem {
636    /// The text document's URI.
637    #[serde(with = "url_serde")]
638    pub uri: Url,
639
640    /// The text document's language identifier.
641    pub language_id: String,
642
643    /// The version number of this document (it will strictly increase after each
644    /// change, including undo/redo).
645    pub version: u64,
646
647    /// The content of the opened text document.
648    pub text: String,
649}
650
651impl TextDocumentItem {
652    pub fn new(uri: Url, language_id: String, version: u64, text: String) -> TextDocumentItem {
653        TextDocumentItem {
654            uri: uri,
655            language_id: language_id,
656            version: version,
657            text: text,
658        }
659    }
660}
661
662/// An identifier to denote a specific version of a text document.
663#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
664pub struct VersionedTextDocumentIdentifier {
665    // This field was "mixed-in" from TextDocumentIdentifier
666    /// The text document's URI.
667    #[serde(with = "url_serde")]
668    pub uri: Url,
669
670    /// The version number of this document.
671    pub version: Option<u64>,
672}
673
674impl VersionedTextDocumentIdentifier {
675    pub fn new(uri: Url, version: u64) -> VersionedTextDocumentIdentifier {
676        VersionedTextDocumentIdentifier {
677            uri: uri,
678            version: Some(version),
679        }
680    }
681}
682
683/// A parameter literal used in requests to pass a text document and a position inside that document.
684#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
685#[serde(rename_all = "camelCase")]
686pub struct TextDocumentPositionParams {
687    // !!!!!! Note:
688    // In the spec ReferenceParams extends TextDocumentPositionParams
689    // This modelled by "mixing-in" TextDocumentPositionParams in ReferenceParams,
690    // so any changes to this type must be effected in sub-type as well.
691    /// The text document.
692    pub text_document: TextDocumentIdentifier,
693
694    /// The position inside the text document.
695    pub position: Position,
696}
697
698impl TextDocumentPositionParams {
699    pub fn new(
700        text_document: TextDocumentIdentifier,
701        position: Position,
702    ) -> TextDocumentPositionParams {
703        TextDocumentPositionParams {
704            text_document: text_document,
705            position: position,
706        }
707    }
708}
709
710/// A document filter denotes a document through properties like language, schema or pattern.
711/// Examples are a filter that applies to TypeScript files on disk or a filter the applies to JSON
712/// files with name package.json:
713///
714/// { language: 'typescript', scheme: 'file' }
715/// { language: 'json', pattern: '**/package.json' }
716#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
717pub struct DocumentFilter {
718    /**
719     * A language id, like `typescript`.
720     */
721    #[serde(skip_serializing_if = "Option::is_none")]
722    pub language: Option<String>,
723
724    /**
725     * A Uri [scheme](#Uri.scheme), like `file` or `untitled`.
726     */
727    #[serde(skip_serializing_if = "Option::is_none")]
728    pub scheme: Option<String>,
729
730    /**
731     * A glob pattern, like `*.{ts,js}`.
732     */
733    #[serde(skip_serializing_if = "Option::is_none")]
734    pub pattern: Option<String>,
735}
736
737/// A document selector is the combination of one or many document filters.
738pub type DocumentSelector = Vec<DocumentFilter>;
739
740// ========================= Actual Protocol =========================
741
742#[derive(Debug, PartialEq, Deserialize, Serialize)]
743#[serde(rename_all = "camelCase")]
744pub struct InitializeParams {
745    /// The process Id of the parent process that started
746    /// the server. Is null if the process has not been started by another process.
747    /// If the parent process is not alive then the server should exit (see exit notification) its process.
748    pub process_id: Option<u64>,
749
750    /// The rootPath of the workspace. Is null
751    /// if no folder is open.
752    #[serde(skip_serializing_if = "Option::is_none")]
753    pub root_path: Option<String>,
754
755    /// The rootUri of the workspace. Is null if no
756    /// folder is open. If both `rootPath` and `rootUri` are set
757    /// `rootUri` wins.
758    #[serde(with = "option_url")]
759    #[serde(default)]
760    pub root_uri: Option<Url>,
761
762    /// User provided initialization options.
763    #[serde(skip_serializing_if = "Option::is_none")]
764    pub initialization_options: Option<Value>,
765
766    /// The capabilities provided by the client (editor)
767    pub capabilities: ClientCapabilities,
768
769    /// The initial trace setting. If omitted trace is disabled ('off').
770    #[serde(default)]
771    #[serde(skip_serializing_if = "Option::is_none")]
772    pub trace: Option<TraceOption>,
773
774    /// The workspace folders configured in the client when the server starts.
775    /// This property is only available if the client supports workspace folders.
776    /// It can be `null` if the client supports workspace folders but none are
777    /// configured.
778    #[serde(skip_serializing_if = "Option::is_none")]
779    pub workspace_folders: Option<Vec<WorkspaceFolder>>,
780}
781
782#[derive(Debug, PartialEq, Deserialize, Serialize)]
783pub struct InitializedParams {}
784
785#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
786pub enum TraceOption {
787    #[serde(rename = "off")]
788    Off,
789    #[serde(rename = "messages")]
790    Messages,
791    #[serde(rename = "verbose")]
792    Verbose,
793}
794
795impl Default for TraceOption {
796    fn default() -> TraceOption {
797        TraceOption::Off
798    }
799}
800
801mod option_url {
802    use serde::{self, Serialize};
803    use url::Url;
804    use url_serde::{De, Ser};
805
806    pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Url>, D::Error>
807    where
808        D: serde::Deserializer<'de>,
809    {
810        serde::Deserialize::deserialize(deserializer)
811            .map(|x: Option<De<Url>>| x.map(|url| url.into_inner()))
812    }
813
814    pub fn serialize<S>(self_: &Option<Url>, serializer: S) -> Result<S::Ok, S::Error>
815    where
816        S: serde::Serializer,
817    {
818        self_.as_ref().map(Ser::new).serialize(serializer)
819    }
820}
821
822#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
823#[serde(rename_all = "camelCase")]
824pub struct GenericCapability {
825    /**
826     * This capability supports dynamic registration.
827     */
828    #[serde(skip_serializing_if = "Option::is_none")]
829    pub dynamic_registration: Option<bool>,
830}
831
832#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
833#[serde(rename_all = "camelCase")]
834pub struct GotoCapability {
835    #[serde(skip_serializing_if = "Option::is_none")]
836    pub dynamic_registration: Option<bool>,
837
838    /// The client supports additional metadata in the form of definition links.
839    pub link_support: Option<bool>,
840}
841
842#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
843#[serde(rename_all = "camelCase")]
844pub struct WorkspaceEditCapability {
845    /**
846     * The client supports versioned document changes in `WorkspaceEdit`s
847     */
848    #[serde(skip_serializing_if = "Option::is_none")]
849    pub document_changes: Option<bool>,
850
851    /**
852     * The resource operations the client supports. Clients should at least
853     * support 'create', 'rename' and 'delete' files and folders.
854     */
855    #[serde(skip_serializing_if = "Option::is_none")]
856    pub resource_operations: Option<Vec<ResourceOperationKind>>,
857
858    /**
859     * The failure handling strategy of a client if applying the workspace edit
860     * failes.
861     */
862    #[serde(skip_serializing_if = "Option::is_none")]
863    pub failure_handling: Option<FailureHandlingKind>,
864}
865
866#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
867#[serde(rename_all = "camelCase")]
868pub struct WorkspaceCapability {
869    /// The server supports workspace folder.
870    #[serde(skip_serializing_if = "Option::is_none")]
871    pub workspace_folders: Option<WorkspaceFolderCapability>,
872}
873
874#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
875#[serde(rename_all = "camelCase")]
876pub struct WorkspaceFolderCapability {
877    #[serde(skip_serializing_if = "Option::is_none")]
878    pub supported: Option<bool>,
879
880    #[serde(skip_serializing_if = "Option::is_none")]
881    pub change_notifications: Option<WorkspaceFolderCapabilityChangeNotifications>,
882}
883
884#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
885#[serde(untagged)]
886pub enum WorkspaceFolderCapabilityChangeNotifications {
887    Bool(bool),
888    Id(String),
889}
890
891#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
892#[serde(rename_all = "camelCase")]
893pub struct WorkspaceFolder {
894    /// The associated URI for this workspace folder.
895    #[serde(with = "url_serde")]
896    pub uri: Url,
897    /// The name of the workspace folder. Defaults to the uri's basename.
898    pub name: String,
899}
900
901#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
902#[serde(rename_all = "camelCase")]
903pub struct DidChangeWorkspaceFoldersParams {
904    /**
905     * The actual workspace folder change event.
906     */
907    pub event: WorkspaceFoldersChangeEvent,
908}
909
910/**
911 * The workspace folder change event.
912 */
913#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
914#[serde(rename_all = "camelCase")]
915pub struct WorkspaceFoldersChangeEvent {
916    /**
917     * The array of added workspace folders
918     */
919    pub added: Vec<WorkspaceFolder>,
920
921    /**
922     * The array of the removed workspace folders
923     */
924    pub removed: Vec<WorkspaceFolder>,
925}
926
927#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Copy, Clone)]
928#[serde(rename_all = "lowercase")]
929pub enum ResourceOperationKind {
930    Create,
931    Rename,
932    Delete,
933}
934
935#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Copy, Clone)]
936#[serde(rename_all = "camelCase")]
937pub enum FailureHandlingKind {
938    Abort,
939    Transactional,
940    TextOnlyTransactional,
941    Undo,
942}
943
944/**
945 * Specific capabilities for the `SymbolKind` in the `workspace/symbol` request.
946 */
947#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
948#[serde(rename_all = "camelCase")]
949pub struct SymbolKindCapability {
950    /**
951     * The symbol kind values the client supports. When this
952     * property exists the client also guarantees that it will
953     * handle values outside its set gracefully and falls back
954     * to a default value when unknown.
955     *
956     * If this property is not present the client only supports
957     * the symbol kinds from `File` to `Array` as defined in
958     * the initial version of the protocol.
959     */
960    pub value_set: Option<Vec<SymbolKind>>,
961}
962
963#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
964#[serde(rename_all = "camelCase")]
965pub struct SymbolCapability {
966    /**
967     * This capability supports dynamic registration.
968     */
969    #[serde(skip_serializing_if = "Option::is_none")]
970    pub dynamic_registration: Option<bool>,
971
972    /**
973     * Specific capabilities for the `SymbolKind` in the `workspace/symbol` request.
974     */
975    #[serde(skip_serializing_if = "Option::is_none")]
976    pub symbol_kind: Option<SymbolKindCapability>,
977}
978
979/**
980 * Workspace specific client capabilities.
981 */
982#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
983#[serde(rename_all = "camelCase")]
984pub struct WorkspaceClientCapabilities {
985    /**
986     * The client supports applying batch edits to the workspace by supporting
987     * the request 'workspace/applyEdit'
988     */
989    #[serde(skip_serializing_if = "Option::is_none")]
990    pub apply_edit: Option<bool>,
991
992    /**
993     * Capabilities specific to `WorkspaceEdit`s
994     */
995    #[serde(skip_serializing_if = "Option::is_none")]
996    pub workspace_edit: Option<WorkspaceEditCapability>,
997
998    /**
999     * Capabilities specific to the `workspace/didChangeConfiguration` notification.
1000     */
1001    #[serde(skip_serializing_if = "Option::is_none")]
1002    pub did_change_configuration: Option<GenericCapability>,
1003
1004    /**
1005     * Capabilities specific to the `workspace/didChangeWatchedFiles` notification.
1006     */
1007    #[serde(skip_serializing_if = "Option::is_none")]
1008    pub did_change_watched_files: Option<GenericCapability>,
1009
1010    /**
1011     * Capabilities specific to the `workspace/symbol` request.
1012     */
1013    #[serde(skip_serializing_if = "Option::is_none")]
1014    pub symbol: Option<SymbolCapability>,
1015
1016    /**
1017     * Capabilities specific to the `workspace/executeCommand` request.
1018     */
1019    #[serde(skip_serializing_if = "Option::is_none")]
1020    pub execute_command: Option<GenericCapability>,
1021
1022    /**
1023     * The client has support for workspace folders.
1024     */
1025    #[serde(skip_serializing_if = "Option::is_none")]
1026    pub workspace_folders: Option<bool>,
1027
1028    /**
1029     * The client supports `workspace/configuration` requests.
1030     */
1031    #[serde(skip_serializing_if = "Option::is_none")]
1032    pub configuration: Option<bool>,
1033}
1034
1035#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1036#[serde(rename_all = "camelCase")]
1037pub struct SynchronizationCapability {
1038    /**
1039     * Whether text document synchronization supports dynamic registration.
1040     */
1041    #[serde(skip_serializing_if = "Option::is_none")]
1042    pub dynamic_registration: Option<bool>,
1043
1044    /**
1045     * The client supports sending will save notifications.
1046     */
1047    #[serde(skip_serializing_if = "Option::is_none")]
1048    pub will_save: Option<bool>,
1049
1050    /**
1051     * The client supports sending a will save request and
1052     * waits for a response providing text edits which will
1053     * be applied to the document before it is saved.
1054     */
1055    #[serde(skip_serializing_if = "Option::is_none")]
1056    pub will_save_wait_until: Option<bool>,
1057
1058    /**
1059     * The client supports did save notifications.
1060     */
1061    #[serde(skip_serializing_if = "Option::is_none")]
1062    pub did_save: Option<bool>,
1063}
1064
1065#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1066#[serde(rename_all = "camelCase")]
1067pub struct CompletionItemCapability {
1068    /**
1069     * Client supports snippets as insert text.
1070     *
1071     * A snippet can define tab stops and placeholders with `$1`, `$2`
1072     * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
1073     * the end of the snippet. Placeholders with equal identifiers are linked,
1074     * that is typing in one will update others too.
1075     */
1076    #[serde(skip_serializing_if = "Option::is_none")]
1077    pub snippet_support: Option<bool>,
1078
1079    /**
1080     * Client supports commit characters on a completion item.
1081     */
1082    #[serde(skip_serializing_if = "Option::is_none")]
1083    pub commit_characters_support: Option<bool>,
1084
1085    /**
1086     * Client supports the follow content formats for the documentation
1087     * property. The order describes the preferred format of the client.
1088     */
1089    #[serde(skip_serializing_if = "Option::is_none")]
1090    pub documentation_format: Option<Vec<MarkupKind>>,
1091
1092    /**
1093     * Client supports the deprecated property on a completion item.
1094     */
1095    #[serde(skip_serializing_if = "Option::is_none")]
1096    pub deprecated_support: Option<bool>,
1097
1098    /**
1099     * Client supports the preselect property on a completion item.
1100     */
1101    #[serde(skip_serializing_if = "Option::is_none")]
1102    pub preselect_support: Option<bool>,
1103}
1104
1105#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1106#[serde(rename_all = "camelCase")]
1107pub struct CompletionItemKindCapability {
1108    /**
1109     * The completion item kind values the client supports. When this
1110     * property exists the client also guarantees that it will
1111     * handle values outside its set gracefully and falls back
1112     * to a default value when unknown.
1113     *
1114     * If this property is not present the client only supports
1115     * the completion items kinds from `Text` to `Reference` as defined in
1116     * the initial version of the protocol.
1117     */
1118    #[serde(skip_serializing_if = "Option::is_none")]
1119    pub value_set: Option<Vec<CompletionItemKind>>,
1120}
1121
1122#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1123#[serde(rename_all = "camelCase")]
1124pub struct HoverCapability {
1125    /**
1126     * Whether completion supports dynamic registration.
1127     */
1128    #[serde(skip_serializing_if = "Option::is_none")]
1129    pub dynamic_registration: Option<bool>,
1130
1131    /**
1132     * Client supports the follow content formats for the content
1133     * property. The order describes the preferred format of the client.
1134     */
1135    #[serde(skip_serializing_if = "Option::is_none")]
1136    pub content_format: Option<Vec<MarkupKind>>,
1137}
1138
1139#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1140#[serde(rename_all = "camelCase")]
1141pub struct CompletionCapability {
1142    /**
1143     * Whether completion supports dynamic registration.
1144     */
1145    #[serde(skip_serializing_if = "Option::is_none")]
1146    pub dynamic_registration: Option<bool>,
1147
1148    /**
1149     * The client supports the following `CompletionItem` specific
1150     * capabilities.
1151     */
1152    #[serde(skip_serializing_if = "Option::is_none")]
1153    pub completion_item: Option<CompletionItemCapability>,
1154
1155    #[serde(skip_serializing_if = "Option::is_none")]
1156    pub completion_item_kind: Option<CompletionItemKindCapability>,
1157
1158    /**
1159     * The client supports to send additional context information for a
1160     * `textDocument/completion` requestion.
1161     */
1162    #[serde(skip_serializing_if = "Option::is_none")]
1163    pub context_support: Option<bool>,
1164}
1165
1166#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1167#[serde(rename_all = "camelCase")]
1168pub struct SignatureInformationSettings {
1169    /**
1170     * Client supports the follow content formats for the documentation
1171     * property. The order describes the preferred format of the client.
1172     */
1173    #[serde(skip_serializing_if = "Option::is_none")]
1174    pub documentation_format: Option<Vec<MarkupKind>>,
1175
1176    #[serde(skip_serializing_if = "Option::is_none")]
1177    pub parameter_information: Option<ParameterInformationSettings>,
1178}
1179
1180#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1181#[serde(rename_all = "camelCase")]
1182pub struct ParameterInformationSettings {
1183    /**
1184    * The client supports processing label offsets instead of a
1185    * simple label string.
1186    */
1187    #[serde(skip_serializing_if = "Option::is_none")]
1188    pub label_offset_support: Option<bool>
1189}
1190
1191#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1192#[serde(rename_all = "camelCase")]
1193pub struct SignatureHelpCapability {
1194    /**
1195     * Whether completion supports dynamic registration.
1196     */
1197    #[serde(skip_serializing_if = "Option::is_none")]
1198    pub dynamic_registration: Option<bool>,
1199
1200    /**
1201     * The client supports the following `SignatureInformation`
1202     * specific properties.
1203     */
1204    #[serde(skip_serializing_if = "Option::is_none")]
1205    pub signature_information: Option<SignatureInformationSettings>,
1206}
1207
1208#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1209#[serde(rename_all = "camelCase")]
1210pub struct PublishDiagnosticsCapability {
1211    /**
1212     * Whether the clients accepts diagnostics with related information.
1213     */
1214    #[serde(skip_serializing_if = "Option::is_none")]
1215    pub related_information: Option<bool>,
1216}
1217
1218/**
1219 * Text document specific client capabilities.
1220 */
1221#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1222#[serde(rename_all = "camelCase")]
1223pub struct TextDocumentClientCapabilities {
1224    #[serde(skip_serializing_if = "Option::is_none")]
1225    pub synchronization: Option<SynchronizationCapability>,
1226    /**
1227     * Capabilities specific to the `textDocument/completion`
1228     */
1229    #[serde(skip_serializing_if = "Option::is_none")]
1230    pub completion: Option<CompletionCapability>,
1231
1232    /**
1233     * Capabilities specific to the `textDocument/hover`
1234     */
1235    #[serde(skip_serializing_if = "Option::is_none")]
1236    pub hover: Option<HoverCapability>,
1237
1238    /**
1239     * Capabilities specific to the `textDocument/signatureHelp`
1240     */
1241    #[serde(skip_serializing_if = "Option::is_none")]
1242    pub signature_help: Option<SignatureHelpCapability>,
1243
1244    /**
1245     * Capabilities specific to the `textDocument/references`
1246     */
1247    #[serde(skip_serializing_if = "Option::is_none")]
1248    pub references: Option<GenericCapability>,
1249
1250    /**
1251     * Capabilities specific to the `textDocument/documentHighlight`
1252     */
1253    #[serde(skip_serializing_if = "Option::is_none")]
1254    pub document_highlight: Option<GenericCapability>,
1255
1256    /**
1257     * Capabilities specific to the `textDocument/documentSymbol`
1258     */
1259    #[serde(skip_serializing_if = "Option::is_none")]
1260    pub document_symbol: Option<DocumentSymbolCapability>,
1261    /**
1262     * Capabilities specific to the `textDocument/formatting`
1263     */
1264    #[serde(skip_serializing_if = "Option::is_none")]
1265    pub formatting: Option<GenericCapability>,
1266
1267    /**
1268     * Capabilities specific to the `textDocument/rangeFormatting`
1269     */
1270    #[serde(skip_serializing_if = "Option::is_none")]
1271    pub range_formatting: Option<GenericCapability>,
1272
1273    /**
1274     * Capabilities specific to the `textDocument/onTypeFormatting`
1275     */
1276    #[serde(skip_serializing_if = "Option::is_none")]
1277    pub on_type_formatting: Option<GenericCapability>,
1278
1279    /**
1280     * Capabilities specific to the `textDocument/declaration`
1281     */
1282    #[serde(skip_serializing_if = "Option::is_none")]
1283    pub declaration: Option<GotoCapability>,
1284
1285    /**
1286     * Capabilities specific to the `textDocument/definition`
1287     */
1288    #[serde(skip_serializing_if = "Option::is_none")]
1289    pub definition: Option<GotoCapability>,
1290
1291    /**
1292     * Capabilities specific to the `textDocument/typeDefinition`
1293     */
1294    #[serde(skip_serializing_if = "Option::is_none")]
1295    pub type_definition: Option<GotoCapability>,
1296
1297    /**
1298     * Capabilities specific to the `textDocument/implementation`
1299     */
1300    #[serde(skip_serializing_if = "Option::is_none")]
1301    pub implementation: Option<GotoCapability>,
1302
1303    /**
1304     * Capabilities specific to the `textDocument/codeAction`
1305     */
1306    #[serde(skip_serializing_if = "Option::is_none")]
1307    pub code_action: Option<CodeActionCapability>,
1308
1309    /**
1310     * Capabilities specific to the `textDocument/codeLens`
1311     */
1312    #[serde(skip_serializing_if = "Option::is_none")]
1313    pub code_lens: Option<GenericCapability>,
1314
1315    /**
1316     * Capabilities specific to the `textDocument/documentLink`
1317     */
1318    #[serde(skip_serializing_if = "Option::is_none")]
1319    pub document_link: Option<GenericCapability>,
1320
1321    /**
1322     * Capabilities specific to the `textDocument/documentColor` and the
1323     * `textDocument/colorPresentation` request.
1324     */
1325    pub color_provider: Option<GenericCapability>,
1326
1327    /**
1328     * Capabilities specific to the `textDocument/rename`
1329     */
1330    #[serde(skip_serializing_if = "Option::is_none")]
1331    pub rename: Option<RenameCapability>,
1332
1333    /**
1334     * Capabilities specific to `textDocument/publishDiagnostics`.
1335     */
1336    #[serde(skip_serializing_if = "Option::is_none")]
1337    pub publish_diagnostics: Option<PublishDiagnosticsCapability>,
1338
1339    /**
1340     * Capabilities specific to `textDocument/foldingRange` requests.
1341     */
1342    #[serde(skip_serializing_if = "Option::is_none")]
1343    pub folding_range: Option<FoldingRangeCapability>,
1344}
1345
1346/**
1347 * Where ClientCapabilities are currently empty:
1348 */
1349#[derive(Debug, PartialEq, Default, Deserialize, Serialize)]
1350#[serde(rename_all = "camelCase")]
1351pub struct ClientCapabilities {
1352    /**
1353     * Workspace specific client capabilities.
1354     */
1355    #[serde(skip_serializing_if = "Option::is_none")]
1356    pub workspace: Option<WorkspaceClientCapabilities>,
1357
1358    /**
1359     * Text document specific client capabilities.
1360     */
1361    #[serde(skip_serializing_if = "Option::is_none")]
1362    pub text_document: Option<TextDocumentClientCapabilities>,
1363
1364    /**
1365     * Experimental client capabilities.
1366     */
1367    #[serde(skip_serializing_if = "Option::is_none")]
1368    pub experimental: Option<Value>,
1369}
1370
1371#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1372pub struct InitializeResult {
1373    /// The capabilities the language server provides.
1374    pub capabilities: ServerCapabilities,
1375}
1376
1377#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1378pub struct InitializeError {
1379    /// Indicates whether the client should retry to send the
1380    /// initilize request after showing the message provided
1381    /// in the ResponseError.
1382    pub retry: bool,
1383}
1384
1385// The server can signal the following capabilities:
1386
1387/// Defines how the host (editor) should sync document changes to the language server.
1388#[derive(Debug, Eq, PartialEq, Clone, Copy)]
1389pub enum TextDocumentSyncKind {
1390    /// Documents should not be synced at all.
1391    None = 0,
1392
1393    /// Documents are synced by always sending the full content of the document.
1394    Full = 1,
1395
1396    /// Documents are synced by sending the full content on open. After that only
1397    /// incremental updates to the document are sent.
1398    Incremental = 2,
1399}
1400
1401impl<'de> serde::Deserialize<'de> for TextDocumentSyncKind {
1402    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1403    where
1404        D: serde::Deserializer<'de>,
1405    {
1406        Ok(match try!(u8::deserialize(deserializer)) {
1407            0 => TextDocumentSyncKind::None,
1408            1 => TextDocumentSyncKind::Full,
1409            2 => TextDocumentSyncKind::Incremental,
1410            i => {
1411                return Err(D::Error::invalid_value(
1412                    de::Unexpected::Unsigned(i as u64),
1413                    &"value between 0 and 2 (inclusive)",
1414                ));
1415            }
1416        })
1417    }
1418}
1419
1420impl serde::Serialize for TextDocumentSyncKind {
1421    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1422    where
1423        S: serde::Serializer,
1424    {
1425        serializer.serialize_u8(*self as u8)
1426    }
1427}
1428
1429/// Completion options.
1430#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1431#[serde(rename_all = "camelCase")]
1432pub struct CompletionOptions {
1433    /// The server provides support to resolve additional information for a completion item.
1434    #[serde(skip_serializing_if = "Option::is_none")]
1435    pub resolve_provider: Option<bool>,
1436
1437    /// The characters that trigger completion automatically.
1438    #[serde(skip_serializing_if = "Option::is_none")]
1439    pub trigger_characters: Option<Vec<String>>,
1440}
1441
1442/// Signature help options.
1443#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1444#[serde(rename_all = "camelCase")]
1445pub struct SignatureHelpOptions {
1446    /// The characters that trigger signature help automatically.
1447    #[serde(skip_serializing_if = "Option::is_none")]
1448    pub trigger_characters: Option<Vec<String>>,
1449}
1450
1451/// Code Lens options.
1452#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1453#[serde(rename_all = "camelCase")]
1454pub struct CodeLensOptions {
1455    /// Code lens has a resolve provider as well.
1456    #[serde(skip_serializing_if = "Option::is_none")]
1457    pub resolve_provider: Option<bool>,
1458}
1459
1460/// Format document on type options
1461#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1462#[serde(rename_all = "camelCase")]
1463pub struct DocumentOnTypeFormattingOptions {
1464    /// A character on which formatting should be triggered, like `}`.
1465    pub first_trigger_character: String,
1466
1467    /// More trigger characters.
1468    #[serde(skip_serializing_if = "Option::is_none")]
1469    pub more_trigger_character: Option<Vec<String>>,
1470}
1471
1472/// Execute command options.
1473#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1474pub struct ExecuteCommandOptions {
1475    /// The commands to be executed on the server
1476    pub commands: Vec<String>,
1477}
1478
1479/**
1480 * Save options.
1481 */
1482#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1483#[serde(rename_all = "camelCase")]
1484pub struct SaveOptions {
1485    /**
1486     * The client is supposed to include the content on save.
1487     */
1488    #[serde(skip_serializing_if = "Option::is_none")]
1489    pub include_text: Option<bool>,
1490}
1491
1492#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1493#[serde(rename_all = "camelCase")]
1494pub struct TextDocumentSyncOptions {
1495    /**
1496     * Open and close notifications are sent to the server.
1497     */
1498    #[serde(skip_serializing_if = "Option::is_none")]
1499    pub open_close: Option<bool>,
1500
1501    /**
1502     * Change notifications are sent to the server. See TextDocumentSyncKind.None, TextDocumentSyncKind.Full
1503     * and TextDocumentSyncKindIncremental.
1504     */
1505    #[serde(skip_serializing_if = "Option::is_none")]
1506    pub change: Option<TextDocumentSyncKind>,
1507
1508    /**
1509     * Will save notifications are sent to the server.
1510     */
1511    #[serde(skip_serializing_if = "Option::is_none")]
1512    pub will_save: Option<bool>,
1513
1514    /**
1515     * Will save wait until requests are sent to the server.
1516     */
1517    #[serde(skip_serializing_if = "Option::is_none")]
1518    pub will_save_wait_until: Option<bool>,
1519
1520    /**
1521     * Save notifications are sent to the server.
1522     */
1523    #[serde(skip_serializing_if = "Option::is_none")]
1524    pub save: Option<SaveOptions>,
1525}
1526
1527#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1528#[serde(untagged)]
1529pub enum TextDocumentSyncCapability {
1530    Kind(TextDocumentSyncKind),
1531    Options(TextDocumentSyncOptions),
1532}
1533
1534#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1535#[serde(untagged)]
1536pub enum ImplementationProviderCapability {
1537    Simple(bool),
1538    Options(StaticTextDocumentRegistrationOptions),
1539}
1540
1541#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1542#[serde(untagged)]
1543pub enum TypeDefinitionProviderCapability {
1544    Simple(bool),
1545    Options(StaticTextDocumentRegistrationOptions),
1546}
1547
1548#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1549#[serde(untagged)]
1550pub enum ColorProviderCapability {
1551    Simple(bool),
1552    ColorProvider(ColorProviderOptions),
1553    Options(StaticTextDocumentColorProviderOptions),
1554}
1555
1556#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1557#[serde(untagged)]
1558pub enum CodeActionProviderCapability {
1559    Simple(bool),
1560    Options(CodeActionOptions),
1561}
1562
1563#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1564#[serde(rename_all = "camelCase")]
1565pub struct CodeActionCapability {
1566    ///
1567    /// This capability supports dynamic registration.
1568    ///
1569    #[serde(skip_serializing_if = "Option::is_none")]
1570    pub dynamic_registration: Option<bool>,
1571
1572    /// The client support code action literals as a valid
1573    /// response of the `textDocument/codeAction` request.
1574    #[serde(skip_serializing_if = "Option::is_none")]
1575    pub code_action_literal_support: Option<CodeActionLiteralSupport>,
1576}
1577
1578#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1579#[serde(rename_all = "camelCase")]
1580pub struct CodeActionLiteralSupport {
1581    /// The code action kind is support with the following value set.
1582    pub code_action_kind: CodeActionKindLiteralSupport,
1583}
1584
1585#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1586#[serde(rename_all = "camelCase")]
1587pub struct CodeActionKindLiteralSupport {
1588    /// The code action kind values the client supports. When this
1589    /// property exists the client also guarantees that it will
1590    /// handle values outside its set gracefully and falls back
1591    /// to a default value when unknown.
1592    pub value_set: Vec<String>,
1593}
1594
1595#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
1596#[serde(rename_all = "camelCase")]
1597pub struct ServerCapabilities {
1598    /// Defines how text documents are synced.
1599    #[serde(skip_serializing_if = "Option::is_none")]
1600    pub text_document_sync: Option<TextDocumentSyncCapability>,
1601
1602    /// The server provides hover support.
1603    #[serde(skip_serializing_if = "Option::is_none")]
1604    pub hover_provider: Option<bool>,
1605
1606    /// The server provides completion support.
1607    #[serde(skip_serializing_if = "Option::is_none")]
1608    pub completion_provider: Option<CompletionOptions>,
1609
1610    /// The server provides signature help support.
1611    #[serde(skip_serializing_if = "Option::is_none")]
1612    pub signature_help_provider: Option<SignatureHelpOptions>,
1613
1614    /// The server provides goto definition support.
1615    #[serde(skip_serializing_if = "Option::is_none")]
1616    pub definition_provider: Option<bool>,
1617
1618    /// The server provides goto type definition support.
1619    #[serde(skip_serializing_if = "Option::is_none")]
1620    pub type_definition_provider: Option<TypeDefinitionProviderCapability>,
1621
1622    /// the server provides goto implementation support.
1623    #[serde(skip_serializing_if = "Option::is_none")]
1624    pub implementation_provider: Option<ImplementationProviderCapability>,
1625
1626    /// The server provides find references support.
1627    #[serde(skip_serializing_if = "Option::is_none")]
1628    pub references_provider: Option<bool>,
1629
1630    /// The server provides document highlight support.
1631    #[serde(skip_serializing_if = "Option::is_none")]
1632    pub document_highlight_provider: Option<bool>,
1633
1634    /// The server provides document symbol support.
1635    #[serde(skip_serializing_if = "Option::is_none")]
1636    pub document_symbol_provider: Option<bool>,
1637
1638    /// The server provides workspace symbol support.
1639    #[serde(skip_serializing_if = "Option::is_none")]
1640    pub workspace_symbol_provider: Option<bool>,
1641
1642    /// The server provides code actions.
1643    #[serde(skip_serializing_if = "Option::is_none")]
1644    pub code_action_provider: Option<CodeActionProviderCapability>,
1645
1646    /// The server provides code lens.
1647    #[serde(skip_serializing_if = "Option::is_none")]
1648    pub code_lens_provider: Option<CodeLensOptions>,
1649
1650    /// The server provides document formatting.
1651    #[serde(skip_serializing_if = "Option::is_none")]
1652    pub document_formatting_provider: Option<bool>,
1653
1654    /// The server provides document range formatting.
1655    #[serde(skip_serializing_if = "Option::is_none")]
1656    pub document_range_formatting_provider: Option<bool>,
1657
1658    /// The server provides document formatting on typing.
1659    #[serde(skip_serializing_if = "Option::is_none")]
1660    pub document_on_type_formatting_provider: Option<DocumentOnTypeFormattingOptions>,
1661
1662    /// The server provides rename support.
1663    #[serde(skip_serializing_if = "Option::is_none")]
1664    pub rename_provider: Option<RenameProviderCapability>,
1665
1666    /// The server provides color provider support.
1667    #[serde(skip_serializing_if = "Option::is_none")]
1668    pub color_provider: Option<ColorProviderCapability>,
1669
1670    /// The server provides folding provider support.
1671    #[serde(skip_serializing_if = "Option::is_none")]
1672    pub folding_range_provider: Option<FoldingRangeProviderCapability>,
1673
1674    /// The server provides execute command support.
1675    #[serde(skip_serializing_if = "Option::is_none")]
1676    pub execute_command_provider: Option<ExecuteCommandOptions>,
1677
1678    /// Workspace specific server capabilities
1679    #[serde(skip_serializing_if = "Option::is_none")]
1680    pub workspace: Option<WorkspaceCapability>,
1681}
1682
1683#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1684pub struct ShowMessageParams {
1685    /// The message type. See {@link MessageType}.
1686    #[serde(rename = "type")]
1687    pub typ: MessageType,
1688
1689    /// The actual message.
1690    pub message: String,
1691}
1692
1693#[derive(Debug, Eq, PartialEq, Clone, Copy)]
1694pub enum MessageType {
1695    /// An error message.
1696    Error = 1,
1697    /// A warning message.
1698    Warning = 2,
1699    /// An information message.
1700    Info = 3,
1701    /// A log message.
1702    Log = 4,
1703}
1704
1705impl<'de> serde::Deserialize<'de> for MessageType {
1706    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1707    where
1708        D: serde::Deserializer<'de>,
1709    {
1710        Ok(match try!(u8::deserialize(deserializer)) {
1711            1 => MessageType::Error,
1712            2 => MessageType::Warning,
1713            3 => MessageType::Info,
1714            4 => MessageType::Log,
1715            i => {
1716                return Err(D::Error::invalid_value(
1717                    de::Unexpected::Unsigned(i as u64),
1718                    &"value of 1, 2, 3 or 4",
1719                ));
1720            }
1721        })
1722    }
1723}
1724
1725impl serde::Serialize for MessageType {
1726    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1727    where
1728        S: serde::Serializer,
1729    {
1730        serializer.serialize_u8(*self as u8)
1731    }
1732}
1733
1734#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1735pub struct ShowMessageRequestParams {
1736    /// The message type. See {@link MessageType}
1737    #[serde(rename = "type")]
1738    pub typ: MessageType,
1739
1740    /// The actual message
1741    pub message: String,
1742
1743    /// The message action items to present.
1744    #[serde(skip_serializing_if = "Option::is_none")]
1745    pub actions: Option<Vec<MessageActionItem>>,
1746}
1747
1748#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1749pub struct MessageActionItem {
1750    /// A short title like 'Retry', 'Open Log' etc.
1751    pub title: String,
1752}
1753
1754#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1755pub struct LogMessageParams {
1756    /// The message type. See {@link MessageType}
1757    #[serde(rename = "type")]
1758    pub typ: MessageType,
1759
1760    /// The actual message
1761    pub message: String,
1762}
1763
1764/**
1765 * General parameters to to register for a capability.
1766 */
1767#[derive(Debug, PartialEq, Deserialize, Serialize)]
1768#[serde(rename_all = "camelCase")]
1769pub struct Registration {
1770    /**
1771     * The id used to register the request. The id can be used to deregister
1772     * the request again.
1773     */
1774    pub id: String,
1775
1776    /**
1777     * The method / capability to register for.
1778     */
1779    pub method: String,
1780
1781    /**
1782     * Options necessary for the registration.
1783     */
1784    #[serde(skip_serializing_if = "Option::is_none")]
1785    pub register_options: Option<Value>,
1786}
1787
1788#[derive(Debug, PartialEq, Deserialize, Serialize)]
1789pub struct RegistrationParams {
1790    pub registrations: Vec<Registration>,
1791}
1792
1793/// Since most of the registration options require to specify a document selector there is a base
1794/// interface that can be used.
1795#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1796#[serde(rename_all = "camelCase")]
1797pub struct TextDocumentRegistrationOptions {
1798    /**
1799     * A document selector to identify the scope of the registration. If set to null
1800     * the document selector provided on the client side will be used.
1801     */
1802    pub document_selector: Option<DocumentSelector>,
1803}
1804
1805#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1806#[serde(rename_all = "camelCase")]
1807pub struct StaticRegistrationOptions {
1808    #[serde(skip_serializing_if = "Option::is_none")]
1809    pub id: Option<String>,
1810}
1811
1812#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1813#[serde(rename_all = "camelCase")]
1814pub struct StaticTextDocumentRegistrationOptions {
1815    /**
1816     * A document selector to identify the scope of the registration. If set to null
1817     * the document selector provided on the client side will be used.
1818     */
1819    pub document_selector: Option<DocumentSelector>,
1820
1821    #[serde(skip_serializing_if = "Option::is_none")]
1822    pub id: Option<String>,
1823}
1824
1825#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1826#[serde(rename_all = "camelCase")]
1827pub struct ColorProviderOptions {}
1828
1829#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1830#[serde(rename_all = "camelCase")]
1831pub struct StaticTextDocumentColorProviderOptions {
1832    /**
1833     * A document selector to identify the scope of the registration. If set to null
1834     * the document selector provided on the client side will be used.
1835     */
1836    pub document_selector: Option<DocumentSelector>,
1837
1838    #[serde(skip_serializing_if = "Option::is_none")]
1839    pub id: Option<String>,
1840}
1841
1842/**
1843 * General parameters to unregister a capability.
1844 */
1845#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1846pub struct Unregistration {
1847    /**
1848     * The id used to unregister the request or notification. Usually an id
1849     * provided during the register request.
1850     */
1851    pub id: String,
1852
1853    /**
1854     * The method / capability to unregister for.
1855     */
1856    pub method: String,
1857}
1858
1859#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1860pub struct UnregistrationParams {
1861    pub unregisterations: Vec<Unregistration>,
1862}
1863
1864#[derive(Debug, PartialEq, Deserialize, Serialize)]
1865pub struct DidChangeConfigurationParams {
1866    /// The actual changed settings
1867    pub settings: Value,
1868}
1869
1870#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1871#[serde(rename_all = "camelCase")]
1872pub struct DidOpenTextDocumentParams {
1873    /// The document that was opened.
1874    pub text_document: TextDocumentItem,
1875}
1876
1877#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1878#[serde(rename_all = "camelCase")]
1879pub struct DidChangeTextDocumentParams {
1880    /// The document that did change. The version number points
1881    /// to the version after all provided content changes have
1882    /// been applied.
1883    pub text_document: VersionedTextDocumentIdentifier,
1884    /// The actual content changes.
1885    pub content_changes: Vec<TextDocumentContentChangeEvent>,
1886}
1887
1888/// An event describing a change to a text document. If range and rangeLength are omitted
1889/// the new text is considered to be the full content of the document.
1890#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1891#[serde(rename_all = "camelCase")]
1892pub struct TextDocumentContentChangeEvent {
1893    /// The range of the document that changed.
1894    #[serde(skip_serializing_if = "Option::is_none")]
1895    pub range: Option<Range>,
1896
1897    /// The length of the range that got replaced.
1898    /// NOTE: seems redundant, see: <https://github.com/Microsoft/language-server-protocol/issues/9>
1899    #[serde(skip_serializing_if = "Option::is_none")]
1900    pub range_length: Option<u64>,
1901
1902    /// The new text of the document.
1903    pub text: String,
1904}
1905
1906/**
1907 * Descibe options to be used when registered for text document change events.
1908 *
1909 * Extends TextDocumentRegistrationOptions
1910 */
1911#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1912#[serde(rename_all = "camelCase")]
1913pub struct TextDocumentChangeRegistrationOptions {
1914    /**
1915     * A document selector to identify the scope of the registration. If set to null
1916     * the document selector provided on the client side will be used.
1917     */
1918    pub document_selector: Option<DocumentSelector>,
1919
1920    /**
1921     * How documents are synced to the server. See TextDocumentSyncKind.Full
1922     * and TextDocumentSyncKindIncremental.
1923     */
1924    pub sync_kind: i32,
1925}
1926
1927/**
1928 * The parameters send in a will save text document notification.
1929 */
1930#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1931#[serde(rename_all = "camelCase")]
1932pub struct WillSaveTextDocumentParams {
1933    /**
1934     * The document that will be saved.
1935     */
1936    pub text_document: TextDocumentIdentifier,
1937
1938    /**
1939     * The 'TextDocumentSaveReason'.
1940     */
1941    pub reason: TextDocumentSaveReason,
1942}
1943
1944/**
1945 * Represents reasons why a text document is saved.
1946 */
1947#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1948pub enum TextDocumentSaveReason {
1949    /**
1950     * Manually triggered, e.g. by the user pressing save, by starting debugging,
1951     * or by an API call.
1952     */
1953    Manual = 1,
1954
1955    /**
1956     * Automatic after a delay.
1957     */
1958    AfterDelay = 2,
1959
1960    /**
1961     * When the editor lost focus.
1962     */
1963    FocusOut = 3,
1964}
1965
1966impl<'de> serde::Deserialize<'de> for TextDocumentSaveReason {
1967    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1968    where
1969        D: serde::Deserializer<'de>,
1970    {
1971        Ok(match try!(u8::deserialize(deserializer)) {
1972            1 => TextDocumentSaveReason::Manual,
1973            2 => TextDocumentSaveReason::AfterDelay,
1974            3 => TextDocumentSaveReason::FocusOut,
1975            i => {
1976                return Err(D::Error::invalid_value(
1977                    de::Unexpected::Unsigned(i as u64),
1978                    &"value of 1, 2 or 3",
1979                ))
1980            }
1981        })
1982    }
1983}
1984
1985impl serde::Serialize for TextDocumentSaveReason {
1986    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1987    where
1988        S: serde::Serializer,
1989    {
1990        serializer.serialize_u8(*self as u8)
1991    }
1992}
1993
1994#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
1995#[serde(rename_all = "camelCase")]
1996pub struct DidCloseTextDocumentParams {
1997    /// The document that was closed.
1998    pub text_document: TextDocumentIdentifier,
1999}
2000
2001#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2002#[serde(rename_all = "camelCase")]
2003pub struct DidSaveTextDocumentParams {
2004    /// The document that was saved.
2005    pub text_document: TextDocumentIdentifier,
2006}
2007
2008#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2009pub struct DidChangeWatchedFilesParams {
2010    /// The actual file events.
2011    pub changes: Vec<FileEvent>,
2012}
2013
2014/// The file event type.
2015#[derive(Debug, Eq, PartialEq, Copy, Clone)]
2016pub enum FileChangeType {
2017    /// The file got created.
2018    Created = 1,
2019
2020    /// The file got changed.
2021    Changed = 2,
2022
2023    /// The file got deleted.
2024    Deleted = 3,
2025}
2026
2027impl<'de> serde::Deserialize<'de> for FileChangeType {
2028    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
2029    where
2030        D: serde::Deserializer<'de>,
2031    {
2032        Ok(match try!(u8::deserialize(deserializer)) {
2033            1 => FileChangeType::Created,
2034            2 => FileChangeType::Changed,
2035            3 => FileChangeType::Deleted,
2036            i => {
2037                return Err(D::Error::invalid_value(
2038                    de::Unexpected::Unsigned(i as u64),
2039                    &"value of 1, 2 or 3",
2040                ))
2041            }
2042        })
2043    }
2044}
2045
2046impl serde::Serialize for FileChangeType {
2047    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2048    where
2049        S: serde::Serializer,
2050    {
2051        serializer.serialize_u8(*self as u8)
2052    }
2053}
2054
2055/// An event describing a file change.
2056#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2057pub struct FileEvent {
2058    /// The file's URI.
2059    #[serde(with = "url_serde")]
2060    pub uri: Url,
2061
2062    /// The change type.
2063    #[serde(rename = "type")]
2064    pub typ: FileChangeType,
2065}
2066
2067impl FileEvent {
2068    pub fn new(uri: Url, typ: FileChangeType) -> FileEvent {
2069        FileEvent { uri: uri, typ: typ }
2070    }
2071}
2072
2073/// Describe options to be used when registered for text document change events.
2074#[derive(Debug, Deserialize, Serialize)]
2075pub struct DidChangeWatchedFilesRegistrationOptions {
2076    /// The watchers to register.
2077    pub watchers: Vec<FileSystemWatcher>,
2078}
2079
2080#[derive(Debug, Deserialize, Serialize)]
2081#[serde(rename_all = "camelCase")]
2082pub struct FileSystemWatcher {
2083    /// The  glob pattern to watch
2084    pub glob_pattern: String,
2085
2086    /// The kind of events of interest. If omitted it defaults to WatchKind.Create |
2087    /// WatchKind.Change | WatchKind.Delete which is 7.
2088    #[serde(skip_serializing_if = "Option::is_none")]
2089    pub kind: Option<WatchKind>,
2090}
2091
2092bitflags! {
2093pub struct WatchKind: u8 {
2094    /// Interested in create events.
2095    const Create = 1;
2096    /// Interested in change events
2097    const Change = 2;
2098    /// Interested in delete events
2099    const Delete = 4;
2100}
2101}
2102
2103impl<'de> serde::Deserialize<'de> for WatchKind {
2104    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
2105    where
2106        D: serde::Deserializer<'de>,
2107    {
2108        let i = try!(u8::deserialize(deserializer));
2109        WatchKind::from_bits(i).ok_or_else(|| {
2110            D::Error::invalid_value(de::Unexpected::Unsigned(i as u64), &"Unknown flag")
2111        })
2112    }
2113}
2114
2115impl serde::Serialize for WatchKind {
2116    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2117    where
2118        S: serde::Serializer,
2119    {
2120        serializer.serialize_u8(self.bits())
2121    }
2122}
2123
2124#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2125pub struct PublishDiagnosticsParams {
2126    /// The URI for which diagnostic information is reported.
2127    #[serde(with = "url_serde")]
2128    pub uri: Url,
2129
2130    /// An array of diagnostic information items.
2131    pub diagnostics: Vec<Diagnostic>,
2132}
2133
2134impl PublishDiagnosticsParams {
2135    pub fn new(uri: Url, diagnostics: Vec<Diagnostic>) -> PublishDiagnosticsParams {
2136        PublishDiagnosticsParams {
2137            uri: uri,
2138            diagnostics: diagnostics,
2139        }
2140    }
2141}
2142
2143#[derive(Debug, PartialEq, Serialize, Deserialize)]
2144#[serde(untagged)]
2145pub enum CompletionResponse {
2146    Array(Vec<CompletionItem>),
2147    List(CompletionList),
2148}
2149
2150#[derive(Debug, PartialEq, Deserialize, Serialize)]
2151#[serde(rename_all = "camelCase")]
2152pub struct CompletionParams {
2153    // This field was "mixed-in" from TextDocumentPositionParams
2154    /// The text document.
2155    pub text_document: TextDocumentIdentifier,
2156
2157    // This field was "mixed-in" from TextDocumentPositionParams
2158    /// The position inside the text document.
2159    pub position: Position,
2160
2161    // CompletionParams properties:
2162    #[serde(skip_serializing_if = "Option::is_none")]
2163    pub context: Option<CompletionContext>,
2164}
2165
2166#[derive(Debug, PartialEq, Deserialize, Serialize)]
2167#[serde(rename_all = "camelCase")]
2168pub struct CompletionContext {
2169    /**
2170     * How the completion was triggered.
2171     */
2172    pub trigger_kind: CompletionTriggerKind,
2173
2174    /**
2175     * The trigger character (a single character) that has trigger code complete.
2176     * Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter`
2177     */
2178    #[serde(skip_serializing_if = "Option::is_none")]
2179    pub trigger_character: Option<String>,
2180}
2181
2182/// How a completion was triggered.
2183#[derive(Debug, PartialEq, Clone, Copy, FromPrimitive)]
2184pub enum CompletionTriggerKind {
2185    Invoked = 1,
2186    TriggerCharacter = 2,
2187    TriggerForIncompleteCompletions = 3,
2188}
2189
2190impl<'de> serde::Deserialize<'de> for CompletionTriggerKind {
2191    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
2192    where
2193        D: serde::Deserializer<'de>,
2194    {
2195        let i = try!(u8::deserialize(deserializer));
2196        CompletionTriggerKind::from_u8(i).ok_or_else(|| {
2197            D::Error::invalid_value(
2198                de::Unexpected::Unsigned(i as u64),
2199                &"value between 1 and 3 (inclusive)",
2200            )
2201        })
2202    }
2203}
2204
2205impl serde::Serialize for CompletionTriggerKind {
2206    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2207    where
2208        S: serde::Serializer,
2209    {
2210        serializer.serialize_u8(*self as u8)
2211    }
2212}
2213
2214/// Represents a collection of [completion items](#CompletionItem) to be presented
2215/// in the editor.
2216#[derive(Debug, PartialEq, Default, Deserialize, Serialize)]
2217#[serde(rename_all = "camelCase")]
2218pub struct CompletionList {
2219    /// This list it not complete. Further typing should result in recomputing
2220    /// this list.
2221    pub is_incomplete: bool,
2222
2223    /// The completion items.
2224    pub items: Vec<CompletionItem>,
2225}
2226
2227#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)]
2228#[serde(untagged)]
2229pub enum Documentation {
2230    String(String),
2231    MarkupContent(MarkupContent),
2232}
2233
2234#[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
2235#[serde(rename_all = "camelCase")]
2236pub struct CompletionItem {
2237    /// The label of this completion item. By default
2238    /// also the text that is inserted when selecting
2239    /// this completion.
2240    pub label: String,
2241
2242    /// The kind of this completion item. Based of the kind
2243    /// an icon is chosen by the editor.
2244    #[serde(skip_serializing_if = "Option::is_none")]
2245    pub kind: Option<CompletionItemKind>,
2246
2247    /// A human-readable string with additional information
2248    /// about this item, like type or symbol information.
2249    #[serde(skip_serializing_if = "Option::is_none")]
2250    pub detail: Option<String>,
2251
2252    /// A human-readable string that represents a doc-comment.
2253    #[serde(skip_serializing_if = "Option::is_none")]
2254    pub documentation: Option<Documentation>,
2255
2256    /// Indicates if this item is deprecated.
2257    #[serde(skip_serializing_if = "Option::is_none")]
2258    pub deprecated: Option<bool>,
2259
2260    /// Select this item when showing.
2261    #[serde(skip_serializing_if = "Option::is_none")]
2262    pub preselect: Option<bool>,
2263
2264    /// A string that shoud be used when comparing this item
2265    /// with other items. When `falsy` the label is used.
2266    #[serde(skip_serializing_if = "Option::is_none")]
2267    pub sort_text: Option<String>,
2268
2269    /// A string that should be used when filtering a set of
2270    /// completion items. When `falsy` the label is used.
2271    #[serde(skip_serializing_if = "Option::is_none")]
2272    pub filter_text: Option<String>,
2273
2274    /// A string that should be inserted a document when selecting
2275    /// this completion. When `falsy` the label is used.
2276    #[serde(skip_serializing_if = "Option::is_none")]
2277    pub insert_text: Option<String>,
2278
2279    /// The format of the insert text. The format applies to both the `insertText` property
2280    /// and the `newText` property of a provided `textEdit`.
2281    #[serde(skip_serializing_if = "Option::is_none")]
2282    pub insert_text_format: Option<InsertTextFormat>,
2283
2284    /// An edit which is applied to a document when selecting
2285    /// this completion. When an edit is provided the value of
2286    /// insertText is ignored.
2287    #[serde(skip_serializing_if = "Option::is_none")]
2288    pub text_edit: Option<TextEdit>,
2289
2290    /// An optional array of additional text edits that are applied when
2291    /// selecting this completion. Edits must not overlap with the main edit
2292    /// nor with themselves.
2293    #[serde(skip_serializing_if = "Option::is_none")]
2294    pub additional_text_edits: Option<Vec<TextEdit>>,
2295
2296    /// An optional command that is executed *after* inserting this completion. *Note* that
2297    /// additional modifications to the current document should be described with the
2298    /// additionalTextEdits-property.
2299    #[serde(skip_serializing_if = "Option::is_none")]
2300    pub command: Option<Command>,
2301
2302    /// An data entry field that is preserved on a completion item between
2303    /// a completion and a completion resolve request.
2304    #[serde(skip_serializing_if = "Option::is_none")]
2305    pub data: Option<Value>,
2306}
2307
2308impl CompletionItem {
2309    /// Create a CompletionItem with the minimum possible info (label and detail).
2310    pub fn new_simple(label: String, detail: String) -> CompletionItem {
2311        CompletionItem {
2312            label: label,
2313            detail: Some(detail),
2314            ..Self::default()
2315        }
2316    }
2317}
2318
2319/// The kind of a completion entry.
2320#[derive(Debug, Eq, PartialEq, Clone, Copy, FromPrimitive)]
2321pub enum CompletionItemKind {
2322    Text = 1,
2323    Method = 2,
2324    Function = 3,
2325    Constructor = 4,
2326    Field = 5,
2327    Variable = 6,
2328    Class = 7,
2329    Interface = 8,
2330    Module = 9,
2331    Property = 10,
2332    Unit = 11,
2333    Value = 12,
2334    Enum = 13,
2335    Keyword = 14,
2336    Snippet = 15,
2337    Color = 16,
2338    File = 17,
2339    Reference = 18,
2340    Folder = 19,
2341    EnumMember = 20,
2342    Constant = 21,
2343    Struct = 22,
2344    Event = 23,
2345    Operator = 24,
2346    TypeParameter = 25,
2347}
2348
2349impl<'de> serde::Deserialize<'de> for CompletionItemKind {
2350    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
2351    where
2352        D: serde::Deserializer<'de>,
2353    {
2354        let i = try!(u8::deserialize(deserializer));
2355        CompletionItemKind::from_u8(i).ok_or_else(|| {
2356            D::Error::invalid_value(
2357                de::Unexpected::Unsigned(i as u64),
2358                &"value between 1 and 18 (inclusive)",
2359            )
2360        })
2361    }
2362}
2363
2364impl serde::Serialize for CompletionItemKind {
2365    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2366    where
2367        S: serde::Serializer,
2368    {
2369        serializer.serialize_u8(*self as u8)
2370    }
2371}
2372
2373/// Defines how to interpret the insert text in a completion item
2374#[derive(Debug, Eq, PartialEq, Clone, Copy, FromPrimitive)]
2375pub enum InsertTextFormat {
2376    PlainText = 1,
2377    Snippet = 2,
2378}
2379
2380impl<'de> serde::Deserialize<'de> for InsertTextFormat {
2381    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
2382    where
2383        D: serde::Deserializer<'de>,
2384    {
2385        let i = try!(u8::deserialize(deserializer));
2386        InsertTextFormat::from_u8(i).ok_or_else(|| {
2387            D::Error::invalid_value(
2388                de::Unexpected::Unsigned(i as u64),
2389                &"value between 1 and 2 (inclusive)",
2390            )
2391        })
2392    }
2393}
2394
2395impl serde::Serialize for InsertTextFormat {
2396    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2397    where
2398        S: serde::Serializer,
2399    {
2400        serializer.serialize_u8(*self as u8)
2401    }
2402}
2403
2404/// The result of a hover request.
2405#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
2406pub struct Hover {
2407    /// The hover's content
2408    pub contents: HoverContents,
2409    /// An optional range is a range inside a text document
2410    /// that is used to visualize a hover, e.g. by changing the background color.
2411    #[serde(skip_serializing_if = "Option::is_none")]
2412    pub range: Option<Range>,
2413}
2414
2415/**
2416 * Hover contents could be single entry or multiple entries.
2417 */
2418#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
2419#[serde(untagged)]
2420pub enum HoverContents {
2421    Scalar(MarkedString),
2422    Array(Vec<MarkedString>),
2423    Markup(MarkupContent),
2424}
2425
2426/**
2427 The marked string is rendered:
2428 - as markdown if it is represented as a string
2429 - as code block of the given langauge if it is represented as a pair of a language and a value
2430
2431 The pair of a language and a value is an equivalent to markdown:
2432     ```${language}
2433     ${value}
2434     ```
2435 */
2436#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
2437#[serde(untagged)]
2438pub enum MarkedString {
2439    String(String),
2440    LanguageString(LanguageString),
2441}
2442
2443#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
2444pub struct LanguageString {
2445    pub language: String,
2446    pub value: String,
2447}
2448
2449impl MarkedString {
2450    pub fn from_markdown(markdown: String) -> MarkedString {
2451        MarkedString::String(markdown)
2452    }
2453
2454    pub fn from_language_code(language: String, code_block: String) -> MarkedString {
2455        MarkedString::LanguageString(LanguageString {
2456            language: language,
2457            value: code_block,
2458        })
2459    }
2460}
2461
2462/// Signature help represents the signature of something
2463/// callable. There can be multiple signature but only one
2464/// active and only one active parameter.
2465#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2466#[serde(rename_all = "camelCase")]
2467pub struct SignatureHelp {
2468    /// One or more signatures.
2469    pub signatures: Vec<SignatureInformation>,
2470
2471    /// The active signature.
2472    #[serde(skip_serializing_if = "Option::is_none")]
2473    pub active_signature: Option<u64>,
2474
2475    /// The active parameter of the active signature.
2476    #[serde(skip_serializing_if = "Option::is_none")]
2477    pub active_parameter: Option<u64>,
2478}
2479
2480/// Represents the signature of something callable. A signature
2481/// can have a label, like a function-name, a doc-comment, and
2482/// a set of parameters.
2483#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2484pub struct SignatureInformation {
2485    /// The label of this signature. Will be shown in
2486    /// the UI.
2487    pub label: String,
2488
2489    /// The human-readable doc-comment of this signature. Will be shown
2490    /// in the UI but can be omitted.
2491    #[serde(skip_serializing_if = "Option::is_none")]
2492    pub documentation: Option<Documentation>,
2493
2494    /// The parameters of this signature.
2495    #[serde(skip_serializing_if = "Option::is_none")]
2496    pub parameters: Option<Vec<ParameterInformation>>,
2497}
2498
2499/// Represents a parameter of a callable-signature. A parameter can
2500/// have a label and a doc-comment.
2501#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2502pub struct ParameterInformation {
2503    /// The label of this parameter information.
2504    ///
2505    /// Either a string or an inclusive start and exclusive end offsets within its containing
2506    /// signature label. (see SignatureInformation.label). *Note*: A label of type string must be
2507    /// a substring of its containing signature label.
2508    pub label: ParameterLabel,
2509
2510    /// The human-readable doc-comment of this parameter. Will be shown
2511    /// in the UI but can be omitted.
2512    #[serde(skip_serializing_if = "Option::is_none")]
2513    pub documentation: Option<Documentation>,
2514}
2515
2516#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2517#[serde(untagged)]
2518pub enum ParameterLabel {
2519    Simple(String),
2520    LabelOffsets([u64; 2]),
2521}
2522
2523#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2524#[serde(rename_all = "camelCase")]
2525pub struct ReferenceParams {
2526    // This field was "mixed-in" from TextDocumentPositionParams
2527    /// The text document.
2528    pub text_document: TextDocumentIdentifier,
2529
2530    // This field was "mixed-in" from TextDocumentPositionParams
2531    /// The position inside the text document.
2532    pub position: Position,
2533
2534    // ReferenceParams properties:
2535    pub context: ReferenceContext,
2536}
2537
2538#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2539#[serde(rename_all = "camelCase")]
2540pub struct ReferenceContext {
2541    /// Include the declaration of the current symbol.
2542    pub include_declaration: bool,
2543}
2544
2545/// A document highlight is a range inside a text document which deserves
2546/// special attention. Usually a document highlight is visualized by changing
2547/// the background color of its range.
2548#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2549pub struct DocumentHighlight {
2550    /// The range this highlight applies to.
2551    pub range: Range,
2552
2553    /// The highlight kind, default is DocumentHighlightKind.Text.
2554    #[serde(skip_serializing_if = "Option::is_none")]
2555    pub kind: Option<DocumentHighlightKind>,
2556}
2557
2558/// A document highlight kind.
2559#[derive(Debug, Eq, PartialEq, Copy, Clone)]
2560pub enum DocumentHighlightKind {
2561    /// A textual occurrance.
2562    Text = 1,
2563
2564    /// Read-access of a symbol, like reading a variable.
2565    Read = 2,
2566
2567    /// Write-access of a symbol, like writing to a variable.
2568    Write = 3,
2569}
2570
2571impl<'de> serde::Deserialize<'de> for DocumentHighlightKind {
2572    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
2573    where
2574        D: serde::Deserializer<'de>,
2575    {
2576        Ok(match try!(u8::deserialize(deserializer)) {
2577            1 => DocumentHighlightKind::Text,
2578            2 => DocumentHighlightKind::Read,
2579            3 => DocumentHighlightKind::Write,
2580            i => {
2581                return Err(D::Error::invalid_value(
2582                    de::Unexpected::Unsigned(i as u64),
2583                    &"1, 2, or 3",
2584                ))
2585            }
2586        })
2587    }
2588}
2589
2590impl serde::Serialize for DocumentHighlightKind {
2591    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2592    where
2593        S: serde::Serializer,
2594    {
2595        serializer.serialize_u8(*self as u8)
2596    }
2597}
2598
2599#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
2600#[serde(rename_all = "camelCase")]
2601pub struct DocumentSymbolCapability {
2602    /// This capability supports dynamic registration.
2603    #[serde(skip_serializing_if = "Option::is_none")]
2604    pub dynamic_registration: Option<bool>,
2605
2606    /// Specific capabilities for the `SymbolKind`.
2607    #[serde(skip_serializing_if = "Option::is_none")]
2608    pub symbol_kind: Option<SymbolKindCapability>,
2609
2610    /// The client support hierarchical document symbols.
2611    #[serde(skip_serializing_if = "Option::is_none")]
2612    pub hierarchical_document_symbol_support: Option<bool>,
2613}
2614
2615#[derive(Debug, PartialEq, Serialize, Deserialize)]
2616#[serde(untagged)]
2617pub enum DocumentSymbolResponse {
2618    Flat(Vec<SymbolInformation>),
2619    Nested(Vec<DocumentSymbol>),
2620}
2621
2622#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2623#[serde(rename_all = "camelCase")]
2624pub struct DocumentSymbolParams {
2625    /// The text document.
2626    pub text_document: TextDocumentIdentifier,
2627}
2628
2629/// Represents programming constructs like variables, classes, interfaces etc.
2630/// that appear in a document. Document symbols can be hierarchical and they have two ranges:
2631/// one that encloses its definition and one that points to its most interesting range,
2632/// e.g. the range of an identifier.
2633#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2634#[serde(rename_all = "camelCase")]
2635pub struct DocumentSymbol {
2636    /// The name of this symbol.
2637    pub name: String,
2638    /// More detail for this symbol, e.g the signature of a function. If not provided the
2639    /// name is used.
2640    #[serde(skip_serializing_if = "Option::is_none")]
2641    pub detail: Option<String>,
2642    /// The kind of this symbol.
2643    pub kind: SymbolKind,
2644    /// Indicates if this symbol is deprecated.
2645    #[serde(skip_serializing_if = "Option::is_none")]
2646    pub deprecated: Option<bool>,
2647    /// The range enclosing this symbol not including leading/trailing whitespace but everything else
2648    /// like comments. This information is typically used to determine if the the clients cursor is
2649    /// inside the symbol to reveal in the symbol in the UI.
2650    pub range: Range,
2651    /// The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
2652    /// Must be contained by the the `range`.
2653    pub selection_range: Range,
2654    /// Children of this symbol, e.g. properties of a class.
2655    #[serde(skip_serializing_if = "Option::is_none")]
2656    pub children: Option<Vec<DocumentSymbol>>,
2657}
2658
2659/// Represents information about programming constructs like variables, classes,
2660/// interfaces etc.
2661#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2662#[serde(rename_all = "camelCase")]
2663pub struct SymbolInformation {
2664    /// The name of this symbol.
2665    pub name: String,
2666
2667    /// The kind of this symbol.
2668    pub kind: SymbolKind,
2669
2670    /// Indicates if this symbol is deprecated.
2671    #[serde(skip_serializing_if = "Option::is_none")]
2672    pub deprecated: Option<bool>,
2673
2674    /// The location of this symbol.
2675    pub location: Location,
2676
2677    /// The name of the symbol containing this symbol.
2678    #[serde(skip_serializing_if = "Option::is_none")]
2679    pub container_name: Option<String>,
2680}
2681
2682/// A symbol kind.
2683#[derive(Debug, Eq, PartialEq, Copy, Clone, FromPrimitive)]
2684pub enum SymbolKind {
2685    File = 1,
2686    Module = 2,
2687    Namespace = 3,
2688    Package = 4,
2689    Class = 5,
2690    Method = 6,
2691    Property = 7,
2692    Field = 8,
2693    Constructor = 9,
2694    Enum = 10,
2695    Interface = 11,
2696    Function = 12,
2697    Variable = 13,
2698    Constant = 14,
2699    String = 15,
2700    Number = 16,
2701    Boolean = 17,
2702    Array = 18,
2703    Object = 19,
2704    Key = 20,
2705    Null = 21,
2706    EnumMember = 22,
2707    Struct = 23,
2708    Event = 24,
2709    Operator = 25,
2710    TypeParameter = 26,
2711
2712    // Capturing all unknown enums by this lib.
2713    Unknown = 255,
2714}
2715
2716impl<'de> serde::Deserialize<'de> for SymbolKind {
2717    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
2718    where
2719        D: serde::Deserializer<'de>,
2720    {
2721        let i = try!(u8::deserialize(deserializer));
2722        Ok(SymbolKind::from_u8(i).unwrap_or(SymbolKind::Unknown))
2723    }
2724}
2725
2726impl serde::Serialize for SymbolKind {
2727    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2728    where
2729        S: serde::Serializer,
2730    {
2731        serializer.serialize_u8(*self as u8)
2732    }
2733}
2734
2735/// The parameters of a Workspace Symbol Request.
2736#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2737pub struct WorkspaceSymbolParams {
2738    /// A non-empty query string
2739    pub query: String,
2740}
2741
2742#[derive(Debug, PartialEq, Deserialize, Serialize)]
2743pub struct ExecuteCommandParams {
2744    /**
2745     * The identifier of the actual command handler.
2746     */
2747    pub command: String,
2748    /**
2749     * Arguments that the command should be invoked with.
2750     */
2751    #[serde(default)]
2752    pub arguments: Vec<Value>,
2753}
2754
2755/**
2756 * Execute command registration options.
2757 */
2758#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2759pub struct ExecuteCommandRegistrationOptions {
2760    /**
2761     * The commands to be executed on the server
2762     */
2763    pub commands: Vec<String>,
2764}
2765
2766#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2767pub struct ApplyWorkspaceEditParams {
2768    /**
2769     * The edits to apply.
2770     */
2771    pub edit: WorkspaceEdit,
2772}
2773
2774#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2775pub struct ApplyWorkspaceEditResponse {
2776    /**
2777     * Indicates whether the edit was applied or not.
2778     */
2779    pub applied: bool,
2780}
2781
2782/// Params for the CodeActionRequest
2783#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2784#[serde(rename_all = "camelCase")]
2785pub struct CodeActionParams {
2786    /// The document in which the command was invoked.
2787    pub text_document: TextDocumentIdentifier,
2788
2789    /// The range for which the command was invoked.
2790    pub range: Range,
2791
2792    /// Context carrying additional information.
2793    pub context: CodeActionContext,
2794}
2795
2796/// response for CodeActionRequest
2797#[derive(Debug, Deserialize, Serialize)]
2798#[serde(untagged)]
2799pub enum CodeActionResponse {
2800    Commands(Vec<Command>),
2801    Actions(Vec<CodeAction>),
2802}
2803
2804/**
2805 * A set of predefined code action kinds
2806 */
2807pub mod code_action_kind {
2808
2809    /**
2810     * Base kind for quickfix actions: 'quickfix'
2811     */
2812    pub const QUICKFIX: &'static str = "quickfix";
2813
2814    /**
2815     * Base kind for refactoring actions: 'refactor'
2816     */
2817    pub const REFACTOR: &'static str = "refactor";
2818
2819    /**
2820     * Base kind for refactoring extraction actions: 'refactor.extract'
2821     *
2822     * Example extract actions:
2823     *
2824     * - Extract method
2825     * - Extract function
2826     * - Extract variable
2827     * - Extract interface from class
2828     * - ...
2829     */
2830    pub const REFACTOR_EXTRACT: &'static str = "refactor.extract";
2831
2832    /**
2833     * Base kind for refactoring inline actions: 'refactor.inline'
2834     *
2835     * Example inline actions:
2836     *
2837     * - Inline function
2838     * - Inline variable
2839     * - Inline constant
2840     * - ...
2841     */
2842    pub const REFACTOR_INLINE: &'static str = "refactor.inline";
2843
2844    /**
2845     * Base kind for refactoring rewrite actions: 'refactor.rewrite'
2846     *
2847     * Example rewrite actions:
2848     *
2849     * - Convert JavaScript function to class
2850     * - Add or remove parameter
2851     * - Encapsulate field
2852     * - Make method static
2853     * - Move method to base class
2854     * - ...
2855     */
2856    pub const REFACTOR_REWRITE: &'static str = "refactor.rewrite";
2857
2858    /**
2859     * Base kind for source actions: `source`
2860     *
2861     * Source code actions apply to the entire file.
2862     */
2863    pub const SOURCE: &'static str = "source";
2864
2865    /**
2866     * Base kind for an organize imports source action: `source.organizeImports`
2867     */
2868    pub const SOURCE_ORGANIZE_IMPORTS: &'static str = "source.organizeImports";
2869}
2870
2871#[derive(Debug, PartialEq, Deserialize, Serialize)]
2872pub struct CodeAction {
2873    /// A short, human-readable, title for this code action.
2874    pub title: String,
2875
2876    /// The kind of the code action.
2877    /// Used to filter code actions.
2878    #[serde(skip_serializing_if = "Option::is_none")]
2879    pub kind: Option<String>,
2880
2881    /// The diagnostics that this code action resolves.
2882    #[serde(skip_serializing_if = "Option::is_none")]
2883    pub diagnostics: Option<Vec<Diagnostic>>,
2884
2885    /// The workspace edit this code action performs.
2886    #[serde(skip_serializing_if = "Option::is_none")]
2887    pub edit: Option<WorkspaceEdit>,
2888
2889    /// A command this code action executes. If a code action
2890    /// provides an edit and a command, first the edit is
2891    /// executed and then the command.
2892    #[serde(skip_serializing_if = "Option::is_none")]
2893    pub command: Option<Command>,
2894}
2895
2896/// Contains additional diagnostic information about the context in which
2897/// a code action is run.
2898#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2899pub struct CodeActionContext {
2900    /// An array of diagnostics.
2901    pub diagnostics: Vec<Diagnostic>,
2902
2903    /// Requested kind of actions to return.
2904    ///
2905    /// Actions not of this kind are filtered out by the client before being shown. So servers
2906    /// can omit computing them.
2907    #[serde(skip_serializing_if = "Option::is_none")]
2908    pub only: Option<Vec<String>>,
2909}
2910
2911#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2912#[serde(rename_all = "camelCase")]
2913pub struct CodeActionOptions {
2914    /**
2915     * CodeActionKinds that this server may return.
2916     *
2917     * The list of kinds may be generic, such as `CodeActionKind.Refactor`, or the server
2918     * may list out every specific kind they provide.
2919     */
2920    #[serde(skip_serializing_if = "Option::is_none")]
2921    pub code_action_kinds: Option<Vec<String>>,
2922}
2923
2924#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2925#[serde(rename_all = "camelCase")]
2926pub struct CodeLensParams {
2927    /// The document to request code lens for.
2928    pub text_document: TextDocumentIdentifier,
2929}
2930
2931/// A code lens represents a command that should be shown along with
2932/// source text, like the number of references, a way to run tests, etc.
2933///
2934/// A code lens is _unresolved_ when no command is associated to it. For performance
2935/// reasons the creation of a code lens and resolving should be done in two stages.
2936#[derive(Debug, PartialEq, Deserialize, Serialize)]
2937pub struct CodeLens {
2938    /// The range in which this code lens is valid. Should only span a single line.
2939    pub range: Range,
2940
2941    /// The command this code lens represents.
2942    #[serde(skip_serializing_if = "Option::is_none")]
2943    pub command: Option<Command>,
2944
2945    /// A data entry field that is preserved on a code lens item between
2946    /// a code lens and a code lens resolve request.
2947    #[serde(skip_serializing_if = "Option::is_none")]
2948    pub data: Option<Value>,
2949}
2950
2951#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2952#[serde(rename_all = "camelCase")]
2953pub struct DocumentLinkParams {
2954    /**
2955     * The document to provide document links for.
2956     */
2957    pub text_document: TextDocumentIdentifier,
2958}
2959
2960/**
2961 * A document link is a range in a text document that links to an internal or external resource, like another
2962 * text document or a web site.
2963 */
2964#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
2965pub struct DocumentLink {
2966    /**
2967     * The range this link applies to.
2968     */
2969    pub range: Range,
2970    /**
2971     * The uri this link points to.
2972     */
2973    #[serde(with = "url_serde")]
2974    pub target: Url,
2975}
2976
2977#[derive(Debug, PartialEq, Deserialize, Serialize)]
2978#[serde(rename_all = "camelCase")]
2979pub struct DocumentFormattingParams {
2980    /// The document to format.
2981    pub text_document: TextDocumentIdentifier,
2982
2983    /// The format options.
2984    pub options: FormattingOptions,
2985}
2986
2987/// Value-object describing what options formatting should use.
2988#[derive(Debug, PartialEq, Serialize, Deserialize)]
2989#[serde(rename_all = "camelCase")]
2990pub struct FormattingOptions {
2991    /// Size of a tab in spaces.
2992    pub tab_size: u64,
2993
2994    /// Prefer spaces over tabs.
2995    pub insert_spaces: bool,
2996
2997    /// Signature for further properties.
2998    #[serde(flatten)]
2999    pub properties: HashMap<String, FormattingProperty>,
3000}
3001
3002#[derive(Debug, PartialEq, Deserialize, Serialize)]
3003#[serde(untagged)]
3004pub enum FormattingProperty {
3005    Bool(bool),
3006    Number(f64),
3007    String(String),
3008}
3009
3010#[derive(Debug, PartialEq, Deserialize, Serialize)]
3011#[serde(rename_all = "camelCase")]
3012pub struct DocumentRangeFormattingParams {
3013    /// The document to format.
3014    pub text_document: TextDocumentIdentifier,
3015
3016    /// The range to format
3017    pub range: Range,
3018
3019    /// The format options
3020    pub options: FormattingOptions,
3021}
3022
3023#[derive(Debug, PartialEq, Deserialize, Serialize)]
3024#[serde(rename_all = "camelCase")]
3025pub struct DocumentOnTypeFormattingParams {
3026    /// The document to format.
3027    pub text_document: TextDocumentIdentifier,
3028
3029    /// The position at which this request was sent.
3030    pub position: Position,
3031
3032    /// The character that has been typed.
3033    pub ch: String,
3034
3035    /// The format options.
3036    pub options: FormattingOptions,
3037}
3038
3039/// Extends TextDocumentRegistrationOptions
3040#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
3041#[serde(rename_all = "camelCase")]
3042pub struct DocumentOnTypeFormattingRegistrationOptions {
3043    /**
3044     * A document selector to identify the scope of the registration. If set to null
3045     * the document selector provided on the client side will be used.
3046     */
3047    pub document_selector: Option<DocumentSelector>,
3048
3049    /**
3050     * A character on which formatting should be triggered, like `}`.
3051     */
3052    pub first_trigger_character: String,
3053
3054    /**
3055     * More trigger characters.
3056     */
3057    #[serde(skip_serializing_if = "Option::is_none")]
3058    pub more_trigger_character: Option<Vec<String>>,
3059}
3060
3061#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
3062#[serde(rename_all = "camelCase")]
3063pub struct RenameParams {
3064    /// The document to format.
3065    pub text_document: TextDocumentIdentifier,
3066
3067    /// The position at which this request was sent.
3068    pub position: Position,
3069
3070    /// The new name of the symbol. If the given name is not valid the
3071    /// request must return a [ResponseError](#ResponseError) with an
3072    /// appropriate message set.
3073    pub new_name: String,
3074}
3075
3076#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
3077#[serde(untagged)]
3078pub enum RenameProviderCapability {
3079    Simple(bool),
3080    Options(RenameOptions),
3081}
3082
3083#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
3084#[serde(rename_all = "camelCase")]
3085pub struct RenameOptions {
3086    /// Renames should be checked and tested before being executed.
3087    #[serde(skip_serializing_if = "Option::is_none")]
3088    pub prepare_provider: Option<bool>,
3089}
3090
3091#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
3092#[serde(rename_all = "camelCase")]
3093pub struct RenameCapability {
3094    /// Whether rename supports dynamic registration.
3095    #[serde(skip_serializing_if = "Option::is_none")]
3096    pub dynamic_registration: Option<bool>,
3097
3098    /// Client supports testing for validity of rename operations before execution.
3099    #[serde(skip_serializing_if = "Option::is_none")]
3100    pub prepare_support: Option<bool>,
3101}
3102
3103#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
3104#[serde(untagged)]
3105pub enum PrepareRenameResponse {
3106    Range(Range),
3107    RangeWithPlaceholder { range: Range, placeholder: String },
3108}
3109
3110#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
3111#[serde(rename_all = "camelCase")]
3112pub struct DocumentColorParams {
3113    /// The text document
3114    pub text_document: TextDocumentIdentifier,
3115}
3116
3117#[derive(Debug, PartialEq, Deserialize, Serialize)]
3118#[serde(rename_all = "camelCase")]
3119pub struct ColorInformation {
3120    /**
3121     * The range in the document where this color appears.
3122     */
3123    pub range: Range,
3124    /**
3125     * The actual color value for this color range.
3126     */
3127    pub color: Color,
3128}
3129
3130#[derive(Debug, PartialEq, Deserialize, Serialize)]
3131#[serde(rename_all = "camelCase")]
3132pub struct Color {
3133    /**
3134     * The red component of this color in the range [0-1].
3135     */
3136    pub red: f64,
3137    /**
3138     * The green component of this color in the range [0-1].
3139     */
3140    pub green: f64,
3141    /**
3142     * The blue component of this color in the range [0-1].
3143     */
3144    pub blue: f64,
3145    /**
3146     * The alpha component of this color in the range [0-1].
3147     */
3148    pub alpha: f64,
3149}
3150
3151#[derive(Debug, PartialEq, Deserialize, Serialize)]
3152#[serde(rename_all = "camelCase")]
3153pub struct ColorPresentationParams {
3154    /**
3155     * The text document.
3156     */
3157    pub text_document: TextDocumentIdentifier,
3158
3159    /**
3160     * The color information to request presentations for.
3161     */
3162    pub color: Color,
3163
3164    /**
3165     * The range where the color would be inserted. Serves as a context.
3166     */
3167    pub range: Range,
3168}
3169
3170#[derive(Debug, PartialEq, Eq, Deserialize, Serialize, Default, Clone)]
3171#[serde(rename_all = "camelCase")]
3172pub struct ColorPresentation {
3173    /**
3174     * The label of this color presentation. It will be shown on the color
3175     * picker header. By default this is also the text that is inserted when selecting
3176     * this color presentation.
3177     */
3178    pub label: String,
3179
3180    /**
3181     * An [edit](#TextEdit) which is applied to a document when selecting
3182     * this presentation for the color.  When `falsy` the [label](#ColorPresentation.label)
3183     * is used.
3184     */
3185    #[serde(skip_serializing_if = "Option::is_none")]
3186    pub text_edit: Option<TextEdit>,
3187
3188    /**
3189     * An optional array of additional [text edits](#TextEdit) that are applied when
3190     * selecting this color presentation. Edits must not overlap with the main [edit](#ColorPresentation.textEdit) nor with themselves.
3191     */
3192    #[serde(skip_serializing_if = "Option::is_none")]
3193    pub additional_text_edits: Option<Vec<TextEdit>>,
3194}
3195
3196#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
3197#[serde(rename_all = "camelCase")]
3198pub struct FoldingRangeParams {
3199    /// The text document.
3200    pub text_document: TextDocumentIdentifier,
3201}
3202
3203#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
3204#[serde(untagged)]
3205pub enum FoldingRangeProviderCapability {
3206    Simple(bool),
3207    FoldingProvider(FoldingProviderOptions),
3208    Options(StaticTextDocumentColorProviderOptions),
3209}
3210
3211#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
3212pub struct FoldingProviderOptions {}
3213
3214#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
3215#[serde(rename_all = "camelCase")]
3216pub struct FoldingRangeCapability {
3217    /**
3218     * Whether implementation supports dynamic registration for folding range providers. If this is set to `true`
3219     * the client supports the new `(FoldingRangeProviderOptions & TextDocumentRegistrationOptions & StaticRegistrationOptions)`
3220     * return value for the corresponding server capability as well.
3221     */
3222    #[serde(skip_serializing_if = "Option::is_none")]
3223    pub dynamic_registration: Option<bool>,
3224
3225    /**
3226     * The maximum number of folding ranges that the client prefers to receive per document. The value serves as a
3227     * hint, servers are free to follow the limit.
3228     */
3229    #[serde(skip_serializing_if = "Option::is_none")]
3230    pub range_limit: Option<u64>,
3231    /**
3232     * If set, the client signals that it only supports folding complete lines. If set, client will
3233     * ignore specified `startCharacter` and `endCharacter` properties in a FoldingRange.
3234     */
3235    #[serde(skip_serializing_if = "Option::is_none")]
3236    pub line_folding_only: Option<bool>,
3237}
3238
3239/**
3240 * Represents a folding range.
3241 */
3242#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
3243#[serde(rename_all = "camelCase")]
3244pub struct FoldingRange {
3245    /**
3246     * The zero-based line number from where the folded range starts.
3247     */
3248    pub start_line: u64,
3249
3250    /**
3251     * The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line.
3252     */
3253    #[serde(skip_serializing_if = "Option::is_none")]
3254    pub start_character: Option<u64>,
3255
3256    /**
3257     * The zero-based line number where the folded range ends.
3258     */
3259    pub end_line: u64,
3260
3261    /**
3262     * The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line.
3263     */
3264    #[serde(skip_serializing_if = "Option::is_none")]
3265    pub end_character: Option<u64>,
3266
3267    /**
3268     * Describes the kind of the folding range such as `comment' or 'region'. The kind
3269     * is used to categorize folding ranges and used by commands like 'Fold all comments'. See
3270     * [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds.
3271     */
3272    #[serde(skip_serializing_if = "Option::is_none")]
3273    pub kind: Option<FoldingRangeKind>,
3274}
3275
3276/**
3277 * Enum of known range kinds
3278 */
3279#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)]
3280#[serde(rename_all = "lowercase")]
3281pub enum FoldingRangeKind {
3282    /// Folding range for a comment
3283    Comment,
3284    /// Folding range for a imports or includes
3285    Imports,
3286    /// Folding range for a region (e.g. `#region`)
3287    Region,
3288}
3289
3290/**
3291 * Describes the content type that a client supports in various
3292 * result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
3293 *
3294 * Please note that `MarkupKinds` must not start with a `$`. This kinds
3295 * are reserved for internal usage.
3296 */
3297#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)]
3298#[serde(rename_all = "lowercase")]
3299pub enum MarkupKind {
3300    /// Plain text is supported as a content format
3301    PlainText,
3302    /// Markdown is supported as a content format
3303    Markdown,
3304}
3305
3306/**
3307 * A `MarkupContent` literal represents a string value which content is interpreted base on its
3308 * kind flag. Currently the protocol supports `plaintext` and `markdown` as markup kinds.
3309 *
3310 * If the kind is `markdown` then the value can contain fenced code blocks like in GitHub issues.
3311 * See <https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting>
3312 *
3313 * Here is an example how such a string can be constructed using JavaScript / TypeScript:
3314 * ```ts
3315 * let markdown: MarkdownContent = {
3316 *  kind: MarkupKind.Markdown,
3317 *	value: [
3318 *		'# Header',
3319 *		'Some text',
3320 *		'```typescript',
3321 *		'someCode();',
3322 *		'```'
3323 *	].join('\n')
3324 * };
3325 * ```
3326 *
3327 * *Please Note* that clients might sanitize the return markdown. A client could decide to
3328 * remove HTML from the markdown to avoid script execution.
3329 */
3330#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)]
3331pub struct MarkupContent {
3332    pub kind: MarkupKind,
3333    pub value: String,
3334}
3335
3336#[cfg(test)]
3337mod tests {
3338    use super::*;
3339    use serde::{Deserialize, Serialize};
3340
3341    fn test_serialization<SER>(ms: &SER, expected: &str)
3342    where
3343        SER: Serialize + for<'de> Deserialize<'de> + PartialEq + std::fmt::Debug,
3344    {
3345        let json_str = serde_json::to_string(ms).unwrap();
3346        assert_eq!(&json_str, expected);
3347        let deserialized: SER = serde_json::from_str(&json_str).unwrap();
3348        assert_eq!(&deserialized, ms);
3349    }
3350
3351    #[test]
3352    fn number_or_string() {
3353        test_serialization(&NumberOrString::Number(123), r#"123"#);
3354
3355        test_serialization(&NumberOrString::String("abcd".into()), r#""abcd""#);
3356    }
3357
3358    #[test]
3359    fn marked_string() {
3360        test_serialization(&MarkedString::from_markdown("xxx".into()), r#""xxx""#);
3361
3362        test_serialization(
3363            &MarkedString::from_language_code("lang".into(), "code".into()),
3364            r#"{"language":"lang","value":"code"}"#,
3365        );
3366    }
3367
3368    #[test]
3369    fn language_string() {
3370        test_serialization(
3371            &LanguageString {
3372                language: "LL".into(),
3373                value: "VV".into(),
3374            },
3375            r#"{"language":"LL","value":"VV"}"#,
3376        );
3377    }
3378
3379    #[test]
3380    fn workspace_edit() {
3381        test_serialization(
3382            &WorkspaceEdit {
3383                changes: Some(vec![].into_iter().collect()),
3384                document_changes: None,
3385            },
3386            r#"{"changes":{}}"#,
3387        );
3388
3389        test_serialization(
3390            &WorkspaceEdit {
3391                changes: None,
3392                document_changes: None,
3393            },
3394            r#"{}"#,
3395        );
3396
3397        test_serialization(&WorkspaceEdit {
3398                                changes: Some(vec![(Url::parse("file://test").unwrap(), vec![])]
3399                                    .into_iter()
3400                                    .collect()),
3401                                document_changes: None,
3402                            },
3403                           r#"{"changes":{"file://test/":[]}}"#);
3404    }
3405
3406    #[test]
3407    fn formatting_options() {
3408        test_serialization(
3409            &FormattingOptions {
3410                tab_size: 123,
3411                insert_spaces: true,
3412                properties: HashMap::new(),
3413            },
3414            r#"{"tabSize":123,"insertSpaces":true}"#,
3415        );
3416
3417        test_serialization(
3418            &FormattingOptions {
3419                tab_size: 123,
3420                insert_spaces: true,
3421                properties: vec![("prop".to_string(), FormattingProperty::Number(1.0))]
3422                    .into_iter()
3423                    .collect(),
3424            },
3425            r#"{"tabSize":123,"insertSpaces":true,"prop":1.0}"#,
3426        );
3427    }
3428
3429    #[test]
3430    fn root_uri_can_be_missing() {
3431        serde_json::from_str::<InitializeParams>(r#"{ "capabilities": {} }"#).unwrap();
3432    }
3433
3434    #[test]
3435    fn test_watch_kind() {
3436        test_serialization(&WatchKind::Create, "1");
3437        test_serialization(&(WatchKind::Create | WatchKind::Change), "3");
3438        test_serialization(
3439            &(WatchKind::Create | WatchKind::Change | WatchKind::Delete),
3440            "7",
3441        );
3442    }
3443
3444    #[test]
3445    fn test_resource_operation_kind() {
3446        test_serialization(
3447            &vec![ResourceOperationKind::Create, ResourceOperationKind::Rename, ResourceOperationKind::Delete],
3448            r#"["create","rename","delete"]"#);
3449    }
3450}