Skip to content

Commit 9432de2

Browse files
committed
[SourceKit] Document source.request.cursorinfo
1 parent e6a1a8c commit 9432de2

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

tools/SourceKit/docs/Protocol.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,86 @@ Welcome to SourceKit. Type ':help' for assistance.
492492
}
493493
```
494494

495+
## Cursor Info
496+
497+
SourceKit is capable of providing information about a specific symbol at a specific cursor, or offset, position in a document.
498+
499+
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.
500+
501+
### Request
502+
503+
```
504+
{
505+
<key.request>: (UID) <source.request.cursorinfo>,
506+
[opt] <key.sourcetext>: (string) // Source contents.
507+
[opt] <key.sourcefile>: (string) // Absolute path to the file.
508+
// **Require**: key.sourcetext or key.sourcefile
509+
[opt] <key.offset>: (int64) // Byte offset of code point inside the source contents.
510+
[opt] <key.usr>: (string) // USR string for the entity.
511+
// **Require**: key.offset or key.usr
512+
[opt] <key.compilerargs>: [string*] // Array of zero or more strings for the compiler arguments,
513+
// e.g ["-sdk", "/path/to/sdk"]. If key.sourcefile is provided,
514+
// these must include the path to that file.
515+
}
516+
```
517+
518+
### Response
519+
520+
```
521+
{
522+
<key.kind>: (UID) // UID for the declaration or reference kind (function, class, etc.).
523+
<key.name>: (string) // Displayed name for the token.
524+
<key.usr>: (string) // USR string for the token.
525+
<key.filepath>: (string) // Path to the file.
526+
<key.offset>: (int64) // Byte offset of the token inside the souce contents.
527+
<key.length>: (ist64) // Length of the token.
528+
<key.typename>: (string) // Text describing the type of the result.
529+
<key.annotated_decl>: (string) // XML representing how the token was declared.
530+
<key.fully_annotated_decl>: (string) // XML representing the token.
531+
[opt] <key.doc.full_as_xml>: (string) // XML representing the token and its documentation.
532+
<key.typeusr>: (string) // USR string for the type.
533+
}
534+
```
535+
536+
### Testing
537+
538+
```
539+
$ sourcekitd-test -req=cursor -offset=<offset> <file> [-- <compiler args>]
540+
$ sourcekitd-test -req=cursor -pos=<line>:<column> <file> [-- <compiler args>]
541+
```
542+
543+
For example, using a document containing:
544+
545+
```
546+
struct Foo {
547+
let bar: String
548+
}
549+
```
550+
551+
To get the information about the type `Foo` you would make one of the following requests:
552+
553+
```
554+
$ sourcekitd-test -req=cursor -offset=7 /path/to/file.swift -- /path/to/file.swift
555+
$ sourcekitd-test -req=cursor -pos=1:8 /path/to/file.swift -- /path/to/file.swift
556+
```
557+
558+
Note that when using `sourcekitd-test`, the output is output in an ad hoc text format, not JSON.
559+
560+
You could also issue the following request in the `sourcekitd-repl`, which produces JSON:
561+
562+
```
563+
$ sourcekitd-repl
564+
Welcome to SourceKit. Type ':help' for assistance.
565+
(SourceKit) {
566+
key.request: source.request.cursorinfo,
567+
key.sourcefile: "/path/to/file.swift",
568+
key.offset: 7,
569+
key.compilerargs: [ "/path/to/file.swift" ]
570+
}
571+
```
572+
573+
574+
495575
# UIDs
496576

497577
## Keys
@@ -511,3 +591,7 @@ Welcome to SourceKit. Type ':help' for assistance.
511591
- `key.usr`
512592
- `key.version_major`
513593
- `key.version_minor`
594+
- `key.annotated_decl`
595+
- `key.fully_annotated_decl`
596+
- `key.doc.full_as_xml`
597+
- `key.typeusr`

0 commit comments

Comments
 (0)