Skip to content

Commit 6ac87ba

Browse files
authored
Merge pull request #58809 from rintaro/ide-completion-rdar91892610
[CodeCompletion] Don't print '_' external parameter name in filterName
2 parents 22548aa + 9e493e3 commit 6ac87ba

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/IDE/CodeCompletionResultPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ static void printCodeCompletionResultFilterName(
496496
case ChunkKind::DeclIntroducer:
497497
++i;
498498
continue;
499+
case ChunkKind::ParameterDeclExternalName:
500+
// Skip '_' parameter external name.
501+
shouldPrint = shouldPrint && C.hasText() && C.getText() != "_";
502+
break;
499503
case ChunkKind::CallArgumentTypeBegin:
500504
case ChunkKind::ParameterDeclTypeBegin:
501505
case ChunkKind::TypeAnnotationBegin:

test/IDE/complete_annotation.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,30 @@ protocol BaseP {
135135
var value: MyStruct
136136
}
137137
class BaseC {
138+
func baseMethod(x: Int) -> Int { }
139+
func baseMethodWithName(x y: Int) -> Int { }
140+
func baseMethodWithEmptyName(_ y: Int) -> Int { }
141+
138142
func baseMethodAsync(x: Int) async -> Int { }
139143
func genericAsyncThrowsConstraint<T, U>(x: T) async throws -> U.Element where U: Collection, U.Element == Int {}
140144
subscript(index: Int) -> (Int) -> Int { }
145+
subscript(withName index: Int) -> Float { }
146+
subscript(_ index: String) -> String { }
141147
}
142148
class DerivedC: BaseC, BaseP {
143149
#^OVERRIDE^#
144150
// OVERRIDE: Begin completions
145151
// OVERRIDE-DAG: Keyword[func]/None: <keyword>func</keyword>; typename=; name=func; sourcetext=func
146152
// OVERRIDE-DAG: Decl[InstanceMethod]/Super: <name>protoMethod</name>() -&gt; (<typeid.sys>UInt8</typeid.sys>) -&gt; <typeid.sys>Void</typeid.sys>; typename=; name=protoMethod(); sourcetext=func protoMethod() -> (UInt8) -> Void {\n<#code#>\n}
147153
// OVERRIDE-DAG: Decl[InstanceVar]/Super: <name>value</name>: <typeid.user>MyStruct</typeid.user>; typename=; name=value; sourcetext=var value: MyStruct
154+
// OVERRIDE-DAG: Decl[InstanceMethod]/Super: <name>baseMethod</name>(<param><param.label>x</param.label>: <param.type><typeid.sys>Int</typeid.sys></param.type></param>) -&gt; <typeid.sys>Int</typeid.sys>; typename=; name=baseMethod(x:); sourcetext=override func baseMethod(x: Int) -> Int {\n<#code#>\n}
155+
// OVERRIDE-DAG: Decl[InstanceMethod]/Super: <name>baseMethodWithName</name>(<param><param.label>x</param.label> <param.param>y</param.param>: <param.type><typeid.sys>Int</typeid.sys></param.type></param>) -&gt; <typeid.sys>Int</typeid.sys>; typename=; name=baseMethodWithName(x:); sourcetext=override func baseMethodWithName(x y: Int) -> Int {\n<#code#>\n}
156+
// OVERRIDE-DAG: Decl[InstanceMethod]/Super: <name>baseMethodWithEmptyName</name>(<param><param.label>_</param.label> <param.param>y</param.param>: <param.type><typeid.sys>Int</typeid.sys></param.type></param>) -&gt; <typeid.sys>Int</typeid.sys>; typename=; name=baseMethodWithEmptyName(:); sourcetext=override func baseMethodWithEmptyName(_ y: Int) -> Int {\n<#code#>\n}
148157
// OVERRIDE-DAG: Decl[InstanceMethod]/Super: <name>baseMethodAsync</name>(<param><param.label>x</param.label>: <param.type><typeid.sys>Int</typeid.sys></param.type></param>) <keyword>async</keyword> -&gt; <typeid.sys>Int</typeid.sys>; typename=; name=baseMethodAsync(x:); sourcetext=override func baseMethodAsync(x: Int) async -> Int {\n<#code#>\n}
149158
// OVERRIDE-DAG: Decl[InstanceMethod]/Super: <name>genericAsyncThrowsConstraint</name>&lt;T, U&gt;(<param><param.label>x</param.label>: <param.type><typeid.user>T</typeid.user></param.type></param>) <keyword>async</keyword> <keyword>throws</keyword> -&gt; <typeid.user>U</typeid.user>.<typeid.sys>Element</typeid.sys> <keyword>where</keyword> <typeid.user>U</typeid.user> : <typeid.sys>Collection</typeid.sys>, <typeid.user>U</typeid.user>.<typeid.sys>Element</typeid.sys> == <typeid.sys>Int</typeid.sys>; typename=; name=genericAsyncThrowsConstraint(x:); sourcetext=override func genericAsyncThrowsConstraint<T, U>(x: T) async throws -> U.Element where U : Collection, U.Element == Int {\n<#code#>\n}
150159
// OVERRIDE-DAG: Decl[Subscript]/Super: <name>subscript</name>(<param><param.param>index</param.param>: <param.type><typeid.sys>Int</typeid.sys></param.type></param>) -&gt; (<typeid.sys>Int</typeid.sys>) -&gt; <typeid.sys>Int</typeid.sys>; typename=; name=subscript(:); sourcetext=override subscript(index: Int) -> (Int) -> Int {\n<#code#>\n}
160+
// OVERRIDE-DAG: Decl[Subscript]/Super: <name>subscript</name>(<param><param.label>withName</param.label> <param.param>index</param.param>: <param.type><typeid.sys>Int</typeid.sys></param.type></param>) -&gt; <typeid.sys>Float</typeid.sys>; typename=; name=subscript(withName:); sourcetext=override subscript(withName index: Int) -> Float {\n<#code#>\n}
161+
// OVERRIDE-DAG: Decl[Subscript]/Super: <name>subscript</name>(<param><param.param>index</param.param>: <param.type><typeid.sys>String</typeid.sys></param.type></param>) -&gt; <typeid.sys>String</typeid.sys>; typename=; name=subscript(:); sourcetext=override subscript(index: String) -> String {\n<#code#>\n}
151162
// OVERRIDE-DAG: Decl[Constructor]/Super: <name>init</name>(); typename=; name=init(); sourcetext=override init() {\n<#code#>\n}
152163
// OVERRIDE: End completions
153164
}

test/IDE/complete_member_decls_from_parent_decl_context.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,13 @@ class SR627_BaseClass<T> {
607607
class SR627_Subclass: SR627_BaseClass<String> {
608608
#^SR627_SUBCLASS^#
609609
// SR627_SUBCLASS: Begin completions
610-
// SR627_SUBCLASS-DAG: Decl[InstanceMethod]/Super: override func myFunction(_ x: String) -> String? {|}; name=myFunction(_:)
610+
// SR627_SUBCLASS-DAG: Decl[InstanceMethod]/Super: override func myFunction(_ x: String) -> String? {|}; name=myFunction(:)
611611
// SR627_SUBCLASS: End completions
612612
}
613613

614614
class SR627_SubSubclass: SR627_Subclass {
615615
#^SR627_SUB_SUBCLASS^#
616616
// SR627_SUB_SUBCLASS: Begin completions
617-
// SR627_SUB_SUBCLASS-DAG: Decl[InstanceMethod]/Super: override func myFunction(_ x: String) -> String? {|}; name=myFunction(_:)
617+
// SR627_SUB_SUBCLASS-DAG: Decl[InstanceMethod]/Super: override func myFunction(_ x: String) -> String? {|}; name=myFunction(:)
618618
// SR627_SUB_SUBCLASS: End completions
619619
}

0 commit comments

Comments
 (0)