diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -381,8 +381,15 @@ for (const EnumConstantDecl *ECD : T->castAs()->getDecl()->enumerators()) if (ECD->getInitVal() == Val) - return llvm::formatv("{0} ({1})", ECD->getNameAsString(), Val).str(); + return llvm::formatv("{0} ({1:x})", ECD->getNameAsString(), Val).str(); } + // Show hex value of integers if they're at least 10 (not negative!) + if (T->isIntegralOrEnumerationType() && + Constant.Val.getInt().getMinSignedBits() <= 64 && + !Constant.Val.getInt().isNegative() && Constant.Val.getInt().uge(10)) + return llvm::formatv("{0} ({1:x})", Constant.Val.getAsString(Ctx, T), + Constant.Val.getInt().getExtValue()) + .str(); return Constant.Val.getAsString(Ctx, T); } diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -513,7 +513,7 @@ HI.Definition = "Color x = GREEN"; HI.Kind = index::SymbolKind::Variable; HI.Type = "enum Color"; - HI.Value = "GREEN (1)"; // Symbolic when hovering on an expression. + HI.Value = "GREEN (0x1)"; // Symbolic when hovering on an expression. }}, {R"cpp( template struct Add { @@ -543,7 +543,7 @@ HI.ReturnType = "int"; HI.Parameters.emplace(); HI.NamespaceScope = ""; - HI.Value = "42"; + HI.Value = "42 (0x2a)"; }}, {R"cpp( const char *[[ba^r]] = "1234"; @@ -1468,7 +1468,7 @@ HI.Definition = "static int hey = 10"; HI.Documentation = "Global variable"; // FIXME: Value shouldn't be set in this case - HI.Value = "10"; + HI.Value = "10 (0xa)"; }}, { R"cpp(// Global variable in namespace @@ -1485,7 +1485,7 @@ HI.NamespaceScope = "ns1::"; HI.Type = "int"; HI.Definition = "static int hey = 10"; - HI.Value = "10"; + HI.Value = "10 (0xa)"; }}, { R"cpp(// Field in anonymous struct