[libclang] Support code-completion inside macro arguments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137973 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp
index eaab73e..fd5b4c2 100644
--- a/lib/Lex/PPMacroExpansion.cpp
+++ b/lib/Lex/PPMacroExpansion.cpp
@@ -358,7 +358,23 @@
         if (CodeComplete)
           CodeComplete->CodeCompleteMacroArgument(MacroName.getIdentifierInfo(),
                                                   MI, NumActuals);
-        LexUnexpandedToken(Tok);
+
+        // Add the code-completion token and finish the lexing normally so that
+        // normal code-completion occurs again with the expanded tokens.
+        ArgTokens.push_back(Tok);
+        // Add a marker EOF token to the end of the token list.
+        Token EOFTok;
+        EOFTok.startToken();
+        EOFTok.setKind(tok::eof);
+        EOFTok.setLocation(Tok.getLocation());
+        EOFTok.setLength(0);
+        ArgTokens.push_back(EOFTok);
+        ++NumActuals;
+        // "Fill out" the other arguments.
+        for (; NumActuals < MI->getNumArgs(); ++NumActuals)
+          ArgTokens.push_back(EOFTok);
+        return MacroArgs::create(MI, ArgTokens.data(), ArgTokens.size(),
+                                 /*isVarargsElided=*/false, *this);
       }
       
       if (Tok.is(tok::eof) || Tok.is(tok::eod)) { // "#if f(<eof>" & "#if f(\n"