<div dir="ltr">Hey everyone,<div><br></div><div>I am poking around Swift compiler to see if I am able to get a full AST out to do some preliminary code sanity check and dead code cleanup. So I was looking at open source <a href="https://github.com/jpsim/SourceKitten">SourceKitten</a> to see if I can retrieve a full AST from it, however, I was not able to enough information from it. So I dug a bit deeper into its dependency <a href="https://github.com/apple/swift/tree/master/tools/SourceKit">SourceKit</a> source code and am poking around the sourcekitd-test scheme. </div><div><br></div><div>With the guidance of the <a href="https://github.com/apple/swift/blob/master/tools/SourceKit/docs/Protocol.md">Protocol.md</a> file, I am able to talk to SourceKit daemon with Indexing request and Documentation request with a single file. </div><div><br></div><div>In order to get a full resolution of the code base, I thought passing in all compiler args would help. So I pass in all the compiler args to the sourcekit request based on the command spit out by <b>xcodebuild</b>, however, the results became <<NULL>> :(</div><div><br></div><div><i>[MinimalSwiftApplication is a minimal iOS app with 3 Swift files]</i></div><div><br></div><div><div>{</div><div> key.request: source.request.docinfo,</div><div> key.compilerargs: [</div><div> "-module-name",</div><div> "MinimalSwiftApplication",</div><div> "-Xfrontend",</div><div> "-c",</div><div> "-sdk",</div><div> "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk",</div><div> "-target",</div><div> "x86_64-apple-ios10.3",</div><div> "/Users/khu/ios/MinimalSwiftApplication/MinimalSwiftApplication/ViewController.swift",</div><div> "/Users/khu/ios/MinimalSwiftApplication/MinimalSwiftApplication/AppDelegate.swift",</div><div> "/Users/khu/ios/MinimalSwiftApplication/MinimalSwiftApplication/Car.swift",</div><div> "-emit-module",</div><div> "-emit-module-path",</div><div> "/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/Objects-normal/x86_64/MinimalSwiftApplication.swiftmodule",</div><div> "-Xcc",</div><div> "-I/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/swift-overrides.hmap",</div><div> "-Xcc",</div><div> "-iquote",</div><div> "-Xcc",</div><div> "/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/MinimalSwiftApplication-generated-files.hmap",</div><div> "-Xcc",</div><div> "-I/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/MinimalSwiftApplication-own-target-headers.hmap",</div><div> "-Xcc",</div><div> "-I/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/MinimalSwiftApplication-all-target-headers.hmap",</div><div> "-Xcc",</div><div> "-iquote",</div><div> "-Xcc",</div><div> "/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/MinimalSwiftApplication-project-headers.hmap",</div><div> "-Xcc",</div><div> "-I/Users/khu/ios/MinimalSwiftApplication/build/Release-iphonesimulator/include",</div><div> "-Xcc",</div><div> "-I/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/DerivedSources/x86_64",</div><div> "-Xcc",</div><div> "-I/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/DerivedSources",</div><div> "-emit-objc-header",</div><div> "-emit-objc-header-path",</div><div> "/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/Objects-normal/x86_64/MinimalSwiftApplication-Swift.h",</div><div> "-Xcc",</div><div> "-working-directory/Users/khu/ios/MinimalSwiftApplication",</div><div> "-D",</div><div> "DEBUG"</div><div> ],</div><div> key.sourcefile: "/Users/khu/ios/MinimalSwiftApplication/MinimalSwiftApplication/ViewController.swift"</div><div>}</div><div>[</div><div>]</div><div><<NULL>></div><div>Program ended with exit code: 0</div><div><br></div><div><b>Besides this, I have another two questions.</b></div><div>1. The information from doc and index request's response is quite scattered. Is that <b>possible</b> to resolve a full AST of the code base from SourceKit framework (like the <a href="http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/psi_files.html">Program Structure Interface</a> format in Intellij)?</div><div>2. Debug sourcekitd-test is easy, is there any guidance to debug the sourcekitd? Basically how to spin off another sourcekitd and debug that.</div><div><br></div>Thanks!<br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><span style="font-size:12.8px">Keqiu</span><br></div></div></div></div></div></div></div>
</div></div>