-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeCompletion] Don't provide 'init(nilLiteral:)' et al in optional context #23502
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
[CodeCompletion] Don't provide 'init(nilLiteral:)' et al in optional context #23502
Conversation
9c1a986
to
10c83de
Compare
lib/IDE/CodeCompletion.cpp
Outdated
// '.some(<some>)' and '.none'. They are useless in most cases. | ||
if (T->getOptionalObjectType() && | ||
VD->getModuleContext()->isStdlibModule() && | ||
(isa<EnumElementDecl>(VD) || isa<ConstructorDecl>(VD))) { |
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.
Ah, you probably don't want to ignore all constructors. Someone could have added their own.
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 think checking VD->getModuleContext()->isStdlibModule()
is enough to limit them to init(nilLiteral: ())
and init(<#Wrapped#>)
. Added test case for that.
Is there any cases which hide user own initializers?
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.
That should be good!
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.
OTOH, maybe we should "just" have a hideFromCodeCompletion
attribute…
…context For unresolved member completion, member decls in `Optional` referenceable by implicit member expression are useless in most cases. - `init(_: <#Wrapped#>)` - `init(nilLiteral: ())` - `.some(<#Wrapped#>)` - `.none` Instead, provide `nil` with erasing `.` instruction. rdar://problem/47806831
10c83de
to
7e3a5dc
Compare
Okay
What's the justification for hiding these? I've seen code that uses this style, particularly in switch cases. It's more discoverable than "?" in a pattern binding. Users from other languages with Optional may also be used to writing things this way. |
Hm, I was thinking mostly about expression context. But yes, |
with "TODO: ignore them in expression context". They are useful in pattern context, so we should provide them in completion.
Restored |
@swift-ci Please smoke test |
@swift-ci Please smoke test |
For unresolved member completion, member decls in
Optional
referenceable with implicit member expression are useless in most cases.init(_: <#Wrapped#>)
init(nilLiteral: ())
Instead, provide
nil
keyword with erasing.
instruction.As for
.some(<#Wrapped#>)
and.none
, although they aren't useful in expression context, it's common to use them in pattern context. So don't hide them until we implement a mechanism to distinguish them.rdar://problem/47806831