-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Swift declarations using SourceKit's version #902
Conversation
579a2fc
to
3ef7b57
Compare
So we used to do this a long time ago, but lost too much of the formatting from the original source to be worthwhile. Also, I think there are printing options for SourceKit (at least internally to the Swift compiler) that allow printing out default parameter values rather than just |
Yes I kept finding small problems needing workarounds; thought I'd keep going though. That print option just controls whether you get |
@johnfairh what would you like to do with this? If it's not a 100% improvement on existing behavior, but improves some aspects, I wouldn't be opposed to having this behavior as a configuration flag. Let me know if you want me to review again. |
@jpsim I think the changes this PR makes are all improvements. If it spots a declaration where the compiler's version is worse (eg. default params,) then it uses the parsed version as today. Let me rebase + retest... |
Fiiiiinally back to this. Reworked code a bit to fix the two problems from before:
Worth a review @jpsim when you have a chance -- I think it improves everything. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've sat on this for long enough. @johnfairh you've accomplished a ton of awesome improvements in this and I think you should merge 😄.
...except when the parsed one has more information or looks better. Notes on the various declarations from sourcekitten: [fully_]annotated_declaration - present if the declaration is compiled (not #if'd out). 'Quick Help' print options, includes all attributes except @available. doc.declaration - from the full_as_xml, so only if there is a doc comment + the decl is compiled. 'Interface' print options. Subtle differences to annotated_declaration: does include @available, does not include @discardableResult, ignores `deinit`. parsed_declaration - from source code, omits attributes on lines above the start of the Swift decl.
Thanks - merging. Code here definitely benefited from the gestation period. |
Still working through specs and tweaking things, appreciate feedback about any of this especially around how
@attribute
s are handled.This changes Swift declarations to use the compiler’s round-tripped version instead of the raw parsed source code in many cases. Improvements:
var fs = “Fred”
then show declvar fs: String
@discardable, @objc, @available
)Still prefer the parsed declaration when it is better:
@escaping / @autoclosure
- SR 6321, try + fix for Swift 4.1.Re. decl attributes, I’ve chosen to stack these each on their own line, to avoid very long lines. I think they’re all useful in docs --- API users may legitimately want to know these? Eg:
[this last fabricated of course but you get the idea...]
Jazzy should handle
@available
in a more visual way but for now I think it’s an improvement to pass through what the author wrote? The highlighting is a bit ugly; there’s a rouge PR to improve it.Notes on spec changes in the specs PR.