@@ -16,6 +16,18 @@ The protocol is documented in the following format:
16
16
- ` "[opt]" ` indicates an optional key.
17
17
- Specific UIDs are written as ` <UID string> ` .
18
18
19
+ # Table of Contents
20
+
21
+ | Request Name | Request Key |
22
+ | -------------:| :------------|
23
+ | [ Code Completion] ( #code-completion ) | source.request.codecomplete |
24
+ | [ Cursor Info] ( #cursor-info ) | source.request.cursorinfo |
25
+ | [ Demangling] ( #demangling ) | source.request.demangle |
26
+ | [ Documentation] ( #documentation ) | source.request.docinfo |
27
+ | [ Module interface generation] ( #module-interface-generation ) | source.request.editor.open.interface |
28
+ | [ Indexing] ( #indexing ) | source.request.indexsource |
29
+ | [ Protocol Version] ( #protocol-version ) | source.request.protocol_version |
30
+
19
31
20
32
# Requests
21
33
@@ -393,7 +405,7 @@ range ::=
393
405
394
406
Sub-diagnostics are only diagnostic notes currently.
395
407
396
- # Demangling
408
+ ## Demangling
397
409
398
410
SourceKit is capable of "demangling" mangled Swift symbols. In other words,
399
411
it's capable of taking the symbol ` _TF13MyCoolPackageg6raichuVS_7Pokemon ` as
@@ -455,6 +467,123 @@ Welcome to SourceKit. Type ':help' for assistance.
455
467
}
456
468
```
457
469
470
+ ## Protocol Version
471
+
472
+ SourceKit can provide information about the version of the protocol that is being used.
473
+
474
+ ### Request
475
+
476
+ ```
477
+ {
478
+ <key.request>: (UID) <source.request.protocol_version>
479
+ }
480
+ ```
481
+
482
+ ### Response
483
+
484
+ ```
485
+ {
486
+ <key.version_major>: (int64) // The major version number in a version string
487
+ <key.version_minor>: (int64) // The minor version number in a version string
488
+ }
489
+ ```
490
+
491
+ ### Testing
492
+
493
+ ```
494
+ $ sourcekitd-test -req=version
495
+ ```
496
+
497
+ or
498
+
499
+ ```
500
+ $ sourcekitd-repl
501
+ Welcome to SourceKit. Type ':help' for assistance.
502
+ (SourceKit) {
503
+ key.request: source.request.protocol_version
504
+ }
505
+ ```
506
+
507
+ ## Cursor Info
508
+
509
+ SourceKit is capable of providing information about a specific symbol at a specific cursor, or offset, position in a document.
510
+
511
+ To gather documentation, SourceKit must be given either the name of a module (key.modulename), the path to a file (key.sourcefile), or some text (key.sourcetext). key.sourcefile is ignored when key.sourcetext is also provided, and both of those keys are ignored if key.modulename is provided.
512
+
513
+ ### Request
514
+
515
+ ```
516
+ {
517
+ <key.request>: (UID) <source.request.cursorinfo>,
518
+ [opt] <key.sourcetext>: (string) // Source contents.
519
+ [opt] <key.sourcefile>: (string) // Absolute path to the file.
520
+ // **Require**: key.sourcetext or key.sourcefile
521
+ [opt] <key.offset>: (int64) // Byte offset of code point inside the source contents.
522
+ [opt] <key.usr>: (string) // USR string for the entity.
523
+ // **Require**: key.offset or key.usr
524
+ [opt] <key.compilerargs>: [string*] // Array of zero or more strings for the compiler arguments,
525
+ // e.g ["-sdk", "/path/to/sdk"]. If key.sourcefile is provided,
526
+ // these must include the path to that file.
527
+ }
528
+ ```
529
+
530
+ ### Response
531
+
532
+ ```
533
+ {
534
+ <key.kind>: (UID) // UID for the declaration or reference kind (function, class, etc.).
535
+ <key.name>: (string) // Displayed name for the token.
536
+ <key.usr>: (string) // USR string for the token.
537
+ <key.filepath>: (string) // Path to the file.
538
+ <key.offset>: (int64) // Byte offset of the token inside the souce contents.
539
+ <key.length>: (ist64) // Length of the token.
540
+ <key.typename>: (string) // Text describing the type of the result.
541
+ <key.annotated_decl>: (string) // XML representing how the token was declared.
542
+ <key.fully_annotated_decl>: (string) // XML representing the token.
543
+ [opt] <key.doc.full_as_xml>: (string) // XML representing the token and its documentation.
544
+ <key.typeusr>: (string) // USR string for the type.
545
+ }
546
+ ```
547
+
548
+ ### Testing
549
+
550
+ ```
551
+ $ sourcekitd-test -req=cursor -offset=<offset> <file> [-- <compiler args>]
552
+ $ sourcekitd-test -req=cursor -pos=<line>:<column> <file> [-- <compiler args>]
553
+ ```
554
+
555
+ For example, using a document containing:
556
+
557
+ ```
558
+ struct Foo {
559
+ let bar: String
560
+ }
561
+ ```
562
+
563
+ To get the information about the type ` Foo ` you would make one of the following requests:
564
+
565
+ ```
566
+ $ sourcekitd-test -req=cursor -offset=7 /path/to/file.swift -- /path/to/file.swift
567
+ $ sourcekitd-test -req=cursor -pos=1:8 /path/to/file.swift -- /path/to/file.swift
568
+ ```
569
+
570
+ Note that when using ` sourcekitd-test ` , the output is output in an ad hoc text format, not JSON.
571
+
572
+ You could also issue the following request in the ` sourcekitd-repl ` , which produces JSON:
573
+
574
+ ```
575
+ $ sourcekitd-repl
576
+ Welcome to SourceKit. Type ':help' for assistance.
577
+ (SourceKit) {
578
+ key.request: source.request.cursorinfo,
579
+ key.sourcefile: "/path/to/file.swift",
580
+ key.offset: 7,
581
+ key.compilerargs: [ "/path/to/file.swift" ]
582
+ }
583
+ ```
584
+
585
+
586
+
458
587
# UIDs
459
588
460
589
## Keys
@@ -472,3 +601,9 @@ Welcome to SourceKit. Type ':help' for assistance.
472
601
- ` key.sourcetext `
473
602
- ` key.typename `
474
603
- ` key.usr `
604
+ - ` key.version_major `
605
+ - ` key.version_minor `
606
+ - ` key.annotated_decl `
607
+ - ` key.fully_annotated_decl `
608
+ - ` key.doc.full_as_xml `
609
+ - ` key.typeusr `
0 commit comments