@@ -1654,20 +1654,25 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
16541654 Context.getIdentifier (" _" ), /* implicit=*/ false );
16551655 auto Result = makeParserResult (Expr);
16561656 if (CodeCompletion) {
1657- std::vector<StringRef> Identifiers;
1658-
1659- // Move lexer to the start of the current line.
1660- L->backtrackToState (L->getStateForBeginningOfTokenLoc (
1661- L->getLocForStartOfLine (SourceMgr, Tok.getLoc ())));
16621657
1658+ // FIXME: Code-completion should be able to find the contextual type
1659+ // from AST.
1660+ std::vector<StringRef> Identifiers;
16631661 bool HasReturn = false ;
1664-
1665- // Until we see the code completion token, collect identifiers.
1666- for (L->lex (Tok); !Tok.is (tok::code_complete); consumeToken ()) {
1667- if (!HasReturn)
1668- HasReturn = Tok.is (tok::kw_return);
1669- if (Tok.is (tok::identifier)) {
1670- Identifiers.push_back (Tok.getText ());
1662+ {
1663+ ParserPositionRAII PPR (*this );
1664+ // Move lexer to the start of the current line.
1665+ L->backtrackToState (L->getStateForBeginningOfTokenLoc (
1666+ L->getLocForStartOfLine (SourceMgr, Tok.getLoc ())));
1667+
1668+ // Until we see the code completion token, collect identifiers.
1669+ for (L->lex (Tok); !Tok.isAny (tok::code_complete, tok::eof);
1670+ consumeTokenWithoutFeedingReceiver ()) {
1671+ if (!HasReturn)
1672+ HasReturn = Tok.is (tok::kw_return);
1673+ if (Tok.is (tok::identifier)) {
1674+ Identifiers.push_back (Tok.getText ());
1675+ }
16711676 }
16721677 }
16731678 CodeCompletion->completeUnresolvedMember (Expr, Identifiers, HasReturn);
0 commit comments