This is a command-line tool that refactors your Swift project.
It's a working-in-progress. Use with caution (version control is your friend)!
All factorino commands operate under the concept of a query. For some subcommands, you need to refine your query until it leads to a canonical definition of a symbol, at which point the refactor will proceed.
Currently, these commands are included:
name | description | require canonical refinement |
---|---|---|
define | find the declaration of the symbol | no |
occur | find references of the symbol | yes |
rename | replace the occurrences of the symbol with a new name | yes |
Here's some example of how this works (TODO: update output as it's implemented)
Let's try to find occurrences of a symbol. Usually, finding its definition is a good place to start:
fact define MyAwesomeClass
If the output includes solely the declaration you expected, then we can move on to finding it's occurrence:
fact occur MyAwesomeClass
Running the define
subcommand is not required. However, if fact define
would
have return multiple definitions, define occur
would refuse to proceed. We can
tell Factorino which of the definition we want to look up by enhancing the
query:
fact occur MyAwesomeClass --path Sources/Path/To/Source --line 4
Here we specify the source (doesn't have to be complete, as long as it's part of the actual path you want), and a line number, which hopefully is enough details to distinguish the definition you want from others.
fact rename
requires similar refinement.
A query is composed of the following components:
- symbol name
- a (partial) path source file where the symbol occurs
- line number in the source file where the symbol occurs (1-based)
- column number in the source file where the symbol occurs (1-based)
Imagine clicking on a symbol in an IDE. That's essentially what the query conveys.
Only symbol name is required in a query.
Alternative to those pieces of information, a query could also be an "USR", a canonical reference to an occurrence to a symbol. Factorino includes the USR of a symbol in its output. You can use it as the query, and skip the other details:
fact occur --usr USR
The underlying technology for this tool is IndexStoreDB, a build artifact
generated by systems such as SwiftPM, or Xcode. This index must be up-to-date
with your project in order for Factorino to operate correctly. In practice, this
means you probably need to build your project prior. You may explicitly tell
Factorino where the index for your project is by the --index-store-path
option. Otherwise Factorino will try its best to infer its location.