Index: clang-tools-extra/trunk/clangd/SourceCode.cpp =================================================================== --- clang-tools-extra/trunk/clangd/SourceCode.cpp +++ clang-tools-extra/trunk/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 collectIdentifiers(llvm::StringRef Content, Index: clang-tools-extra/trunk/clangd/unittests/SourceCodeTests.cpp =================================================================== --- clang-tools-extra/trunk/clangd/unittests/SourceCodeTests.cpp +++ clang-tools-extra/trunk/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,