Skip to content

Commit b1efc21

Browse files
committed
[CodeCompletion] Don't ignore .some(Wrapped) and .none for now
with "TODO: ignore them in expression context". They are useful in pattern context, so we should provide them in completion.
1 parent 7e3a5dc commit b1efc21

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3637,12 +3637,13 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
36373637
return false;
36383638
}
36393639

3640-
// In optional context, ignore '.init(<some>)', 'init(nilLiteral:)',
3641-
// '.some(<some>)' and '.none'. They are useless in most cases.
36423640
if (T->getOptionalObjectType() &&
3643-
VD->getModuleContext()->isStdlibModule() &&
3644-
(isa<EnumElementDecl>(VD) || isa<ConstructorDecl>(VD))) {
3645-
return false;
3641+
VD->getModuleContext()->isStdlibModule()) {
3642+
// In optional context, ignore '.init(<some>)', 'init(nilLiteral:)',
3643+
if (isa<ConstructorDecl>(VD))
3644+
return false;
3645+
// TODO: Ignore '.some(<Wrapped>)' and '.none' too *in expression
3646+
// context*. They are useful in pattern context though.
36463647
}
36473648

36483649
// Enum element decls can always be referenced by implicit member

test/IDE/complete_unresolved_members.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,29 +242,29 @@ class C4 {
242242
var _: SomeEnum1??? = .#^UNRESOLVED_OPT_3^#
243243
}
244244
}
245-
// UNRESOLVED_3: Begin completions
245+
// UNRESOLVED_3: Begin completions, 2 items
246246
// UNRESOLVED_3-DAG: Decl[EnumElement]/ExprSpecific: North[#SomeEnum1#]; name=North
247247
// UNRESOLVED_3-DAG: Decl[EnumElement]/ExprSpecific: South[#SomeEnum1#]; name=South
248248
// UNRESOLVED_3-NOT: SomeOptions1
249249
// UNRESOLVED_3-NOT: SomeOptions2
250250
// UNRESOLVED_3-NOT: none
251251
// UNRESOLVED_3-NOT: some(
252252

253-
// UNRESOLVED_3_OPT: Begin completions
253+
// UNRESOLVED_3_OPT: Begin completions, 5 items
254254
// UNRESOLVED_3_OPT-DAG: Decl[EnumElement]/ExprSpecific: North[#SomeEnum1#];
255255
// UNRESOLVED_3_OPT-DAG: Decl[EnumElement]/ExprSpecific: South[#SomeEnum1#];
256256
// UNRESOLVED_3_OPT-DAG: Keyword[nil]/ExprSpecific/Erase[1]: nil[#SomeEnum1?#]; name=nil
257-
// UNRESOLVED_3_OPT-NOT: none
258-
// UNRESOLVED_3_OPT-NOT: some
257+
// UNRESOLVED_3_OPT-DAG: Decl[EnumElement]/ExprSpecific: none[#Optional<SomeEnum1>#]; name=none
258+
// UNRESOLVED_3_OPT-DAG: Decl[EnumElement]/ExprSpecific: some({#SomeEnum1#})[#Optional<SomeEnum1>#];
259259
// UNRESOLVED_3_OPT-NOT: init({#(some):
260260
// UNRESOLVED_3_OPT-NOT: init({#nilLiteral:
261261

262-
// UNRESOLVED_3_OPTOPTOPT: Begin completions
262+
// UNRESOLVED_3_OPTOPTOPT: Begin completions, 5 items
263263
// UNRESOLVED_3_OPTOPTOPT-DAG: Decl[EnumElement]/ExprSpecific: North[#SomeEnum1#];
264264
// UNRESOLVED_3_OPTOPTOPT-DAG: Decl[EnumElement]/ExprSpecific: South[#SomeEnum1#];
265265
// UNRESOLVED_3_OPTOPTOPT-DAG: Keyword[nil]/ExprSpecific/Erase[1]: nil[#SomeEnum1???#]; name=nil
266-
// UNRESOLVED_3_OPTOPTOPT-NOT: none
267-
// UNRESOLVED_3_OPTOPTOPT-NOT: some
266+
// UNRESOLVED_3_OPTOPTOPT-DAG: Decl[EnumElement]/ExprSpecific: none[#Optional<SomeEnum1??>#]; name=none
267+
// UNRESOLVED_3_OPTOPTOPT-DAG: Decl[EnumElement]/ExprSpecific: some({#SomeEnum1??#})[#Optional<SomeEnum1??>#];
268268
// UNRESOLVED_3_OPTOPTOPT-NOT: init({#(some):
269269
// UNRESOLVED_3_OPTOPTOPT-NOT: init({#nilLiteral:
270270

@@ -277,16 +277,17 @@ extension Optional where Wrapped == Somewhere {
277277
}
278278
func testOptionalWithCustomExtension() {
279279
var _: Somewhere? = .#^UNRESOLVED_OPT_4^#
280-
// UNRESOLVED_OPT_4: Begin completions
280+
// UNRESOLVED_OPT_4: Begin completions, 7 items
281281
// UNRESOLVED_OPT_4-DAG: Decl[EnumElement]/ExprSpecific: earth[#Somewhere#];
282282
// UNRESOLVED_OPT_4-DAG: Decl[EnumElement]/ExprSpecific: mars[#Somewhere#];
283283
// UNRESOLVED_OPT_4-DAG: Keyword[nil]/ExprSpecific/Erase[1]: nil[#Somewhere?#]; name=nil
284+
// UNRESOLVED_OPT_4-DAG: Decl[EnumElement]/ExprSpecific: none[#Optional<Somewhere>#]; name=none
285+
// UNRESOLVED_OPT_4-DAG: Decl[EnumElement]/ExprSpecific: some({#Somewhere#})[#Optional<Somewhere>#];
284286
// UNRESOLVED_OPT_4-DAG: Decl[Constructor]/CurrNominal: init({#str: String#})[#Optional<Somewhere>#]; name=init(str: String)
285287
// UNRESOLVED_OPT_4-DAG: Decl[StaticVar]/CurrNominal/TypeRelation[Identical]: nowhere[#Optional<Somewhere>#]; name=nowhere
286-
// UNRESOLVED_OPT_4-NOT: none
287-
// UNRESOLVED_OPT_4-NOT: some
288288
// UNRESOLVED_OPT_4-NOT: init({#(some):
289289
// UNRESOLVED_OPT_4-NOT: init({#nilLiteral:
290+
// UNRESOLVED_OPT_4: End completions
290291
}
291292

292293

0 commit comments

Comments
 (0)