-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspecification.txt
3798 lines (3292 loc) · 119 KB
/
specification.txt
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
LSP
Overview
Implementations
Specification
Inspector
Language Server Protocol Specification
This document describes version 3.x of the language server protocol. An implementation for node of the 3.0 version of the protocol can be found here.
The 2.x version of this document can be found here. The 1.x version of this document can be found here.
Note: edits to this specification can be made via a pull request against this markdown document.
Base Protocol
The base protocol consists of a header and a content part (comparable to HTTP). The header and content part are separated by a ‘\r\n’.
Header Part
The header part consists of header fields. Each header field is comprised of a name and a value, separated by ‘: ‘ (a colon and a space). Each header field is terminated by ‘\r\n’. Considering the last header field and the overall header itself are each terminated with ‘\r\n’, and that at least one header is mandatory, this means that two ‘\r\n’ sequences always immediately precede the content part of a message.
Currently the following header fields are supported:
Header Field Name Value Type Description
Content-Length number The length of the content part in bytes. This header is required.
Content-Type string The mime type of the content part. Defaults to application/vscode-jsonrpc; charset=utf-8
The header part is encoded using the ‘ascii’ encoding. This includes the ‘\r\n’ separating the header and content part.
Content Part
Contains the actual content of the message. The content part of a message uses JSON-RPC to describe requests, responses and notifications. The content part is encoded using the charset provided in the Content-Type field. It defaults to utf-8, which is the only encoding supported right now. Prior versions of the protocol used the string constant utf8 which is not a correct encoding constant according to specification). For backwards compatibility it is highly recommended that a client and a server treats the string utf8 as utf-8.
Example:
Content-Length: ...\r\n
\r\n
{
"jsonrpc": "2.0",
"id": 1,
"method": "textDocument/didOpen",
"params": {
...
}
}
Base Protocol JSON structures
The following TypeScript definitions describe the base JSON-RPC protocol:
Abstract Message
A general message as defined by JSON-RPC. The language server protocol always uses “2.0” as the jsonrpc version.
interface Message {
jsonrpc: string;
}
Request Message
A request message to describe a request between the client and the server. Every processed request must send a response back to the sender of the request.
interface RequestMessage extends Message {
/**
* The request id.
*/
id: number | string;
/**
* The method to be invoked.
*/
method: string;
/**
* The method's params.
*/
params?: Array<any> | object;
}
Response Message
Response Message sent as a result of a request. If a request doesn’t provide a result value the receiver of a request still needs to return a response message to conform to the JSON RPC specification. The result property of the ResponseMessage should be set to null in this case to signal a successful request.
interface ResponseMessage extends Message {
/**
* The request id.
*/
id: number | string | null;
/**
* The result of a request. This can be omitted in
* the case of an error.
*/
result?: any;
/**
* The error object in case a request fails.
*/
error?: ResponseError<any>;
}
interface ResponseError<D> {
/**
* A number indicating the error type that occurred.
*/
code: number;
/**
* A string providing a short description of the error.
*/
message: string;
/**
* A Primitive or Structured value that contains additional
* information about the error. Can be omitted.
*/
data?: D;
}
export namespace ErrorCodes {
// Defined by JSON RPC
export const ParseError: number = -32700;
export const InvalidRequest: number = -32600;
export const MethodNotFound: number = -32601;
export const InvalidParams: number = -32602;
export const InternalError: number = -32603;
export const serverErrorStart: number = -32099;
export const serverErrorEnd: number = -32000;
export const ServerNotInitialized: number = -32002;
export const UnknownErrorCode: number = -32001;
// Defined by the protocol.
export const RequestCancelled: number = -32800;
}
Notification Message
A notification message. A processed notification message must not send a response back. They work like events.
interface NotificationMessage extends Message {
/**
* The method to be invoked.
*/
method: string;
/**
* The notification's params.
*/
params?: Array<any> | object;
}
$ Notifications and Requests
Notification and requests whose methods start with ‘$/’ are messages which are protocol implementation dependent and might not be implementable in all clients or servers. For example if the server implementation uses a single threaded synchronous programming language then there is little a server can do to react to a ‘$/cancelRequest’. If a server or client receives notifications or requests starting with ‘$/’ it is free to ignore them if they are unknown.
Cancellation Support (:arrow_right: :arrow_left:)
The base protocol offers support for request cancellation. To cancel a request, a notification message with the following properties is sent:
Notification:
method: ‘$/cancelRequest’
params: CancelParams defined as follows:
interface CancelParams {
/**
* The request id to cancel.
*/
id: number | string;
}
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. If the requests returns an error response on cancellation it is advised to set the error code to ErrorCodes.RequestCancelled.
Language Server Protocol
The language server protocol defines a set of JSON-RPC request, response and notification messages which are exchanged using the above base protocol. This section starts describing the basic JSON structures used in the protocol. The document uses TypeScript interfaces to describe these. Based on the basic JSON structures, the actual requests with their responses and the notifications are described.
In general, the language server protocol supports JSON-RPC messages, however the base protocol defined here uses a convention such that the parameters passed to request/notification messages should be of object type (if passed at all). However, this does not disallow using Array parameter types in custom messages.
The protocol currently assumes that one server serves one tool. There is currently no support in the protocol to share one server between different tools. Such a sharing would require additional protocol to either lock a document to support concurrent editing.
Basic JSON Structures
URI
URI’s are transferred as strings. The URI’s format is defined in http://tools.ietf.org/html/rfc3986
foo://example.com:8042/over/there?name=ferret#nose
\_/ \______________/\_________/ \_________/ \__/
| | | | |
scheme authority path query fragment
| _____________________|__
/ \ / \
urn:example:animal:ferret:nose
We also maintain a node module to parse a string into scheme, authority, path, query, and fragment URI components. The GitHub repository is https://github.com/Microsoft/vscode-uri the npm module is https://www.npmjs.com/package/vscode-uri.
Many of the interfaces contain fields that correspond to the URI of a document. For clarity, the type of such a field is declared as a DocumentUri. Over the wire, it will still be transferred as a string, but this guarantees that the contents of that string can be parsed as a valid URI.
type DocumentUri = string;
Text Documents
The current protocol is tailored for textual documents whose content can be represented as a string. There is currently no support for binary documents. A position inside a document (see Position definition below) is expressed as a zero-based line and character offset. The offsets are based on a UTF-16 string representation. So a string of the form a𐐀b the character offset of the character a is 0, the character offset of 𐐀 is 1 and the character offset of b is 3 since 𐐀 is represented using two code units in UTF-16. To ensure that both client and server split the string into the same line representation the protocol specifies the following end-of-line sequences: ‘\n’, ‘\r\n’ and ‘\r’.
Positions are line end character agnostic. So you can not specify a position that denotes \r|\n or \n| where | represents the character offset.
export const EOL: string[] = ['\n', '\r\n', '\r'];
Position
Position in a text document expressed as zero-based line and zero-based character offset. A position is between two characters like an ‘insert’ cursor in a editor.
interface Position {
/**
* Line position in a document (zero-based).
*/
line: number;
/**
* Character offset on a line in a document (zero-based). Assuming that the line is
* represented as a string, the `character` value represents the gap between the
* `character` and `character + 1`.
*
* If the character value is greater than the line length it defaults back to the
* line length.
*/
character: number;
}
Range
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. If you want to specify a range that contains a line including the line ending character(s) then use an end position denoting the start of the next line. For example:
{
start: { line: 5, character: 23 },
end : { line 6, character : 0 }
}
interface Range {
/**
* The range's start position.
*/
start: Position;
/**
* The range's end position.
*/
end: Position;
}
Location
Represents a location inside a resource, such as a line inside a text file.
interface Location {
uri: DocumentUri;
range: Range;
}
Diagnostic
Represents a diagnostic, such as a compiler error or warning. Diagnostic objects are only valid in the scope of a resource.
interface Diagnostic {
/**
* The range at which the message applies.
*/
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.
*/
severity?: number;
/**
* The diagnostic's code, which might appear in the user interface.
*/
code?: number | string;
/**
* A human-readable string describing the source of this
* diagnostic, e.g. 'typescript' or 'super lint'.
*/
source?: string;
/**
* The diagnostic's message.
*/
message: string;
/**
* An array of related diagnostic information, e.g. when symbol-names within
* a scope collide all definitions can be marked via this property.
*/
relatedInformation?: DiagnosticRelatedInformation[];
}
The protocol currently supports the following diagnostic severities:
namespace DiagnosticSeverity {
/**
* Reports an error.
*/
export const Error = 1;
/**
* Reports a warning.
*/
export const Warning = 2;
/**
* Reports an information.
*/
export const Information = 3;
/**
* Reports a hint.
*/
export const Hint = 4;
}
/**
* Represents a related message and source code location for a diagnostic. This should be
* used to point to code locations that cause or related to a diagnostics, e.g when duplicating
* a symbol in a scope.
*/
export interface DiagnosticRelatedInformation {
/**
* The location of this related diagnostic information.
*/
location: Location;
/**
* The message of this related diagnostic information.
*/
message: string;
}
Command
Represents a reference to a command. Provides a title which will be used to represent a command in the UI. Commands are identified by a string identifier. The protocol currently doesn’t specify a set of well-known commands. So executing a command requires some tool extension code.
interface Command {
/**
* Title of the command, like `save`.
*/
title: string;
/**
* The identifier of the actual command handler.
*/
command: string;
/**
* Arguments that the command handler should be
* invoked with.
*/
arguments?: any[];
}
TextEdit
A textual edit applicable to a text document.
interface TextEdit {
/**
* The range of the text document to be manipulated. To insert
* text into a document create a range where start === end.
*/
range: Range;
/**
* The string to be inserted. For delete operations use an
* empty string.
*/
newText: string;
}
TextEdit[]
Complex text manipulations are described with an array of TextEdit’s, representing a single change to the document.
All text edits ranges refer to positions in the original document. Text edits ranges must never overlap, that means no part of the original document must be manipulated by more than one edit. However, it is possible that multiple edits have the same start position: multiple inserts, or any number of inserts followed by a single remove or replace edit. If multiple inserts have the same position, the order in the array defines the order in which the inserted strings appear in the resulting text.
TextDocumentEdit
Describes textual changes on a single text document. The text document is referred to as a VersionedTextDocumentIdentifier to allow clients to check the text document version before an edit is applied. A TextDocumentEdit describes all changes on a version Si and after they are applied move the document to version Si+1. So the creator of a TextDocumentEdit doesn’t need to sort the array or do any kind of ordering. However the edits must be non overlapping.
export interface TextDocumentEdit {
/**
* The text document to change.
*/
textDocument: VersionedTextDocumentIdentifier;
/**
* The edits to be applied.
*/
edits: TextEdit[];
}
File Resource changes
New in version 3.13:
File resource changes allow servers to create, rename and delete files anf folders via the client. Note that the names talk about files but the operations are supposed to work on files and folders. This is in line with other naming in the Language Server Protocol (see file watchers which can watch files and folders). The corresponding change literals look as follows:
/**
* Options to create a file.
*/
export interface CreateFileOptions {
/**
* Overwrite existing file. Overwrite wins over `ignoreIfExists`
*/
overwrite?: boolean;
/**
* Ignore if exists.
*/
ignoreIfExists?: boolean;
}
/**
* Create file operation
*/
export interface CreateFile {
/**
* A create
*/
kind: 'create';
/**
* The resource to create.
*/
uri: string;
/**
* Additional options
*/
options?: CreateFileOptions;
}
/**
* Rename file options
*/
export interface RenameFileOptions {
/**
* Overwrite target if existing. Overwrite wins over `ignoreIfExists`
*/
overwrite?: boolean;
/**
* Ignores if target exists.
*/
ignoreIfExists?: boolean;
}
/**
* Rename file operation
*/
export interface RenameFile {
/**
* A rename
*/
kind: 'rename';
/**
* The old (existing) location.
*/
oldUri: string;
/**
* The new location.
*/
newUri: string;
/**
* Rename options.
*/
options?: RenameFileOptions;
}
/**
* Delete file options
*/
export interface DeleteFileOptions {
/**
* Delete the content recursively if a folder is denoted.
*/
recursive?: boolean;
/**
* Ignore the operation if the file doesn't exist.
*/
ignoreIfNotExists?: boolean;
}
/**
* Delete file operation
*/
export interface DeleteFile {
/**
* A delete
*/
kind: 'delete';
/**
* The file to delete.
*/
uri: string;
/**
* Delete options.
*/
options?: DeleteFileOptions;
}
WorkspaceEdit
A workspace edit represents changes to many resources managed in the workspace. The edit should either provide changes or documentChanges. If the client can handle versioned document edits and if documentChanges are present, the latter are preferred over changes.
export interface WorkspaceEdit {
/**
* Holds changes to existing resources.
*/
changes?: { [uri: string]: TextEdit[]; };
/**
* Depending on the client capability `workspace.workspaceEdit.resourceOperations` document changes
* are either an array of `TextDocumentEdit`s to express changes to n different text documents
* where each text document edit addresses a specific version of a text document. Or it can contain
* above `TextDocumentEdit`s mixed with create, rename and delete file / folder operations.
*
* Whether a client supports versioned document edits is expressed via
* `workspace.workspaceEdit.documentChanges` client capability.
*
* If a client neither supports `documentChanges` nor `workspace.workspaceEdit.resourceOperations` then
* only plain `TextEdit`s using the `changes` property are supported.
*/
documentChanges?: (TextDocumentEdit[] | (TextDocumentEdit | CreateFile | RenameFile | DeleteFile)[]);
}
TextDocumentIdentifier
Text documents are identified using a URI. On the protocol level, URIs are passed as strings. The corresponding JSON structure looks like this:
interface TextDocumentIdentifier {
/**
* The text document's URI.
*/
uri: DocumentUri;
}
TextDocumentItem
An item to transfer a text document from the client to the server.
interface TextDocumentItem {
/**
* The text document's URI.
*/
uri: DocumentUri;
/**
* The text document's language identifier.
*/
languageId: string;
/**
* The version number of this document (it will increase after each
* change, including undo/redo).
*/
version: number;
/**
* The content of the opened text document.
*/
text: string;
}
In the specification, each text document has a unique specific language identifier. The following table lists all currently defined language identifiers:
Language Identifier
Windows Bat bat
BibTeX bibtex
Clojure clojure
Coffeescript coffeescript
C c
C++ cpp
C# csharp
CSS css
Diff diff
Dockerfile dockerfile
F# fsharp
Git git-commit and git-rebase
Go go
Groovy groovy
Handlebars handlebars
HTML html
Ini ini
Java java
JavaScript javascript
JSON json
LaTeX latex
Less less
Lua lua
Makefile makefile
Markdown markdown
Objective-C objective-c
Objective-C++ objective-cpp
Perl perl and perl6
PHP php
Powershell powershell
Pug jade
Python python
R r
Razor (cshtml) razor
Ruby ruby
Rust rust
Sass scss (syntax using curly brackets), sass (indented syntax)
ShaderLab shaderlab
Shell Script (Bash) shellscript
SQL sql
Swift swift
TypeScript typescript
TeX tex
Visual Basic vb
XML xml
XSL xsl
YAML yaml
VersionedTextDocumentIdentifier
An identifier to denote a specific version of a text document.
interface VersionedTextDocumentIdentifier extends TextDocumentIdentifier {
/**
* The version number of this document. If a versioned text document identifier
* is sent from the server to the client and the file is not open in the editor
* (the server has not received an open notification before) the server can send
* `null` to indicate that the version is known and the content on disk is the
* truth (as speced with document content ownership).
*
* The version number of a document will increase after each change, including
* undo/redo. The number doesn't need to be consecutive.
*/
version: number | null;
}
TextDocumentPositionParams
Was TextDocumentPosition in 1.0 with inlined parameters.
A parameter literal used in requests to pass a text document and a position inside that document.
interface TextDocumentPositionParams {
/**
* The text document.
*/
textDocument: TextDocumentIdentifier;
/**
* The position inside the text document.
*/
position: Position;
}
DocumentFilter
A document filter denotes a document through properties like language, scheme or pattern. An example is a filter that applies to TypeScript files on disk. Another example is a filter the applies to JSON files with name package.json:
{ language: 'typescript', scheme: 'file' }
{ language: 'json', pattern: '**/package.json' }
export interface DocumentFilter {
/**
* A language id, like `typescript`.
*/
language?: string;
/**
* A Uri [scheme](#Uri.scheme), like `file` or `untitled`.
*/
scheme?: string;
/**
* A glob pattern, like `*.{ts,js}`.
*/
pattern?: string;
}
A document selector is the combination of one or more document filters.
export type DocumentSelector = DocumentFilter[];
MarkupContent
A MarkupContent literal represents a string value which content can be represented in different formats. Currently plaintext and markdown are supported formats. A MarkupContent is usually used in documentation properties of result literals like CompletionItem or SignatureInformation.
/**
* Describes the content type that a client supports in various
* result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
*
* Please note that `MarkupKinds` must not start with a `$`. This kinds
* are reserved for internal usage.
*/
export namespace MarkupKind {
/**
* Plain text is supported as a content format
*/
export const PlainText: 'plaintext' = 'plaintext';
/**
* Markdown is supported as a content format
*/
export const Markdown: 'markdown' = 'markdown';
}
export type MarkupKind = 'plaintext' | 'markdown';
/**
* A `MarkupContent` literal represents a string value which content is interpreted base on its
* kind flag. Currently the protocol supports `plaintext` and `markdown` as markup kinds.
*
* If the kind is `markdown` then the value can contain fenced code blocks like in GitHub issues.
* See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting
*
* Here is an example how such a string can be constructed using JavaScript / TypeScript:
* ```ts
* let markdown: MarkdownContent = {
* kind: MarkupKind.Markdown,
* value: [
* '# Header',
* 'Some text',
* '```typescript',
* 'someCode();',
* '```'
* ].join('\n')
* };
* ```
*
* *Please Note* that clients might sanitize the return markdown. A client could decide to
* remove HTML from the markdown to avoid script execution.
*/
export interface MarkupContent {
/**
* The type of the Markup
*/
kind: MarkupKind;
/**
* The content itself
*/
value: string;
}
Actual Protocol
This section documents the actual language server protocol. It uses the following format:
a header describing the request
a Request: section describing the format of the request sent. The method is a string identifying the request the params are documented using a TypeScript interface
a Response: section describing the format of the response. The result item describes the returned data in case of a success. The error.data describes the returned data in case of an error. Please remember that in case of a failure the response already contains an error.code and an error.message field. These fields are only speced if the protocol forces the use of certain error codes or messages. In cases where the server can decide on these values freely they aren’t listed here.
a Registration Options section describing the registration option if the request or notification supports dynamic capability registration.
Request, Notification and response ordering
Responses to requests should be sent in the roughly same order as the requests appear on the server or client side. So for example if a server receives a textDocument/completion request and then a textDocument/signatureHelp request it will usually first return the response for the textDocument/completion and then the response for textDocument/signatureHelp.
However, the server may decide to use a parallel execution strategy and may wish to return responses in a different order than the requests were received. The server may do so as long as this reordering doesn’t affect the correctness of the responses. For example, reordering the result of textDocument/completion and textDocument/signatureHelp is allowed, as these each of these requests usually won’t affect the output of the other. On the other hand, the server most likely should not reorder textDocument/definition and textDocument/rename requests, since the executing the latter may affect the result of the former.
Server lifetime
The current protocol specification defines that the lifetime of a server is managed by the client (e.g. a tool like VS Code or Emacs). It is up to the client to decide when to start (process-wise) and when to shutdown a server.
Initialize Request (:leftwards_arrow_with_hook:)
The initialize request is sent as the first request from the client to the server. If the server receives a request or notification before the initialize request it should act as follows:
For a request the response should be an error with code: -32002. The message can be picked by the server.
Notifications should be dropped, except for the exit notification. This will allow the exit of a server without an initialize request.
Until the server has responded to the initialize request with an InitializeResult, the client must not send any additional requests or notifications to the server. In addition the server is not allowed to send any requests or notifications to the client until it has responded with an InitializeResult, with the exception that during the initialize request the server is allowed to send the notifications window/showMessage, window/logMessage and telemetry/event as well as the window/showMessageRequest request to the client.
The initialize request may only be sent once.
Request:
method: ‘initialize’
params: InitializeParams defined as follows:
interface 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.
*/
processId: number | null;
/**
* The rootPath of the workspace. Is null
* if no folder is open.
*
* @deprecated in favour of rootUri.
*/
rootPath?: string | null;
/**
* The rootUri of the workspace. Is null if no
* folder is open. If both `rootPath` and `rootUri` are set
* `rootUri` wins.
*/
rootUri: DocumentUri | null;
/**
* User provided initialization options.
*/
initializationOptions?: any;
/**
* The capabilities provided by the client (editor or tool)
*/
capabilities: ClientCapabilities;
/**
* The initial trace setting. If omitted trace is disabled ('off').
*/
trace?: 'off' | 'messages' | 'verbose';
/**
* The workspace folders configured in the client when the server starts.
* This property is only available if the client supports workspace folders.
* It can be `null` if the client supports workspace folders but none are
* configured.
*
* Since 3.6.0
*/
workspaceFolders?: WorkspaceFolder[] | null;
}
Where ClientCapabilities, TextDocumentClientCapabilities and WorkspaceClientCapabilities are defined as follows:
WorkspaceClientCapabilities define capabilities the editor / tool provides on the workspace:
New in version 3.13: ResourceOperationKind and FailureHandlingKind and the client capability workspace.workspaceEdit.resourceOperations as well as workspace.workspaceEdit.failureHandling.
/**
* The kind of resource operations supported by the client.
*/
export type ResourceOperationKind = 'create' | 'rename' | 'delete';
export namespace ResourceOperationKind {
/**
* Supports creating new files and folders.
*/
export const Create: ResourceOperationKind = 'create';
/**
* Supports renaming existing files and folders.
*/
export const Rename: ResourceOperationKind = 'rename';
/**
* Supports deleting existing files and folders.
*/
export const Delete: ResourceOperationKind = 'delete';
}
export type FailureHandlingKind = 'abort' | 'transactional' | 'undo' | 'textOnlyTransactional';
export namespace FailureHandlingKind {
/**
* Applying the workspace change is simply aborted if one of the changes provided
* fails. All operations executed before the failing operation stay executed.
*/
export const Abort: FailureHandlingKind = 'abort';
/**
* All operations are executed transactional. That means they either all
* succeed or no changes at all are applied to the workspace.
*/
export const Transactional: FailureHandlingKind = 'transactional';
/**
* If the workspace edit contains only textual file changes they are executed transactional.
* If resource changes (create, rename or delete file) are part of the change the failure
* handling startegy is abort.
*/
export const TextOnlyTransactional: FailureHandlingKind = 'textOnlyTransactional';
/**
* The client tries to undo the operations already executed. But there is no
* guaruntee that this is succeeding.
*/
export const Undo: FailureHandlingKind = 'undo';
}
/**
* Workspace specific client capabilities.
*/
export interface WorkspaceClientCapabilities {
/**
* The client supports applying batch edits to the workspace by supporting
* the request 'workspace/applyEdit'
*/
applyEdit?: boolean;
/**
* Capabilities specific to `WorkspaceEdit`s
*/
workspaceEdit?: {
/**
* The client supports versioned document changes in `WorkspaceEdit`s
*/
documentChanges?: boolean;
/**
* The resource operations the client supports. Clients should at least
* support 'create', 'rename' and 'delete' files and folders.
*/
resourceOperations?: ResourceOperationKind[];
/**
* The failure handling strategy of a client if applying the workspace edit
* failes.
*/
failureHandling?: FailureHandlingKind;
};
/**
* Capabilities specific to the `workspace/didChangeConfiguration` notification.
*/
didChangeConfiguration?: {
/**
* Did change configuration notification supports dynamic registration.
*/
dynamicRegistration?: boolean;
};
/**
* Capabilities specific to the `workspace/didChangeWatchedFiles` notification.
*/
didChangeWatchedFiles?: {
/**
* Did change watched files notification supports dynamic registration.
*/
dynamicRegistration?: boolean;
};
/**
* Capabilities specific to the `workspace/symbol` request.
*/
symbol?: {
/**
* Symbol request supports dynamic registration.
*/
dynamicRegistration?: boolean;
/**
* Specific capabilities for the `SymbolKind` in the `workspace/symbol` request.
*/
symbolKind?: {
/**
* The symbol kind values the client supports. When this
* property exists the client also guarantees that it will
* handle values outside its set gracefully and falls back
* to a default value when unknown.
*
* If this property is not present the client only supports
* the symbol kinds from `File` to `Array` as defined in
* the initial version of the protocol.
*/
valueSet?: SymbolKind[];
}
};
/**
* Capabilities specific to the `workspace/executeCommand` request.
*/
executeCommand?: {
/**
* Execute command supports dynamic registration.
*/
dynamicRegistration?: boolean;
};
/**
* The client has support for workspace folders.
*
* Since 3.6.0
*/
workspaceFolders?: boolean;
/**
* The client supports `workspace/configuration` requests.
*
* Since 3.6.0
*/
configuration?: boolean;
}
TextDocumentClientCapabilities define capabilities the editor / tool provides on text documents.
/**
* Text document specific client capabilities.
*/
export interface TextDocumentClientCapabilities {
synchronization?: {
/**
* Whether text document synchronization supports dynamic registration.
*/
dynamicRegistration?: boolean;
/**
* The client supports sending will save notifications.
*/
willSave?: boolean;
/**
* The client supports sending a will save request and
* waits for a response providing text edits which will
* be applied to the document before it is saved.
*/
willSaveWaitUntil?: boolean;
/**
* The client supports did save notifications.
*/
didSave?: boolean;
}
/**
* Capabilities specific to the `textDocument/completion`
*/
completion?: {
/**
* Whether completion supports dynamic registration.
*/
dynamicRegistration?: boolean;
/**
* The client supports the following `CompletionItem` specific
* capabilities.
*/
completionItem?: {
/**
* Client supports snippets as insert text.
*
* A snippet can define tab stops and placeholders with `$1`, `$2`
* and `${3:foo}`. `$0` defines the final tab stop, it defaults to
* the end of the snippet. Placeholders with equal identifiers are linked,
* that is typing in one will update others too.
*/
snippetSupport?: boolean;
/**
* Client supports commit characters on a completion item.
*/
commitCharactersSupport?: boolean
/**
* Client supports the follow content formats for the documentation
* property. The order describes the preferred format of the client.
*/
documentationFormat?: MarkupKind[];
/**
* Client supports the deprecated property on a completion item.
*/
deprecatedSupport?: boolean;
/**
* Client supports the preselect property on a completion item.
*/
preselectSupport?: boolean;
}
completionItemKind?: {
/**
* The completion item kind values the client supports. When this
* property exists the client also guarantees that it will
* handle values outside its set gracefully and falls back
* to a default value when unknown.
*