vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Can cpptools support excluding some files while formating?

Open AlanKing95 opened this issue 2 years ago • 7 comments

Feature Request

"C_Cpp.files.exclude" has no effects. Sometimes i want to modify some files but i don't want to change their formats. I think this is a useful function.

AlanKing95 avatar Aug 29 '22 07:08 AlanKing95

How is the formatting invoked? Is it from a formatOnSave?

sean-mcmanus avatar Aug 29 '22 21:08 sean-mcmanus

Yeah, currently, C_Cpp.files.exclude isn't checked when formatting, i.e. it's checked for operations involving global symbols and code analysis (with the additional C_Cpp.codeAnalysis.exclude setting as well).

We could potentially add a setting equivalent to C_Cpp.formatting.exclude which would inherit from C_Cpp.files.exclude, but due to the existing C_Cpp.formatting setting we'd need to use some alternative setting name.

sean-mcmanus avatar Aug 29 '22 22:08 sean-mcmanus

How is the formatting invoked? Is it from a formatOnSave?

In one project, I need to open this configuration when I want to modify some files and need to close this configuration when I want to modify some other files, this is so inconvenient!

A setting equivalent to C_Cpp.formatting.exclude will be perfect.

AlanKing95 avatar Aug 30 '22 01:08 AlanKing95

One potential workaround is to have a 2nd workspace folder for the files that shouldn't be formatted (and set it's formatOnSave differently).

Another potential workaround if you're using clang-format for formatting is to add a .clang-format file to the root of the folder that has the files that shouldn't be formatted:

---
Language: Cpp
DisableFormat: true

sean-mcmanus avatar Aug 30 '22 01:08 sean-mcmanus

One potential workaround is to have a 2nd workspace folder for the files that shouldn't be formatted (and set it's formatOnSave differently).

Another potential workaround if you're using clang-format for formatting is to add a .clang-format file to the root of the folder that has the files that shouldn't be formatted:

---
Language: Cpp
DisableFormat: true

Actually my project was configured like this: "C_Cpp.clang_format_style": "{ BasedOnStyle: Google, ColumnLimit: 100}", Is there a way to set C_Cpp.clang_format_style like .clang-format?

AlanKing95 avatar Aug 30 '22 09:08 AlanKing95

Yeah, you could change the style to "file" (the default) (or "file:<path>/.clang-format") and put a .clang-format file with

---
BasedOnStyle: Google
ColumnLimit: 100

at the root location where you want formatting to be applied.

And setting

"C_Cpp.clang_format_fallbackStyle": "{ DisableFormat: true }"

will cause formatting to be disable for other folders where a .clang-format doesn't exist in the folder or its parent, or if you want to disable formatting for a subfolder, you could add the previously mentioned .clang-format to that subfolder.

sean-mcmanus avatar Aug 30 '22 19:08 sean-mcmanus

DisableFormat

That works for me, thank you!

AlanKing95 avatar Aug 31 '22 06:08 AlanKing95

This feature request is being closed due to insufficient upvotes. Please leave a 👍-upvote or 👎-downvote reaction on the issue to help us prioritize it. When enough upvotes are received, this issue will be eligible for our backlog.

github-actions[bot] avatar Dec 18 '22 11:12 github-actions[bot]