[PATCH] D108972: [clangd] Omit type hints that are too long

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 6 23:33:45 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGc2810f2c1655: [clangd] Omit type hints that are too long (authored by nridge).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108972/new/

https://reviews.llvm.org/D108972

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -591,6 +591,17 @@
   )cpp");
 }
 
+TEST(TypeHints, LongTypeName) {
+  assertTypeHints(R"cpp(
+    template <typename, typename, typename>
+    struct A {};
+    struct MultipleWords {};
+    A<MultipleWords, MultipleWords, MultipleWords> foo();
+    // Omit type hint past a certain length (currently 32)
+    auto var = foo();
+  )cpp");
+}
+
 // FIXME: Low-hanging fruit where we could omit a type hint:
 //  - auto x = TypeName(...);
 //  - auto x = (TypeName) (...);
Index: clang-tools-extra/clangd/InlayHints.cpp
===================================================================
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -331,8 +331,9 @@
     if (!T.getTypePtrOrNull())
       return;
 
-    addInlayHint(R, InlayHintKind::TypeHint,
-                 std::string(Prefix) + T.getAsString(TypeHintPolicy));
+    std::string TypeName = T.getAsString(TypeHintPolicy);
+    if (TypeName.length() < TypeNameLimit)
+      addInlayHint(R, InlayHintKind::TypeHint, std::string(Prefix) + TypeName);
   }
 
   std::vector<InlayHint> &Results;
@@ -341,6 +342,8 @@
   StringRef MainFileBuf;
   const HeuristicResolver *Resolver;
   PrintingPolicy TypeHintPolicy;
+
+  static const size_t TypeNameLimit = 32;
 };
 
 std::vector<InlayHint> inlayHints(ParsedAST &AST) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108972.370993.patch
Type: text/x-patch
Size: 1558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210907/9dcc0e72/attachment.bin>


More information about the cfe-commits mailing list