BigBahss / vscode-cmantic

C/C++ code generation for VS Code: Generate Definitions, Getters, Setters, and much more.
https://bigbahss.github.io/vscode-cmantic/
MIT License
84 stars 9 forks source link

Add missing members to the initializer list #14

Closed Wastus closed 3 years ago

Wastus commented 3 years ago

This would be a very neat feature. Add a member, forget it in an initializer list and get an option to add it, no more going through the list and find the one that is missing.

Not sure how everyone is doing the formatting, we use clang-format on save, so just pasting it anywhere in the list would be fine as it would get moved accordingly on save.

BigBahss commented 3 years ago

I like this, but I can't think of a good way to implement it. Since there's no requirement that members be initialized in the initializer list, it would be difficult to know when the user added a new member and forgot to add it to an initializer list. I wouldn't want the light-bulb to pop up for every member that doesn't appear in every initializer list (which also seems like it would be a lot of unnecessary background analysis).

Also, I'm just curious if you've been following recent commits to master, because the next version is going to have a 'Generate Constructor' feature which will generate the boiler-plate for the initializer list. Just wondering if these suggestions are coincidences or in response to that feature.

Wastus commented 3 years ago

I haven't looked at the commits, it's just that I'm coming from VS2019 + Resharper Ultimate and I'm looking for some features I often used in Resharper. So far your extension is the most active one moving in the direction to become Resharper for VS Code. So I'm throwing my things at you :-)

I liked this because (not very often but it happens) sometimes the standard initializer is not what I intended and then I have a silly bug because my initial value was wrong. So for me, it is a helping hand not to forget these things.

BigBahss commented 3 years ago

I've never heard of Resharper, I'll have to look into that (lately I've been looking at CLion for inspiration). I'm glad you've found my extension to be useful!

I'll have to think about a good way to implement this. I'm also wondering if this is something that could caught by compiler warnings or a static analysis tool like clang-tidy. While those things might not be able to auto-fix the issue, they might be better suited for this problem. I'll look into Resharper to get some idea on how it might be done.

Wastus commented 3 years ago

Resharper is also from Jetbrains. I don't think it offers features over CLion, but I haven't used CLion myself, so just an educated guess. It's origin is for C# but later C++ features were added. So it really could be, that I'm seeing a clangd or clang-tidy message here. I'll have to research which module emits those messages. I can have a look tomorrow, maybe I should try and set-up clang-tidy as well, I've just spotted an extension for that as well...

The compilers we are using (embedded stuff) don't complain about missing initializers on any setting, so those won't help in my case.

Wastus commented 3 years ago

Okay I just checked with my Resharper installation, it is indeed a clang-tidy rule which covers this. So if there is an extension that covers this, there isn't really a need to reinvent the wheel.

BigBahss commented 3 years ago

I just got done researching this myself, not realizing you already found it haha. It looks like this is the rule, and apparently it can auto-fix. I really ought to learn clang-tidy, it seems very useful. I'll close this.