Skip to content
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

Question: is it possible to include local vars/calls in structure? #151

Closed
delebedev opened this issue Jan 29, 2016 · 2 comments
Closed

Comments

@delebedev
Copy link
Contributor

consider snippet:

private func foo(dictionary: [Int: Int]) -> Int {
    let a = 2
    dictionary.flatMap { foo in return foo }
    return 1
}

SourceKitten Produces:

  "key.substructure" : [
    {
      "key.kind" : "source.lang.swift.decl.function.free",
      "key.offset" : 22,
      "key.nameoffset" : 27,
      "key.namelength" : 27,
      "key.bodyoffset" : 63,
      "key.bodylength" : 73,
      "key.accessibility" : "source.lang.swift.accessibility.private",
      "key.substructure" : [
        {
          "key.kind" : "source.lang.swift.decl.var.parameter",
          "key.offset" : 31,
          "key.nameoffset" : 0,
          "key.namelength" : 0,
          "key.length" : 10,
          "key.typename" : "[Int: Int]",
          "key.name" : "dictionary"
        },
        {
          "key.kind" : "source.lang.swift.decl.var.parameter",
          "key.offset" : 103,
          "key.nameoffset" : 0,
          "key.namelength" : 0,
          "key.length" : 3,
          "key.typename" : "foo",
          "key.name" : "foo"
        }
      ],
      "key.name" : "foo(_:)",
      "key.length" : 115
    }
  ],
  "key.offset" : 0,
  "key.diagnostic_stage" : "source.diagnostic.stage.swift.parse",
  "key.length" : 138
}

I've expected to see a here or at least expr.call for flatMap. However it might be that structure is just structure: but then I do not realize how to distinct between function parameters and foo parameter in closure (needed for realm/SwiftLint#415)

Non related:
I wanted to debug it myself, but

xcrun sourcekitd-test
xcrun: error: unable to find utility "sourcekitd-test", not a developer tool or in PATH

Any advice on that?

@jpsim
Copy link
Owner

jpsim commented Jan 29, 2016

SourceKitten's Structure builder is really just a thin wrapper around SourceKit's editor.open request. See Structure.swift and Request.EditorOpen which then is sent and the response from SourceKit is mapped to a Dictionary<String, SourceKitRepresentable>, then finally converted to JSON and printed.

So in other words, to expand the contents of Structure, you'd need to do that in SourceKit itself.

sourcekitd-test is a tool built to test SourceKit that was originally included in some early Xcode 6 betas, but subsequently removed, so it hasn't shipped with Xcode since Xcode 6 beta 3-4 IIRC. You can find the source for the tool here: https://github.com/apple/swift/tree/master/tools/SourceKit/tools/sourcekitd-test

I hope that helps!

@delebedev
Copy link
Contributor Author

Since it works as designed I'm closing the issue

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

No branches or pull requests

2 participants