v1nh1shungry created this revision. v1nh1shungry added a reviewer: nridge. Herald added subscribers: kadircet, arphaman. Herald added a project: All. v1nh1shungry requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D138300 Files: clang-tools-extra/clangd/InlayHints.cpp clang-tools-extra/clangd/unittests/InlayHintTests.cpp Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/InlayHintTests.cpp +++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp @@ -1141,6 +1141,10 @@ ExpectedHint{": int &", "z"}); } +TEST(TypeHints, Decltype) { + assertTypeHints("decltype(0) $i[[i]];", ExpectedHint{": int", "i"}); +} + TEST(TypeHints, NoQualifiers) { assertTypeHints(R"cpp( namespace A { Index: clang-tools-extra/clangd/InlayHints.cpp =================================================================== --- clang-tools-extra/clangd/InlayHints.cpp +++ clang-tools-extra/clangd/InlayHints.cpp @@ -296,17 +296,25 @@ return true; } - if (D->getType()->getContainedAutoType()) { - if (!D->getType()->isDependentType()) { + auto T = D->getType(); + if (T->getContainedAutoType()) { + if (!T->isDependentType()) { // Our current approach is to place the hint on the variable // and accordingly print the full type // (e.g. for `const auto& x = 42`, print `const int&`). // Alternatively, we could place the hint on the `auto` // (and then just print the type deduced for the `auto`). - addTypeHint(D->getLocation(), D->getType(), /*Prefix=*/": "); + addTypeHint(D->getLocation(), T, /*Prefix=*/": "); } } + // Show type hint for decltype, e.g. + // for `decltype(0) i;`, show `decltype(0) i: int;` + if (T->isDecltypeType()) + addTypeHint(D->getLocation(), + llvm::cast<DecltypeType>(T)->getUnderlyingType(), + /*Prefix=*/": "); + // Handle templates like `int foo(auto x)` with exactly one instantiation. if (auto *PVD = llvm::dyn_cast<ParmVarDecl>(D)) { if (D->getIdentifier() && PVD->getType()->isDependentType() &&
Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/InlayHintTests.cpp +++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp @@ -1141,6 +1141,10 @@ ExpectedHint{": int &", "z"}); } +TEST(TypeHints, Decltype) { + assertTypeHints("decltype(0) $i[[i]];", ExpectedHint{": int", "i"}); +} + TEST(TypeHints, NoQualifiers) { assertTypeHints(R"cpp( namespace A { Index: clang-tools-extra/clangd/InlayHints.cpp =================================================================== --- clang-tools-extra/clangd/InlayHints.cpp +++ clang-tools-extra/clangd/InlayHints.cpp @@ -296,17 +296,25 @@ return true; } - if (D->getType()->getContainedAutoType()) { - if (!D->getType()->isDependentType()) { + auto T = D->getType(); + if (T->getContainedAutoType()) { + if (!T->isDependentType()) { // Our current approach is to place the hint on the variable // and accordingly print the full type // (e.g. for `const auto& x = 42`, print `const int&`). // Alternatively, we could place the hint on the `auto` // (and then just print the type deduced for the `auto`). - addTypeHint(D->getLocation(), D->getType(), /*Prefix=*/": "); + addTypeHint(D->getLocation(), T, /*Prefix=*/": "); } } + // Show type hint for decltype, e.g. + // for `decltype(0) i;`, show `decltype(0) i: int;` + if (T->isDecltypeType()) + addTypeHint(D->getLocation(), + llvm::cast<DecltypeType>(T)->getUnderlyingType(), + /*Prefix=*/": "); + // Handle templates like `int foo(auto x)` with exactly one instantiation. if (auto *PVD = llvm::dyn_cast<ParmVarDecl>(D)) { if (D->getIdentifier() && PVD->getType()->isDependentType() &&
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits