New Code Visualizer for Swift: Source Is View

Hello, Swifty people! For April Prototypes Day I want to share a brand new API visualization tool I've been working on in tandem with my work on module stability. I call it—not for any particular reason, mind you—Source Is View.

"RESULT IS ENUM OF SUCCESS AND FAILURE WHERE FAILURE ISA ERROR"

Taking cues from a recent pioneer in experimental predicate logic, Source Is View displays your Swift code in a friendly, declaration-oriented manner, using a delightful acrostic format to show type members. Identifiers are given unique colors for easy visual matching.

"SUIT HAS <. < IS FUNC AND PUBLIC AND STATIC. < TAKES SUIT AND SUIT. < RETURN BOOL."

Source Is View is implemented using SwiftSyntax, so it understands your code as well as you do when you're not paying attention to what an identifier actually means. It even understands pointlessly complicated functions like this one:

extension Int {
  fileprivate mutating func mixUp(_ other: inout [Int?]) throws {}
}

"INT HAS MIXUP. MIXUP IS FUNC AND FILE. MIXUP TAKES INOUT ARRAY OF OPT OF INT. MIXUP CAN MUTATE AND THROW."

I plan to put the implementation up later today (it's still in a pretty messy state and needs a bit of cleanup first), but I hope everyone sees what kind of game changer this sort of visualization is.*

More seriously, this was a fun exploration of the SwiftSyntax library and even if it's not the best code out there it's still a thing you can do with it. Thanks also to Kishikawa Katsumi's Swift AST Explorer, which is invaluable for figuring out how SwiftSyntax represents things.

The custom font used is Bryndan Write, available for free. The identifiers are rendered in Chalkboard if you don't have Bryndan Write installed.

* It isn't one.

49 Likes

SOURCE IS CLONE

https://github.com/jrose-apple/SourceIsView

4 Likes

Thanks for my favorite April's Fool joke :stuck_out_tongue: