mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CodeComplete] Adjust the end location of a delayed-parsing var decl. rdar://22981278
Before this commit, for a var decl at top level, code completion engine assumes the code completion token contained in this decl is the end point of the delayed parsing, i.e. the second pass of code completion. This may lead to incomplete ASTs during the second pass, for instance, when the code completion token lies at the second argument of a call expr that takes three arguments. We fix the issue by allowing the first pass to pre-register the end location of a top-level var decl since the first pass is a more error-tolerant and holistic parsing, and the second pass to reuse this loc. Swift SVN r32729
This commit is contained in:
@@ -1707,7 +1707,9 @@ void Parser::consumeDecl(ParserPosition BeginParserPosition,
|
||||
|
||||
// Consume the code completion token, if there is one.
|
||||
consumeIf(tok::code_complete);
|
||||
SourceLoc EndLoc = Tok.getLoc();
|
||||
SourceLoc EndLoc = DelayedDeclEnd.isValid() &&
|
||||
SourceMgr.isBeforeInBuffer(Tok.getLoc(), DelayedDeclEnd) ?
|
||||
DelayedDeclEnd : Tok.getLoc();
|
||||
State->delayDecl(PersistentParserState::DelayedDeclKind::Decl, Flags.toRaw(),
|
||||
CurDeclContext, { BeginLoc, EndLoc },
|
||||
BeginParserPosition.PreviousLoc);
|
||||
@@ -3770,8 +3772,12 @@ ParserStatus Parser::parseDeclVar(ParseDeclOptions Flags,
|
||||
|
||||
// If we are doing second pass of code completion, we don't want to
|
||||
// suddenly cut off parsing and throw away the declaration.
|
||||
if (init.hasCodeCompletion() && isCodeCompletionFirstPass())
|
||||
if (init.hasCodeCompletion() && isCodeCompletionFirstPass()) {
|
||||
|
||||
// Register the end of the init as the end of the delayed parsing.
|
||||
DelayedDeclEnd = init.get() ? init.get()->getEndLoc() : SourceLoc();
|
||||
return makeParserCodeCompletionStatus();
|
||||
}
|
||||
|
||||
if (init.isNull())
|
||||
return makeParserError();
|
||||
|
||||
Reference in New Issue
Block a user