<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 &lt;&lt;NULL&gt;&gt; :(</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>    &quot;-module-name&quot;,</div><div>    &quot;MinimalSwiftApplication&quot;,</div><div>    &quot;-Xfrontend&quot;,</div><div>    &quot;-c&quot;,</div><div>    &quot;-sdk&quot;,</div><div>    &quot;/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk&quot;,</div><div>    &quot;-target&quot;,</div><div>    &quot;x86_64-apple-ios10.3&quot;,</div><div>    &quot;/Users/khu/ios/MinimalSwiftApplication/MinimalSwiftApplication/ViewController.swift&quot;,</div><div>    &quot;/Users/khu/ios/MinimalSwiftApplication/MinimalSwiftApplication/AppDelegate.swift&quot;,</div><div>    &quot;/Users/khu/ios/MinimalSwiftApplication/MinimalSwiftApplication/Car.swift&quot;,</div><div>    &quot;-emit-module&quot;,</div><div>    &quot;-emit-module-path&quot;,</div><div>    &quot;/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/Objects-normal/x86_64/MinimalSwiftApplication.swiftmodule&quot;,</div><div>    &quot;-Xcc&quot;,</div><div>    &quot;-I/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/swift-overrides.hmap&quot;,</div><div>    &quot;-Xcc&quot;,</div><div>    &quot;-iquote&quot;,</div><div>    &quot;-Xcc&quot;,</div><div>    &quot;/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/MinimalSwiftApplication-generated-files.hmap&quot;,</div><div>    &quot;-Xcc&quot;,</div><div>    &quot;-I/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/MinimalSwiftApplication-own-target-headers.hmap&quot;,</div><div>    &quot;-Xcc&quot;,</div><div>    &quot;-I/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/MinimalSwiftApplication-all-target-headers.hmap&quot;,</div><div>    &quot;-Xcc&quot;,</div><div>    &quot;-iquote&quot;,</div><div>    &quot;-Xcc&quot;,</div><div>    &quot;/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/MinimalSwiftApplication-project-headers.hmap&quot;,</div><div>    &quot;-Xcc&quot;,</div><div>    &quot;-I/Users/khu/ios/MinimalSwiftApplication/build/Release-iphonesimulator/include&quot;,</div><div>    &quot;-Xcc&quot;,</div><div>    &quot;-I/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/DerivedSources/x86_64&quot;,</div><div>    &quot;-Xcc&quot;,</div><div>    &quot;-I/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/DerivedSources&quot;,</div><div>    &quot;-emit-objc-header&quot;,</div><div>    &quot;-emit-objc-header-path&quot;,</div><div>    &quot;/Users/khu/ios/MinimalSwiftApplication/build/MinimalSwiftApplication.build/Release-iphonesimulator/MinimalSwiftApplication.build/Objects-normal/x86_64/MinimalSwiftApplication-Swift.h&quot;,</div><div>    &quot;-Xcc&quot;,</div><div>    &quot;-working-directory/Users/khu/ios/MinimalSwiftApplication&quot;,</div><div>    &quot;-D&quot;,</div><div>    &quot;DEBUG&quot;</div><div>  ],</div><div>  key.sourcefile: &quot;/Users/khu/ios/MinimalSwiftApplication/MinimalSwiftApplication/ViewController.swift&quot;</div><div>}</div><div>[</div><div>]</div><div>&lt;&lt;NULL&gt;&gt;</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&#39;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>