Open bolismauro opened 8 years ago
High level, you'd need to send the compiler arguments to the Index request for SourceKit to index your files as a whole. In practice exactly what that means, what changes are necessary in SourceKittenFramework, how to invoke it, order of operations, you'd need to figure all that out.
Thanks for your answer, I found an (hacky?) way to make my example works. In need to further testing more complicated stuff.
let modulePath = "/path/to/project"
let moduleName = "projectName"
let module = Module(xcodeBuildArguments: [], name: moduleName, inPath: modulePath)
guard let module = module else { print("nope..!"); exit(0); }
let r = Request.Index(file: "/path/to/main.swift", arguments: module.compilerArguments).send()
print(toJSON(toAnyObject(r)))
What do you think?
Yes @bolismauro, that's the way to do it. Though it should also be possible to perform the index without having to build the whole project with Xcode (which also indexes the files!). But you'd need to know the raw swiftc
compiler arguments and pass those to Request.Index
rather than rely on xcodebuild
to parse them.
Alright, thanks!
I will dig into the swift
compiler, but I think this solution can be good enough for our use case since we don't have hard time constraints
Thanks again for your help!
Hi everyone, First of all I want to apologize if I use this issue for a question and not for a real issue, probably SO would be a better place, but I haven't found any related or relevant question about SourceKit or SourceKitten so I decided to ask here, feel free to close this issue if this is not appropriate.
I'm trying to create a refactoring tool for our internal codebase and I started using SourceKitten and following this talk https://realm.io/news/appbuilders-jp-simard-sourcekit/ I also studied the source code of both SourceKitten and SwiftLint to understand what is the best approach.
Basically I'm using
Request.Index
to get information about the source code and in particular I'm using the USR to understand how refactor things. I managed to make it work for a single file, but now that I'm trying to make the refactor works across multiple files I'm blocked.I basically don't find a way to find the same information (basically kind/usr/line/column) for multiple files.
So just to give an example. I have two files structs.swift
main.swift
I run this code
And this is what I get
I basically lose the information about what is defined in
struct.swift
. If I merge everything in a single file and I run the same code I obtain what I need (I omit the result because it is very long). This of course happens also if I indexstruct.swift
before and thenmain.swift
.I guess I need a sort of way to pass a module, a project or something to sourcekit. I tried to understand how the doc feature in SourceKitten works but I of course receive a different kind of information, and in particular I don't receive the information I need for the refactoring
Thanks for your help!