Skip to content

Commit

Permalink
Update APIs to conform to Swift 3 API Design Guidelines (jpsim#264)
Browse files Browse the repository at this point in the history
* label argument in CXCursor.swiftDeclaration() method

* rename CodeCompletionItem.parseResponse(_:) for Swift 3

* update File.swift for Swift 3 API Design Guidelines

* update Language enum members to be lowercase for Swift 3 API Design Guidelines

* Rename DynamicLinkLibrary.loadSymbol(_:) to load(symbol:)

for Swift 3 API Design Guidelines

* update library_wrapper.swift for Swift 3 API Design Guidelines

* update ObjCDeclarationKind members to Swift 3 API Design Guidelines

* change ObjCDeclarationKind.fromClang(_:) to an initializer

* update OffsetMap for Swift 3 API Design Guidelines

* refactor Request.swift for Swift 3 API Design Guidelines

* update SourceDeclaration.swift for Swift 3 API Design Guidelines

* update SourceDeclaration.swift for Swift 3 API Design Guidelines

* update StatementKind, SwiftDeclarationKind and SyntaxKind enums

to have lowercase members to comply with Swift 3 API Design Guidelines

* refactor String+SourceKitten.swift for Swift 3 API Design Guidelines

* refactor SwiftDocKey for Swift 3 API Design Guidelines

* refactor SyntaxMap for Swift 3 API Design Guidelines

* update Xcode.swift for Swift 3 API Design Guidelines

* update sourcekitten target for Swift 3 API Design Guidelines

* refactor tests for Swift 3 API Design Guidelines

* amend Swift 3 changelog entry to note API changes

* lowercase Request members to conform to Swift 3 API Design Guidelines

* lowercase Request.Error members to conform to Swift 3 API Design Guidelines (jpsim#272)

`@available` will be added by separate commit.
  • Loading branch information
jpsim authored Oct 18, 2016
1 parent b6cc96c commit a1188e3
Show file tree
Hide file tree
Showing 44 changed files with 957 additions and 968 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

##### Breaking

* SourceKitten now requires Xcode 8.0 and Swift 3.0 to build.
* SourceKitten now requires Xcode 8.0 and Swift 3.0 to build.
APIs have been adapted to conform to the Swift 3 API Design Guidelines.
[JP Simard](https://github.com/jpsim)
[Norio Nomura](https://github.com/norio-nomura)

Expand Down
24 changes: 12 additions & 12 deletions Source/SourceKittenFramework/Clang+SourceKitten.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,27 @@ extension CXCursor {
}

func objCKind() -> ObjCDeclarationKind {
return ObjCDeclarationKind.fromClang(kind)
return ObjCDeclarationKind(kind)
}

func str() -> String? {
let cursorExtent = extent()
let contents = try! String(contentsOfFile: cursorExtent.start.file, encoding: .utf8)
return contents.substringWithSourceRange(cursorExtent.start, end: cursorExtent.end)
return contents.substringWithSourceRange(start: cursorExtent.start, end: cursorExtent.end)
}

func name() -> String {
let spelling = clang_getCursorSpelling(self).str()!
let type = objCKind()
if let usrString = usr(), spelling.isEmpty && type == .Enum {
if let usrString = usr(), spelling.isEmpty && type == .enum {
// libClang considers enums declared like `typedef enum {} name;` rather than `NS_ENUM()`
// to have a cursor spelling of "" (empty string). So we parse the USR to extract the actual name.
let prefix = "c:@EA@"
assert(usrString.hasPrefix(prefix))
let index = usrString.index(usrString.startIndex,
offsetBy: prefix.lengthOfBytes(using: .utf8))
return usrString.substring(from: index)
} else if type == .Category, let usrNSString = usr() as NSString? {
} else if type == .category, let usrNSString = usr() as NSString? {
let ext = (usrNSString.range(of: "c:objc(ext)").location == 0)
let regex = try! NSRegularExpression(pattern: "(\\w+)@(\\w+)", options: [])
let range = NSRange(location: 0, length: usrNSString.length)
Expand All @@ -119,9 +119,9 @@ extension CXCursor {
} else {
fatalError("Couldn't get category name")
}
} else if type == .MethodInstance {
} else if type == .methodInstance {
return "-" + spelling
} else if type == .MethodClass {
} else if type == .methodClass {
return "+" + spelling
}
return spelling
Expand Down Expand Up @@ -185,7 +185,7 @@ extension CXCursor {
return commentBody
}

func swiftDeclaration(_ compilerArguments: [String]) -> String? {
func swiftDeclaration(compilerArguments: [String]) -> String? {
let file = location().file
let swiftUUID: String
if let uuid = interfaceUUIDMap[file] {
Expand All @@ -194,16 +194,16 @@ extension CXCursor {
swiftUUID = NSUUID().uuidString
interfaceUUIDMap[file] = swiftUUID
// Generate Swift interface, associating it with the UUID
_ = Request.Interface(file: file, uuid: swiftUUID).send()
_ = Request.interface(file: file, uuid: swiftUUID).send()
}

guard let usr = usr(),
let usrOffset = Request.FindUSR(file: swiftUUID, usr: usr).send()[SwiftDocKey.Offset.rawValue] as? Int64 else {
let usrOffset = Request.findUSR(file: swiftUUID, usr: usr).send()[SwiftDocKey.offset.rawValue] as? Int64 else {
return nil
}

let cursorInfo = Request.CursorInfo(file: swiftUUID, offset: usrOffset, arguments: compilerArguments).send()
guard let docsXML = cursorInfo[SwiftDocKey.FullXMLDocs.rawValue] as? String,
let cursorInfo = Request.cursorInfo(file: swiftUUID, offset: usrOffset, arguments: compilerArguments).send()
guard let docsXML = cursorInfo[SwiftDocKey.fullXMLDocs.rawValue] as? String,
let swiftDeclaration = SWXMLHash.parse(docsXML).children.first?["Declaration"].element?.text else {
return nil
}
Expand Down Expand Up @@ -245,7 +245,7 @@ extension CXComment {
}
fatalError("not text: \(child.kind())")
}
return [.Para(paragraphString.stringByRemovingCommonLeadingWhitespaceFromLines(), kindString)]
return [.Para(paragraphString.removingCommonLeadingWhitespaceFromLines(), kindString)]
}

func kind() -> CXCommentKind {
Expand Down
6 changes: 3 additions & 3 deletions Source/SourceKittenFramework/ClangTranslationUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public struct ClangTranslationUnit {
.distinct()
.sorted()
.groupBy { $0.location.file }
.map { insertMarks($0) }
.map { insertMarks(declarations: $0) }
}

/**
Expand All @@ -77,8 +77,8 @@ public struct ClangTranslationUnit {
- parameter path: Path to run `xcodebuild` from. Uses current path by default.
*/
public init?(headerFiles: [String], xcodeBuildArguments: [String], inPath path: String = FileManager.default.currentDirectoryPath) {
let xcodeBuildOutput = runXcodeBuild(xcodeBuildArguments + ["-dry-run"], inPath: path) ?? ""
guard let clangArguments = parseCompilerArguments(xcodeBuildOutput as NSString, language: .ObjC, moduleName: nil) else {
let xcodeBuildOutput = runXcodeBuild(arguments: xcodeBuildArguments + ["-dry-run"], inPath: path) ?? ""
guard let clangArguments = parseCompilerArguments(xcodebuildOutput: xcodeBuildOutput as NSString, language: .objc, moduleName: nil) else {
fputs("could not parse compiler arguments\n\(xcodeBuildOutput)\n", stderr)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion Source/SourceKittenFramework/CodeCompletionItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public struct CodeCompletionItem: CustomStringConvertible {
return toJSON(dictionaryValue as NSDictionary)
}

public static func parseResponse(_ response: [String: SourceKitRepresentable]) -> [CodeCompletionItem] {
public static func parse(response: [String: SourceKitRepresentable]) -> [CodeCompletionItem] {
return (response["key.results"] as! [SourceKitRepresentable]).map { item in
let dict = item as! [String: SourceKitRepresentable]
return CodeCompletionItem(kind: dict["key.kind"] as! String,
Expand Down
Loading

0 comments on commit a1188e3

Please sign in to comment.