Skip to content

Commit d2ff82c

Browse files
authored
Merge pull request #5699 from benlangmuir/cc-after-varlet
2 parents 4ee4703 + e43a1d3 commit d2ff82c

File tree

2 files changed

+75
-7
lines changed

2 files changed

+75
-7
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,9 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
13871387
case tok::code_complete:
13881388
Result = makeParserResult(new (Context) CodeCompletionExpr(Tok.getRange()));
13891389
Result.setHasCodeCompletion();
1390-
if (CodeCompletion)
1390+
if (CodeCompletion &&
1391+
// We cannot code complete anything after var/let.
1392+
(!InVarOrLetPattern || InVarOrLetPattern == IVOLP_InMatchingPattern))
13911393
CodeCompletion->completePostfixExprBeginning(dyn_cast<CodeCompletionExpr>(
13921394
Result.get()));
13931395
consumeToken(tok::code_complete);

test/IDE/complete_pattern.swift

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
1+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_ATOM_1 | %FileCheck %s -check-prefix=NO_COMPLETIONS
2+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_ATOM_2 | %FileCheck %s -check-prefix=NO_COMPLETIONS
3+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_ATOM_3 | %FileCheck %s -check-prefix=NO_COMPLETIONS
4+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_ATOM_4 | %FileCheck %s -check-prefix=NO_COMPLETIONS
5+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_ATOM_5 | %FileCheck %s -check-prefix=NO_COMPLETIONS
6+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_ATOM_6 | %FileCheck %s -check-prefix=NO_COMPLETIONS
7+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_ATOM_7 | %FileCheck %s -check-prefix=NO_COMPLETIONS
8+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_ATOM_8 | %FileCheck %s -check-prefix=NO_COMPLETIONS
9+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_ATOM_9 | %FileCheck %s -check-prefix=NO_COMPLETIONS
10+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_ATOM_10 | %FileCheck %s -check-prefix=NO_COMPLETIONS
11+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_ATOM_11 | %FileCheck %s -check-prefix=NO_COMPLETIONS
12+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_ATOM_12 | %FileCheck %s -check-prefix=NO_COMPLETIONS
13+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_IF_CASE_1 | %FileCheck %s -check-prefix=GLOBAL
14+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_IF_CASE_2 | %FileCheck %s -check-prefix=NO_COMPLETIONS
15+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_ATOM_1 | %FileCheck %s -check-prefix=NO_COMPLETIONS
16+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_ATOM_2 | %FileCheck %s -check-prefix=NO_COMPLETIONS
17+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_ATOM_3 | %FileCheck %s -check-prefix=NO_COMPLETIONS
18+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_ATOM_4 | %FileCheck %s -check-prefix=NO_COMPLETIONS
19+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_ATOM_5 | %FileCheck %s -check-prefix=NO_COMPLETIONS
20+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_ATOM_6 | %FileCheck %s -check-prefix=NO_COMPLETIONS
21+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_ATOM_7 | %FileCheck %s -check-prefix=NO_COMPLETIONS
22+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_ATOM_8 | %FileCheck %s -check-prefix=NO_COMPLETIONS
23+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_ATOM_9 | %FileCheck %s -check-prefix=NO_COMPLETIONS
24+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_ATOM_10 | %FileCheck %s -check-prefix=NO_COMPLETIONS
25+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_ATOM_11 | %FileCheck %s -check-prefix=NO_COMPLETIONS
26+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_ATOM_12 | %FileCheck %s -check-prefix=NO_COMPLETIONS
27+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_IF_CASE_1 | %FileCheck %s -check-prefix=GLOBAL
28+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_INFUNC_IF_CASE_2 | %FileCheck %s -check-prefix=NO_COMPLETIONS
129

30+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_IS_1 > %t.types.txt
31+
// RUN: %FileCheck %s -check-prefix=GLOBAL_NEGATIVE < %t.types.txt
232

