Vscode-cpptools: Feature request: Path to clang-format file

Created on 21 May 2019  路  10Comments  路  Source: microsoft/vscode-cpptools

Give us the option to specify the path to the clang-format file on our settings.json. Code bases usually keep one in order to standardize coding style, but would be amazing if I could format the files with my own .clang-format file without touching the file from the code base.
As an extension of this, an option to choose which .clang-format file to use would be most needed when selecting Format Document in the Show All Commands list. Something like:

Format Document (User defined)
Format Document (Standard)

Where Standard would use the standard .clang-format searching and fallback rules, and User defined is the file defined in the settings file.

Feature Request Code Formatting Language Service help wanted quick fix

All 10 comments

The current workaround is to set the C_Cpp.clang_format_style (to an inline { ... } format and not a file path). Is there a reason that isn't sufficient?

I don't know. Maybe because I intend on overriding a lot of rules, making inline overriding silly; cluttering the settings file with the whole clang-format stuff is also silly; and because, like you said, it's a workaround.

@KaeLL : Agreed. For comparison with other similar plugins, the Uncrustify plugin has this option to set your uncrustify.cfg file path (uncrustify.configPath).

Sorry for dumping, but there is any workaround for this idea?

Hi, I was looking for this as well, and would like to try my hand at adding it myself :)
any relevant guidance that could help me other than what appears in CONTRIBUTING.md?

anyway, will try to get it done and simply open a PR...

@AdamEr8 master branch might be broken without our updated binaries from our pending 0.29.0-insiders2, but you could base it off release. I'm not 100% sure how this would be implemented...I guess converting the .clang-format file to a clang_format_style?. FYI, we send clang_format_* settings to our closed source cpptools process, so ideally your PR wouldn't require any cpptools process changes.

I'm not 100% sure how this would be implemented...I guess converting the .clang-format file to a clang_format_style?

Yes, I've been wondering about it as well.
It's either converting to clang_format_style, or could be to back-up any .clang-format in the running dir, copy the custom file, apply clang-format, and restore to old state, but I think it's obvious using the dedicated cmd arg is cleaner and safer.

one problem with converting to clang_format_style, is that it doesn't have any notion of "sections" for different languages like a .clang-format has.
So should I take the global/common section + Cpp section, and ignore the rest?
(does the C/C++ Extension only apply clang-formatting to C/C++ files..?)

The cpptools process gets VS Code format requests from VS Code via the LSP (https://microsoft.github.io/language-server-protocol/specification#textDocument_formatting), which is registered to handle C/C++ at https://github.com/microsoft/vscode-cpptools/blob/release/Extension/src/LanguageServer/client.ts#L1202 , so we don't format other languages, and having a non-Cpp "Language: " section in a .clang-format file will generate an error, so just using the global+Cpp sections seems good.

Thanks for the detailed explanation! much appreciated.

Was this page helpful?
0 / 5 - 0 ratings