Wirena / clang-format-configurator-v2

Interactive clang-format configuration tool
https://clang-format-configurator.site/
MIT License
83 stars 3 forks source link

Clang-format-configurator-v2

Interactively create a clang-format configuration while watching how the changes affect your code.

Check it out at https://clang-format-configurator.site/

Clang-format-configurator-v2 is a written from scratch successor of clang-format-configurator with following bugs fixed and new features implemented:

User guide

Basic info

Clang-format tool defaults all unset options to values from selected BasedOnStyle when doing formatting, this configurator follows such behaviour: every time BasedOnStyle is changed, all options are filled with values from selected style, when user uploads their .clang-format config file, configurator also automatically fills all unset options to match style from user's config.

Default values for enum options in dropdown selectors are marked with asterisk (*) on Firefox and with different color and italic font style on other browsers. Default values for strings and numbers are set as a placeholder (can be seen when input field is empty). Setting dropdown selectors to blank does the same thing as setting them to current style's default value.

String selectors have "Unset" button to the right of an edit field and work this way:

Config File page

Well, "Upload"/"Download" buttons are for uploading/downloading config file, editor is for editing or copypasting config file contents in-place. "Close" button disgards all changes to config file, "Load Config" buttons applies them.

"Remove duplicates with BasedOnStyle (Not tested)" checkbox is for removing options, which values match selected BasedOnStyle style. This feature is not properly tested.

Diff mode

Configurator formats code on the left/top panel, code on the right/bottom panel is left unchanged.

Btw, if you want to make formatting as close as possible to existing formatted code, then try clang-unformat

Build and Development

Build and Run

Requirements: docker, nodejs, linux or wsl

  1. Build clang-format binaries and frontend config

    llvm/prepare.sh script creates debian docker image, builds clang-format from source, dumps styles and copy artifacts outside of container, then launches llvm/build-config.py script

    Whole process takes around 30 minutes on Intel i5 12600

    cd llvm
    ./prepare.sh --all

    Clang-format binaries are placed in server/third-party/clang-format direcotry, docs and defaults are in llvm/docs/ and llvm/defaults/ respectively and config is written into llvm/config.json. front-end/src/config.json is a soft link to llvm/config.json

    Install JS dependencies

    cd front-end
    npm install
  2. Configure server and client

    • Set URL of Format endpoint in front-end/src/config.json using FormatApiUrl key, or keep http://localhost:8080/format? by default
    • Set server bind address in server/config.json using key bind-addr
    • Set path to TLS key and certificate in server/config.json using keys certificate-file and key-file or leave it empty to run plain HTTP server without encryption
  3. Run and Debug with VS Code

    • Run "Debug React App" to debug front-end
    • Run "Golang Remote Debug" to debug server in docker container
    • Run "Golang Local Debug" to debug server locally if you have golang installed

Clang-format version list modification

Config file format

Config file format is not documented. It's generated by llvm/build-config.py script, and this script is utter shitcode. Even I don't understand how it works anymore.

TODOs: