Skip to content

Commit 54963be

Browse files
committed
[CodeCompletion] Fix completion of collection type in top-level code
We forgot to return a code-completion status, so we didn't get to it in the second phase. let foo: [<here>] rdar://problem/24441902
1 parent da37e94 commit 54963be

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

lib/Parse/ParseType.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,9 @@ ParserResult<TypeRepr> Parser::parseTypeCollection() {
617617
: diag::expected_rbracket_array_type,
618618
lsquareLoc);
619619

620+
if (firstTy.hasCodeCompletion() || secondTy.hasCodeCompletion())
621+
return makeParserCodeCompletionStatus();
622+
620623
// If we couldn't parse anything for one of the types, propagate the error.
621624
if (firstTy.isNull() || (colonLoc.isValid() && secondTy.isNull()))
622625
return makeParserError();

test/IDE/complete_at_top_level.swift

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,40 @@
2424

2525
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_CLOSURE_1 | FileCheck %s -check-prefix=TOP_LEVEL_CLOSURE_1
2626

27-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_VAR_TYPE_1 > %t.toplevel.txt
28-
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_1 < %t.toplevel.txt
29-
// RUN: FileCheck %s -check-prefix=NEGATIVE < %t.toplevel.txt
27+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_VAR_TYPE_1 > %t.toplevel.1.txt
28+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_1 < %t.toplevel.1.txt
29+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_NEGATIVE_1 < %t.toplevel.1.txt
30+
// RUN: FileCheck %s -check-prefix=NEGATIVE < %t.toplevel.1.txt
31+
32+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_VAR_TYPE_2 > %t.toplevel.2.txt
33+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_1 < %t.toplevel.2.txt
34+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_NEGATIVE_1 < %t.toplevel.2.txt
35+
// RUN: FileCheck %s -check-prefix=NEGATIVE < %t.toplevel.2.txt
36+
37+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_VAR_TYPE_3 > %t.toplevel.3.txt
38+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_1 < %t.toplevel.3.txt
39+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_NEGATIVE_1 < %t.toplevel.3.txt
40+
// RUN: FileCheck %s -check-prefix=NEGATIVE < %t.toplevel.3.txt
41+
42+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_VAR_TYPE_4 > %t.toplevel.4.txt
43+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_1 < %t.toplevel.4.txt
44+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_NEGATIVE_1 < %t.toplevel.4.txt
45+
// RUN: FileCheck %s -check-prefix=NEGATIVE < %t.toplevel.4.txt
46+
47+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_VAR_TYPE_5 > %t.toplevel.5.txt
48+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_1 < %t.toplevel.5.txt
49+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_NEGATIVE_1 < %t.toplevel.5.txt
50+
// RUN: FileCheck %s -check-prefix=NEGATIVE < %t.toplevel.5.txt
51+
52+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_VAR_TYPE_5 > %t.toplevel.5.txt
53+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_1 < %t.toplevel.5.txt
54+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_NEGATIVE_1 < %t.toplevel.5.txt
55+
// RUN: FileCheck %s -check-prefix=NEGATIVE < %t.toplevel.5.txt
56+
57+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_VAR_TYPE_6 > %t.toplevel.6.txt
58+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_1 < %t.toplevel.6.txt
59+
// RUN: FileCheck %s -check-prefix=TOP_LEVEL_VAR_TYPE_NEGATIVE_1 < %t.toplevel.6.txt
60+
// RUN: FileCheck %s -check-prefix=NEGATIVE < %t.toplevel.6.txt
3061

3162
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_STMT_1 | FileCheck %s -check-prefix=PLAIN_TOP_LEVEL
3263
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_STMT_2 | FileCheck %s -check-prefix=PLAIN_TOP_LEVEL
@@ -218,6 +249,27 @@ var topLevelVarType1 : #^TOP_LEVEL_VAR_TYPE_1^#
218249
// TOP_LEVEL_VAR_TYPE_1: Begin completions
219250
// TOP_LEVEL_VAR_TYPE_1-DAG: Decl[Struct]/CurrModule: FooStruct[#FooStruct#]{{; name=.+$}}
220251
// TOP_LEVEL_VAR_TYPE_1: End completions
252+
// TOP_LEVEL_VAR_TYPE_NEGATIVE_1-NOT: Decl[GlobalVar
253+
// TOP_LEVEL_VAR_TYPE_NEGATIVE_1-NOT: Decl[FreeFunc
254+
func resyncParserA1_1() {}
255+
256+
var topLevelVarType2 : [#^TOP_LEVEL_VAR_TYPE_2^#]
257+
258+
func resyncParserA1_2() {}
259+
260+
var topLevelVarType3 : [#^TOP_LEVEL_VAR_TYPE_3^#: Int]
261+
262+
func resyncParserA1_3() {}
263+
264+
var topLevelVarType4 : [Int: #^TOP_LEVEL_VAR_TYPE_4^#]
265+
266+
func resyncParserA1_4() {}
267+
268+
if let topLevelVarType5 : [#^TOP_LEVEL_VAR_TYPE_5^#] {}
269+
270+
func resyncParserA1_5() {}
271+
272+
guard let topLevelVarType6 : [#^TOP_LEVEL_VAR_TYPE_6^#] else {}
221273

222274
func resyncParserA2() {}
223275

0 commit comments

Comments
 (0)