Skip to content

Commit df89d28

Browse files
authored
Merge pull request #37280 from rintaro/ide-completon-se0293-rdar76355405
[CodeCompletion] Update for SE-0293 Property Wrappers for func params
2 parents 8b3147c + a01a3ad commit df89d28

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

include/swift/AST/NameLookup.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,7 @@ class FindLocalVal : public StmtVisitor<FindLocalVal> {
555555
VisibleDeclConsumer &Consumer)
556556
: SM(SM), Loc(Loc), Consumer(Consumer) {}
557557

558-
void checkValueDecl(ValueDecl *D, DeclVisibilityKind Reason) {
559-
Consumer.foundDecl(D, Reason);
560-
}
558+
void checkValueDecl(ValueDecl *D, DeclVisibilityKind Reason);
561559

562560
void checkPattern(const Pattern *Pat, DeclVisibilityKind Reason);
563561

lib/AST/NameLookup.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2755,7 +2755,35 @@ void FindLocalVal::checkPattern(const Pattern *Pat, DeclVisibilityKind Reason) {
27552755
return;
27562756
}
27572757
}
2758-
2758+
void FindLocalVal::checkValueDecl(ValueDecl *D, DeclVisibilityKind Reason) {
2759+
if (!D)
2760+
return;
2761+
if (auto var = dyn_cast<VarDecl>(D)) {
2762+
auto dc = var->getDeclContext();
2763+
if ((isa<AbstractFunctionDecl>(dc) || isa<ClosureExpr>(dc)) &&
2764+
var->hasAttachedPropertyWrapper()) {
2765+
// FIXME: This is currently required to set the interface type of the
2766+
// auxiliary variables (unless 'var' is a closure param).
2767+
(void)var->getPropertyWrapperBackingPropertyType();
2768+
2769+
auto vars = var->getPropertyWrapperAuxiliaryVariables();
2770+
if (vars.backingVar) {
2771+
Consumer.foundDecl(vars.backingVar, Reason);
2772+
}
2773+
if (vars.projectionVar) {
2774+
Consumer.foundDecl(vars.projectionVar, Reason);
2775+
}
2776+
if (vars.localWrappedValueVar) {
2777+
Consumer.foundDecl(vars.localWrappedValueVar, Reason);
2778+
2779+
// If 'localWrappedValueVar' exists, the original var is shadowed.
2780+
return;
2781+
}
2782+
}
2783+
}
2784+
Consumer.foundDecl(D, Reason);
2785+
}
2786+
27592787
void FindLocalVal::checkParameterList(const ParameterList *params) {
27602788
for (auto param : *params) {
27612789
checkValueDecl(param, DeclVisibilityKind::FunctionParameter);

test/IDE/complete_property_delegate.swift

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@
66
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SELF_VARNAME | %FileCheck %s -check-prefix=CONTEXT_VARNAME
77
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SELF_STORAGE_VARNAME | %FileCheck %s -check-prefix=CONTEXT_STORAGE_VARNAME
88

9+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PARAM | %FileCheck %s -check-prefix=PARAM
10+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PARAM_CLOSURE | %FileCheck %s -check-prefix=PARAM
11+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=LOCAL | %FileCheck %s -check-prefix=LOCAL
12+
913
@propertyWrapper
1014
struct Lazzzy<T> {
1115
var wrappedValue: T
16+
var projectedValue: String { "" }
17+
18+
init(wrappedValue: T) { fatalError() }
19+
1220
func delegateOperation() -> Int {}
1321
}
1422

@@ -26,6 +34,7 @@ class MyClass {
2634
let _ = #^CONTEXT^#
2735
// CONTEXT: Begin completions
2836
// CONTEXT-DAG: Decl[InstanceVar]/CurrNominal: foo[#MyMember#];
37+
// CONTEXT-DAG: Decl[InstanceVar]/CurrNominal: $foo[#String#];
2938
// CONTEXT-DAG: Decl[InstanceVar]/CurrNominal: _foo[#Lazzzy<MyMember>#];
3039
// CONTEXT: End completions
3140

@@ -38,9 +47,10 @@ class MyClass {
3847
// CONTEXT_VARNAME-DAG: End completions
3948

4049
let _ = _foo.#^CONTEXT_STORAGE_VARNAME^#
41-
// CONTEXT_STORAGE_VARNAME: Begin completions, 3 items
50+
// CONTEXT_STORAGE_VARNAME: Begin completions, 4 items
4251
// CONTEXT_STORAGE_VARNAME-DAG: Keyword[self]/CurrNominal: self[#Lazzzy<MyMember>#]; name=self
4352
// CONTEXT_STORAGE_VARNAME-DAG: Decl[InstanceVar]/CurrNominal: wrappedValue[#MyMember#]; name=wrappedValue
53+
// CONTEXT_STORAGE_VARNAME-DAG: Decl[InstanceVar]/CurrNominal: projectedValue[#String#]; name=projectedValue
4454
// CONTEXT_STORAGE_VARNAME-DAG: Decl[InstanceMethod]/CurrNominal: delegateOperation()[#Int#]; name=delegateOperation()
4555
// CONTEXT_STORAGE_VARNAME-NOT: _
4656
// CONTEXT_STORAGE_VARNAME: End completions
@@ -55,3 +65,34 @@ class MyClass {
5565
// Same as CONTEXT_STORAGE_VARNAME.
5666
}
5767
}
68+
69+
func paramTest(@Lazzzy arg: MyMember) {
70+
#^PARAM^#
71+
// PARAM: Begin completions
72+
// PARAM-DAG: Decl[LocalVar]/Local: arg[#MyMember#]; name=arg
73+
// PARAM-DAG: Decl[LocalVar]/Local: $arg[#String#]; name=$arg
74+
// PARAM-DAG: Decl[LocalVar]/Local: _arg[#Lazzzy<MyMember>#]; name=_arg
75+
// PARAM-DAG: Decl[FreeFunction]/CurrModule: paramTest({#arg: MyMember#})[#Void#]; name=paramTest(arg: MyMember)
76+
// PARAM: End completions
77+
}
78+
func closureTest() {
79+
func receive(fn: (MyMember) -> Void) {}
80+
81+
receive { (@Lazzzy arg: MyMember) in
82+
#^PARAM_CLOSURE^#
83+
// Same as PARAM
84+
}
85+
}
86+
87+
func localTest() {
88+
@Lazzzy var local: MyMember = .zero
89+
90+
#^LOCAL^#
91+
// LOCAL: Begin completions
92+
// LOCAL-DAG: Decl[LocalVar]/Local: local[#MyMember#]; name=local
93+
// LOCAL-DAG: Decl[LocalVar]/Local: $local[#String#]; name=$local
94+
// LOCAL-DAG: Decl[LocalVar]/Local: _local[#Lazzzy<MyMember>#]; name=_local
95+
// LOCAL-DAG: Decl[FreeFunction]/CurrModule: paramTest({#arg: MyMember#})[#Void#]; name=paramTest(arg: MyMember)
96+
// LOCAL: End completions
97+
}
98+

0 commit comments

Comments
 (0)