Clangd Auto Config Extension
A VSCode extension that automatically generates compile_commands.json and .clangd configuration files for C/C++ projects, and intelligently filters out unused source files to help Clangd focus on analyzing the actual compiled code.
Features
- 🚀 One-Click Compilation DB Generation: Run
compiledb -n make (configurable) to generate compile_commands.json
- 🔍 Auto-Resolve Implicit
#include "xxx.c" Files: Automatically detect and inject compile records for hidden .c files that are #include-ed by other source files
- ⚙️ One-Click
.clangd Generation: Convert the VSCode settings template into a .clangd YAML configuration file
- 🧹 Smart File Filtering: Automatically hide un-compiled .c/.h files via
files.exclude based on compile_commands.json
- 🛡️ Whitelist Protection:
tools, scripts, lib, python, doc, and other folders are never hidden by default
- 🎯 Header Exclusive Filtering: When enabled, only selected .h files in a directory are kept visible; all others are hidden
- 📋 Custom Glob Exclude Rules: Support additional file exclusion via glob patterns (equivalent to regex)
- 📦 Webview Sidebar Panel: GUI with real-time status display and one-click operations
- 📌 Standalone Filter Command: Run source file filtering independently without regenerating the compilation database
Requirements
- VSCode 1.60.0 or higher
compiledb tool installed (pip install compiledb)
- The project must be buildable with
make (or a custom build command)
Installation
- Clone or download this extension
- Open VSCode and go to Extensions view
- Click
··· → Install from VSIX... and select the extension package
- Or run
vsce package in the extension directory to build it yourself
Usage
- Click the Clangd Config icon 🚀 in the VSCode activity bar
- Configure parameters in the sidebar panel:
- Make subdirectory: Relative path if
make should run in a subdirectory
- Custom Glob excludes: Additional file patterns to exclude (one per line)
- Enable header exclusive filtering: Check, then pick the .h files you want to keep
- Click 💾 Save Config to save filter rules
- Click 🚀 Generate Config to run the full pipeline
Method 2: Command Palette
Press Ctrl+Shift+P and run one of these commands:
| Command |
Description |
Clangd: 生成配置并过滤工程 |
Full pipeline: compile DB → resolve implicit .c → generate .clangd → filter files |
Clangd: 手动执行源码过滤 |
Run file filtering only (based on existing compile_commands.json) |
Configuration
Search for clangd-autoconfig in VSCode settings:
clangd-autoconfig.compiledbCommand
Command to generate compile_commands.json. Default: compiledb -n make
clangd-autoconfig.makeDirectory
Make subdirectory (relative to workspace root). Default: "" (empty = run at workspace root)
clangd-autoconfig.whitelistFolders
Whitelisted folders that will never be hidden. Default: ["tools", "scripts", "lib", "python", "doc", ".vscode", ".git", "out"]
clangd-autoconfig.customGlobExcludes
Custom glob exclude patterns (equivalent to regex). Default: []
Enable header exclusive filtering mode. Default: false
List of active header file paths to keep. Default: []
clangd-autoconfig.defaultClangdConfig
Default .clangd configuration template.
Example:
{
"clangd-autoconfig.defaultClangdConfig": {
"CompileFlags": {
"InheritFromEnvironment": false,
"Add": ["-std=c++17"]
},
"Index": {
"Background": "Build",
"BackgroundWorkers": 8
},
"General": {
"MemoryUsage": "1000MB"
}
}
}
How It Works
Full Pipeline (generateConfig)
compiledb -n make → compile_commands.json
│
├─ Scan #include "xxx.c" → inject compile records for hidden .c files
│
├─ Generate .clangd (YAML format from settings template)
│
└─ Traverse workspace, analyze against compile_commands.json:
├─ Compiled .c/.cpp → keep visible
├─ Un-compiled .c/.cpp → hide via files.exclude
├─ Header directories → smart detection via -I/-isystem paths
└─ Whitelist folders → always keep visible
File Filtering Logic
- Whitelist first: Whitelisted folders and their contents are never hidden
- Implicit .c patching: When
#include "foo.c" is found but foo.c is not in the compile DB, the parent file's compile command is cloned and injected
- Header exclusive mode: When enabled, unselected .h files in the same directory as selected ones are hidden
- Custom Globs: Supports any glob pattern that VSCode
files.exclude accepts
Technical Highlights
- Pure Node.js: No external dependencies, low overhead
- Native VSCode API: Uses
files.exclude workspace setting — no actual filesystem changes
- Webview Panel: Adapts to VSCode theme (dark/light)
- Incremental Updates: Preserves existing
files.exclude rules, only appends new ones
Troubleshooting
- compiledb not found: Install it with
pip install compiledb
- Permission denied: Make sure VSCode has write access to the workspace directory
- compile_commands.json not generated: Verify
make runs successfully in your project directory
- Files not hidden: Check whitelist settings — remove folders from whitelist if you want them filtered
- Hidden files still shown:
files.exclude only hides files in the VSCode UI; it does not affect compilation
License
MIT