Skip to content

Commit 821d45b

Browse files
authored
Merge pull request #23498 from rintaro/ide-completion-findparsed-ignoreimplicit
[CodeCompletion] Look through implicit exprs to find the parsed expr
2 parents 714a2b4 + bfaa6af commit 821d45b

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ class ExprFinder : public ASTWalker {
176176
Expr *get() const { return FoundExpr; }
177177

178178
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
179-
if (TargetRange == E->getSourceRange() && !isa<ImplicitConversionExpr>(E) &&
180-
!isa<AutoClosureExpr>(E) && !isa<ConstructorRefCallExpr>(E)) {
179+
if (TargetRange == E->getSourceRange() && !E->isImplicit() &&
180+
!isa<ConstructorRefCallExpr>(E)) {
181181
assert(!FoundExpr && "non-nullptr for found expr");
182182
FoundExpr = E;
183183
return {false, nullptr};

test/IDE/complete_value_expr.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@
195195
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CLOSURE_IN_MEMBERDECLINIT_2 | %FileCheck %s -check-prefix=FOO_OBJECT_DOT
196196
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CLOSURE_IN_MEMBERDECLINIT_3 | %FileCheck %s -check-prefix=FOO_OBJECT_DOT
197197

198+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_ARRAY_LITERAL_1 | %FileCheck %s -check-prefix=SIMPLE_OBJECT_DOT
199+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_ARRAY_LITERAL_2 | %FileCheck %s -check-prefix=SIMPLE_OBJECT_DOT
200+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_DICTIONARY_LITERAL_1 | %FileCheck %s -check-prefix=SIMPLE_OBJECT_DOT
201+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_DICTIONARY_LITERAL_2 | %FileCheck %s -check-prefix=SIMPLE_OBJECT_DOT
202+
198203
// Test code completion of expressions that produce a value.
199204

200205
struct FooStruct {
@@ -2143,3 +2148,25 @@ extension String {
21432148
obj.#^CLOSURE_IN_MEMBERDECLINIT_3^#
21442149
}
21452150
}
2151+
2152+
struct SimpleStruct {
2153+
func foo() -> SimpleStruct {}
2154+
}
2155+
// SIMPLE_OBJECT_DOT: Begin completions
2156+
// SIMPLE_OBJECT_DOT-DAG: Keyword[self]/CurrNominal: self[#SimpleStruct#]; name=self
2157+
// SIMPLE_OBJECT_DOT-DAG: Decl[InstanceMethod]/CurrNominal{{(/TypeRelation\[Identical\])?}}: foo()[#SimpleStruct#]; name=foo()
2158+
// SIMPLE_OBJECT_DOT: End completions
2159+
func testInCollectionLiteral(value: SimpleStruct) {
2160+
let _ = [
2161+
value.#^IN_ARRAY_LITERAL_1^#
2162+
]
2163+
let _ = [
2164+
value.#^IN_ARRAY_LITERAL_2^#,
2165+
]
2166+
let _: [String: String] = [
2167+
value.#^IN_DICTIONARY_LITERAL_1^#
2168+
]
2169+
let _: [String: String] = [
2170+
value.#^IN_DICTIONARY_LITERAL_2^# : "test"
2171+
]
2172+
}

0 commit comments

Comments
 (0)