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

vscode-clangd does not honor .clang-format-ignore. #756

Open
yong-li opened this issue Dec 12, 2024 · 2 comments
Open

vscode-clangd does not honor .clang-format-ignore. #756

yong-li opened this issue Dec 12, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@yong-li
Copy link

yong-li commented Dec 12, 2024

vscode settings used:

{
    "cmake.configureOnOpen": true
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
}

Create a C++ source file.
Create a .clang-format-ignore file and add the source file path in it.
Edit the C++ source file.
Save the source file. The file is formatted on save.

Other than using the comment // clang-format off in code, is there a way for me to exclude certain files from being formatted on save?

@yong-li yong-li added the bug Something isn't working label Dec 12, 2024
@JVApen
Copy link
Contributor

JVApen commented Dec 23, 2024

It seems that the .clang-format-ignore is a feature that is implemented specifically for clang-format exe rather than for libclang users.
The sources that I could find: https://github.com/llvm/llvm-project/blob/a60050cf1966eb8d46253c8da13df52ac8b9ec33/clang/tools/clang-format/ClangFormat.cpp#L588
This is the same file that contains the main function.

@JVApen
Copy link
Contributor

JVApen commented Dec 23, 2024

I had a similar problem myself and I abused that clang-format supports multiple languages. If you can deduce the behavior from the filename, you can mark the file as cuda-cpp instead of regular c++. Once you have this distinction, you can use a language specific setting to enable the formatter for regular C++ and disable it for cuda-cpp.
In my case, this 5 minute change in the config solved the issue I had.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants