Skip to content

Conversation

@Tradias
Copy link
Collaborator

@Tradias Tradias commented Aug 12, 2024

VSCode

  1. Install xaver.clang-format extension (if you already have the clangd extension then you can skip this step)
  2. Open keyboard shortcuts (press ctrl + k followed by ctrl + s)
  3. Search for Format Document, change the keybind as desired. Ctrl + alt + f seems to be a common bind, it also works on https://godbolt.org/
  4. Open any header or cpp file and press the keybind. It will ask you to configure a formatter, select xaver.clang-format. Alternatively put this into user settings.json:
    "[cpp]": {
        "editor.defaultFormatter": "xaver.clang-format"
    },
    "[c]": {
        "editor.defaultFormatter": "xaver.clang-format"
    },

Pre-commit hook

Since this is a multi language project you will probably want to set up a more sophisticated hook that formats and lints c++, python and java. https://pre-commit.com/ might be able to do that but I have not looked into it. For a pure CMake-based hook for C++ see https://github.com/Tradias/asio-grpc/blob/master/cmake/AsioGrpcInstallGitHooks.cmake for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants