[PATCH] D157205: [clangd] Add hexadecimal member offsets and sizes to hover popup

tetra via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 6 11:17:41 PDT 2023


tetraxile updated this revision to Diff 547595.
tetraxile added a comment.

Thanks for the suggestion SR_team, I've just added that.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157205/new/

https://reviews.llvm.org/D157205

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3383,7 +3383,7 @@
 Type: type (aka can_type)
 Value = value
 Offset: 12 (0xc) bytes
-Size: 4 (0x4) bytes (+4 (0x4) bytes padding)
+Size: 4 bytes (+4 bytes padding)
 
 // In test::Bar
 def)",
@@ -3404,8 +3404,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 4 (0x4) bytes and 3 (0x3) bits
-Size: 25 (0x19) bits (+4 (0x4) bits padding)
+Offset: 4 bytes and 3 bits
+Size: 25 (0x19) bits (+4 bits padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1404,8 +1404,8 @@
 static std::string formatSize(uint64_t SizeInBits) {
   uint64_t Value = SizeInBits % 8 == 0 ? SizeInBits / 8 : SizeInBits;
   const char *Unit = Value != 0 && Value == SizeInBits ? "bit" : "byte";
-  return llvm::formatv("{0} ({0:x}) {1}{2}", Value, Unit, Value == 1 ? "" : "s")
-      .str();
+  const char *Fmt = Value >= 10 ? "{0} ({0:x}) {1}{2}" : "{0} {1}{2}";
+  return llvm::formatv(Fmt, Value, Unit, Value == 1 ? "" : "s").str();
 }
 
 // Offsets are shown in bytes + bits, so offsets of different fields


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157205.547595.patch
Type: text/x-patch
Size: 1400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230806/fcfd1ced/attachment.bin>


More information about the cfe-commits mailing list