[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 21 00:18:34 PDT 2025


================
@@ -2305,7 +2335,45 @@ TEST(BlockEndHints, PointerToMemberFunction) {
       $ptrmem[[}]]
     } // suppress
   )cpp",
-                      ExpectedHint{" // if", "ptrmem"});
+                      ExpectedHint{" // if ()", "ptrmem"});
+}
+
+TEST(BlockEndHints, MinLineLimit) {
+  assertBlockEndHintsWithOpts(
+      R"cpp(
+    namespace ns {
+      int Var;
+      int func1();
+      int func2(int, int);
+      struct S {
+        int Field;
+        int method1() const;
+        int method2(int, int) const;
+      $struct[[}]];
----------------
HighCommander4 wrote:

It's not necessary.

The core assertion the tests make is [this one](https://searchfox.org/llvm/rev/bb21a6819b3fb9d689de776f7ee768030dfbacea/clang-tools-extra/clangd/unittests/InlayHintTests.cpp#101-102):

```
  EXPECT_THAT(hintsOfKind(AST, Kind),
              ElementsAre(HintMatcher(Expected, Source)...));
```

`hintsOfKind(AST, Kind)` returns **all** inlay hints of the specified kind in the code; its output does not depend on the presence or absence of annotations in the code.

`ElementsAre(...)` then assert that these returned hints match the provided `ExpectedHint` objects, including how many there are. If in the test case you have two `ExpectedHint` objects, and the `hintsOfKind()` starts returning three hints, the test will start failing.

The only purpose of the annotations is so that you can name a range passed in to an `ExpectedHint`; if you never need to name the range, you don't need the annotation.

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


More information about the cfe-commits mailing list