Skip to content

Commit dca057d

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. (cherry picked from commit b1efc21)
1 parent 612297f commit dca057d

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
@@ -3615,12 +3615,13 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
36153615
return false;
36163616
}
36173617

3618-
// In optional context, ignore '.init(<some>)', 'init(nilLiteral:)',
3619-
// '.some(<some>)' and '.none'. They are useless in most cases.
36203618
if (T->getOptionalObjectType() &&
3621-
VD->getModuleContext()->isStdlibModule() &&
3622-
(isa<EnumElementDecl>(VD) || isa<ConstructorDecl>(VD))) {
3623-
return false;
3619+
VD->getModuleContext()->isStdlibModule()) {
3620+
// In optional context, ignore '.init(<some>)', 'init(nilLiteral:)',
3621+
if (isa<ConstructorDecl>(VD))
3622+
return false;
3623+
// TODO: Ignore '.some(<Wrapped>)' and '.none' too *in expression
3624+
// context*. They are useful in pattern context though.
36243625
}
36253626

36263627
// 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
@@ -241,29 +241,29 @@ class C4 {
241241
var _: SomeEnum1??? = .#^UNRESOLVED_OPT_3^#
242242
}
243243
}
244-
// UNRESOLVED_3: Begin completions
244+
// UNRESOLVED_3: Begin completions, 2 items
245245
// UNRESOLVED_3-DAG: Decl[EnumElement]/ExprSpecific: North[#SomeEnum1#]; name=North
246246
// UNRESOLVED_3-DAG: Decl[EnumElement]/ExprSpecific: South[#SomeEnum1#]; name=South
247247
// UNRESOLVED_3-NOT: SomeOptions1
248248
// UNRESOLVED_3-NOT: SomeOptions2
249249
// UNRESOLVED_3-NOT: none
250250
// UNRESOLVED_3-NOT: some(
251251

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

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

@@ -276,16 +276,17 @@ extension Optional where Wrapped == Somewhere {
276276
}
277277
func testOptionalWithCustomExtension() {
278278
var _: Somewhere? = .#^UNRESOLVED_OPT_4^#
279-
// UNRESOLVED_OPT_4: Begin completions
279+
// UNRESOLVED_OPT_4: Begin completions, 7 items
280280
// UNRESOLVED_OPT_4-DAG: Decl[EnumElement]/ExprSpecific: earth[#Somewhere#];
281281
// UNRESOLVED_OPT_4-DAG: Decl[EnumElement]/ExprSpecific: mars[#Somewhere#];
282282
// UNRESOLVED_OPT_4-DAG: Keyword[nil]/ExprSpecific/Erase[1]: nil[#Somewhere?#]; name=nil
283+
// UNRESOLVED_OPT_4-DAG: Decl[EnumElement]/ExprSpecific: none[#Optional<Somewhere>#]; name=none
284+
// UNRESOLVED_OPT_4-DAG: Decl[EnumElement]/ExprSpecific: some({#Somewhere#})[#Optional<Somewhere>#];
283285
// UNRESOLVED_OPT_4-DAG: Decl[Constructor]/CurrNominal: init({#str: String#})[#Optional<Somewhere>#]; name=init(str: String)
284286
// UNRESOLVED_OPT_4-DAG: Decl[StaticVar]/CurrNominal/TypeRelation[Identical]: nowhere[#Optional<Somewhere>#]; name=nowhere
285-
// UNRESOLVED_OPT_4-NOT: none
286-
// UNRESOLVED_OPT_4-NOT: some
287287
// UNRESOLVED_OPT_4-NOT: init({#(some):
288288
// UNRESOLVED_OPT_4-NOT: init({#nilLiteral:
289+
// UNRESOLVED_OPT_4: End completions
289290
}
290291

291292

0 commit comments

Comments
 (0)