-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Can 'Visual Studio' format style be modified? #657
Comments
Internally, the Visual Studio style setting we use is similar to |
First of all: not sure what I'm doing wrong, though VSCode seems to ignore
There are no As per formatting features of Visual Studio: for example it lets me keep empty lines in various locations:
Whereas ClangFormat removes them. |
You're on Windows? We have a known bug with .clang-format not being found on Linux/Mac, but if it's not working on Windows, then that sounds like a different problem. I just tried your settings in a .clang-format in the root of my workspace and it worked. Yeah, the empty lines thing looks like it's possibly a bug with clang-format because the MaxEmptyLinesToKeep setting isn't being used. It would probably have to be fixed in clang-format. |
Oh, sorry forgot to mention, I use VSCode on Linux (Ubuntu 16.04). Is there a workaround for the said bug? |
The workaround is to change your clang_format_fallbackStyle to one of the non-Visual Studio presets, such as LLVM. That will cause clang-format itself to recognize the .clang-format file. |
Thanks for the workaround! Ok, I've compiled the major differences between Visual Studio code formatting and clang-format which affect our codebase. First, the formatting settings for which I've found no counterparts in clang-format:
Then, the formatting behavior (with no corresponding settings) which I could not replicate using clang-format:
Lastly, Visual Studio formatting is more relaxed giving some freedom to choose what should and shouldn't be enforced by the coding style; whereas clang-format's settings mostly have no "do not enforce" option. |
Okay, those seem like a lot of differences. The "Visual Studio" style we setup up was just intended as a rough approximation given the limits of clang-format. The 2 options would be to make the modifications to clang-format or to port the formatting code used in VS and use that instead of clang-format. I think the reason we choose to use clang-format for formatting was that it was cross-platform and the VS formatting code was not. |
Hi, any update on this issue? |
Unfortunately, we do not have an update on this issue. Personally, I would love to have this feature as well, but it hasn't gotten enough upvotes to make it to the top of the backlog. |
Where should we upvote it? |
Add a +1 to the first comment in this issue. |
Like I just did? (I don't see yours, still you say you want this feature as well, did I miss something?) thanks! |
Yes, that's correct. Since we manage the backlog, I haven't been voting on things since I can add my vote in on the fly. 😄 |
It seems like this issue is tracking porting VS's formatting instead of using clang_format. We recently added AccessModifierOffset: - to the "Visual Studio" format to more closely match VS. If anyone else has a modification we can use to our default clang_format settings to more closely match VS then let us know. |
@travid112 Also, are you doing Format Document or Format on Type or Format on Save? Can you provide a code sample and an example .clang-format file? See also #5901 (i.e. set |
@emptyVoid @christophe-calmejane https://github.com/microsoft/vscode-cpptools/releases/tag/0.30.0-insiders has support for the various Visual Studio formatting settings instead of using the "emulated" clang-format implementation. Let us know if you have any feedback on that (note: you may want to change some of the default settings, see #5907 ). |
I actually had to install Clang formatter and configure a file to use it with VSC because it wasn't doing anything at all but well by the way I learn about it and I have it working now, thanks for the comments :) |
I would like to replicate the Visual Studio 2013 formatting settings (Tools -> Options -> Text Editor -> C/C++ -> Formatting) we use in VSCode. Is it possible to modify
"C_Cpp.clang_format_style": "Visual Studio"
style's settings?I've already tried to replicate them using .clang-format to no avail, cant get it to format in the same style.
The text was updated successfully, but these errors were encountered: