sourcekitten Docs (93% documented)

sourcekitten Reference Functions Reference

Functions

The following functions are available globally.

  • Converts any path into an absolute path

    Declaration

    Swift

    func absolutePath(path: NSString) -> String

    Parameters

    path

    An arbitrary path

    Return Value

    path represented as an absolute path

  • Returns offsets of all the line breaks in the fileContents global

    Declaration

    Swift

    func lineBreaks() -> [Int]

    Return Value

    line breaks

  • Sends a request to SourceKit returns the response as an XPCDictionary.

    Declaration

    Swift

    func sendSourceKitRequest(request: xpc_object_t?) -> XPCDictionary

    Parameters

    request

    Request to send synchronously to SourceKit

    Return Value

    SourceKit output

  • Cache SourceKit requests for strings from UIDs

    Declaration

    Swift

    func stringForSourceKitUID(uid: UInt64) -> String?

    Parameters

    uid

    UID received from sourcekitd* responses

    Return Value

    Cached UID string if available, other

  • Print message to STDERR and exit(1)

    Declaration

    Swift

    func error(message: String)

    Parameters

    message

    message to print

  • Print message to STDERR. Useful for UI messages without affecting STDOUT data.

    Declaration

    Swift

    func printSTDERR(message: String)

    Parameters

    message

    message to print.

  • Parse declaration from XPC dictionary.

    See more

    Declaration

    Swift

    func parseDeclaration(dictionary: XPCDictionary) -> String?

    Parameters

    dictionary

    XPC dictionary to extract declaration from.

    Return Value

    String declaration if successfully parsed.

  • Process a SourceKit editor.open response dictionary by removing undocumented tokens with no documented children. Add cursor.info information for declarations. Add name to mark comments.

    Declaration

    Swift

    func processDictionary(inout dictionary: XPCDictionary,
        _ cursorInfoRequest: xpc_object_t? = nil) -> Bool

    Parameters

    dictionary

    XPCDictionary to mutate.

    cursorInfoRequest

    SourceKit xpc dictionary to use to send cursorinfo request.

    Return Value

    Whether or not the dictionary should be kept.

  • Find parent offsets for given documented offsets.

    Declaration

    Swift

    func mapOffsets(dictionary: XPCDictionary, inout documentedTokenOffsets: [Int: Int], file: String)

    Parameters

    dictionary

    Parent document to search for ranges.

    documentedTokenOffsets

    inout dictionary of documented token offsets mapping to their parent offsets.

    file

    File where these offsets are located.

  • Find integer offsets of documented tokens

    Declaration

    Swift

    func documentedTokenOffsets(syntaxMap: NSData, file: String) -> [Int]

    Parameters

    syntaxMap

    Syntax Map returned from SourceKit editor.open request

    file

    File to parse

    Return Value

    Array of documented token offsets

  • Find integer offsets of documented tokens

    Declaration

    Swift

    func documentedTokenOffsets(file: String) -> [Int]

    Parameters

    file

    File to parse

    Return Value

    Array of documented token offsets

  • Convert XPCDictionary to JSON

    Declaration

    Swift

    func toJSON(dictionary: XPCDictionary) -> String

    Parameters

    dictionary

    XPCDictionary to convert

    Return Value

    Converted JSON

  • Convert XPCArray of XPCDictionary’s to JSON

    Declaration

    Swift

    func toJSON(array: XPCArray) -> String

    Parameters

    array

    XPCArray of XPCDictionary’s to convert

    Return Value

    Converted JSON

  • JSON Object to JSON String

    Declaration

    Swift

    func toJSON(object: AnyObject) -> String

    Parameters

    object

    Object to convert to JSON.

    Return Value

    JSON string representation of the input object.

  • Convert XPCDictionary to [String: AnyObject] for conversion using NSJSONSerialization. See toJSON(_:)

    Declaration

    Swift

    func toAnyObject(dictionary: XPCDictionary) -> [String: AnyObject]

    Parameters

    dictionary

    XPCDictionary to convert

    Return Value

    JSON-serializable Dictionary

  • Run xcodebuild clean build -dry-run along with any passed in build arguments. Return STDERR and STDOUT as a combined string.

    Declaration

    Swift

    func run_xcodebuild(arguments: [String]) -> String?

    Parameters

    arguments

    array of arguments to pass to xcodebuild

    Return Value

    xcodebuild STDERR+STDOUT output

  • Run sourcekitten as a new process.

    Declaration

    Swift

    func run_self(processArguments: [String]) -> String?

    Parameters

    processArguments

    arguments to pass to new sourcekitten process

    Return Value

    sourcekitten STDOUT output

  • Parses the compiler arguments needed to compile the language aspects of an Xcode project

    See more

    Declaration

    Swift

    func compiler_arguments_from_xcodebuild_output(xcodebuildOutput: NSString, #language: Language) -> [String]?

    Parameters

    xcodebuildOutput

    output of xcodebuild to be parsed for compiler arguments

    Return Value

    array of compiler arguments

  • Print JSON and XML-formatted docs for the specified Swift file.

    Declaration

    Swift

    func docs_for_swift_compiler_args(arguments: [String], file: String)

    Parameters

    arguments

    compiler arguments to pass to SourceKit

    file

    Path to Swift file to document

  • Insert a document in a parent at the given offset.

    See more

    Declaration

    Swift

    func insertDoc(doc: XPCDictionary, inout parent: XPCDictionary, offset: Int64, file: String) -> Bool

    Parameters

    doc

    Document to insert

    parent

    Document to insert into

    offset

    Parent’s offset

    file

    File where parent and doc are located

    Return Value

    Whether or not the insertion succeeded

  • Returns an array of swift file names in an array

    Declaration

    Swift

    func swiftFilesFromArray(array: [String]) -> [String]

    Parameters

    array

    Array to be filtered

    Return Value

    the array of swift files

  • Print file structure information as JSON to STDOUT

    Declaration

    Swift

    func printStructure(#file: String)

    Parameters

    file

    Path to the file to parse for structure information

  • Print syntax information as JSON to STDOUT

    Declaration

    Swift

    func printSyntax(#file: String)

    Parameters

    file

    Path to the file to parse for syntax highlighting information

  • Print syntax information as JSON to STDOUT

    Declaration

    Swift

    func printSyntax(#text: String)

    Parameters

    text

    Swift source code to parse for syntax highlighting information

  • Print syntax information as JSON to STDOUT

    Declaration

    Swift

    func printSyntax(sourceKitResponse: XPCDictionary)

    Parameters

    sourceKitResponse

    XPC object returned from SourceKit editor.open call

  • Prints help message in console

    Declaration

    Swift

    func printHelp()
  • Iterates over Clang translation unit to find all its XML comments. Prints to STDOUT.

    Declaration

    Swift

    func printXML(translationUnit: CXTranslationUnit) -> Void

    Parameters

    translationUnit

    Clang translation unit created from Clang index, file path and compiler arguments.

  • Build Clang translation unit from Objective-C header file path and prints its XML comments to STDOUT.

    Declaration

    Swift

    func objc(headerFiles: [String], args: [String])

    Parameters

    headerFilePath

    Absolute path to Objective-C header file.

  • Parse command-line arguments & call the appropriate function.

    Declaration

    Swift

    func main()
  • Enable comparison of XPCRepresentable objects.

    Declaration

    Swift

    public func !=(lhs: XPCRepresentable, rhs: XPCRepresentable) -> Bool
  • Enable comparison of XPCRepresentable objects.

    Declaration

    Swift

    public func ==(lhs: XPCRepresentable, rhs: XPCRepresentable) -> Bool
  • Initialize the SourceKit XPC service. This should only be done once per session (as Xcode does).

    Declaration

    Swift

    @asmname("sourcekitd_initialize") func sourcekitd_initialize() -> Int
  • Print string description of XPC request to STDOUT

    Declaration

    Swift

    @asmname("sourcekitd_request_description_dump") func sourcekitd_request_description_dump(_: xpc_object_t?) -> Void
  • Print string description of XPC response to STDOUT

    Declaration

    Swift

    @asmname("sourcekitd_response_description_dump") func sourcekitd_response_description_dump(_: xpc_object_t?) -> Void
  • Print string description of XPC response and its file description to STDOUT NOTE: This does not work, instead simply causing a fatal I/O error

    Declaration

    Swift

    @asmname("sourcekitd_response_description_dump_filedesc") func sourcekitd_response_description_dump_filedesc(_: xpc_object_t?) -> Void
  • Returns whether or not XPC response is an error NOTE: I’ve never seen this return true, despite SourceKit requests failing with an error message

    Declaration

    Swift

    @asmname("sourcekitd_response_is_error") func sourcekitd_response_is_error(_: xpc_object_t?) -> Bool
  • Send a synchronous request to SourceKit. Response is returned as an xpc_object_t. Typically an XPC dictionary.

    Declaration

    Swift

    @asmname("sourcekitd_send_request_sync") func sourcekitd_send_request_sync(_: xpc_object_t?) -> xpc_object_t?
  • Get uid from its c string representation.

    Declaration

    Swift

    @asmname("sourcekitd_uid_get_from_cstr") func sourcekitd_uid_get_from_cstr(_: UnsafePointer<CChar>) -> UInt64
  • Get c string representation of a uid

    Declaration

    Swift

    @asmname("sourcekitd_uid_get_string_ptr") func sourcekitd_uid_get_string_ptr(_: UInt64) -> UnsafePointer<CChar>
  • Converts an XPCRepresentable object to its xpc_object_t value.

    Declaration

    Swift

    public func toXPCGeneral(object: XPCRepresentable) -> xpc_object_t?

    Parameters

    object

    XPCRepresentable object to convert.

    Return Value

    Converted XPC object.

  • Converts an xpc_object_t to its Swift value (XPCRepresentable).

    Declaration

    Swift

    public func fromXPCGeneral(xpcObject: xpc_object_t) -> XPCRepresentable?

    Parameters

    xpcObject

    xpc_object_t object to to convert.

    Return Value

    Converted XPCRepresentable object.

  • Converts an Array of XPCRepresentable objects to its xpc_object_t value.

    Declaration

    Swift

    public func toXPC(array: XPCArray) -> xpc_object_t

    Parameters

    array

    Array of XPCRepresentable objects to convert.

    Return Value

    Converted XPC array.

  • Converts an xpc_object_t array to an Array of XPCRepresentable objects.

    Declaration

    Swift

    public func fromXPC(xpcObject: xpc_object_t) -> XPCArray

    Parameters

    xpcObject

    XPC array to to convert.

    Return Value

    Converted Array of XPCRepresentable objects.

  • Converts a Dictionary of XPCRepresentable objects to its xpc_object_t value.

    Declaration

    Swift

    public func toXPC(dictionary: XPCDictionary) -> xpc_object_t

    Parameters

    dictionary

    Dictionary of XPCRepresentable objects to convert.

    Return Value

    Converted XPC dictionary.

  • Converts an xpc_object_t dictionary to a Dictionary of XPCRepresentable objects.

    Declaration

    Swift

    public func fromXPC(xpcObject: xpc_object_t) -> XPCDictionary

    Parameters

    xpcObject

    XPC dictionary to to convert.

    Return Value

    Converted Dictionary of XPCRepresentable objects.

  • Converts a String to an xpc_object_t string.

    Declaration

    Swift

    public func toXPC(string: String) -> xpc_object_t?

    Parameters

    string

    String to convert.

    Return Value

    Converted XPC string.

  • Converts an xpc_object_t string to a String.

    Declaration

    Swift

    public func fromXPC(xpcObject: xpc_object_t) -> String?

    Parameters

    xpcObject

    XPC string to to convert.

    Return Value

    Converted String.

  • Converts an NSDate to an xpc_object_t date.

    Declaration

    Swift

    public func toXPC(date: NSDate) -> xpc_object_t?

    Parameters

    date

    NSDate to convert.

    Return Value

    Converted XPC date.

  • Converts an xpc_object_t date to an NSDate.

    Declaration

    Swift

    public func fromXPC(xpcObject: xpc_object_t) -> NSDate?

    Parameters

    xpcObject

    XPC date to to convert.

    Return Value

    Converted NSDate.

  • Converts an NSData to an xpc_object_t data.

    Declaration

    Swift

    public func toXPC(data: NSData) -> xpc_object_t?

    Parameters

    data

    Data to convert.

    Return Value

    Converted XPC data.

  • Converts an xpc_object_t data to an NSData.

    Declaration

    Swift

    public func fromXPC(xpcObject: xpc_object_t) -> NSData?

    Parameters

    xpcObject

    XPC data to to convert.

    Return Value

    Converted NSData.

  • Converts a UInt64 to an xpc_object_t uint64.

    Declaration

    Swift

    public func toXPC(number: UInt64) -> xpc_object_t?

    Parameters

    number

    UInt64 to convert.

    Return Value

    Converted XPC uint64.

  • Converts an xpc_object_t uint64 to a UInt64.

    Declaration

    Swift

    public func fromXPC(xpcObject: xpc_object_t) -> UInt64?

    Parameters

    xpcObject

    XPC uint64 to to convert.

    Return Value

    Converted UInt64.

  • Converts an Int64 to an xpc_object_t int64.

    Declaration

    Swift

    public func toXPC(number: Int64) -> xpc_object_t?

    Parameters

    number

    Int64 to convert.

    Return Value

    Converted XPC int64.

  • Converts an xpc_object_t int64 to a Int64.

    Declaration

    Swift

    public func fromXPC(xpcObject: xpc_object_t) -> Int64?

    Parameters

    xpcObject

    XPC int64 to to convert.

    Return Value

    Converted Int64.

  • Converts a Double to an xpc_object_t double.

    Declaration

    Swift

    public func toXPC(number: Double) -> xpc_object_t?

    Parameters

    number

    Double to convert.

    Return Value

    Converted XPC double.

  • Converts an xpc_object_t double to a Double.

    Declaration

    Swift

    public func fromXPC(xpcObject: xpc_object_t) -> Double?

    Parameters

    xpcObject

    XPC double to to convert.

    Return Value

    Converted Double.

  • Converts a Bool to an xpc_object_t bool.

    Declaration

    Swift

    public func toXPC(bool: Bool) -> xpc_object_t?

    Parameters

    bool

    Bool to convert.

    Return Value

    Converted XPC bool.

  • Converts an xpc_object_t bool to a Bool.

    Declaration

    Swift

    public func fromXPC(xpcObject: xpc_object_t) -> Bool?

    Parameters

    xpcObject

    XPC bool to to convert.

    Return Value

    Converted Bool.

  • Converts an NSFileHandle to an equivalent xpc_object_t file handle.

    Declaration

    Swift

    public func toXPC(fileHandle: NSFileHandle) -> xpc_object_t?

    Parameters

    fileHandle

    NSFileHandle to convert.

    Return Value

    Converted XPC file handle. Equivalent but not necessarily identical to the input.

  • Converts an xpc_object_t file handle to an equivalent NSFileHandle.

    Declaration

    Swift

    public func fromXPC(xpcObject: xpc_object_t) -> NSFileHandle?

    Parameters

    xpcObject

    XPC file handle to to convert.

    Return Value

    Converted NSFileHandle. Equivalent but not necessarily identical to the input.