yaml -> sourcekit -> json
skit
is a dead simple CLI for interacting with
sourcekit
.
Here's an example of a request that returns the structure of the source:
Create a request.yaml
:
key.request: source.request.editor.open
key.name: "example.swift"
key.sourcetext: "struct Foo {}"
Run skit
:
$ skit request.yaml
Get the response from sourcekitd
:
{
"key.offset": 0,
"key.length": 14,
"key.diagnostic_stage": "source.diagnostic.stage.swift.parse",
"key.syntaxmap": [
{
"key.kind": "source.lang.swift.syntaxtype.keyword",
"key.offset": 0,
"key.length": 6
},
{
"key.kind": "source.lang.swift.syntaxtype.identifier",
"key.offset": 7,
"key.length": 3
}
],
"key.substructure": [
{
"key.kind": "source.lang.swift.decl.struct",
"key.accessibility": "source.lang.swift.accessibility.internal",
"key.name": "Foo",
"key.offset": 0,
"key.length": 13,
"key.nameoffset": 7,
"key.namelength": 3,
"key.bodyoffset": 12,
"key.bodylength": 0
}
]
}
sourcekit
supports many request types, for details on what you can do
see the protocol documentation.
$ brew install keith/formulae/skit
$ docker pull smileykeith/skit:TAG
NOTE: The tags for docker line up with the git tags on this repo.
$ make install
The protocol documentation defines most of the requests
you can use with sourcekit
SourceKitten
provides a
much better interface for specific requests, meaning you don't need to
deal with the implementation details of sourcekit
sourcekit
is open source! so you can read the source
for more details on how the pieces fit together
JP Simard (the author of SourceKitten
) has written some blog
posts and done a
talk
about how sourcekit
works
If you're interested in reproducing something that Xcode does, you can
see the communication between Xcode and sourcekitd
by setting
SOURCEKIT_LOGGING=3
and launching Xcode