Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C struct members and enum values are not shown on type hover #959

Open
apsigma opened this issue Dec 21, 2021 · 3 comments · May be fixed by llvm/llvm-project#89557
Open

C struct members and enum values are not shown on type hover #959

apsigma opened this issue Dec 21, 2021 · 3 comments · May be fixed by llvm/llvm-project#89557
Assignees

Comments

@apsigma
Copy link

apsigma commented Dec 21, 2021

I have noticed in my project that if I hover on a struct type, it does give me some information on the struct definition, but only the name of the struct. I would really like it if the hover would show the definition of the members of the struct. The same goes for enums, the hover only shows the name, not the named possible values.

Current hover of a struct (in this case I am hovering over the update_counter part of the variable declaration):

image

When I use the variable later I do get suggestions when doing my_variable.something, and go to definition also work as expected.

Similarily for enums, go to definition works, and my_enum = ... gives me good suggestions:

image

Is this information available in the hover response, but is a conscious decision to not show this? Or is it VS Code not allowing it? Or is it not part of the hover response?

Clangd version: Ubuntu clangd version 12.0.0-3ubuntu1~20.04.4
VS Code version: 1.63.2
VS Code clangd extension version: v0.1.13

@sam-mccall sam-mccall transferred this issue from clangd/vscode-clangd Dec 21, 2021
@sam-mccall
Copy link
Member

(transferred as this isn't editor specific)

We don't show bodies of classes/enums/functions etc by policy, because they are often/usually large and it's hard to draw the line. It's unlikely we'd change this I think.

The {} is confusing though, as it looks like an empty definition instead of an abbreviated one.

Possible alternatives:

  • {...}. Some ambiguity with pack/vararg notation, wonder what clang-format would do with it.
  • ;. May be confusing with some decls like enums or namespaces that can not be declared without being defined (in at least some cases)

What do you think of these?

@apsigma
Copy link
Author

apsigma commented Dec 21, 2021

Alright, yes they can get quite large, so that sounds like a reasonable policy. Although, the difference from eg. functions, is that functions have their parameters in the hover information, both as part of the source code line, and in a formatted text above, potentially with more description from comments.

So I guess that would be an argument for creating a formatted list of members or something like that for structs. But like you say, that could be very long, but should be smaller than the actual body of the struct source code, since that will likely contain eg. comments.

Yes, the {} are somewhat confusing. I guess either could work, but like you say, both of them can cause some confusion. Variable hovers present the variable declaration, without ;, as does typedef:ed types, eg. a my_int is with the header "type-alias my_int" and the source line typedef int my_int, without ;.

So I would probably in that case go for no {} and no ; either, so only eg. struct my_struct.

Also, it's weird that structs have the newline in between the curly braces, but the enum does not.

@HighCommander4
Copy link

I wrote a patch that modifies clangd's behaviour to print public struct fields and enum members in hovers: llvm/llvm-project#89557.

I think limiting the patch to these cases (as opposed to e.g. printing all class members including methods, printing function bodies etc.) should address at least part of the concern about length.

Granted, there are also enums with many members and structs with many public fields, and the patch will result in long hover contents for these, but on the whole I think would be an acceptable tradeoff: long hovers aren't a terrible user experience (they just become scrollable), and in the more common case of structs/enums with a few members, being able to see the members at a glance is quite useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants