[clang-tools-extra] [clangd] Support go-to-definition on type hints. The core part (PR #86629)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Tue May 21 23:45:24 PDT 2024


================
@@ -1637,6 +1678,144 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
                         ExpectedHint{": static_vector<int>", "vector_name"});
 }
 
+template <typename... Labels>
+void assertTypeLinkHints(StringRef Code, StringRef HintRange,
+                         Labels... ExpectedLabels) {
+  Annotations Source(Code);
+  auto HintAt = [&](llvm::ArrayRef<InlayHint> InlayHints,
+                    llvm::StringRef Range) {
----------------
HighCommander4 wrote:

This lambda doesn't seem to give us much, it's only called once.

Suggestion: inline its contents, so below we have:

```c++
  auto Hints = hintsOfKind(AST, InlayHintKind::Type);
  auto Hint = llvm::find_if(Hints, [&](const InlayHint &InlayHint) {
    return InlayHint.range == Source.range(HintRange);
  });
```

Now we can use gtest facilities to issue a more informative assert message:

```c++
  ASSERT_TRUE(Hint != Hints.end()) << "No hint was found at " << HintRange;
```

(Last line then becomes `EXPECT_THAT(Hint->label, ElementsAre(...));`)

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


More information about the cfe-commits mailing list