clang-hesongVS Code extension that bundles
Windows only. No build tools required on your machine — the native exe is pre-built and included.
Commands
Right-click any Quick start
The file is rewritten in place (see warning above). On failure, check the clang-hesong output channel ( ConfigurationExtension setting (optional)Default config path is
Tool config (required)Example
Config keysSummary (details below):
The extension sets
|
| Include type | Need -I? |
Example |
|---|---|---|
| Your project headers | Yes | -IC:\my-project\src, -IC:\my-project\include |
| Third-party / vendored headers | Yes | -IC:\my-project\thirdparty\foo\include |
| Transitive headers (A includes B includes C) | Yes — every level | If foo.h pulls in bar/baz.h, the -I that finds bar/ must be listed |
C/C++ standard library (<vector>, <stdio.h>, …) |
No | Clang already knows system include paths for the chosen -std |
Why: The bundled tool does not guess your project layout. It runs Clang on one file as a translation unit: Clang follows #include and must open each header file on disk. If a project or third-party header path is missing from -I, Clang reports file not found, parsing stops, and the run fails (non-zero exit) or produces unreliable output.
Practical rule: Copy the same -I (and -D) flags you use in CMake/msbuild/your real build for that target. When in doubt, add another -I rather than omit one.
Typical entries:
| Flag | Purpose |
|---|---|
-std=c++17 / -std=c++20 |
Language standard (also selects correct stdlib headers) |
-IC:\path\to\include |
Project and third-party header search paths |
-DNAME=value |
Macros your headers/source depend on |
-Wno-... |
Optional: suppress parse noise |
"compile_args": [
"-std=c++20",
"-IC:\\my-project\\src",
"-IC:\\my-project\\include",
"-IC:\\my-project\\thirdparty\\foo\\include"
]
On Windows, use escaped backslashes or forward slashes in JSON.
this_module_include_dirs (optional)
Semantics: Directories that mark your code. Only symbols from headers under these paths are renamed; system and third-party headers are left unchanged. Recommended for all real projects.
clear_all_blank_lines_inside_function (optional)
Semantics: Removes extra blank lines inside function bodies. Does not affect spacing between top-level functions. Default: false.
cut_all_comments (optional)
Semantics: After AST rewriting, removes comments from the generated source in a text post-pass. Default: false.
Typical use: AI-assisted coding often leaves large volumes of low-value comments (“this function initializes…”, restated obvious logic, boilerplate doc blocks). Turning this on clears that noise so the file reads like normal hand-written code.
Requires cut_all_comments: true before cut_all_comments_exception_substr_set has any effect.
cut_all_comments_exception_substr_set (optional)
Requires: cut_all_comments: true
Rule (read carefully):
- When
cut_all_commentsis on, every//and/* */comment is removed by default. - Exception: a comment is kept only if its full text contains at least one substring from this list (case-sensitive, anywhere in the line/block).
- Comments that do not match any substring → deleted.
Why this exists: You usually want to wipe AI-generated clutter without losing a few comments you care about — license headers ("Copyright"), your own tags ("hesong"), TODO markers, etc. Put those marker words here; everything else goes.
Example:
"cut_all_comments": true,
"cut_all_comments_exception_substr_set": ["hesong", "Copyright", "TODO"]
| Comment in source | Kept? | Reason |
|---|---|---|
// Initialize the widget |
❌ Removed | No substring match — typical AI filler |
// This loop iterates over all items |
❌ Removed | No match |
// hesong: do not rename this block |
✅ Kept | Contains hesong |
/* Copyright (c) 2026 My Corp */ |
✅ Kept | Contains Copyright |
// TODO: fix edge case |
✅ Kept | Contains TODO |
If cut_all_comments_exception_substr_set is omitted or empty while cut_all_comments is true, all comments are removed — no exceptions.
force_braces_for_single_statement_after_condition (optional)
Semantics: Wraps unbraced single-statement bodies of if / for / while / etc. in { }. Default: false.
blank_lines_between_fucntion_and_any_object (optional)
Spelling: Key is
fucntion(historical typo) — must match exactly.
Semantics: Sets blank lines between top-level declarations (-1 or omit = off, 0 = none, 2 = exactly two blank lines between functions/classes/globals, etc.).
JSON → exe argument mapping
| JSON key | Exe argument |
|---|---|
naming_style |
naming_style=snake |
compile_args |
one compile_arg=... per array element |
this_module_include_dirs |
this_module_include_dirs={dir1,dir2} |
clear_all_blank_lines_inside_function |
clear_all_blank_lines_inside_function=true |
cut_all_comments |
cut_all_comments=true |
cut_all_comments_exception_substr_set |
cut_all_comments_exception_substr_set={a,b} |
force_braces_for_single_statement_after_condition |
force_braces_for_single_statement_after_condition=true |
blank_lines_between_fucntion_and_any_object |
blank_lines_between_fucntion_and_any_object=2 |
Sample config in this repo: clang-hesong.json.example — copy to your workspace as .vscode/clang-hesong.json.
Troubleshooting
| Symptom | Fix | |
|---|---|---|
Config must contain naming_style |
Add "naming_style": "snake" |
|
compile_args array error |
Add at least one -std and -I flag |
|
Bundled exe not found |
Reinstall extension; verify bin/win32-x64/clang-format-hesong.exe exists |
|
No saved file is selected |
Save the file, then right-click it | |
Parse errors / run failed / file not found in output |
Missing -I for a direct or indirect project/third-party header |
Add all include dirs from your real build (not stdlib). Every header in the #include chain must resolve. |
| Parse errors in output (other) | Missing -D macros or wrong -std |
Match your project’s compile flags |
| Third-party symbols renamed | Fix this_module_include_dirs to your module roots only |
|
| Windows only error | This extension requires Windows x64 |
Third-party licenses
This extension is not affiliated with or endorsed by the LLVM Project.
| Part | License |
|---|---|
VS Code extension (extension.js, docs) |
MIT — LICENSE |
Bundled clang-format-hesong.exe (LLVM/Clang AST) |
Apache-2.0 WITH LLVM-exception — THIRD_PARTY_NOTICES.md |
When redistributing the .vsix or installed package, keep both LICENSE and THIRD_PARTY_NOTICES.md.
Reporting issues
Bug reports and feature requests: GitHub Issues
Please include:
- VS Code version (
Help→About) - Windows version
- Your
.vscode/clang-hesong.json(redact paths if needed) - Full log from Output → clang-hesong
- A minimal
.cpp/.hsample and steps to reproduce, if possible
Requirements
- C/C++ source files (see scope above)
- Windows x64
- VS Code 1.90+
- Valid
compile_args:-std, all project/third-party-Ipaths, and any required-Dmacros (see compile_args)