Auto-Format doesn't seem to work
S/W:
ReSharper Ultimate 2018.1
VS 15.7.1
Following the performance suggestions, I set "Disable automatic formatting by Visual Studio" in ReSharper/Options/Performance Guide
"Auto-format on semicolon" is checked
I customize ReSharper's C++ Formatting Style to put spaces around '='
In a source file, I enter "a=b". When I hit ';', no auto-formatting occurs. I can select the line and use the paintbrush/Format selection and it works fine.
What am I doing wrong?
Please sign in to leave a comment.
Hello Mark,
Unfortunately auto-format on semicolon/closing braces is not yet implemented for C++, please follow https://youtrack.jetbrains.com/issue/RSCPP-18671 if you are interested.
Thanks!
Thanks, Igor!
A suggestion: you might want to make this clear in the UI
Looks like RSCPP-18671 is now 4 years old, it is still unclear in the UI, and Rider is supposedly in beta for Unreal Engine support now. Is this going to be fixed anytime soon?
What exactly do you suggest we fix in the UI?
Auto-format is hard for us because we need the full syntax tree to run the formatter. Building the syntax tree can take some time, so we can't just do it in order to not hang the UI. We can add ad-hoc auto-format for some formatting options which we can implement purely with the lexer alone, but e.g. even with '=' it does not work so well, since '=' is used both in assignment and in '= default/delete' specifiers. Which options specifically would you like to have supported?
That's interesting. I was wondering what was different about it compared to other languages where it is already implemented, such as C#. Specifically, I found this forum after wondering why typing the semicolon does not hard wrap long lines for me, which is something I used often with Unity.
For UI, the main confusion comes from the fact that the options are at the top of the page in a general category, implying that it works for all languages. There are sections below on the same page for C#, C++, etc so maybe it could move to an applicable one there? Alternatively, since it might apply to multiple languages, even a tooltip specifying that it does not work with C++ or what languages it does apply to would be helpful. Right now it feels like a bug because the only way to verify that it doesn't work with C++ is to google and find this page.
In the meantime, is there a keyboard shortcut to format the current line? I've only found one to format the current file. That would at least allow it to be a deliberate action triggered by the user where a UI hitch might be more acceptable.
Thanks, we'll try to make this more clear in the typing assist options page.
I don't think there's a shortcut to format just the current line, but you can always use the "Reformat Code" (Ctrl+Alt+Enter) action to reformat the entire file. Alternatively, there's a context action to format a compound statement block when the caret is on a brace.
Updated C++ settings block:
I think that makes sense. I would of course still love to see these two options come to C++, so I'll keep following RSCPP-18671 and cross my fingers. Thanks!