[PATCH] D147395: [Clangd] Make the type hint length limit configurable

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 3 04:01:32 PDT 2023


hokein added a comment.

Thanks for the contribution!



================
Comment at: clang-tools-extra/clangd/Config.h:151
+    // Limit the length of type names in inlay hints.
+    size_t TypeNameLimit = 32;
   } InlayHints;
----------------
I would extend it a bit more -- 0 means no limit. 

Can you also add a unittest in `TEST(TypeHints, LongTypeName)` in `InlayHintTests.cpp`? 


================
Comment at: clang-tools-extra/clangd/ConfigFragment.h:326
+    /// Limit the length of type name hints.
+    std::optional<Located<std::string>> TypeNameLimit;
   };
----------------
if we add `uint32Value` method (see my other comment), then the type is `std::optional<Located<uint32_t>>`. 


================
Comment at: clang-tools-extra/clangd/ConfigYAML.cpp:258
+    Dict.handle("TypeNameLimit", [&](Node &N) {
+      if (auto Value = scalarValue(N, "TypeNameLimit"))
+        F.TypeNameLimit = *Value;
----------------
Similar to the `boolValue`, I think it would be better to have a `uint32Value` method (this is the first time that we have an integer in the config), something like below

```
 std::optional<Located<uint32_t>> uint32Value(Node &N, llvm::StringRef Desc) {
   if (auto Scalar = scalarValue(N, Desc)) {
        unsigned long long n;
        if (getAsUnsignedInteger(Scalar, 0, n)) {
           warning(Desc + "invalid number", N);
           return;
        }
        return Located<uint32_t>(n, Scalar->Range);
    }
    return std::nullopt;
}
```




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147395



More information about the cfe-commits mailing list