An adorable little framework and command line tool for interacting with SourceKit.
SourceKitten links and communicates with sourcekitd.framework to parse the Swift AST, extract comment docs for Swift or Objective-C projects, get syntax data for a Swift file and lots more!
Installation
Building SourceKitten requires Xcode 13.3 or later or a Swift 5.6
toolchain or later with the Swift Package Manager.
SourceKitten typically supports previous versions of SourceKit.
Homebrew
Run brew install sourcekitten.
Swift Package Manager
Run swift build in the root directory of this project.
Then run: bazel run @com_github_jpsim_sourcekitten//:sourcekitten -- -h
Xcode (via Make)
Run make install in the root directory of this project.
Package
Download and open SourceKitten.pkg from the releases tab.
Command Line Usage
Once SourceKitten is installed, you may use it from the command line.
$ sourcekitten help
OVERVIEW: An adorable little command line tool for interacting with SourceKit
USAGE: sourcekitten <subcommand>
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
complete Generate code completion options
doc Print Swift or Objective-C docs as JSON
format Format Swift file
index Index Swift file and print as JSON
module-info Obtain information about a Swift module and print as JSON
request Run a raw SourceKit request
structure Print Swift structure information as JSON
syntax Print Swift syntax information as JSON
version Display the current version of SourceKitten
See 'sourcekitten help <subcommand>' for detailed help.
How is SourceKit resolved?
SourceKitten searches for SourceKit in the following order:
Running sourcekitten complete --file file.swift --offset 123 or
sourcekitten complete --text "0." --offset 2 will print out code completion
options for the offset in the file/text provided:
Running sourcekitten doc will pass all arguments after what is parsed to
xcodebuild (or directly to the compiler, SourceKit/clang, in the
--single-file mode).
Running sourcekitten structure --file file.swift or sourcekitten structure --text "struct A { func b() {} }" will return a JSON array of structure information:
Running sourcekitten syntax --file file.swift or sourcekitten syntax --text "import Foundation // Hello World" will return a JSON array of syntax highlighting information:
Most of the functionality of the sourcekitten command line tool is actually encapsulated in a framework named SourceKittenFramework.
If you’re interested in using SourceKitten as part of another tool, or perhaps extending its functionality, take a look at the SourceKittenFramework source code to see if the API fits your needs.
Note: SourceKitten is written entirely in Swift, and the SourceKittenFramework API is not designed to interface with Objective-C.
SourceKitten
An adorable little framework and command line tool for interacting with SourceKit.
SourceKitten links and communicates with
sourcekitd.framework
to parse the Swift AST, extract comment docs for Swift or Objective-C projects, get syntax data for a Swift file and lots more!Installation
Building SourceKitten requires Xcode 13.3 or later or a Swift 5.6 toolchain or later with the Swift Package Manager.
SourceKitten typically supports previous versions of SourceKit.
Homebrew
Run
brew install sourcekitten
.Swift Package Manager
Run
swift build
in the root directory of this project.Bazel
Add the following to your
WORKSPACE
file:Then run:
bazel run @com_github_jpsim_sourcekitten//:sourcekitten -- -h
Xcode (via Make)
Run
make install
in the root directory of this project.Package
Download and open SourceKitten.pkg from the releases tab.
Command Line Usage
Once SourceKitten is installed, you may use it from the command line.
How is SourceKit resolved?
SourceKitten searches for SourceKit in the following order:
$XCODE_DEFAULT_TOOLCHAIN_OVERRIDE
$TOOLCHAIN_DIR
xcrun -find swift
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
~/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
~/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
On Linux, SourceKit is expected to be located in
/usr/lib/libsourcekitdInProc.so
or specified by theLINUX_SOURCEKIT_LIB_PATH
environment variable.Projects Built With SourceKitten
See More
Complete
Running
sourcekitten complete --file file.swift --offset 123
orsourcekitten complete --text "0." --offset 2
will print out code completion options for the offset in the file/text provided:To use the iOS SDK, pass
-sdk
and-target
arguments preceded by--
:Doc
Running
sourcekitten doc
will pass all arguments after what is parsed toxcodebuild
(or directly to the compiler, SourceKit/clang, in the--single-file
mode).Example usage
sourcekitten doc -- -workspace SourceKitten.xcworkspace -scheme SourceKittenFramework
sourcekitten doc --single-file file.swift -- -j4 file.swift
sourcekitten doc --module-name Alamofire -- -project Alamofire.xcodeproj
sourcekitten doc -- -workspace Haneke.xcworkspace -scheme Haneke
sourcekitten doc --objc Realm/Realm.h -- -x objective-c -isysroot $(xcrun --show-sdk-path) -I $(pwd)
Structure
Running
sourcekitten structure --file file.swift
orsourcekitten structure --text "struct A { func b() {} }"
will return a JSON array of structure information:Syntax
Running
sourcekitten syntax --file file.swift
orsourcekitten syntax --text "import Foundation // Hello World"
will return a JSON array of syntax highlighting information:Request
Running
sourcekitten request --yaml [FILE|TEXT]
will execute a sourcekit request with the given yaml. For example:SourceKittenFramework
Most of the functionality of the
sourcekitten
command line tool is actually encapsulated in a framework named SourceKittenFramework.If you’re interested in using SourceKitten as part of another tool, or perhaps extending its functionality, take a look at the SourceKittenFramework source code to see if the API fits your needs.
Note: SourceKitten is written entirely in Swift, and the SourceKittenFramework API is not designed to interface with Objective-C.
License
MIT licensed.