Skip to content

[WIP] Introduce SourcekitVariant #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 79 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
4a9150a
Add `SourceKitVariant` that try to replacing `SourceKitRepresentable`
norio-nomura Oct 18, 2016
b5e80e7
Add VariantPerformanceTests
norio-nomura Oct 18, 2016
edcab52
Treat `did` as `String`
norio-nomura Oct 18, 2016
13a36c3
Add `==` functions
norio-nomura Oct 18, 2016
f819bf0
Add extension for SwiftDocKey and attributes
norio-nomura Oct 18, 2016
543d175
Fix variable names in tests
norio-nomura Oct 18, 2016
82f2545
Add `testFindAvailables()`
norio-nomura Oct 18, 2016
fb2af89
Replace "walking" tests with "FindAvailables" tests
norio-nomura Oct 19, 2016
2a7ffb3
Move VariantPerformanceTests.swift to Tests/SourceKittenFrameworkTests
norio-nomura Oct 19, 2016
bff857c
Add "RequestEditorOpen" tests
norio-nomura Oct 19, 2016
0a23691
Store `.uid` as `.string`
norio-nomura Oct 19, 2016
c3068dc
Make `SourceKitVariant` conforms to `ExpressibleByStringLiteral` and …
norio-nomura Oct 19, 2016
7a45891
Make convenient properties for SwiftDocKey to public
norio-nomura Oct 19, 2016
347cc4b
Add `__sourcekitd_variant_*_apply`
norio-nomura Oct 20, 2016
3583c90
Run `VariantPerformanceTests` on Linux
norio-nomura Oct 20, 2016
09b4fcf
Remove thisFile
norio-nomura Oct 20, 2016
e45455e
Add UID that represents sourcekitd_uid_t
norio-nomura Oct 21, 2016
980f51e
Change SourceKitVariant._VariantCore to store uid as UID
norio-nomura Oct 21, 2016
063ae3f
Merge branch 'master' into nn-sourcekit-variant
norio-nomura Oct 27, 2016
3bc26a2
Use `Request.failableSend()` instead of `Request.send()`
norio-nomura Oct 27, 2016
c6dad5c
Fix access levels
norio-nomura Nov 7, 2016
fe75589
Merge branch 'master' into nn-sourcekit-variant
norio-nomura Nov 7, 2016
a905f38
Merge branch 'master' into nn-sourcekit-variant
norio-nomura Nov 10, 2016
2284cb6
PR feedback
norio-nomura Nov 10, 2016
1af1356
Merge branch 'master' into nn-sourcekit-variant
norio-nomura Nov 14, 2016
13d12ff
Merge branch 'master' into nn-sourcekit-variant
norio-nomura Nov 17, 2016
7e4879a
Merge branch 'master' into nn-sourcekit-variant
norio-nomura Nov 21, 2016
21ade91
Add UIDNamespace
norio-nomura Oct 22, 2016
a2f1200
Add `func ==` to each UIDNamespace implementation
norio-nomura Oct 22, 2016
e0aafcd
Wrap generated `UIDNamespace`s into `UID`
norio-nomura Nov 7, 2016
1661bbe
Refine process of extracting UID from sourcekitd binaries
norio-nomura Nov 10, 2016
d00da98
Use `.uid` property to `contains()`
norio-nomura Nov 10, 2016
5375dce
Update UIDNamespace+generated to using desired types
norio-nomura Nov 14, 2016
47c7ace
Remove `UIDNamespace.leaf(_:)`
norio-nomura Nov 16, 2016
646a4c8
Revert build configuration to “Debug” that changed on b5e80e7
norio-nomura Nov 16, 2016
2d3df30
Update UIDNamespace+generated.swift
norio-nomura Nov 16, 2016
950c897
Remove property accessor static methods from SourceKitVariant
norio-nomura Nov 16, 2016
0602d2d
Infer sub namespace member from string begins with “.”
norio-nomura Nov 16, 2016
85f9d36
Add precondition that detects usage of unknown UID on DEBUG build
norio-nomura Nov 17, 2016
c0744bd
Implement `Equatable` inside types conforming `UIDNamespace`
norio-nomura Nov 21, 2016
633e0eb
Change style of comment outed and keep.
norio-nomura Nov 21, 2016
08b228f
Change type and comments of some properties in SourceKitVariant
norio-nomura Nov 21, 2016
ceda0cd
Make `UIDNamespaceTests` compatible to Linux
norio-nomura Nov 21, 2016
82657c9
Remove manually generated UID definitions
norio-nomura Nov 21, 2016
14e6f3d
Change nested namespaces to flat namespaces
norio-nomura Nov 25, 2016
2b8f8fa
Improve comparing UIDNamespaces
norio-nomura Nov 27, 2016
f84b38d
Add `isMemberOf*` properties to `UID`
norio-nomura Nov 27, 2016
a07999e
Improve SourceKitVariant
norio-nomura Nov 28, 2016
878f861
Add SourceKitVariantTests
norio-nomura Nov 28, 2016
3593234
Merge pull request #278 from jpsim/nn-experimental-uidnamespace
norio-nomura Nov 28, 2016
67fc377
Change Structure to use SourceKitVariant
norio-nomura Nov 21, 2016
734b4b4
Fix build on Linux
norio-nomura Nov 28, 2016
fe8e3a2
Change File, OffsetMap, SwiftDocs, SyntaxMap and SyntaxToken to use S…
norio-nomura Nov 28, 2016
c527d63
overwrite = false
norio-nomura Nov 28, 2016
3056ffb
Change remaining use of `failableSend()` to `failableSend2()`
norio-nomura Nov 28, 2016
b3d5fe3
Remove VariantPerformanceTests.swift
norio-nomura Nov 28, 2016
c351f2c
Replace `failableSend2()` as `failableSend()`
norio-nomura Nov 28, 2016
eac7d21
Deprecate `SourceKitRepresentable`
norio-nomura Nov 28, 2016
54d0270
Change SourceKitVariant to use copy-on-write
norio-nomura Nov 28, 2016
c64391d
Fix copy-on-write on `SourceKitVariant.removeValue(forKey:)`
norio-nomura Nov 28, 2016
62e1be7
Change knownUIDs* to referencing static type members instead of creat…
norio-nomura Nov 29, 2016
a6ceba1
Add caching mechanism for `sourcekitd_uid_t` and `String` to `UID`
norio-nomura Nov 29, 2016
b6fa629
Remove `uidStringMap` and `String` extensions for `sourcekitd_uid_t`
norio-nomura Nov 29, 2016
93e3aee
Add `SourceKitObject` that represents `sourcekitd_object_t` in Swift
norio-nomura Nov 29, 2016
cd8aaa7
Use `SourceKitObject` instead of `sourcekitd_object_t`
norio-nomura Nov 29, 2016
f0ee433
Merge branch 'master' into nn-sourcekit-variant
norio-nomura Nov 30, 2016
86b9596
Merge branch 'master' into nn-sourcekit-variant
norio-nomura Dec 3, 2016
e838e65
Avoid using `+` operator for joining `[String]` and ArrayLiteral
norio-nomura Dec 3, 2016
0af6eec
Fix crashes on test with DEBUG configuration
norio-nomura Dec 3, 2016
29b6496
Stop generating invalid member to UIDNamespace+generated
norio-nomura Dec 22, 2016
a4a1214
Stop asserting on detecting unknown uid string
norio-nomura Dec 22, 2016
2224d14
Merge commit 'cff312365b7d18d1f7ce043f54f4bffcbdba6e70' into nn-sourc…
norio-nomura Dec 24, 2016
f5a2e0b
Merge commit 'a014d42cd55beb06a157a063ed8d1e6b372a73e4' into nn-sourc…
norio-nomura Dec 24, 2016
41a6fba
Merge branch 'master' into nn-sourcekit-variant
norio-nomura Dec 24, 2016
bccc7a3
Fix and silence SwiftLint violations
norio-nomura Dec 24, 2016
3d5fd39
Merge branch 'master' into nn-sourcekit-variant
norio-nomura Feb 3, 2017
8a9d890
Merge branch 'master' into nn-sourcekit-variant
norio-nomura Apr 7, 2017
874da0a
Silence SwiftLint violations
norio-nomura Apr 7, 2017
50caf4c
Update UIDNamespace+generated.swift to Xcode 8.3
norio-nomura Apr 7, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ excluded:
- Source/SourceKittenFramework/library_wrapper_Documentation.swift
- Source/SourceKittenFramework/library_wrapper_Index.swift
- Source/SourceKittenFramework/library_wrapper_sourcekitd.swift
- Source/SourceKittenFramework/UIDNamespace+generated.swift
opt_in_rules:
- attributes
- closure_end_indentation
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@
[JP Simard](https://github.com/jpsim)
[Norio Nomura](https://github.com/norio-nomura)

* Some APIs changed to `throws`.
* `File.format(trimmingTrailingWhitespace:useTabs:indentWidth:) throws`
* `Structure.init(file:) throws`
* `SyntaxMap.init(file:) throws`
[Norio Nomura](https://github.com/norio-nomura)

##### Enhancements

* Add `--spm-module [ModuleName]` flag to `complete` to automatically detect
Expand Down
13 changes: 8 additions & 5 deletions Source/SourceKittenFramework/Clang+SourceKitten.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,20 @@ extension CXCursor {
swiftUUID = NSUUID().uuidString
setUUIDString(uidString: swiftUUID, for: file)
// Generate Swift interface, associating it with the UUID
_ = Request.interface(file: file, uuid: swiftUUID).send()
guard let _ = try? Request.interface(file: file, uuid: swiftUUID).failableSend() else {
return nil
}
}

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

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 {
guard let cursorInfo = try? Request.cursorInfo(file: swiftUUID, offset: usrOffset, arguments: compilerArguments).failableSend(),
let docsXML = cursorInfo.docFullAsXML,
let swiftDeclaration = SWXMLHash.parse(docsXML).children.first?["Declaration"].element?.text else {
return nil
}
return swiftDeclaration
Expand Down
39 changes: 16 additions & 23 deletions Source/SourceKittenFramework/CodeCompletionItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ fileprivate extension Dictionary {
}

public struct CodeCompletionItem: CustomStringConvertible {
#if os(Linux)
public typealias NumBytesInt = Int
#else
public typealias NumBytesInt = Int64
#endif

public let kind: String
public let context: String
public let name: String?
Expand All @@ -32,7 +26,7 @@ public struct CodeCompletionItem: CustomStringConvertible {
public let moduleName: String?
public let docBrief: String?
public let associatedUSRs: String?
public let numBytesToErase: NumBytesInt?
public let numBytesToErase: Int?

/// Dictionary representation of CodeCompletionItem. Useful for NSJSONSerialization.
public var dictionaryValue: [String: Any] {
Expand All @@ -49,30 +43,29 @@ public struct CodeCompletionItem: CustomStringConvertible {
}

public var description: String {
return toJSON(dictionaryValue.bridge())
return toJSON(dictionaryValue)
}

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,
context: dict["key.context"] as! String,
name: dict["key.name"] as? String,
descriptionKey: dict["key.description"] as? String,
sourcetext: dict["key.sourcetext"] as? String,
typeName: dict["key.typename"] as? String,
moduleName: dict["key.modulename"] as? String,
docBrief: dict["key.doc.brief"] as? String,
associatedUSRs: dict["key.associated_usrs"] as? String,
numBytesToErase: dict["key.num_bytes_to_erase"] as? NumBytesInt)
}
public static func parse(response: SourceKitVariant) -> [CodeCompletionItem] {
return response.results?.map { dict in
return CodeCompletionItem(kind: dict.kind?.description ?? "",
context: dict.context!,
name: dict.name,
descriptionKey: dict.description,
sourcetext: dict.sourceText,
typeName: dict.typeName,
moduleName: dict.moduleName,
docBrief: dict.docBrief,
associatedUSRs: dict.associatedUsrs,
numBytesToErase: dict["key.num_bytes_to_erase"]?.int)
} ?? []
}
}

// MARK: - migration support
extension CodeCompletionItem {
@available(*, unavailable, renamed: "parse(response:)")
public static func parseResponse(_ response: [String: SourceKitRepresentable]) -> [CodeCompletionItem] {
public static func parseResponse(_ response: [String: Any]) -> [CodeCompletionItem] {
fatalError()
}
}
Loading