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

clang-format: Use style configuration file #470

Closed
xiaguan opened this issue Feb 3, 2023 · 4 comments
Closed

clang-format: Use style configuration file #470

xiaguan opened this issue Feb 3, 2023 · 4 comments
Labels
educational Issues that contain useful content formatting Lsp-formatting related issues good-first-issue Good for newcomers usage User-specific issues

Comments

@xiaguan
Copy link

xiaguan commented Feb 3, 2023

Feature description

大部分C/C++工程采用clang-format控制格式,并且都会放到根目录下,仓库的format不会读取这个文件,导致我如果开启format-on-save的话,它不能按照我预期去格式化。我想如果增加这个feature对大部分C/C++工程都是很好用的。如果不增加这个feature的话,是否可以在wiki中增加如何自定义format格式的方法?
万分感谢。

Additional information

No response

@xiaguan xiaguan added the enhancement New feature or request label Feb 3, 2023
@Jint-lzxy
Copy link
Collaborator

That's possible. Instead of specifying the options explicitly, change this line:

return { formatCommand = "clang-format -style='{BasedOnStyle: LLVM, IndentWidth: 4}'", formatStdin = true }

to:

return { formatCommand = "clang-format -style=file", formatStdin = true } 

@Jint-lzxy Jint-lzxy added good-first-issue Good for newcomers usage User-specific issues and removed enhancement New feature or request labels Feb 3, 2023
@Jint-lzxy Jint-lzxy changed the title 是否可以为C/C++ 工程 采用.clang-format文件直接格式化? clang-format: Use style configuration file Feb 3, 2023
@ayamir
Copy link
Owner

ayamir commented Feb 3, 2023

Just remove all of args after clang-format, it will respect your project's format style defined by .clang-format. Like this:

return { formatCommand = "clang-format", formatStdin = true } 

No need to assign -style=file argu.

@Jint-lzxy
Copy link
Collaborator

If you would like to learn more details, visit: docs/ClangFormat#standalone-tool

@xiaguan
Copy link
Author

xiaguan commented Feb 4, 2023

thanks

@xiaguan xiaguan closed this as completed Feb 4, 2023
@CharlesChiuGit CharlesChiuGit added the educational Issues that contain useful content label Feb 9, 2023
@Jint-lzxy Jint-lzxy added the formatting Lsp-formatting related issues label Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
educational Issues that contain useful content formatting Lsp-formatting related issues good-first-issue Good for newcomers usage User-specific issues
Projects
None yet
Development

No branches or pull requests

4 participants