Using SPM 5.6 plugins to generate CasePaths?
#72
tgrapperon
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
|
@tgrapperon Thanks for taking the time to write this out. Just so I understand, you are not suggesting generating case paths as we've done in the past, but instead you are suggesting an SPM plugin-driven transform layer that would process, for example, existing |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The latest version of SPM allows to define plugin targets and modules. These plugins can act as prebuild tools that can potentially automatically run and generate the code. For example, swift-protobuf is already capable of generating data types corresponding to some protobuf definitions in
.protofiles. These generated files are pre-build products and not checked out with the repository.The discussion about Regex Literals seems to condemn the use of
/as a prefix operator (or at least its convenient usage, without having to add back-ticks in the best of foreseeable outcomes). If theCasePathfunctionality is evoked and acknowledged by multiple core team members as some potential evolution ofKeyPaths, there is no clear timeframe. This feature has already been soft-pitched in Swift Forums in the past and received very few comments by the core team (none to my knowledge, but I may have missed some as I don't know everybody). So it's probably safer to bet that/will be prohibited as prefix operator way beforeKeyPaths can fulfillCasePaths role.So it seems there's a case for code-gen using SPM plugins to fill the gap in the meantime.
swift-case-pathswould ship with a plugin, and clients of this plugin would see their enums'CasePath's automatically generated at build time. By installingCasePaths in extensions of their enums, we would gain code completion with better inference, and a few ns when extracting them.Fortunately, code generation of
CasePathis easy once enums are extracted with their cases and associated values. To extract these enums, there are a few possibilities:Using Sourcery would introduce a foreign third-party dependency, which is a point of failure.
swift-syntaxsetup is also fragile and requires matching theSwiftversion of the project with the one it knows, which can be inconvenient when using beta versions of Xcode. This is also a third-party library, albeit semi-official.swift-parsingshould be able to handle the task, but it importsswift-benchmarks. This wouldn't be an issue in TCA projects where this library is also imported.The ad-hoc solution has no dependency, and parsing enums in the wild seems achievable, albeit less conveniently than with
swift-parsing.Of course, this plugin could be implemented as a third party, but I wanted to discuss the opportunity of including it in
swift-case-pathsdirectly untilKeyPaths are up to the task, and what are your thoughts about the parsing question, or the whole code-gen idea using plugins in general.Beta Was this translation helpful? Give feedback.
All reactions