Author: Haojian Wu Date: 2022-01-27T21:22:03+01:00 New Revision: 0cf75aac42eb6bd800405d152dfe7414a9ab6d99
URL: https://github.com/llvm/llvm-project/commit/0cf75aac42eb6bd800405d152dfe7414a9ab6d99 DIFF: https://github.com/llvm/llvm-project/commit/0cf75aac42eb6bd800405d152dfe7414a9ab6d99.diff LOG: [clangd] Enable hover on character literal. In the initial hover expression patch (https://reviews.llvm.org/D72500), we disabled all literals. There is some value on running hover on character literals (e.g. see the int value of the char). Differential Revision: https://reviews.llvm.org/D117864 Added: Modified: clang-tools-extra/clangd/Hover.cpp clang-tools-extra/clangd/unittests/HoverTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index d1d8142f53cb..5a11a1ce44c0 100644 --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -736,7 +736,7 @@ HoverInfo getDeducedTypeHoverContents(QualType QT, const syntax::Token &Tok, bool isLiteral(const Expr *E) { // Unfortunately there's no common base Literal classes inherits from // (apart from Expr), therefore these exclusions. - return llvm::isa<CharacterLiteral>(E) || llvm::isa<CompoundLiteralExpr>(E) || + return llvm::isa<CompoundLiteralExpr>(E) || llvm::isa<CXXBoolLiteralExpr>(E) || llvm::isa<CXXNullPtrLiteralExpr>(E) || llvm::isa<FixedPointLiteral>(E) || llvm::isa<FloatingLiteral>(E) || diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index b0974d99f0ac..b40b60d92e52 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -1224,7 +1224,6 @@ TEST(Hover, NoHover) { )cpp", // literals "auto x = t^rue;", - "auto x = '^A';", "auto x = ^(int){42};", "auto x = ^42.;", "auto x = ^42.0i;", @@ -1250,6 +1249,11 @@ TEST(Hover, All) { const char *const Code; const std::function<void(HoverInfo &)> ExpectedBuilder; } Cases[] = { + {"auto x = [['^A']]; // character literal", + [](HoverInfo &HI) { + HI.Name = "expression", HI.Type = "char"; + HI.Value = "65 (0x41)"; + }}, { R"cpp(// Local variable int main() { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits