diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/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, diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp --- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -423,6 +423,12 @@ )cpp", {"bar", ""}, }, + { + R"cpp( + // Parse until EOF + namespace bar{})cpp", + {""}, + }, { R"cpp( // Namespaces with multiple chunks.