[clang-tools-extra] 4b2cf98 - [clangd] Support type hints for `decltype(expr)`
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 19 13:10:41 PST 2022
Author: v1nh1shungry
Date: 2022-12-19T16:10:26-05:00
New Revision: 4b2cf982cc51b425b935842e64aa7ec645ad6807
URL: https://github.com/llvm/llvm-project/commit/4b2cf982cc51b425b935842e64aa7ec645ad6807
DIFF: https://github.com/llvm/llvm-project/commit/4b2cf982cc51b425b935842e64aa7ec645ad6807.diff
LOG: [clangd] Support type hints for `decltype(expr)`
Reviewed By: nridge
Differential Revision: https://reviews.llvm.org/D138300
Added:
Modified:
clang-tools-extra/clangd/InlayHints.cpp
clang-tools-extra/clangd/unittests/InlayHintTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp
index 07328b62e1fb3..6bbad09b9f7bd 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -218,6 +218,13 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
StructuredBindingPolicy.PrintCanonicalTypes = true;
}
+ bool VisitTypeLoc(TypeLoc TL) {
+ if (const auto *DT = llvm::dyn_cast<DecltypeType>(TL.getType()))
+ if (QualType UT = DT->getUnderlyingType(); !UT->isDependentType())
+ addTypeHint(TL.getSourceRange(), UT, ": ");
+ return true;
+ }
+
bool VisitCXXConstructExpr(CXXConstructExpr *E) {
// Weed out constructor calls that don't look like a function call with
// an argument list, by checking the validity of getParenOrBraceRange().
diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 26e3936595db1..fa90abec02cbc 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1361,6 +1361,29 @@ TEST(TypeHints, Aliased) {
EXPECT_THAT(hintsOfKind(AST, InlayHintKind::Type), IsEmpty());
}
+TEST(TypeHints, Decltype) {
+ assertTypeHints(R"cpp(
+ $a[[decltype(0)]] a;
+ // FIXME: will be nice to show `: int` instead
+ $b[[decltype(a)]] b;
+ const $c[[decltype(0)]] &c = b;
+
+ // Don't show for dependent type
+ template <class T>
+ constexpr decltype(T{}) d;
+
+ $e[[decltype(0)]] e();
+ auto f() -> $f[[decltype(0)]];
+
+ template <class, class> struct Foo;
+ using G = Foo<$g[[decltype(0)]], float>;
+ )cpp",
+ ExpectedHint{": int", "a"},
+ ExpectedHint{": decltype(0)", "b"},
+ ExpectedHint{": int", "c"}, ExpectedHint{": int", "e"},
+ ExpectedHint{": int", "f"}, ExpectedHint{": int", "g"});
+}
+
TEST(DesignatorHints, Basic) {
assertDesignatorHints(R"cpp(
struct S { int x, y, z; };
More information about the cfe-commits
mailing list