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

Format of .clang-format file? #571

Closed
Gruntfuggly opened this issue Mar 15, 2017 · 8 comments
Closed

Format of .clang-format file? #571

Gruntfuggly opened this issue Mar 15, 2017 · 8 comments

Comments

@Gruntfuggly
Copy link

Is there any documentation for the format of the .clang-format file when the "file" settings is used?

From experimentation, the only way I can get the .clang-format file to work is if it's contents are in the same format as suggested in the settings comments.

For example:

{
    BasedOnStyle: Mozilla,
    NamespaceIndentation: Inner,
    AccessModifierOffset: -4,
    UseTab: Never,
    BreakBeforeBraces: Allman}

Note - the closing brace needs to be on the same line as the last statement. or it doesn't work.

Is this expected? If I use a standard clang-format file (non-JSON), it doesn't work.

I would like to be able to specify a custom format for BreakBeforeBraces, but I don't know how to then specify the BraceWrapping sub flags. I've tried several combinations of JSON and flags names, but it simply fails to format the file.

Is there a way to get any diagnostic information?

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Mar 15, 2017

The clang-format documentation is unfortunately not very good, particularly in regards to examples and explanations of usage: http://releases.llvm.org/3.8.0/tools/clang/docs/ClangFormatStyleOptions.html . The .clang-format file is not supposed to contain JSON. You can call the binary itself to output a sample, e.g. clang-format -style=llvm -dump-config > .clang-format. Our extension doesn't expose the clang-format errors unfortunately. You could try to get errors via calling the .exe itself.

It seems you want to use something like


BreakBeforeBraces: Custom
BraceWrapping:
    AfterClass: true

@Gruntfuggly
Copy link
Author

I'm not sure what is going wrong then, because if I put the above snippet into ~/.clang-format, it simply fails. If the file contains the contents that I originally posted it works.

e.g.

BreakBeforeBraces: Allman

fails, but

{
    BreakBeforeBraces: Allman}

works.

It looks like the extension reads the file and uses it as if the content was inserted directly into "clang-format.style" from the settings file?

@sean-mcmanus
Copy link
Contributor

Oh, I found that we have a bug logged with the .clang-format file not working on Linux/Mac. I can't get the .clang-format to work at all on Linux, even with the inline formatting.

@Gruntfuggly
Copy link
Author

Sorry - I should have added some platform specifics.

It does work for me on Linux (without the flags), but that last bracket needs to be on the same line. 8-)

@sean-mcmanus
Copy link
Contributor

That is strange. I can't repro the behavior you're describing, and I debugged the code on Linux and we're failing to recognize the .clang-format file completely and it's using the hard-coded "Visual Studio" style. I assume fixing this issue would also fix your scenario, even though I can't repro the symptom. It won't be fixed in the next update, but we have a bunch of Linux-only bugs we'll hopefully be able to fix in the update after the next one.

@Gruntfuggly
Copy link
Author

OK. At the moment I'm using a separate clang-format extension with formatting disabled in C/C++. Seems to work OK, but it would be cool have it all in the one extension.

If you need further details of my set up, let me know.

@avalon1610
Copy link

{
BreakBeforeBraces: Allman,
}

this may works.
seems clang-format parse comma incorrectly. Also note there must be "one" blank space after colon

@bobbrow
Copy link
Member

bobbrow commented Jul 6, 2018

We now print clang-format errors to the Output window to help you diagnose issues with the file format. If you are still having problems with this, let us know.

@bobbrow bobbrow closed this as completed Jul 6, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants