RFC: Reusing .clang-format-ignore (original) (raw)
September 15, 2025, 6:01am 1
Hello all,
Add a setting to control whether formatting is applied to changes made by a code action · Issue #2476 · clangd/clangd · GitHub was logged by a user asking for clangd to selectively format. This is a feature that already exists in the clang-format executable and seems easily lifted from main function into the library.
When proposing this @HighCommander4 stated:
(Depending on the details, it may also need an RFC, e.g. if the proposal involves modifying the behaviour of existing libFormat APIs to start paying attention to .clang-format-ignore. If it just involves adding a new API for checking .clang-format-ignore and leaving it to consumers of libFormat to decide whether or not to use that, then no RFC is needed.)
I see a couple of possible ways to implement this:
- Make it the responsibility of the caller of
format()to check if the file should be ignored - I’m worried this to optional, resulting in many callers which need it to not check this
- Putting the check inside the
reformat()function - This will ensure it to be used consistently, though risking different behavior at all places where it is used (I see this as the intention of the ignore file)
- Adding an extra argument to the reformat function, such that every caller is forced to provide the blobs, an empty vector could be used when we explicitly want to ignore it
- This could break a lot of code that uses this function, while I don’t think the value is worth it
- We move the ignore list inside the .clang-format file and options
- Would duplicate the functionality, increasing maintenance and confusion for users
For reference, a search on reformat( in the LLVM codebase give 28 files including documentation and tests.
My preference goes to the second option.
Logged this as an issue on the tracker: