-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SourceKit] Add accessibility in extension structure (SR-4823) #11260
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
[SourceKit] Add accessibility in extension structure (SR-4823) #11260
Conversation
...I may be misunderstanding what you're going for here, but as discussed previously on Swift-Evolution, extensions don't have their own accessibility. Sometimes, it is allowed to write |
I know that formally extensions themselves doesn't have accessibility, but since For example, SwiftLint has a rule to enforce that if all the members from an extension have the same accessibility, you should use the shorthand form. Currently, the implementation needs to look for all tokens with If this information was available on the extension structure, that implementation would be much simpler and reliable. |
Cool, I can see how that's useful. However, it is misleading to label extensions as internal when they lack a modifier; that's simply not what they are. |
What do you think it'd be better? Omit the key when there's no modifier? |
IMO, that would be superior, yes. Would that be a problematic approach? |
From my point of view, no. I'd just like to hear from more people involved in SourceKit before implementing it. Maybe @nkcsgexi? |
@marcelofabri could you elaborated why we need to handle the accessibility of extension explicitly here? do we have issue with syntax highlighting? |
No issues with syntax highlighting, it's more about providing more information for clients. In particular, SwiftLint has some rules that would benefit from that information:
|
Interesting, thanks for clarification! Judging from the requirements, we really don't need to infer accessibility when an extension has no explicit one, am I right? i.e. we need to only report the accessibility user specified. |
Right, I just wanted to check if that'd be the preferred approach before making changes. Just to be clear: |
Right, this seems to me a better approach. To do this, could you refactor the accessibility collection part of |
static Accessibility inferDefaultAccessibility(const ExtensionDecl *ED) { | ||
auto StrictAccess = getAccessibilityStrictly(ED); | ||
if (StrictAccess.hasValue()) | ||
return StrictAccess.getValue(); |
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.
Thanks! Minor nitpick: this above three lines can be combined to:
if (auto StrictAccess = getAccessibilityStrictly(ED))
return StrictAccess.getValue();
auto StrictAccess = getAccessibilityStrictly(ED); | ||
if (StrictAccess.hasValue()) { | ||
AccessLevel = getAccessibilityUID(StrictAccess.getValue()); | ||
} |
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.
Same here : )
@swift-ci please smoke test |
🎉 |
Adds the
key.accessibility
key insource.lang.swift.decl.extension
structure.Resolves SR-4823.