Skip to content

Commit 1985cfd

Browse files
authored
Merge pull request swiftlang#30652 from rintaro/ide-completion-func-in-closure-rdar60838686
[CodeCompletion] Don't run second pass for decls in closures
2 parents ffe8a2b + 7b7599a commit 1985cfd

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,6 +2838,15 @@ ParserResult<Expr> Parser::parseExprClosure() {
28382838
ParserStatus Status;
28392839
Status |= parseBraceItems(bodyElements, BraceItemListKind::Brace);
28402840

2841+
if (SourceMgr.rangeContainsCodeCompletionLoc({leftBrace, PreviousLoc})) {
2842+
// Ignore 'CodeCompletionDelayedDeclState' inside closures.
2843+
// Completions inside functions body inside closures at top level should
2844+
// be considered top-level completions.
2845+
if (State->hasCodeCompletionDelayedDeclState())
2846+
(void)State->takeCodeCompletionDelayedDeclState();
2847+
Status.setHasCodeCompletion();
2848+
}
2849+
28412850
// Parse the closing '}'.
28422851
SourceLoc rightBrace;
28432852
bool missingRBrace = parseMatchingToken(tok::r_brace, rightBrace,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
struct MyValue {
2+
var value = 1
3+
}
4+
func foo(fn: () -> Void) {}
5+
_ = foo {
6+
func innerFunc(value: MyValue) {
7+
value. // HERE
8+
}
9+
}
10+
11+
struct MyStruct {
12+
var x = { () -> Int in
13+
class InnerC {
14+
init(value: MyValue) {
15+
value. // HERE
16+
}
17+
}
18+
}()
19+
}
20+
21+
// RUN: %sourcekitd-test \
22+
// RUN: -req=track-compiles == \
23+
// RUN: -req=complete -pos=7:11 -repeat-request=2 %s -- %s -parse-as-library == \
24+
// RUN: -req=complete -pos=15:15 -repeat-request=2 %s -- %s -parse-as-library \
25+
// RUN: > %t.response.library
26+
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response.library
27+
// RUN: %FileCheck --check-prefix=LIB_TRACE %s < %t.response.library
28+
29+
// RESULT-LABEL: key.results: [
30+
// RESULT: key.description: "value"
31+
// RESULT-LABEL: key.results: [
32+
// RESULT: key.description: "value"
33+
// RESULT-LABEL: key.results: [
34+
// RESULT: key.description: "value"
35+
// RESULT-LABEL: key.results: [
36+
// RESULT: key.description: "value"
37+
38+
// LIB_TRACE-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
39+
40+
// RUN: %sourcekitd-test \
41+
// RUN: -req=track-compiles == \
42+
// RUN: -req=complete -pos=7:11 -repeat-request=2 %s -- %s == \
43+
// RUN: -req=complete -pos=15:15 -repeat-request=2 %s -- %s \
44+
// RUN: > %t.response.script
45+
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response.script
46+
// RUN: %FileCheck --check-prefix=SCRIPT_TRACE %s < %t.response.script
47+
48+
// SCRIPT_TRACE-LABEL: key.notification: source.notification.compile-did-finish,
49+
// SCRIPT_TRACE-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
50+
// SCRIPT_TRACE-LABEL: key.notification: source.notification.compile-did-finish,
51+
// SCRIPT_TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
52+
// SCRIPT_TRACE-LABEL: key.notification: source.notification.compile-did-finish,
53+
// SCRIPT_TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
54+
// SCRIPT_TRACE-LABEL: key.notification: source.notification.compile-did-finish,
55+
// SCRIPT_TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"

0 commit comments

Comments
 (0)