[clang-tools-extra] [clangd] Prevent printing huge initializer lists in hover definitions (PR #79746)

Raoul Wols via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 10 12:12:37 PST 2024


================
@@ -138,15 +138,9 @@ std::string getNamespaceScope(const Decl *D) {
 
 std::string printDefinition(const Decl *D, PrintingPolicy PP,
                             const syntax::TokenBuffer &TB) {
-  if (auto *VD = llvm::dyn_cast<VarDecl>(D)) {
-    if (auto *IE = VD->getInit()) {
-      // Initializers might be huge and result in lots of memory allocations in
-      // some catostrophic cases. Such long lists are not useful in hover cards
-      // anyway.
-      if (200 < TB.expandedTokens(IE->getSourceRange()).size())
-        PP.SuppressInitializers = true;
-    }
-  }
+  // Initializers might be huge and result in lots of memory allocations in some
+  // catostrophic cases. Such long lists are not useful in hover cards anyway.
+  PP.EntireContentsOfLargeArray = false;
----------------
rwols wrote:

OK, I check the size of the children() now when the initializer expression is not in the main file, and added two unit tests that verify that for a large initializer list from a header file it won't render, while a "small" initializer list will still render.

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


More information about the cfe-commits mailing list