Skip to content

Instantly share code, notes, and snippets.

@OdNairy
Created June 14, 2016 05:17
Show Gist options
  • Save OdNairy/62de23d6627d518c38fed078a0581046 to your computer and use it in GitHub Desktop.
Save OdNairy/62de23d6627d518c38fed078a0581046 to your computer and use it in GitHub Desktop.
import Foundation
//
// XcodeKitDefines.h
// Xcode
//
// Copyright © 2016 Apple Inc. All rights reserved.
//
/** The build version of XcodeKit itself.
\note This is not the Xcode version number.
*/
public var XCXcodeKitVersionNumber: Double
//
// XCSourceEditorCommand.h
// Xcode
//
// Copyright © 2016 Apple Inc. All rights reserved.
//
/** Information about the source editor command that the user invoked, such as the identifier of the command, the text buffer on which the command is to operate, and whether the command has been canceled by Xcode or the user. */
public class XCSourceEditorCommandInvocation : NSObject {
/** The identifier of the command the user invoked. */
public var commandIdentifier: String { get }
/** The buffer of source text on which the command can operate. */
public var buffer: XCSourceTextBuffer { get }
/** Invoked by Xcode to indicate that the invocation has been canceled by the user. After receiving a cancellation, the command's completionHandler must still be invoked, but no changes will be applied.
\note Make no assumptions about the thread or queue on which the cancellation handler is invoked.
*/
public var cancellationHandler: () -> Swift.Void
}
/** A command provided by a source editor extension. There does not need to be a one-to-one mapping between command classes and commands: Multiple commands can be handled by a single class, by checking their invocation's commandIdentifier at runtime. */
public protocol XCSourceEditorCommand : NSObjectProtocol {
/** Perform the action associated with the command using the information in \a invocation. Xcode will pass the code a completion handler that it must invoke to finish performing the command, passing nil on success or an error on failure.
A canceled command must still call the completion handler, passing nil.
\note Make no assumptions about the thread or queue on which this method will be invoked.
*/
public func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: (NSError?) -> Swift.Void)
}
//
// XCSourceEditorExtension.h
// Xcode
//
// Copyright © 2016 Apple Inc. All rights reserved.
//
/** A key in the dictionary that defines one source editor command. Source editor commands are defined via an array of dictionaries under the XCSourceEditorCommandDefinitions key of a Xcode Source Editor Extension's NSExtensionAttributes within its Info.plist. */
public struct XCSourceEditorCommandDefinitionKey : RawRepresentable, Equatable, Hashable, Comparable {
public init(rawValue: String)
}
extension XCSourceEditorCommandDefinitionKey {
/** The identifier of the source editor command in its attributes. */
public static let identifierKey: XCSourceEditorCommandDefinitionKey
/** The name of the source editor command in its attributes. */
public static let nameKey: XCSourceEditorCommandDefinitionKey
/** The class of the source editor command, in its attributes. */
public static let classNameKey: XCSourceEditorCommandDefinitionKey
}
/** An Xcode Source Editor Extension is an instance of a class conforming to this protocol, which is set as the value of the XCSourceEditorExtensionPrincipalClass key in the NSExtensionAttributes dictionary in the extension's Info.plist.
\note Make no assumptions about the thread or queue on which any methods will be invoked or properties will be accessed, including the designated initializer.
*/
public protocol XCSourceEditorExtension : NSObjectProtocol {
/** Invoked when the extension has been launched, which may be some time before the extension actually receives a command (if ever).
\note Make no assumptions about the thread or queue on which this method will be invoked.
*/
optional public func extensionDidFinishLaunching()
/** An array of command definitions, just as they appear in the XCSourceEditorCommandDefinitions key of this extension's NSExtensionAttributes in its Info.plist.
\note Make no assumptions about the thread or queue on which this property will be read.
*/
optional public var commandDefinitions: [[XCSourceEditorCommandDefinitionKey : AnyObject]] { get }
}
//
// XCSourceTextBuffer.h
// Xcode
//
// Copyright © 2016 Apple Inc. All rights reserved.
//
/** A buffer representing some editor text. Mutations to the buffer are tracked and committed when a command returns YES and has not been canceled by the user. */
public class XCSourceTextBuffer : NSObject {
/** The UTI of the content in the buffer. */
public var contentUTI: String { get }
/** The number of space characters represented by a tab character in the buffer. */
public var tabWidth: Int { get }
/** The number of space characters used for indentation of the text in the buffer. */
public var indentationWidth: Int { get }
/** Whether tabs are used for indentation, or just spaces. When tabs are used for indentation, indented text is effectively padded to the indentation width using space characters, and then every tab width space characters is replaced with a tab character.
For example, say an XCSourceTextBuffer instance has a tabWith of 8, an indentationWidth of 4, and its usesTabsForIndentation is true. The first indentation level will be represented by four space characters, the second by a tab character, the third by a tab followed by four space characters, the fourth by two tab characters, and so on.
*/
public var usesTabsForIndentation: Bool { get }
/** The lines of text in the buffer, including line endings. Line breaks within a single buffer are expected to be consistent. Adding a "line" that itself contains line breaks will actually modify the array as well, changing its count, such that each line added is a separate element. */
public var lines: NSMutableArray { get }
/** The text selections in the buffer; an empty range represents an insertion point. Modifying the lines of text in the buffer will automatically update the selections to match. */
public var selections: NSMutableArray { get }
/** The complete buffer's string representation, as a convenience. Changes to `lines` are immediately reflected in this property, and vice versa. */
public var completeBuffer: String
}
//
// XCSourceTextPosition.h
// Xcode
//
// Copyright © 2016 Apple Inc. All rights reserved.
//
/** A single text position within a buffer. All coordinates are zero-based. */
public struct XCSourceTextPosition {
public var line: Int
public var column: Int
public init()
public init(line: Int, column: Int)
}
//
// XCSourceTextRange.h
// Xcode
//
// Copyright © 2016 Apple Inc. All rights reserved.
//
/** A range of text in a buffer. A range with equal start and end positions may be used to indicate a point within the buffer, such as an insertion point. The start and end may be improperly ordered transiently, but must be properly ordered before passing an XCSourceTextRange to other API. */
public class XCSourceTextRange : NSObject, NSCopying {
public var start: XCSourceTextPosition
public var end: XCSourceTextPosition
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment