================
@@ -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) {
+    auto *Hint = llvm::find_if(InlayHints, [&](const InlayHint &InlayHint) {
+      return InlayHint.range == Source.range(Range);
+    });
+    assert(Hint && "No range was found");
+    return llvm::ArrayRef(Hint->label);
+  };
+
+  TestTU TU = TestTU::withCode(Source.code());
+  TU.ExtraArgs.push_back("-std=c++2c");
+  auto AST = TU.build();
+
+  Config C;
+  C.InlayHints.TypeNameLimit = 0;
+  WithContextValue WithCfg(Config::Key, std::move(C));
+
+  auto Hints = hintsOfKind(AST, InlayHintKind::Type);
+  EXPECT_THAT(HintAt(Hints, HintRange),
+              ElementsAre(HintLabelPieceMatcher(ExpectedLabels, Source)...));
+}
+
+TEST(TypeHints, Links) {
+  StringRef Source(R"cpp(
+    $Package[[template <class T, class U>
----------------
zyn0217 wrote:

@HighCommander4 I explored it a bit more:

I explored it a bit more:

1. Using `RecordDecl::getBeginLoc()` does work in terms of the protocol, but 
this SourceLocation points to the first keyword token of the definition, i.e., 
the location of struct/class, which doesn't seem acceptable to us.

2. The better approach to having the identifier location is to resort to 
`TypeLocs`, which is involved regarding the current implementation of 
`addTypeHint()` because it's taking a `QualType` as a parameter and changing it 
to `TypeSourceInfo/TypeLoc` might require some surgery.

I think I'm in favor of shifting the current `TypeHint` implementation to rely 
on `TypeLocs`. We probably need a separate patch before this one. WDYT? Or is 
there any possible approach to obtaining the location of the identifier without 
using `TypeLocs`?

https://github.com/llvm/llvm-project/pull/86629
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to