Skip to content

Commit 19d13c3

Browse files
committed
Reapply "[CodeCompletion] Don't show the loop index before it is visible"
With the tests updated to account for not having the correct behaviour for brace-stmt items from after the code-completion point. That part turns out to be harder to fix. This reverts commit a5325e6.
1 parent f6b969f commit 19d13c3

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

lib/AST/NameLookupImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ class FindLocalVal : public StmtVisitor<FindLocalVal> {
188188
if (!isReferencePointInRange(S->getSourceRange()))
189189
return;
190190
visit(S->getBody());
191-
checkPattern(S->getPattern(), DeclVisibilityKind::LocalVariable);
191+
if (!isReferencePointInRange(S->getSequence()->getSourceRange()))
192+
checkPattern(S->getPattern(), DeclVisibilityKind::LocalVariable);
192193
}
193194

194195
void visitBraceStmt(BraceStmt *S, bool isTopLevelCode = false) {

lib/Parse/ParseStmt.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,8 +2463,6 @@ ParserResult<Stmt> Parser::parseStmtForEach(SourceLoc ForLoc,
24632463
ParserResult<Expr> Where;
24642464
if (consumeIf(tok::kw_where)) {
24652465
Where = parseExprBasic(diag::expected_foreach_where_expr);
2466-
if (Where.hasCodeCompletion())
2467-
return makeParserCodeCompletionResult<Stmt>();
24682466
if (Where.isNull())
24692467
Where = makeParserErrorResult(new (Context) ErrorExpr(Tok.getLoc()));
24702468
Status |= Where;

test/IDE/complete_expr_postfix_begin.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENERIC_TYPEALIAS_1 | FileCheck %s -check-prefix=MY_ALIAS
5858
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENERIC_TYPEALIAS_2 | FileCheck %s -check-prefix=MY_ALIAS
5959

60+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_FOR_EACH_1 | FileCheck %s -check-prefix=IN_FOR_EACH_1
61+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_FOR_EACH_2 | FileCheck %s -check-prefix=IN_FOR_EACH_1
62+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_FOR_EACH_3 | FileCheck %s -check-prefix=IN_FOR_EACH_3
63+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_FOR_EACH_4 | FileCheck %s -check-prefix=IN_FOR_EACH_3
64+
6065
//
6166
// Test code completion at the beginning of expr-postfix.
6267
//
@@ -407,3 +412,46 @@ func testGenericTypealias2() {
407412
var y: MyAlias<Int>
408413
y = #^GENERIC_TYPEALIAS_2^#
409414
}
415+
416+
func testInForEach1(arg: Int) {
417+
let local = 2
418+
for index in #^IN_FOR_EACH_1^# {
419+
let inBody = 3
420+
}
421+
let after = 4
422+
// IN_FOR_EACH_1-NOT: Decl[LocalVar]
423+
// IN_FOR_EACH_1: Decl[LocalVar]/Local: local[#Int#];
424+
// FIXME: shouldn't show 'after' here.
425+
// IN_FOR_EACH_1: Decl[LocalVar]/Local: after[#Int#];
426+
// IN_FOR_EACH_1: Decl[LocalVar]/Local: arg[#Int#];
427+
// IN_FOR_EACH_1-NOT: Decl[LocalVar]
428+
}
429+
func testInForEach2(arg: Int) {
430+
let local = 2
431+
for index in 1 ... #^IN_FOR_EACH_2^# {
432+
let inBody = 3
433+
}
434+
let after = 4
435+
}
436+
func testInForEach3(arg: Int) {
437+
let local = 2
438+
for index: Int in 1 ... 2 where #^IN_FOR_EACH_3^# {
439+
let inBody = 3
440+
}
441+
let after = 4
442+
// IN_FOR_EACH_3-NOT: Decl[LocalVar]
443+
// IN_FOR_EACH_3: Decl[LocalVar]/Local: index[#Int#];
444+
// IN_FOR_EACH_3-NOT: Decl[LocalVar]
445+
// IN_FOR_EACH_3: Decl[LocalVar]/Local: local[#Int#];
446+
// FIXME: shouldn't show 'after' here.
447+
// IN_FOR_EACH_3: Decl[LocalVar]/Local: after[#Int#];
448+
// IN_FOR_EACH_3: Decl[LocalVar]/Local: arg[#Int#];
449+
// IN_FOR_EACH_3-NOT: Decl[LocalVar]
450+
}
451+
func testInForEach4(arg: Int) {
452+
let local = 2
453+
for index in 1 ... 2 {
454+
#^IN_FOR_EACH_4^#
455+
}
456+
let after = 4
457+
}

0 commit comments

Comments
 (0)