decomp.me icon indicating copy to clipboard operation
decomp.me copied to clipboard

Show sizeof and offset of struct members when using language server

Open tomsons26 opened this issue 2 years ago • 3 comments

This would be a great improvement that would reduce guesswork of making sure structs are correctly sized and padded and quickly figuring out what sizeof may be used in code for example when allocating a struct. There are catches tho, compiler specific packing/padding and default packing/padding as well as compiler packing/padding arguments.

For example MSVC usually packs to 4 bytes, but if the struct contains a double it packs to 8. I suppose these nuances could be specified in compiler config and language server would need to be aware of what compiler args for packing are being used?

tomsons26 avatar Sep 24 '23 16:09 tomsons26

This isn't reliable as part of the language server, since the language server is always clangd, and thus won't be able to exactly replicate e.g. MSVC. Unless we can solve that problem, this isn't feasible.

bates64 avatar Sep 25 '23 09:09 bates64

maybe there's a way to tell the language server the sizes of primitives

ethteck avatar Sep 25 '23 09:09 ethteck

@nanaian clang has an MSVC-compatible frontend (in the form of clang-cl), so it should be possible to set it up to mostly work. (I say mostly because clang-cl has a few minor rough edges with the alignment of some exotic primitives like AVX stuff, but it shouldn't impact the vast majority of uses).

roblabla avatar Sep 25 '23 09:09 roblabla