[clangd] Fix parseNamespaceEvents to parse the last token

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68020

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@372875 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/clangd/SourceCode.cpp b/clangd/SourceCode.cpp
index 95f250c..ee0b74a 100644
--- a/clangd/SourceCode.cpp
+++ b/clangd/SourceCode.cpp
@@ -659,6 +659,9 @@
 
   while (!Lex.LexFromRawLexer(Tok))
     A(Tok);
+  // LexFromRawLexer returns true after it lexes last token, so we still have
+  // one more token to report.
+  A(Tok);
 }
 
 llvm::StringMap<unsigned> collectIdentifiers(llvm::StringRef Content,
diff --git a/clangd/unittests/SourceCodeTests.cpp b/clangd/unittests/SourceCodeTests.cpp
index cd9ccf0..771396d 100644
--- a/clangd/unittests/SourceCodeTests.cpp
+++ b/clangd/unittests/SourceCodeTests.cpp
@@ -441,6 +441,16 @@
               "c::d",
           },
       },
+      {
+          "",
+          {""},
+      },
+      {
+          R"cpp(
+            // Parse until EOF
+            namespace bar{})cpp",
+          {""},
+      },
   };
   for (const auto& Case : Cases) {
     EXPECT_EQ(Case.second,