Skip to content

Commit ab04345

Browse files
authored
Merge pull request swiftlang#33262 from rintaro/ide-completion-rdar66456159
[CodeCompletion] Disable multi trailing closure completion at newline
2 parents 9a88b4e + 5936ddb commit ab04345

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,6 +3227,16 @@ Parser::parseTrailingClosures(bool isExprBasic, SourceRange calleeRange,
32273227
if (!Tok.is(tok::code_complete))
32283228
break;
32293229

3230+
// FIXME: Additional trailing closure completion on newline positions.
3231+
// let foo = SomeThing {
3232+
// ...
3233+
// }
3234+
// <HERE>
3235+
// This was previously enabled, but it failed to suggest 'foo' because
3236+
// the token was considered a part of the initializer.
3237+
if (Tok.isAtStartOfLine())
3238+
break;
3239+
32303240
// If the current completion mode doesn't support trailing closure
32313241
// completion, leave the token here and let "postfix completion" to
32323242
// handle it.

test/IDE/complete_multiple_trailingclosure.swift

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INIT_FALLBACK_2 | %FileCheck %s -check-prefix=INIT_FALLBACK
1818
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=MEMBERDECL_SAMELINE | %FileCheck %s -check-prefix=MEMBERDECL_SAMELINE
1919
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=MEMBERDECL_NEWLINE | %FileCheck %s -check-prefix=MEMBERDECL_NEWLINE
20+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INITIALIZED_VARDECL_SAMELINE | %FileCheck %s -check-prefix=INITIALIZED_VARDECL_SAMELINE
21+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INITIALIZED_VARDECL_NEWLINE | %FileCheck %s -check-prefix=INITIALIZED_VARDECL_NEWLINE
2022

2123
func globalFunc1(fn1: () -> Int, fn2: () -> String) {}
2224
func testGlobalFunc() {
@@ -27,8 +29,8 @@ func testGlobalFunc() {
2729
// GLOBALFUNC_SAMELINE-DAG: Pattern/ExprSpecific: {#fn2: () -> String {|}#}[#() -> String#];
2830
// GLOBALFUNC_SAMELINE: End completions
2931

30-
// GLOBALFUNC_NEWLINE: Begin completions, 1 items
31-
// GLOBALFUNC_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: () -> String {|}#}[#() -> String#];
32+
// GLOBALFUNC_NEWLINE: Begin completions
33+
// FIXME-GLOBALFUNC_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: () -> String {|}#}[#() -> String#];
3234
// GLOBALFUNC_NEWLINE: End completions
3335

3436
globalFunc1()
@@ -60,7 +62,7 @@ func testMethod(value: MyStruct) {
6062
// METHOD_SAMELINE: End completions
6163

6264
// METHOD_NEWLINE: Begin completions
63-
// METHOD_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: (() -> String)? {|}#}[#(() -> String)?#];
65+
// FIXME-METHOD_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: (() -> String)? {|}#}[#(() -> String)?#];
6466
// METHOD_NEWLINE-DAG: Keyword[class]/None: class;
6567
// METHOD_NEWLINE-DAG: Keyword[if]/None: if;
6668
// METHOD_NEWLINE-DAG: Keyword[try]/None: try;
@@ -91,8 +93,8 @@ func testOverloadedInit() {
9193
// INIT_OVERLOADED_SAMELINE: End completions
9294

9395
// INIT_OVERLOADED_NEWLINE: Begin completions
94-
// INIT_OVERLOADED_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: () -> String {|}#}[#() -> String#];
95-
// INIT_OVERLOADED_NEWLINE-DAG: Pattern/ExprSpecific: {#fn3: () -> String {|}#}[#() -> String#];
96+
// FIXME-INIT_OVERLOADED_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: () -> String {|}#}[#() -> String#];
97+
// FIXME-INIT_OVERLOADED_NEWLINE-DAG: Pattern/ExprSpecific: {#fn3: () -> String {|}#}[#() -> String#];
9698
// INIT_OVERLOADED_NEWLINE-DAG: Keyword[class]/None: class;
9799
// INIT_OVERLOADED_NEWLINE-DAG: Keyword[if]/None: if;
98100
// INIT_OVERLOADED_NEWLINE-DAG: Keyword[try]/None: try;
@@ -118,8 +120,8 @@ func testOptionalInit() {
118120
// INIT_OPTIONAL_SAMELINE: End completions
119121

120122
// INIT_OPTIONAL_NEWLINE: Begin completions
121-
// INIT_OPTIONAL_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: () -> String {|}#}[#() -> String#];
122-
// INIT_OPTIONAL_NEWLINE-DAG: Pattern/ExprSpecific: {#fn3: () -> String {|}#}[#() -> String#];
123+
// FIXME-INIT_OPTIONAL_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: () -> String {|}#}[#() -> String#];
124+
// FIXME-INIT_OPTIONAL_NEWLINE-DAG: Pattern/ExprSpecific: {#fn3: () -> String {|}#}[#() -> String#];
123125
// INIT_OPTIONAL_NEWLINE-DAG: Keyword[class]/None: class;
124126
// INIT_OPTIONAL_NEWLINE-DAG: Keyword[if]/None: if;
125127
// INIT_OPTIONAL_NEWLINE-DAG: Keyword[try]/None: try;
@@ -142,8 +144,8 @@ func testOptionalInit() {
142144
// INIT_REQUIRED_SAMELINE_1-DAG: Pattern/ExprSpecific: {#fn2: () -> String {|}#}[#() -> String#];
143145
// INIT_REQUIRED_SAMELINE_1: End completions
144146

145-
// INIT_REQUIRED_NEWLINE_1: Begin completions, 1 items
146-
// INIT_REQUIRED_NEWLINE_1-DAG: Pattern/ExprSpecific: {#fn2: () -> String {|}#}[#() -> String#];
147+
// INIT_REQUIRED_NEWLINE_1: Begin completions
148+
// FIXME-INIT_REQUIRED_NEWLINE_1-DAG: Pattern/ExprSpecific: {#fn2: () -> String {|}#}[#() -> String#];
147149
// INIT_REQUIRED_NEWLINE_1: End completions
148150

149151
// missing 'fn3'.
@@ -158,8 +160,8 @@ func testOptionalInit() {
158160
// INIT_REQUIRED_SAMELINE_2-DAG: Pattern/ExprSpecific: {#fn3: () -> String {|}#}[#() -> String#];
159161
// INIT_REQUIRED_SAMELINE_2: End completions
160162

161-
// INIT_REQUIRED_NEWLINE_2: Begin completions, 1 items
162-
// INIT_REQUIRED_NEWLINE_2-DAG: Pattern/ExprSpecific: {#fn3: () -> String {|}#}[#() -> String#];
163+
// INIT_REQUIRED_NEWLINE_2: Begin completions
164+
// FIXME-INIT_REQUIRED_NEWLINE_2-DAG: Pattern/ExprSpecific: {#fn3: () -> String {|}#}[#() -> String#];
163165
// INIT_REQUIRED_NEWLINE_2: End completions
164166

165167
// Call is completed.
@@ -225,7 +227,7 @@ struct TestNominalMember: P {
225227
// MEMBERDECL_SAMELINE: End completions
226228

227229
// MEMBERDECL_NEWLINE: Begin completions
228-
// MEMBERDECL_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: (() -> String)? {|}#}[#(() -> String)?#]; name=fn2: (() -> String)?
230+
// FIXME-MEMBERDECL_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: (() -> String)? {|}#}[#(() -> String)?#]; name=fn2: (() -> String)?
229231
// MEMBERDECL_NEWLINE-DAG: Keyword[enum]/None: enum; name=enum
230232
// MEMBERDECL_NEWLINE-DAG: Keyword[func]/None: func; name=func
231233
// MEMBERDECL_NEWLINE-DAG: Keyword[private]/None: private; name=private
@@ -234,3 +236,22 @@ struct TestNominalMember: P {
234236
// MEMBERDECL_NEWLINE-DAG: Decl[InstanceMethod]/Super: func foo() {|}; name=foo()
235237
// MEMBERDECL_NEWLINE: End completions
236238
}
239+
240+
func testInitializedVarDecl() {
241+
let localVal = TestStruct {
242+
1
243+
} #^INITIALIZED_VARDECL_SAMELINE^#
244+
#^INITIALIZED_VARDECL_NEWLINE^#
245+
// INITIALIZED_VARDECL_SAMELINE: Begin completions, 4 items
246+
// INITIALIZED_VARDECL_SAMELINE-NOT: localVal
247+
// INITIALIZED_VARDECL_SAMELINE-DAG: Pattern/ExprSpecific: {#fn2: () -> String {|}#}[#() -> String#];
248+
// INITIALIZED_VARDECL_SAMELINE-DAG: Pattern/ExprSpecific: {#fn3: () -> String {|}#}[#() -> String#];
249+
// INITIALIZED_VARDECL_SAMELINE-DAG: Decl[InstanceMethod]/CurrNominal: .testStructMethod()[#Void#];
250+
// INITIALIZED_VARDECL_SAMELINE-DAG: Keyword[self]/CurrNominal: .self[#TestStruct#];
251+
// INITIALIZED_VARDECL_SAMELINE-NOT: localVal
252+
// INITIALIZED_VARDECL_SAMELINE: End completions
253+
254+
// INITIALIZED_VARDECL_NEWLINE: Begin completions
255+
// INITIALIZED_VARDECL_NEWLINE-DAG: Decl[LocalVar]/Local: localVal[#TestStruct#];
256+
// INITIALIZED_VARDECL_NEWLINE: End completions
257+
}

0 commit comments

Comments
 (0)