I’m working on a proposal to introduce CountedSet
, cousin to NSCountedSet
, to Swift. This kind of type involves a massive amount of doc comment content. I decided to adapt the comments from Cocoa Foundation (for NSCountedSet
) and Swift Foundation (for Set
) as part of my coding and quickly found how ridiculous it was to do this by hand.
At first I tried to write an Xcode “reflow doc comments” extension but as I found in the past, Xcode extensions are a dreadful pain to program and debug. It really wasn’t worth doing this (although it would be my preferred workflow for use) in terms of spending my time well.
Instead, I decided to create a simple playground. I’d paste my Swift file into a known Resources file (in this case, test.swift
, although I’m sure you can come up with a better name than that if you use this). I’d process the text with a simple playground implementation and print to stdout.
It was an interesting problem to solve and one that took slightly longer than I anticipated. It’s also one that’s only partially complete. The log jams involved looking ahead at the next line to decide when each blob of text was complete so it could be reflowed, preserving paragraph breaks in the comments, respecting code blocks, and leaving any in-file code intact. Reflowing the words was much easier. I’m sure you’ve written that part of it in any number of algorithms and intro-language classes.
The parts I didn’t tackle were the special formatting required for doc comment keywords, like - Parameter
, - Returns
, - SeeAlso
, and so forth. The associated lines for these items must be reflowed with proper indentation so the Quick Help parser can properly parse them. I leave that for another day because they are relatively minor work compared to reflowing long and complex doc comments as a whole.
I’ve put my code up on Github if you want to offer improvements, fixes, or feedback:
One Comment
I actually have an Xcode editor extension already to reflow doc comments to 100 characters, and being aware of backticked spans and indenting for – Parameter, etc. it is a bit quick’n’dirty though which is why I haven’t released it publicly.