Skip to content

Commit cfeece9

Browse files
modocachetkremenek
authored andcommitted
[docs] Spruce up Protocol docs for "docinfo" (#2401)
Modify the documentation for `source.request.docinfo` to match the format of the rest of the documentation: "Request", "Response", and "Testing".
1 parent be25fce commit cfeece9

File tree

1 file changed

+94
-23
lines changed

1 file changed

+94
-23
lines changed

tools/SourceKit/docs/Protocol.md

Lines changed: 94 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The protocol is documented in the following format:
1919

2020
# Requests
2121

22-
## Code-Completion
22+
## Code Completion
2323

2424
SourceKit is capable of providing code completion suggestions. To do so, it
2525
must be given either the path to a file (`key.sourcefile`), or some text
@@ -70,7 +70,7 @@ $ sourcekitd-test -req=complete -offset=<offset> <file> [-- <compiler args>]
7070
```
7171

7272
For example, to get a code completion suggestion for the 58th character in an
73-
ASCII file at `path/to/file.swift`:
73+
ASCII file at `/path/to/file.swift`:
7474

7575
```
7676
$ sourcekitd-test -req=complete -offset=58 /path/to/file.swift -- /path/to/file.swift
@@ -92,7 +92,7 @@ Welcome to SourceKit. Type ':help' for assistance.
9292
## Indexing
9393

9494
SourceKit is capable of "indexing" source code, responding with which ranges
95-
of text contain what kinds of source code. In other words, SourceKit is
95+
of text contain what kinds of source code. For example, SourceKit is
9696
capable of telling you that "the source code on line 2, column 9, is a
9797
reference to a struct".
9898

@@ -162,7 +162,7 @@ dependency ::=
162162
$ sourcekitd-test -req=index <file> [-- <compiler args>]
163163
```
164164

165-
For example, to index a file at `path/to/file.swift`:
165+
For example, to index a file at `/path/to/file.swift`:
166166

167167
```
168168
$ sourcekitd-test -req=index /path/to/file.swift -- /path/to/file.swift
@@ -180,44 +180,115 @@ Welcome to SourceKit. Type ':help' for assistance.
180180
}
181181
```
182182

183-
## DocInfo
183+
## Documentation
184+
185+
SourceKit is capable of gathering symbols and their documentation, either
186+
from Swift source code or from a Swift module. SourceKit returns a list of
187+
symbols and, if they are documented, the documentation for those symbols.
188+
189+
To gather documentation, SourceKit must be given either the name of a module
190+
(`key.modulename`), the path to a file (`key.sourcefile`), or some text
191+
(`key.sourcetext`). `key.sourcefile` is ignored when `key.sourcetext` is also
192+
provided, and both of those keys are ignored if `key.modulename` is provided.
193+
194+
### Request
184195

185196
```
186197
{
187-
"key.request": source.request.docinfo,
188-
"key.modulename": "Foundation",
189-
"key.compilerargs": ["-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk"]
198+
<key.request>: (UID) <source.request.docinfo>
199+
[opt] <key.modulename>: (string) // The name of the Swift module.
200+
[opt] <key.sourcetext>: (string) // Source contents.
201+
[opt] <key.sourcefile>: (string) // Absolute path to the file.
202+
[opt] <key.compilerargs> [string*] // Array of zero or more strings for the compiler arguments
203+
// e.g ["-sdk", "/path/to/sdk"]. If key.sourcefile is provided,
204+
// these must include the path to that file.
190205
}
191206
```
192207

193-
This will return:
208+
### Response
194209

195-
- `key.sourcetext`: The pretty-printed module interface in swift source code
196-
- `key.annotations`: An array of annotations for the tokens of source text, they refer to the text via offset+length entries. This includes syntactic annotations (e.g. keywords) and semantic ones. The semantic ones include the name and USR of the referenced symbol.
197-
- `key.entities`: A structure of the symbols, similar to what the indexing request returns (a class has its methods as sub-entities, etc.). This includes the function parameters and their types as entities. Each entity refers to the range of the original text via offset+length entries.
210+
```
211+
{
212+
<key.sourcetext>: (string) // Source contents.
213+
<key.annotations>: (array) [annotation*] // An array of annotations for the tokens of
214+
// source text, they refer to the text via offset + length
215+
// entries. This includes syntactic annotations (e.g.
216+
// keywords) and semantic ones. The semantic ones include
217+
// the name and USR of the referenced symbol.
218+
[opt] <key.entities>: (array) [entity*] // A structure of the symbols, similar to what the indexing
219+
// request returns (a class has its methods as sub-entities,
220+
// etc.). This includes the function parameters and their
221+
// types as entities. Each entity refers to the range of the
222+
// original text via offset + length entries.
223+
[opt] <key.diagnostics>: (array) [diagnostic*] // Compiler diagnostics emitted during parsing of a source file.
224+
// This key is only present if a diagnostic was emitted (and thus
225+
// the length of the array is non-zero).
226+
}
227+
```
198228

229+
```
230+
annotation ::=
231+
{
232+
<key.kind>: (UID) // UID for the declaration kind (function, class, etc.).
233+
<key.offset>: (int64) // Location of the annotated token.
234+
<key.length>: (int64) // Length of the annotated token.
235+
}
236+
```
199237

200-
For source text (you can also pass a source filename with `key.sourcefile`):
238+
```
239+
entity ::=
240+
{
241+
<key.kind>: (UID) // UID for the declaration or reference kind (function, class, etc.).
242+
<key.name>: (string) // Displayed name for the entity.
243+
<key.usr>: (string) // USR string for the entity.
244+
<key.offset>: (int64) // Location of the entity.
245+
<key.length>: (int64) // Length of the entity.
246+
<key.fully_annotated_decl>: (string) // XML representing the entity, its USR, etc.
247+
[opt] <key.doc.full_as_xml>: (string) // XML representing the entity and its documentation. Only present
248+
// when the entity is documented.
249+
[opt] <key.entities>: (array) [entity+] // One or more entities contained in the particular entity (sub-classes, references, etc.).
250+
}
251+
```
201252

202253
```
254+
diagnostic ::=
203255
{
204-
"key.request": source.request.docinfo,
205-
"key.sourcefile": "/whatever/virtual/path",
206-
"key.sourcetext": "import Foundation\n var s: NSString\n",
207-
"key.compilerargs": ["/whatever/virtual/path", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk"]
256+
<key.line>: (int64) // The line upon which the diagnostic was emitted.
257+
<key.column>: (int64) // The column upon which the diagnostic was emitted.
258+
<key.filepath>: (string) // The absolute path to the file that was being parsed
259+
// when the diagnostic was emitted.
260+
<key.severity>: (UID) // The severity of the diagnostic. Can be one of:
261+
// - source.diagnostic.severity.note
262+
// - source.diagnostic.severity.warning
263+
// - source.diagnostic.severity.error
264+
<key.description>: (string) // A description of the diagnostic.
208265
}
209266
```
210267

211-
This will return
268+
### Testing
269+
270+
```
271+
$ sourcekitd-test -req=doc-info <file> [-- <compiler args>]
272+
```
212273

213-
- `key.annotations`
214-
- `key.entities`
274+
For example, to gather documentation info for a file at `/path/to/file.swift`:
215275

216-
...which will refer to the original text, and:
276+
```
277+
$ sourcekitd-test -req=doc-info /path/to/file.swift -- /path/to/file.swift
278+
```
217279

218-
- `key.diagnostics`
280+
You could also issue the following request in the `sourcekitd-repl` to
281+
gather all the documentation info for Foundation (careful, it's a lot!):
219282

220-
...for any compiler diagnostics during parsing.
283+
```
284+
$ sourcekitd-repl
285+
Welcome to SourceKit. Type ':help' for assistance.
286+
(SourceKit) {
287+
key.request: source.request.docinfo,
288+
key.modulename: "Foundation",
289+
key.compilerargs: ["-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk"]
290+
}
291+
```
221292

222293
## Module interface generation
223294

0 commit comments

Comments
 (0)