Swift Local Refactoring

Xcode 9 includes a brand new refactoring engine. It can transform code locally within a single Swift source file, or globally, such as renaming a method or property that occurs in multiple files and even different languages. The logic behind local refactorings is implemented entirely in the compiler and SourceKit, and is now open source in the swift repository. Therefore, any Swift enthusiast can contribute refactoring actions to the language. This post discusses how a simple refactoring can be implemented and surfaced in Xcode.

swift.org/blog/swift-local-refactoring/

Xcode 9 features a new refactoring engine that transforms Swift code either locally in one file or globally across files and languages. The engine's local refactoring logic resides in the compiler and SourceKit, now open source in the swift repository, allowing community contributions to add new actions.

Local refactorings fall into cursor-based or range-based categories, using pre-analyzed info like ResolvedCursorInfo or ResolvedRangeInfo to check applicability and perform text edits via methods in Refactoring.cpp.

Developers test actions with the swift-refactor tool for context and code changes, then integrate them into Xcode by building and selecting a local toolchain. Potential new refactoring ideas can be proposed via Swift's issue database.


Category:

Year: