/
lib.rs
1636 lines (1370 loc) · 53 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
Language Server Protocol types for Rust.
Based on: https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md
Last protocol update:
08/Dec/2016 at commit:
https://github.com/Microsoft/language-server-protocol/commit/00520823bd4c8060bb1963964615aa005594381b
This library uses the URL crate for parsing URIs.
Note that there is some confusion on the meaning of URLs vs URIs:
http://stackoverflow.com/a/28865728/393898 .
According to that information, on the classical sense of "URLs", "URLs" are a subset of URIs,
But on the modern/new meaning of URLs, they are the same as URIs.
The important take-away aspect is that the URL crate should be able to parse any URI,
such as `urn:isbn:0451450523`.
*/
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#[macro_use]
extern crate enum_primitive;
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
extern crate url;
extern crate url_serde;
use url::Url;
use std::collections::HashMap;
use std::fmt;
use serde::de;
use serde::de::Error as Error_;
use serde_json::Value;
/* ----------------- Auxiliary types ----------------- */
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum NumberOrString {
Number(u64),
String(String),
}
/* ----------------- Cancel support ----------------- */
/// The base protocol now offers support for request cancellation. To cancel a request,
/// a notification message with the following properties is sent:
///
/// A request that got canceled still needs to return from the server and send a response back.
/// It can not be left open / hanging. This is in line with the JSON RPC protocol that requires
/// that every request sends a response back. In addition it allows for returning partial results on cancel.
pub const NOTIFICATION__Cancel: &'static str = "$/cancelRequest";
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct CancelParams {
/// The request id to cancel.
pub id: NumberOrString,
}
/* ----------------- Basic JSON Structures ----------------- */
/// Position in a text document expressed as zero-based line and character offset.
/// A position is between two characters like an 'insert' cursor in a editor.
#[derive(Debug, PartialEq, Copy, Clone, Default, Deserialize, Serialize)]
pub struct Position {
/// Line position in a document (zero-based).
pub line: u64,
/// Character offset on a line in a document (zero-based).
pub character: u64,
}
impl Position {
pub fn new(line: u64, character: u64) -> Position {
Position {
line: line,
character: character,
}
}
}
/// A range in a text document expressed as (zero-based) start and end positions.
/// A range is comparable to a selection in an editor. Therefore the end position is exclusive.
#[derive(Debug, PartialEq, Copy, Clone, Default, Deserialize, Serialize)]
pub struct Range {
/// The range's start position.
pub start: Position,
/// The range's end position.
pub end: Position,
}
impl Range {
pub fn new(start: Position, end: Position) -> Range {
Range {
start: start,
end: end,
}
}
}
/// Represents a location inside a resource, such as a line inside a text file.
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct Location {
#[serde(deserialize_with = "url_serde::deserialize", serialize_with = "url_serde::serialize")]
pub uri: Url,
pub range: Range,
}
impl Location {
pub fn new(uri: Url, range: Range) -> Location {
Location {
uri: uri,
range: range,
}
}
}
/// Represents a diagnostic, such as a compiler error or warning.
/// Diagnostic objects are only valid in the scope of a resource.
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct Diagnostic {
/// The range at which the message applies.
pub range: Range,
/// The diagnostic's severity. Can be omitted. If omitted it is up to the
/// client to interpret diagnostics as error, warning, info or hint.
pub severity: Option<DiagnosticSeverity>,
/// The diagnostic's code. Can be omitted.
pub code: Option<NumberOrString>,
// code?: number | string;
/// A human-readable string describing the source of this
/// diagnostic, e.g. 'typescript' or 'super lint'.
pub source: Option<String>,
/// The diagnostic's message.
pub message: String,
}
impl Diagnostic {
pub fn new(range: Range,
severity: Option<DiagnosticSeverity>,
code: Option<NumberOrString>,
source: Option<String>,
message: String)
-> Diagnostic {
Diagnostic {
range: range,
severity: severity,
code: code,
source: source,
message: message,
}
}
pub fn new_simple(range: Range, message: String) -> Diagnostic {
Self::new(range, None, None, None, message)
}
pub fn new_with_code_number(range: Range,
severity: DiagnosticSeverity,
code_number: u64,
source: Option<String>,
message: String)
-> Diagnostic {
let code = Some(NumberOrString::Number(code_number));
Self::new(range, Some(severity), code, source, message)
}
}
/// The protocol currently supports the following diagnostic severities:
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum DiagnosticSeverity {
/// Reports an error.
Error = 1,
/// Reports a warning.
Warning = 2,
/// Reports an information.
Information = 3,
/// Reports a hint.
Hint = 4,
}
impl serde::Deserialize for DiagnosticSeverity {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: serde::Deserializer
{
Ok(match try!(u8::deserialize(deserializer)) {
1 => DiagnosticSeverity::Error,
2 => DiagnosticSeverity::Warning,
3 => DiagnosticSeverity::Information,
4 => DiagnosticSeverity::Hint,
i => {
return Err(D::Error::invalid_value(de::Unexpected::Unsigned(i as u64),
&"value of 1, 2, 3 or 4"));
}
})
}
}
impl serde::Serialize for DiagnosticSeverity {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: serde::Serializer
{
serializer.serialize_u8(*self as u8)
}
}
/**
Represents a reference to a command. Provides a title which will be used to represent a command in the UI.
Commands are identitifed using a string identifier and the protocol currently doesn't specify a set of
well known commands. So executing a command requires some tool extension code.
*/
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct Command {
/// Title of the command, like `save`.
pub title: String,
/// The identifier of the actual command handler.
pub command: String,
/// Arguments that the command handler should be
/// invoked with.
#[serde(skip_serializing_if="Option::is_none")]
pub arguments: Option<Vec<Value>>,
}
impl Command {
pub fn new(title: String, command: String, arguments: Option<Vec<Value>>) -> Command {
Command {
title: title,
command: command,
arguments: arguments,
}
}
}
/// A textual edit applicable to a text document.
///
/// If n `TextEdit`s are applied to a text document all text edits describe changes to the initial document version.
/// Execution wise text edits should applied from the bottom to the top of the text document. Overlapping text edits
/// are not supported.
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct TextEdit {
/// The range of the text document to be manipulated. To insert
/// text into a document create a range where start === end.
pub range: Range,
/// The string to be inserted. For delete operations use an
/// empty string.
#[serde(rename="newText")]
pub new_text: String,
}
impl TextEdit {
pub fn new(range: Range, new_text: String) -> TextEdit {
TextEdit {
range: range,
new_text: new_text,
}
}
}
/// A workspace edit represents changes to many resources managed in the workspace.
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct WorkspaceEdit {
/// Holds changes to existing resources.
#[serde(deserialize_with = "deserialize_url_map", serialize_with = "serialize_url_map")]
pub changes: HashMap<Url, Vec<TextEdit>>,
// changes: { [uri: string]: TextEdit[]; };
}
fn deserialize_url_map<D>(deserializer: D) -> Result<HashMap<Url, Vec<TextEdit>>, D::Error>
where D: serde::Deserializer
{
struct UrlMapVisitor;
impl de::Visitor for UrlMapVisitor {
type Value = HashMap<Url, Vec<TextEdit>>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("map")
}
fn visit_map<M>(self, mut visitor: M) -> Result<Self::Value, M::Error>
where M: de::MapVisitor
{
let mut values = HashMap::with_capacity(visitor.size_hint().0);
// While there are entries remaining in the input, add them
// into our map.
while let Some((key, value)) = visitor.visit::<url_serde::De<Url>, _>()? {
values.insert(key.into_inner(), value);
}
Ok(values)
}
}
// Instantiate our Visitor and ask the Deserializer to drive
// it over the input data, resulting in an instance of MyMap.
deserializer.deserialize_map(UrlMapVisitor)
}
fn serialize_url_map<S>(changes: &HashMap<Url, Vec<TextEdit>>,
serializer: S)
-> Result<S::Ok, S::Error>
where S: serde::Serializer
{
use serde::ser::SerializeMap;
let mut map = serializer.serialize_map(Some(changes.len()))?;
for (k, v) in changes {
map.serialize_key(k.as_str())?;
map.serialize_value(v)?;
}
map.end()
}
impl WorkspaceEdit {
pub fn new(changes: HashMap<Url, Vec<TextEdit>>) -> WorkspaceEdit {
WorkspaceEdit { changes: changes }
}
}
/// Text documents are identified using a URI. On the protocol level, URIs are passed as strings.
/// The corresponding JSON structure looks like this:
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct TextDocumentIdentifier {
// !!!!!! Note:
// In the spec VersionedTextDocumentIdentifier extends TextDocumentIdentifier
// This modelled by "mixing-in" TextDocumentIdentifier in VersionedTextDocumentIdentifier,
// so any changes to this type must be effected in the sub-type as well.
/// The text document's URI.
#[serde(deserialize_with = "url_serde::deserialize", serialize_with = "url_serde::serialize")]
pub uri: Url,
}
impl TextDocumentIdentifier {
pub fn new(uri: Url) -> TextDocumentIdentifier {
TextDocumentIdentifier { uri: uri }
}
}
/// An item to transfer a text document from the client to the server.
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct TextDocumentItem {
/// The text document's URI.
#[serde(deserialize_with = "url_serde::deserialize", serialize_with = "url_serde::serialize")]
pub uri: Url,
/// The text document's language identifier.
#[serde(rename="languageId")]
pub language_id: Option<String>,
/// The version number of this document (it will strictly increase after each
/// change, including undo/redo).
pub version: Option<u64>,
/// The content of the opened text document.
pub text: String,
}
impl TextDocumentItem {
pub fn new(uri: Url,
language_id: Option<String>,
version: Option<u64>,
text: String)
-> TextDocumentItem {
TextDocumentItem {
uri: uri,
language_id: language_id,
version: version,
text: text,
}
}
}
/// An identifier to denote a specific version of a text document.
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct VersionedTextDocumentIdentifier {
// This field was "mixed-in" from TextDocumentIdentifier
/// The text document's URI.
#[serde(deserialize_with = "url_serde::deserialize", serialize_with = "url_serde::serialize")]
pub uri: Url,
/// The version number of this document.
pub version: u64,
}
impl VersionedTextDocumentIdentifier {
pub fn new(uri: Url, version: u64) -> VersionedTextDocumentIdentifier {
VersionedTextDocumentIdentifier {
uri: uri,
version: version,
}
}
}
/// A parameter literal used in requests to pass a text document and a position inside that document.
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct TextDocumentPositionParams {
// !!!!!! Note:
// In the spec ReferenceParams extends TextDocumentPositionParams
// This modelled by "mixing-in" TextDocumentPositionParams in ReferenceParams,
// so any changes to this type must be effected in sub-type as well.
/// The text document.
#[serde(rename="textDocument")]
pub text_document: TextDocumentIdentifier,
/// The position inside the text document.
pub position: Position,
}
impl TextDocumentPositionParams {
pub fn new(text_document: TextDocumentIdentifier,
position: Position)
-> TextDocumentPositionParams {
TextDocumentPositionParams {
text_document: text_document,
position: position,
}
}
}
/* ========================= Actual Protocol ========================= */
/**
The initialize request is sent as the first request from the client to the server.
If the server receives request or notification before the `initialize` request it should act as follows:
* for a request the respond should be errored with `code: -32001`. The message can be picked by the server.
* notifications should be dropped.
*/
pub const REQUEST__Initialize: &'static str = "initialize";
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct InitializeParams {
/// The process Id of the parent process that started
/// the server. Is null if the process has not been started by another process.
/// If the parent process is not alive then the server should exit (see exit notification) its process.
#[serde(rename="processId")]
pub process_id: Option<u64>,
/// The rootPath of the workspace. Is null
/// if no folder is open.
#[serde(rename="rootPath")]
pub root_path: Option<String>,
/// User provided initialization options.
#[serde(rename="initializationOptions")]
pub initialization_options: Option<Value>,
/// The capabilities provided by the client (editor)
pub capabilities: ClientCapabilities,
}
/**
* Where ClientCapabilities are currently empty:
*/
pub type ClientCapabilities = Value;
#[derive(Debug, PartialEq, Default, Deserialize, Serialize)]
pub struct InitializeResult {
/// The capabilities the language server provides.
pub capabilities: ServerCapabilities,
}
#[derive(Debug, PartialEq, Default, Deserialize, Serialize)]
pub struct InitializeError {
/// Indicates whether the client should retry to send the
/// initilize request after showing the message provided
/// in the ResponseError.
pub retry: bool,
}
// The server can signal the following capabilities:
/// Defines how the host (editor) should sync document changes to the language server.
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum TextDocumentSyncKind {
/// Documents should not be synced at all.
None = 0,
/// Documents are synced by always sending the full content of the document.
Full = 1,
/// Documents are synced by sending the full content on open. After that only
/// incremental updates to the document are sent.
Incremental = 2,
}
impl serde::Deserialize for TextDocumentSyncKind {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: serde::Deserializer
{
Ok(match try!(u8::deserialize(deserializer)) {
0 => TextDocumentSyncKind::None,
1 => TextDocumentSyncKind::Full,
2 => TextDocumentSyncKind::Incremental,
i => {
return Err(D::Error::invalid_value(de::Unexpected::Unsigned(i as u64),
&"value between 0 and 2 (inclusive)"));
}
})
}
}
impl serde::Serialize for TextDocumentSyncKind {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: serde::Serializer
{
serializer.serialize_u8(*self as u8)
}
}
/// Completion options.
#[derive(Debug, PartialEq, Default, Deserialize, Serialize)]
pub struct CompletionOptions {
/// The server provides support to resolve additional information for a completion item.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="resolveProvider")]
pub resolve_provider: Option<bool>,
/// The characters that trigger completion automatically.
#[serde(rename="triggerCharacters")]
pub trigger_characters: Vec<String>,
}
/// Signature help options.
#[derive(Debug, PartialEq, Default, Deserialize, Serialize)]
pub struct SignatureHelpOptions {
/// The characters that trigger signature help automatically.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="triggerCharacters")]
pub trigger_characters: Option<Vec<String>>,
}
/// Code Lens options.
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct CodeLensOptions {
/// Code lens has a resolve provider as well.
#[serde(rename="resolveProvider")]
pub resolve_provider: Option<bool>,
}
/// Format document on type options
#[derive(Debug, PartialEq, Default, Deserialize, Serialize)]
pub struct DocumentOnTypeFormattingOptions {
/// A character on which formatting should be triggered, like `}`.
#[serde(rename="firstTriggerCharacter")]
pub first_trigger_character: String,
/// More trigger characters.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="moreTriggerCharacter")]
pub more_trigger_character: Option<Vec<String>>,
}
#[derive(Debug, PartialEq, Default, Deserialize, Serialize)]
pub struct ServerCapabilities {
/// Defines how text documents are synced.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="textDocumentSync")]
pub text_document_sync: Option<TextDocumentSyncKind>,
/// The server provides hover support.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="hoverProvider")]
pub hover_provider: Option<bool>,
/// The server provides completion support.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="completionProvider")]
pub completion_provider: Option<CompletionOptions>,
/// The server provides signature help support.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="signatureHelpProvider")]
pub signature_help_provider: Option<SignatureHelpOptions>,
/// The server provides goto definition support.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="definitionProvider")]
pub definition_provider: Option<bool>,
/// The server provides find references support.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="referencesProvider")]
pub references_provider: Option<bool>,
/// The server provides document highlight support.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="documentHighlightProvider")]
pub document_highlight_provider: Option<bool>,
/// The server provides document symbol support.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="documentSymbolProvider")]
pub document_symbol_provider: Option<bool>,
/// The server provides workspace symbol support.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="workspaceSymbolProvider")]
pub workspace_symbol_provider: Option<bool>,
/// The server provides code actions.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="codeActionProvider")]
pub code_action_provider: Option<bool>,
/// The server provides code lens.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="codeLensProvider")]
pub code_lens_provider: Option<CodeLensOptions>,
/// The server provides document formatting.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="documentFormattingProvider")]
pub document_formatting_provider: Option<bool>,
/// The server provides document range formatting.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="documentRangeFormattingProvider")]
pub document_range_formatting_provider: Option<bool>,
/// The server provides document formatting on typing.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="documentOnTypeFormattingProvider")]
pub document_on_type_formatting_provider: Option<DocumentOnTypeFormattingOptions>,
/// The server provides rename support.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="renameProvider")]
pub rename_provider: Option<bool>,
}
/**
* The shutdown request is sent from the client to the server. It asks the server to shut down,
* but to not exit (otherwise the response might not be delivered correctly to the client).
* There is a separate exit notification that asks the server to exit.
*/
pub const REQUEST__Shutdown: &'static str = "shutdown";
/**
* A notification to ask the server to exit its process.
* The server should exit with success code 0 if the shutdown request has been received before;
* otherwise with error code 1.
*/
pub const NOTIFICATION__Exit: &'static str = "exit";
/**
* The show message notification is sent from a server to a client to ask the client to display a particular message
* in the user interface.
*/
pub const NOTIFICATION__ShowMessage: &'static str = "window/showMessage";
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct ShowMessageParams {
/// The message type. See {@link MessageType}.
#[serde(rename="type")]
pub typ: MessageType,
/// The actual message.
pub message: String,
}
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum MessageType {
/// An error message.
Error = 1,
/// A warning message.
Warning = 2,
/// An information message.
Info = 3,
/// A log message.
Log = 4,
}
impl serde::Deserialize for MessageType {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: serde::Deserializer
{
Ok(match try!(u8::deserialize(deserializer)) {
1 => MessageType::Error,
2 => MessageType::Warning,
3 => MessageType::Info,
4 => MessageType::Log,
i => {
return Err(D::Error::invalid_value(de::Unexpected::Unsigned(i as u64),
&"value of 1, 2, 3 or 4"));
}
})
}
}
impl serde::Serialize for MessageType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: serde::Serializer
{
serializer.serialize_u8(*self as u8)
}
}
/**
* The show message request is sent from a server to a client to ask the client to display a particular message
* in the user interface. In addition to the show message notification the request allows to pass actions and to
* wait for an answer from the client.
*/
pub const REQUEST__ShowMessageRequest: &'static str = "window/showMessageRequest";
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct ShowMessageRequestParams {
/// The message type. See {@link MessageType}
#[serde(rename="type")]
pub typ: MessageType,
/// The actual message
pub message: String,
/// The message action items to present.
#[serde(skip_serializing_if="Option::is_none")]
pub actions: Option<Vec<MessageActionItem>>,
}
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct MessageActionItem {
/// A short title like 'Retry', 'Open Log' etc.
pub title: String,
}
/**
* The log message notification is sent from the server to the client to ask the client to log a particular message.
*/
pub const NOTIFICATION__LogMessage: &'static str = "window/logMessage";
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct LogMessageParams {
/// The message type. See {@link MessageType}
#[serde(rename="type")]
pub typ: MessageType,
/// The actual message
pub message: String,
}
/**
* The telemetry notification is sent from the server to the client to ask the client to log a telemetry event.
*/
pub const NOTIFICATION__TelemetryEvent: &'static str = "telemetry/event";
/**
* A notification sent from the client to the server to signal the change of configuration settings.
*/
pub const NOTIFICATION__WorkspaceChangeConfiguration: &'static str = "workspace/didChangeConfiguration";
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct DidChangeConfigurationParams {
/// The actual changed settings
pub settings: Value,
}
/**
* The document open notification is sent from the client to the server to signal newly opened text documents.
* The document's truth is now managed by the client and the server must not try to read the document's truth
* using the document's uri.
*/
pub const NOTIFICATION__DidOpenTextDocument: &'static str = "textDocument/didOpen";
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct DidOpenTextDocumentParams {
/// The document that was opened.
#[serde(rename="textDocument")]
pub text_document: TextDocumentItem,
}
/**
* The document change notification is sent from the client to the server to signal changes to a text document.
* In 2.0 the shape of the params has changed to include proper version numbers and language ids.
*/
pub const NOTIFICATION__DidChangeTextDocument: &'static str = "textDocument/didChange";
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct DidChangeTextDocumentParams {
/// The document that did change. The version number points
/// to the version after all provided content changes have
/// been applied.
#[serde(rename="textDocument")]
pub text_document: VersionedTextDocumentIdentifier,
/// The actual content changes.
#[serde(rename="contentChanges")]
pub content_changes: Vec<TextDocumentContentChangeEvent>,
}
/// An event describing a change to a text document. If range and rangeLength are omitted
/// the new text is considered to be the full content of the document.
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct TextDocumentContentChangeEvent {
/// The range of the document that changed.
pub range: Option<Range>,
/// The length of the range that got replaced.
/// NOTE: seems redundant, see: https://github.com/Microsoft/language-server-protocol/issues/9
#[serde(rename="rangeLength")]
pub range_length: Option<u64>,
/// The new text of the document.
pub text: String,
}
/**
* The document close notification is sent from the client to the server when the document got closed in the client.
* The document's truth now exists where the document's uri points to (e.g. if the document's uri is a file uri
* the truth now exists on disk).
*/
pub const NOTIFICATION__DidCloseTextDocument: &'static str = "textDocument/didClose";
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct DidCloseTextDocumentParams {
/// The document that was closed.
#[serde(rename="textDocument")]
pub text_document: TextDocumentIdentifier,
}
/**
* The document save notification is sent from the client to the server when the document was saved in the client.
*/
pub const NOTIFICATION__DidSaveTextDocument: &'static str = "textDocument/didSave";
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct DidSaveTextDocumentParams {
/// The document that was saved.
#[serde(rename="textDocument")]
pub text_document: TextDocumentIdentifier,
}
/**
* The watched files notification is sent from the client to the server when the client detects changes to files
* watched by the language client.
*/
pub const NOTIFICATION__DidChangeWatchedFiles: &'static str = "workspace/didChangeWatchedFiles";
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct DidChangeWatchedFilesParams {
/// The actual file events.
pub changes: Vec<FileEvent>,
}
/// The file event type.
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum FileChangeType {
/// The file got created.
Created = 1,
/// The file got changed.
Changed = 2,
/// The file got deleted.
Deleted = 3,
}
impl serde::Deserialize for FileChangeType {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: serde::Deserializer
{
Ok(match try!(u8::deserialize(deserializer)) {
1 => FileChangeType::Created,
2 => FileChangeType::Changed,
3 => FileChangeType::Deleted,
i => {
return Err(D::Error::invalid_value(de::Unexpected::Unsigned(i as u64),
&"value of 1, 2 or 3"))
}
})
}
}
impl serde::Serialize for FileChangeType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: serde::Serializer
{
serializer.serialize_u8(*self as u8)
}
}
/// An event describing a file change.
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct FileEvent {
/// The file's URI.
#[serde(deserialize_with = "url_serde::deserialize", serialize_with = "url_serde::serialize")]
pub uri: Url,
/// The change type.
#[serde(rename="type")]
pub typ: FileChangeType,
}
impl FileEvent {
pub fn new(uri: Url, typ: FileChangeType) -> FileEvent {
FileEvent {
uri: uri,
typ: typ,
}
}
}
/**
* Diagnostics notification are sent from the server to the client to signal results of validation runs.
*/
pub const NOTIFICATION__PublishDiagnostics: &'static str = "textDocument/publishDiagnostics";
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct PublishDiagnosticsParams {
/// The URI for which diagnostic information is reported.
#[serde(deserialize_with = "url_serde::deserialize", serialize_with = "url_serde::serialize")]
pub uri: Url,
/// An array of diagnostic information items.
pub diagnostics: Vec<Diagnostic>,
}
impl PublishDiagnosticsParams {
pub fn new(uri: Url, diagnostics: Vec<Diagnostic>) -> PublishDiagnosticsParams {
PublishDiagnosticsParams {
uri: uri,
diagnostics: diagnostics,
}
}
}
/**
The Completion request is sent from the client to the server to compute completion items at a given cursor position.
Completion items are presented in the IntelliSense user interface. If computing full completion items is expensive,
servers can additionally provide a handler for the completion item resolve request ('completionItem/resolve').
This request is sent when a completion item is selected in the user interface. A typically use case is for example:
the 'textDocument/completion' request doesn't fill in the documentation property for returned completion items
since it is expensive to compute. When the item is selected in the user interface then a 'completionItem/resolve'
request is sent with the selected completion item as a param. The returned completion item should have the
documentation property filled in.
*/
// result: CompletionItem[] | CompletionList FIXME
pub const REQUEST__Completion: &'static str = "textDocument/completion";
/// Represents a collection of [completion items](#CompletionItem) to be presented
/// in the editor.
#[derive(Debug, PartialEq, Default, Deserialize, Serialize)]
pub struct CompletionList {
/// This list it not complete. Further typing should result in recomputing
/// this list.
#[serde(rename="isIncomplete")]
pub is_incomplete: bool,
/// The completion items.
pub items: Vec<CompletionItem>,
}
#[derive(Debug, PartialEq, Default, Deserialize, Serialize)]
pub struct CompletionItem {
/// The label of this completion item. By default
/// also the text that is inserted when selecting
/// this completion.
pub label: String,
/// The kind of this completion item. Based of the kind
/// an icon is chosen by the editor.
#[serde(skip_serializing_if="Option::is_none")]
pub kind: Option<CompletionItemKind>,
/// A human-readable string with additional information
/// about this item, like type or symbol information.
#[serde(skip_serializing_if="Option::is_none")]
pub detail: Option<String>,
/// A human-readable string that represents a doc-comment.
#[serde(skip_serializing_if="Option::is_none")]
pub documentation: Option<String>,
/// A string that shoud be used when comparing this item
/// with other items. When `falsy` the label is used.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="sortText")]
pub sort_text: Option<String>,
/// A string that should be used when filtering a set of
/// completion items. When `falsy` the label is used.
#[serde(skip_serializing_if="Option::is_none")]
#[serde(rename="filterText")]
pub filter_text: Option<String>,