Skip to content

Commit e7360e0

Browse files
committed
[CodeCompletion] Disable multi trailing closure completion at newline
let value = SomeThing { ... } <HERE> Since Parser parses code-completion token as a part of the expression, completion failed to suggest 'value'. Also, the type of 'value' is often '<<error type>>' because of the code completion token. For now, disable additional trailing closure completion (suggesting 'label: { <#code#> }') on newline positions. Users still get the compltion on the same line as the closing brace. rdar://problem/66456159 (cherry picked from commit 5936ddb)
1 parent 5d3b598 commit e7360e0

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
@@ -3203,6 +3203,16 @@ Parser::parseTrailingClosures(bool isExprBasic, SourceRange calleeRange,
32033203
if (!Tok.is(tok::code_complete))
32043204
break;
32053205

3206+
// FIXME: Additional trailing closure completion on newline positions.
3207+
// let foo = SomeThing {
3208+
// ...
3209+
// }
3210+
// <HERE>
3211+
// This was previously enabled, but it failed to suggest 'foo' because
3212+
// the token was considered a part of the initializer.
3213+
if (Tok.isAtStartOfLine())
3214+
break;
3215+
32063216
// If the current completion mode doesn't support trailing closure
32073217
// completion, leave the token here and let "postfix completion" to
32083218
// 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 in|}#}[#() -> String#];
2830
// GLOBALFUNC_SAMELINE: End completions
2931

30-
// GLOBALFUNC_NEWLINE: Begin completions, 1 items
31-
// GLOBALFUNC_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: () -> String {() -> String in|}#}[#() -> String#];
32+
// GLOBALFUNC_NEWLINE: Begin completions
33+
// FIXME-GLOBALFUNC_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: () -> String {() -> String in|}#}[#() -> 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 in|}#}[#(() -> String)?#];
65+
// FIXME-METHOD_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: (() -> String)? {() -> String in|}#}[#(() -> 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 in|}#}[#() -> String#];
95-
// INIT_OVERLOADED_NEWLINE-DAG: Pattern/ExprSpecific: {#fn3: () -> String {() -> String in|}#}[#() -> String#];
96+
// FIXME-INIT_OVERLOADED_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: () -> String {() -> String in|}#}[#() -> String#];
97+
// FIXME-INIT_OVERLOADED_NEWLINE-DAG: Pattern/ExprSpecific: {#fn3: () -> String {() -> String in|}#}[#() -> 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 in|}#}[#() -> String#];
122-
// INIT_OPTIONAL_NEWLINE-DAG: Pattern/ExprSpecific: {#fn3: () -> String {() -> String in|}#}[#() -> String#];
123+
// FIXME-INIT_OPTIONAL_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: () -> String {() -> String in|}#}[#() -> String#];
124+
// FIXME-INIT_OPTIONAL_NEWLINE-DAG: Pattern/ExprSpecific: {#fn3: () -> String {() -> String in|}#}[#() -> 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 in|}#}[#() -> 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 in|}#}[#() -> String#];
147+
// INIT_REQUIRED_NEWLINE_1: Begin completions
148+
// FIXME-INIT_REQUIRED_NEWLINE_1-DAG: Pattern/ExprSpecific: {#fn2: () -> String {() -> String in|}#}[#() -> 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 in|}#}[#() -> 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 in|}#}[#() -> String#];
163+
// INIT_REQUIRED_NEWLINE_2: Begin completions
164+
// FIXME-INIT_REQUIRED_NEWLINE_2-DAG: Pattern/ExprSpecific: {#fn3: () -> String {() -> String in|}#}[#() -> 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 in|}#}[#(() -> String)?#]; name=fn2: (() -> String)?
230+
// FIXME-MEMBERDECL_NEWLINE-DAG: Pattern/ExprSpecific: {#fn2: (() -> String)? {() -> String in|}#}[#(() -> 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 in|}#}[#() -> String#];
248+
// INITIALIZED_VARDECL_SAMELINE-DAG: Pattern/ExprSpecific: {#fn3: () -> String {() -> String in|}#}[#() -> 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)