Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2838,6 +2838,15 @@ ParserResult<Expr> Parser::parseExprClosure() {
ParserStatus Status;
Status |= parseBraceItems(bodyElements, BraceItemListKind::Brace);

if (SourceMgr.rangeContainsCodeCompletionLoc({leftBrace, PreviousLoc})) {
// Ignore 'CodeCompletionDelayedDeclState' inside closures.
// Completions inside functions body inside closures at top level should
// be considered top-level completions.
if (State->hasCodeCompletionDelayedDeclState())
(void)State->takeCodeCompletionDelayedDeclState();
Status.setHasCodeCompletion();
}

// Parse the closing '}'.
SourceLoc rightBrace;
bool missingRBrace = parseMatchingToken(tok::r_brace, rightBrace,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
struct MyValue {
var value = 1
}
func foo(fn: () -> Void) {}
_ = foo {
func innerFunc(value: MyValue) {
value. // HERE
}
}

struct MyStruct {
var x = { () -> Int in
class InnerC {
init(value: MyValue) {
value. // HERE
}
}
}()
}

// RUN: %sourcekitd-test \
// RUN: -req=track-compiles == \
// RUN: -req=complete -pos=7:11 -repeat-request=2 %s -- %s -parse-as-library == \
// RUN: -req=complete -pos=15:15 -repeat-request=2 %s -- %s -parse-as-library \
// RUN: > %t.response.library
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response.library
// RUN: %FileCheck --check-prefix=LIB_TRACE %s < %t.response.library

// RESULT-LABEL: key.results: [
// RESULT: key.description: "value"
// RESULT-LABEL: key.results: [
// RESULT: key.description: "value"
// RESULT-LABEL: key.results: [
// RESULT: key.description: "value"
// RESULT-LABEL: key.results: [
// RESULT: key.description: "value"

// LIB_TRACE-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"

// RUN: %sourcekitd-test \
// RUN: -req=track-compiles == \
// RUN: -req=complete -pos=7:11 -repeat-request=2 %s -- %s == \
// RUN: -req=complete -pos=15:15 -repeat-request=2 %s -- %s \
// RUN: > %t.response.script
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response.script
// RUN: %FileCheck --check-prefix=SCRIPT_TRACE %s < %t.response.script

// SCRIPT_TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// SCRIPT_TRACE-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// SCRIPT_TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// SCRIPT_TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// SCRIPT_TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// SCRIPT_TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// SCRIPT_TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// SCRIPT_TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"