Skip to content

Add SourceKitObject that represents sourcekitd_object_t in Swift#490

Merged
jpsim merged 6 commits into
masterfrom
nn-add-SourceKitObject
Mar 7, 2018
Merged

Add SourceKitObject that represents sourcekitd_object_t in Swift#490
jpsim merged 6 commits into
masterfrom
nn-add-SourceKitObject

Conversation

@norio-nomura

@norio-nomura norio-nomura commented Feb 7, 2018

Copy link
Copy Markdown
Collaborator

This adds SourceKitObject, SourceKitObjectConvertible and UID that salvaged from #274.
Fixes #489
This is a different solution than #488.
By using this changes, the sample code in #487 (comment) can be written as following:

func requestSymbolSuperclasses(_ kind: SymbolKind, name: String, usr: String) -> [String: Any] {
    let response: [String: Any]

    do {
        response = try Request.customRequest(request: [
            "key.request": UID(RequestKind.symbolSuperclasses),
            "key.symbol": [
                "key.indexer.arg.symbol.name": name,
                "key.indexer.arg.symbol.kind": kind.rawValue,
                "key.indexer.arg.symbol.language": "Xcode.SourceCodeLanguage.Swift",
                "key.indexer.arg.symbol.resolution": usr
            ]
        ]).send()
    } catch {
        fatalError("Symbol superclasses request failed: \(error)")
    }

    return response
}

/cc: @ileitch

@ileitch

ileitch commented Feb 7, 2018

Copy link
Copy Markdown
Contributor

So much nicer! 💯

@jpsim jpsim left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome. Everything I've ever dreamed of. 😍

@@ -196,7 +196,7 @@ public enum Request {
/// A `cursorinfo` request for an offset in the given file, using the `arguments` given.
case cursorInfo(file: String, offset: Int64, arguments: [String])
/// A custom request by passing in the sourcekitd_object_t directly.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should update this comment.


import Foundation
#if SWIFT_PACKAGE
import SourceKit

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I generally avoid indenting compiler directive bodies. See https://github.com/jpsim/SourceKitten/blob/0.19.1/Source/sourcekitten/main.swift#L9-L15

}
}

extension UID: Hashable {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on using the auto-synthesized Hashable implementation for Swift 4.1+?

extension UID: Hashable {
#if !swift(>=4.1)
    public var hashValue: Int {
        return uid.hashValue
    }

    public static func == (lhs: UID, rhs: UID) -> Bool {
        return lhs.uid == rhs.uid
    }
#endif
}

I don't feel strongly, but it seems like it might be easier to find code that can be removed once we require Swift 4.1+ to compile SourceKitten.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not doing this. Can't auto-synthesize Hashable conformance outside the source module.


class SourceKitObjectTests: XCTestCase {

func testExample() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testDescription?

@norio-nomura norio-nomura force-pushed the nn-add-SourceKitObject branch from 20a5707 to 5720e1a Compare February 9, 2018 09:07
@norio-nomura

Copy link
Copy Markdown
Collaborator Author

Thanks for reviews!
Sorry, I changed it considerably other than pointed out.

  • Changed SourceKitObject to class for using sourcekitd_request_release() on deinit
  • Change SourceKitObjectConvertible.sourceKitObject from a property to a throwing method
  • Make SourceKitObject conforms to ExpressibleByBooleanLiteral

Could you please review again?

@norio-nomura

Copy link
Copy Markdown
Collaborator Author

@jpsim Should I open another PR against this branch for changes that added after previous reviews?

@jpsim

jpsim commented Feb 12, 2018

Copy link
Copy Markdown
Owner

No need for a separate PR, I'll review this shortly. Looks mostly good, I think I just have a few pieces of small but breaking feedback

@ileitch

ileitch commented Mar 7, 2018

Copy link
Copy Markdown
Contributor

Any news on this? Would be nice to have in a release :)

@jpsim

jpsim commented Mar 7, 2018

Copy link
Copy Markdown
Owner

Sorry the delay is entirely my fault. I'll review & merge this now.

@jpsim jpsim force-pushed the nn-add-SourceKitObject branch from 5720e1a to b182a23 Compare March 7, 2018 07:12
@jpsim

jpsim commented Mar 7, 2018

Copy link
Copy Markdown
Owner

I renamed SourceKitObjectConvertible.sourceKitObject to sourcekitdObject to avoid confusion between 'SourceKitObject's and sourcekitd "objects". I hope that's ok with you. I'll merge this as soon as tests pass CI.

@jpsim

jpsim commented Mar 7, 2018

Copy link
Copy Markdown
Owner

Tired of waiting for CI. Will fix if I get notified of failures when tests eventually run on master.

@jpsim jpsim merged commit 371e210 into master Mar 7, 2018
@jpsim jpsim deleted the nn-add-SourceKitObject branch March 7, 2018 08:10
@norio-nomura norio-nomura restored the nn-add-SourceKitObject branch March 7, 2018 11:31
@norio-nomura

Copy link
Copy Markdown
Collaborator Author

Some CI jobs for this PR failed since the branch has been removed before starting jobs.
I tried to re-run them, but it can't.
Since CI jobs for master branch passed, it may be ok.

@norio-nomura norio-nomura deleted the nn-add-SourceKitObject branch March 7, 2018 12:42
@jpsim

jpsim commented Mar 7, 2018

Copy link
Copy Markdown
Owner

Yes that’s expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants