[clang] [clang-tools-extra] [clangd] Support parsing comments without ASTContext (PR #78491)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 14 06:22:34 PDT 2024


================
@@ -316,5 +319,26 @@ std::string getReturnType(const CodeCompletionString &CCS) {
   return "";
 }
 
+comments::FullComment *parseComment(llvm::StringRef Comment,
+                                    llvm::BumpPtrAllocator &Allocator,
+                                    comments::CommandTraits &Traits) {
+  // The comment lexer expects markers, so add them back
+  auto CommentWithMarkers = "/*" + Comment.str() + "*/";
+
+  SourceManagerForFile SourceMgrForFile("mock_file.cpp", CommentWithMarkers);
+  SourceManager &SourceMgr = SourceMgrForFile.get();
+
+  comments::Lexer L(Allocator, SourceMgr.getDiagnostics(), Traits,
+                    SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()),
+                    CommentWithMarkers.data(),
+                    CommentWithMarkers.data() + CommentWithMarkers.size());
+  comments::Sema S(Allocator, SourceMgr, SourceMgr.getDiagnostics(), Traits,
+                   nullptr);
----------------
erichkeane wrote:

we need a `/*stuff=*/` style comment for the `nullptr` here.

https://github.com/llvm/llvm-project/pull/78491


More information about the cfe-commits mailing list