333
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PATTERN_IS_1 > %t.types.txt
434
// RUN: %FileCheck %s -check-prefix=GLOBAL_NEGATIVE < %t.types.txt
@@ -60,19 +90,55 @@ protocol BarProtocol {
6090

6191
typealias FooTypealias = Int
6292

93+
// GLOBAL: Begin completions
94+
// GLOBAL-DAG: fooObject
95+
// GLOBAL-DAG: fooFunc
96+
// GLOBAL-DAG: FooTypealias
97+
// GLOBAL-DAG: FooProtocol
98+
// GLOBAL-DAG: FooClass
99+
// GLOBAL: End completions
100+
63101
// GLOBAL_NEGATIVE-NOT: fooObject
64102
// GLOBAL_NEGATIVE-NOT: fooFunc
65103

66104
//===---
67105
//===--- Test that we don't try to suggest anything where pattern-atom is expected.
68106
//===---
69107

70-
var #^PATTERN_ATOM_1^#
71-
var (#^PATTERN_ATOM_2^#
72-
var (a, #^PATTERN_ATOM_3^#
73-
var (a #^PATTERN_ATOM_4^#
74-
var ((#^PATTERN_ATOM_5^#
75-
var ((a, b), #^PATTERN_ATOM_6^#
108+
// NO_COMPLETIONS-NOT: Begin completions
109+
110+
// Use do { } to reset the parser after broken syntax.
111+
do { var #^PATTERN_ATOM_1^# }
112+
do { var (#^PATTERN_ATOM_2^# }
113+
do {var (a, #^PATTERN_ATOM_3^# }
114+
do {var (a #^PATTERN_ATOM_4^# }
115+
do {var ((#^PATTERN_ATOM_5^# }
116+
do {var ((a, b), #^PATTERN_ATOM_6^# }
117+
do {guard var #^PATTERN_ATOM_7^# }
118+
do {guard var #^PATTERN_ATOM_8^# else { fatalError() } }
119+
do {guard let #^PATTERN_ATOM_9^# else { fatalError() } }
120+
do {guard let a = Optional(1), let #^PATTERN_ATOM_10^# else { fatalError() } }
121+
do {if let #^PATTERN_ATOM_11^# {} }
122+
do {if let a = Optional(1), let #^PATTERN_ATOM_12^# {} }
123+
do {if case #^PATTERN_IF_CASE_1^# {} }
124+
do {if case let #^PATTERN_IF_CASE_2^# {} }
125+
126+
func inFunc() {
127+
do { var #^PATTERN_INFUNC_ATOM_1^# }
128+
do { var (#^PATTERN_INFUNC_ATOM_2^# }
129+
do {var (a, #^PATTERN_INFUNC_ATOM_3^# }
130+
do {var (a #^PATTERN_INFUNC_ATOM_4^# }
131+
do {var ((#^PATTERN_INFUNC_ATOM_5^# }
132+
do {var ((a, b), #^PATTERN_INFUNC_ATOM_6^# }
133+
do {guard var #^PATTERN_INFUNC_ATOM_7^# }
134+
do {guard var #^PATTERN_INFUNC_ATOM_8^# else { fatalError() } }
135+
do {guard let #^PATTERN_INFUNC_ATOM_9^# else { fatalError() } }
136+
do {guard let a = Optional(1), let #^PATTERN_INFUNC_ATOM_10^# else { fatalError() } }
137+
do {if let #^PATTERN_INFUNC_ATOM_11^# {} }
138+
do {if let a = Optional(1), let #^PATTERN_INFUNC_ATOM_12^# {} }
139+
do {if case #^PATTERN_INFUNC_IF_CASE_1^# {} }
140+
do {if case let #^PATTERN_INFUNC_IF_CASE_2^# {} }
141+
}
76142

77143
//===---
78144
//===--- Test that we complete the type in 'is' pattern.

0 commit comments

Comments
 (0)