Hornet C/C++
Hornet C/C++ is a C/C++ language extension for VS Code with four parsing modes, project indexing and interactive function call graphs.
Demo

Explore call relationships and navigate to the code. The demo shows the call graph, animated connection tracing, four parsing modes, and shortcuts for CPU usage, logs and index maintenance. The graph also supports expanding and collapsing branches.
Open the demo · Download the latest release
This repository distributes extension installers and user documentation. This release channel has its own version sequence, starting at 0.0.1.
Download and install
Open the latest release and download the appropriate .vsix file from Assets.
| Environment |
Installer suffix |
| Windows x64 |
win32-x64.vsix |
| Windows ARM64 |
win32-arm64.vsix |
| Linux x64 |
linux-x64.vsix |
| Linux ARM64 |
linux-arm64.vsix |
| Linux ARMHF |
linux-armhf.vsix |
| macOS Intel |
darwin-x64.vsix |
| macOS Apple Silicon |
darwin-arm64.vsix |
| Alpine Linux x64 |
alpine-x64.vsix |
| Alpine Linux ARM64 |
alpine-arm64.vsix |
| Universal |
universal.vsix |
In VS Code, open Extensions, choose … → Install from VSIX…, select the installer, then run Developer: Reload Window.
You can also install from the command line:
code --install-extension ./hornet-cpp-0.0.12-win32-x64.vsix --force
The Marketplace extension ID is codehubcloud.hornet-cpp. VS Code 1.85 or later is required. Earlier GitHub 0.0.1/0.0.2 packages used hornet.hornet-cpp: uninstall that extension, install the Marketplace edition, and reload VS Code. A different publisher creates a different extension identity, so this migration requires a manual installation once. Do not keep both editions enabled.
For Remote SSH, WSL or Dev Containers, install the extension on the workspace host and choose an installer for that host's operating system. Browser-only VS Code cannot run the local processes required by this extension.
Check for updates
Changes in 0.0.12
- Compact expanded branches using the space they occupy in each column, and keep the main caller trunk horizontally aligned with the selected function.
- Match the default vertical node spacing to the direct callee column. Allow extra spacing at joins so independent caller chains remain horizontal.
- Fit the complete graph after expanding or collapsing all branches, including in short panels, and preserve smooth zooming for large graphs.
Changes in 0.0.11
- Display every call as its own right-side node, including repeated calls to the same function and multiple calls on one line. Sort nodes by the caller's source line and column, including after expanding branches.
- Show the call's file, line and column on each callee node. Double-click opens that exact call directly, including calls whose definitions are unavailable.
- Preserve independent branch controls for repeated calls and keep recursive expansion finite. Variable reference navigation keeps its existing behavior.
Changes in 0.0.9
- Move all graph actions to the native toolbar at the top right of the panel, alongside the panel tabs. Remove the duplicate title, inline toolbar and status bar so the canvas fills the content area.
- Remove saved legacy graph/reference splits during upgrades. Symbol References opens separately on demand, and graph information, counts and usage hints are available through the information action.
- Make Expand all follow every caller and callee level by default instead of stopping after three levels. Set
hornet-cpp.callhierarchy.expandAllMaxDepth to 0 for unlimited depth or a positive number for a custom limit. Cycles and the 1024-node cap remain bounded.
Changes in 0.0.8
- Resolve calls through variables, including Eigen element access, as
operator() instead of unrelated functions with the same variable name.
- Show callable variables as
mean ⇢ operator() with a short dashed arrow. Keep different variables separate while preserving definition navigation and repeated call sites.
- Reduce the graph toolbar and status bar to one compact row each. Keep full usage hints and index notices available on hover.
- Follow the VS Code display language for graph controls, definition status, tooltips and messages in English or Chinese.
Changes in 0.0.7
- Build function relationships directly from the scanned inventory; merge repeated calls and equivalent macro definitions while preserving their source locations.
- Match overloads using argument counts, inferred expression types, typedefs, casts and standard conversion ranks, including default parameters. Retain candidates when syntax information cannot distinguish them.
- Index compilation-database sources, external and forced headers, continued macro definitions and conditional branches; find indexed macros even when an include edge is unavailable.
- Share Hybrid's bundled inventory, bound parser-worker memory and concurrency, and prevent managed compilation databases and Git metadata refreshes from triggering repeated scans.
- Rebuild older caches to collect argument-type metadata. After installing, reload VS Code and run Hornet: Rebuild Index once.
Changes in 0.0.6
- Run all four modes with bundled parsers, without discovering, downloading or starting clangd. Compiler now provides syntax analysis; full compiler semantics, diagnostics and refactoring are not supported by these modes.
- Replace workspace-sized JSON cache writes with bounded per-document shards; preserve the previous complete cache on write failures and rebuild oversized legacy caches.
- Fix indexing of generated files larger than eight million characters, including the 17 MB parser that previously caused the project index to fail.
- Report indexing failures with the file URI in both Hornet-DB and the main Hornet output.
Changes in 0.0.5
- Complete class and structure member graphs for constructor initialization, out-of-line methods, nested
this access and static members. Static member declarations and definitions share one graph.
- Unify variable references in the graph and hierarchy tree: writes on the left, reads on the right, with compound assignments and increments on both sides. Parameters, locals, globals, arrays, function pointers, enums and unions use the same view.
- Fix namespace and extern variable binding, support semantic backends returning a single definition location, and correct legacy database cleanup for Windows short paths.
Changes in 0.0.4
- Increase the graph node limit from 250 to 1024, including the center node.
- Press F6 on a selected variable or function, or the symbol at the cursor, to open its relationship graph. Reassign the shortcut in VS Code's Keyboard Shortcuts editor.
Changes in 0.0.3
C_Cpp.intelliSenseEngine defaults to default; Hornet no longer forces it to disabled.
- Right-click a structure member or global variable and choose Hornet Show Graph. Writers appear on the left, readers on the right; compound assignments and increments appear on both sides. Double-click an access node to open that reference. Semantic read/write highlights take priority; syntax fallback does not trace aliases or reference-parameter side effects.
- Each selected mode maintains its own
.vscode/hornet/index/<mode>/index.json inventory of source/header symbols, including opened files using their saved disk contents. Hybrid keeps its two built-in indexes separately. All four modes work without clangd; explicit exclusions still apply.
- Variable graphs distinguish declaration identities across function/block scopes, files, ordinary variables and structure owners. Center labels show category, owner/function, file and declaration line. Tag and Flyweight use syntax scopes and simple receiver types; unresolved member accesses are omitted. Complex C++ type resolution is outside the bundled syntax parsers.
- Graphs open directly for the cursor symbol without a candidate picker. Generated indexes, managed compile commands and default builds use
.vscode/hornet/. Recognized legacy indexes migrate automatically; other extensions' files and VS Code settings stay in place. Explicit custom storage paths remain supported.
For the Marketplace edition, VS Code's Auto Update uses the extension marketplace. The built-in Check for Updates command described below checks GitHub Releases separately. The already-published GitHub 0.0.2 assets retain their original hornet publisher; they are not the Marketplace migration installer.
Run Hornet C/C++: Check for Updates, or select Check for Updates in the Hornet status menu. Hornet checks the public release repository and selects the VSIX for the workspace host, including SSH, WSL and containers. Choose Download and Install to verify its SHA-256 checksum and install through VS Code, then reload the window. Open Release opens the release page instead.
Startup checks run at most once per day and notify once per available version. Set hornet-cpp.updates.checkOnStartup to false for manual checks only. Checks and downloads respect the VS Code HTTP proxy and HTTPS_PROXY / HTTP_PROXY. Background failures appear in Open Logs; manual failures also offer the release page.
Current release: 0.0.12 follows 0.0.11 in this release channel. If an older installer cannot check for updates, install the current VSIX manually and reload VS Code.
User guide and walkthrough
Run Hornet C/C++: Get Started for the built-in five-step walkthrough, or Hornet C/C++: Open User Guide for the offline manual. Both are also available from the Hornet status menu. The walkthrough follows the VS Code display language and remembers progress; English and Chinese manuals are bundled. VS Code handles the walkthrough's initial display on installation.
Open your first project
- Open and trust a C/C++ project folder.
- All four modes work offline using bundled C/C++ parsers. Tag is the default. No mode discovers, downloads or starts clangd, and no compilation database is required.
- Hornet builds the project index. A spinning status icon and a percentage with file counts show progress; hover for details. When indexing completes, the status changes to Hornet C/C++: idle.
- Right-click a function and choose Hornet Show Graph.
Platform-specific installers do not include a native clangd or compiler. Cross-compilation projects still need the actual toolchain, header paths and preprocessor definitions.
Features
- Completion, hover information, definition/declaration navigation and references.
- Bundled formatting, outlines and symbol search.
- Call hierarchy, variable read/write graphs and interactive function call graphs.
- Compilation database import, merge, validation, discovery and project index refresh.
- Separate configuration and language services for each workspace folder.
All four modes use bundled syntax parsers and support the bundled formatter. Full compiler semantics, type hierarchy, rename, refactoring and compiler diagnostics are outside these modes.
Function call graph
Right-click a C/C++ function and run Hornet Show Graph to open the Hornet Graph panel.
You can also select a variable or function name, or place the cursor on it, and press F6 in a C/C++ or CUDA editor. To customize or remove the shortcut, open Preferences: Open Keyboard Shortcuts, search for @command:hornet-cpp.showCallGraph, and edit its binding.
- Use the plus/minus buttons on either side of a function to expand or collapse relationships. The selected function keeps its screen position and zoom level while new nodes are arranged around it.
- Use the toolbar to expand or collapse branches together and fit the result to the panel. Expansion respects the configured depth and the graph's node limit. Fit graph shows the complete graph even in a short panel; zoom in to inspect large graphs.
- Hover over or click a connection to highlight its calling direction.
- Click the background or press Esc to clear the selected connection.
- Each call has its own right-side node, including repeated calls to the same function. Nodes show the caller's file, line and column and follow source order from top to bottom; double-click a node to open that exact call.
- Drag the background to pan, and scroll or use the toolbar to zoom.
- Use the center action to continue exploring from a different function.
Each graph loads up to 1024 functions. For larger call chains, change the center to explore another section. Branches reserve space only in columns they both occupy, so a tall expanded subtree keeps its parent's leaf siblings evenly spaced. Shared caller trunks align with the selected function; their upstream node groups use the direct callee column's adjacent-node spacing by default. Converging caller columns can widen their gaps to keep independent caller chains horizontal. Connection arrows attach to function ports.
Compilation settings and indexing
Hornet stores processed compile commands in .vscode/hornet/compile-db/compile_commands.json. Run Hornet C/C++: Import Compilation Database to import an existing database, or use a configured CMake build directory.
All four modes use bundled syntax parsers. They provide navigation, references, symbols, completion and call graphs, with possible ambiguity for same-name symbols. Macros, conditional compilation, template instantiation and full C++ type resolution are not evaluated. Semantic rename, refactoring, inlay hints, semantic coloring and compiler diagnostics are not advertised by these parsers.
Run Hornet Build Index, or click the indexing status item, to refresh the index. Indexing does not compile or link your program.
Example settings:
{
"hornet-cpp.languageProvider": "Tag",
"hornet-cpp.cpuUsage": "Medium",
"hornet-cpp.syntaxColor.enable": true
}
Open extension settings with Hornet C/C++ → gear → Extension Settings, or search for @ext:codehubcloud.hornet-cpp. Setting descriptions and option labels follow the VS Code display language. JSON configuration keys and saved values remain unchanged.
To use your own formatting configuration, set hornet-cpp.clangd.formatFilePath to an absolute path or a workspace-relative path such as ${workspaceFolder}/config/.clang-format. An explicit file takes priority over project configuration. If no file is found and clangd.forceFormatStyle is enabled, the bundled Hornet fallback uses LLVM style with four-space indentation and a 120-column limit.
Parsing modes
Click the mode in the status bar or run Hornet C/C++: Switch Parsing Mode.
| Mode |
Behavior |
Requirements |
| Hybrid |
Combines built-in syntax-tree and Tag/Flyweight indexes, routed by compile-command coverage |
No native language server; compilation database optional |
| Flyweight |
Runs the Tree-sitter C/C++ WebAssembly parser in background workers, with incremental syntax trees for recent files |
No compiler, clangd or compilation database required |
| Compiler |
Compatibility profile using the bundled C/C++ syntax-tree parser |
No clangd, native server, toolchain or compilation database required |
| Tag (default) |
Builds lexical tags with syntax scopes and receiver types for variable binding in background workers |
No additional tools required |
All four modes use bundled syntax parsers. They provide navigation, references, symbols, completion and call graphs, with possible ambiguity for same-name symbols. Macros, conditional compilation, template instantiation and full C++ type resolution are not evaluated. Semantic rename, refactoring, inlay hints, semantic coloring and compiler diagnostics are not advertised by these parsers.
The built-in syntax index uses a small JSON manifest and per-document shards, with bounded serialization records to avoid the V8 string-length limit. Failed writes retain the previous complete cache. Building or rebuilding this inventory does not start, download or restart clangd. Source and header discovery includes uppercase file extensions and is independent of .gitignore, files.exclude and search.exclude. Hornet's global and mode-specific exclusions determine what is indexed; Tag and Flyweight exclude build/output directories by default. Read or parse failures are recorded in the logs. Parser and formatter WebAssembly assets are bundled in the VSIX.
Custom native server executables must support the expected protocol. The built-in cache, symbol search and Hornet formatting fallback are this project's implementations; related settings describe differences from the original custom servers.
Status and maintenance
Hover over Hornet C/C++: idle to see activation state, installed version, mode and CPU usage. Click the status item to open the maintenance menu.
- Open Extension Logs / Open Parser Logs / Open Hornet-DB Logs open extension, compiler and syntax-index logs.
- Open Settings opens Hornet settings. The mode and CPU controls offer direct changes. CPU usage defaults to Maximum; High, Medium and Low are also available.
- Update Index refreshes the built-in index. Rebuild Index discards its in-memory inventory and scans the project again with the bundled parser; both work without clangd.
- Reload window reloads VS Code.
- Clear Errors clears current Hornet diagnostics. Later analysis may report them again.
- FAQ opens troubleshooting information.
CPU settings control the background parser workers and their duty cycle; they are approximate targets rather than operating-system resource limits. Hornet-DB is the log name for the lightweight syntax index.
FAQ
Old clangd setup errors? All four modes now work without clangd. Install the current build, reload VS Code and run Rebuild Index. No server setup is needed.
Index or call relationships are incomplete: Check Hornet exclusions, unreadable source files and parser errors in Open Hornet-DB Logs. The four bundled modes provide syntax relationships and do not resolve full C++ semantics.
Duplicate completion or diagnostics: Check whether another enabled C/C++ extension is providing the same language features.
Inspect logs: Run Hornet C/C++: Open Logs, then check the extension version and bundled-parser startup messages.
Feedback
Report problems in Issues, including the operating system, CPU architecture, VS Code/extension versions and reproduction steps. Review logs before sharing them because they may contain local project paths.
Third-party notices
The installer includes LICENSE.txt and ThirdPartyNotices.txt. Hornet C/C++ is an independent tool, not Microsoft's official C/C++ extension.
中文说明 / Chinese documentation
Hornet C/C++ 是面向 VS Code 的 C/C++ 语言扩展,提供四种解析模式、项目索引和交互式函数调用图。
功能演示

看清调用关系,快速定位代码。 动图依次展示函数调用图、连线动态追踪、四种解析模式,以及 CPU、日志和索引维护入口。调用图还支持一键展开和折叠。
单独打开动图 · 下载最新版本
本仓库发布插件安装包和使用说明。安装包从 0.0.1 开始独立编号。
下载与安装
打开 最新版本,在 Assets 中下载适合当前环境的 .vsix 文件。
| 使用环境 |
安装包后缀 |
| Windows x64 |
win32-x64.vsix |
| Windows ARM64 |
win32-arm64.vsix |
| Linux x64 |
linux-x64.vsix |
| Linux ARM64 |
linux-arm64.vsix |
| Linux ARMHF |
linux-armhf.vsix |
| macOS Intel |
darwin-x64.vsix |
| macOS Apple Silicon |
darwin-arm64.vsix |
| Alpine Linux x64 |
alpine-x64.vsix |
| Alpine Linux ARM64 |
alpine-arm64.vsix |
| 通用包 |
universal.vsix |
在 VS Code 中打开扩展视图,点击右上角 … → Install from VSIX… / 从 VSIX 安装…,选择下载的安装包,再执行 Developer: Reload Window / 开发人员: 重新加载窗口。
也可以使用命令行,例如:
code --install-extension ./hornet-cpp-0.0.12-win32-x64.vsix --force
市场版扩展 ID 为 codehubcloud.hornet-cpp,要求 VS Code 1.85 或更新版本。之前 GitHub 的 0.0.1/0.0.2 安装包使用 hornet.hornet-cpp:请卸载旧扩展,安装市场版,再重新加载 VS Code。发布者不同会产生不同扩展 ID,因此首次迁移需要手动安装一次,请勿同时启用两个版本。
Remote SSH、WSL 和开发容器应在远程工作区环境安装扩展,并选择对应远程系统的包。浏览器版 VS Code 不支持本扩展需要的本地进程。
调用图按每一列实际占用的空间预留间距,只有占用相同列的子树才互相让位;展开较高的右侧子树时,父级同列的叶子兄弟节点仍保持均匀间距。源码顺序约束下的重复调用会重新压紧排列,避免累积大段纵向空白。共享调用主干与中心函数保持同一水平中线,上游节点组默认采用右侧直接被调用函数列的相邻节点间距;中间汇合列可适当放宽间距,让独立调用链保持水平。普通折线统一在相邻列的中线处转弯;点击单个分支展开时,所点击函数保持原位。顶部的全部展开、全部折叠会重新适配画布;“适应画布”可在较矮的面板中显示完整关系图,节点较多时可放大查看。
检查更新
0.0.12 更新
- 按各列实际占用压紧展开的分支,让主要调用链与中心函数保持水平对齐。
- 默认纵向间距与右侧直接被调用函数列一致;汇合列允许适当放宽间距,让独立调用链保持水平。
- 全部展开、全部折叠后自动适应画布,较矮的面板也可显示完整图形,并保持大图缩放平顺。
0.0.11 更新
- 右侧按每次调用分别显示节点,同一函数的重复调用和同一行中的多次调用也分别列出。按调用者源码的行号、列号排序,展开分支后仍保持顺序。
- 被调用节点标明调用文件、行号和列号,双击直接跳转到对应的那次调用;即使未找到定义也可跳转调用位置。
- 重复调用的分支可独立展开和折叠,递归展开能够正常终止。变量引用跳转保持原有行为。
0.0.9 更新
- 将所有关系图操作移到面板右上角的原生工具栏,与面板标签同一行;移除重复标题、图内工具栏和状态栏,让画布占满内容区域。
- 升级时移除旧版保存的图形与引用分栏;“符号引用”按需单独打开,统计、操作说明和索引提示统一通过信息按钮查看。
- 展开全部默认遍历所有调用者与被调用者层级,不再只展开三层。
hornet-cpp.callhierarchy.expandAllMaxDepth 为 0 时不限深度,正数可自定义层数限制;保留循环去重和 1024 个节点的上限。
0.0.8 更新
- 将变量调用(包括 Eigen 元素访问)识别为
operator(),避免错误连接到与变量同名的普通函数。
- 使用短小虚线箭头显示
mean ⇢ operator();不同变量分别显示,并保留定义跳转和重复调用位置。
- 顶部工具栏和底部状态栏各压缩为一行,将更多空间留给关系图;完整操作说明和索引提示可悬停查看。
- 图中的按钮、定义状态、悬停提示和消息跟随 VS Code 显示语言切换中文或英文。
0.0.7 更新
- 直接使用扫描索引建立函数关系,合并重复调用及内容相同的宏定义,并保留源码位置。
- 按参数个数、推断的实参类型、typedef、强制转换及标准转换优先级匹配重载,支持默认参数;语法信息不足以区分时保留候选。
- 补齐编译数据库源文件、外部及强制包含头文件、多行宏和条件分支的索引;include 链缺失时仍可回查已入库的宏定义。
- Hybrid 共享内置索引,限制解析线程的内存及并发,避免托管编译数据库和 Git 元数据刷新触发重复扫描。
- 旧缓存自动失效以收集实参类型信息。安装后请重载 VS Code,并执行一次 Hornet: Rebuild Index。
0.0.6 更新
- 四种模式均使用内置解析器,不发现、下载或启动 clangd。Compiler 改为语法分析;内置模式不提供完整编译器语义、诊断或重构。
- 缓存改用按文件分片及分块写入,避免整库 JSON 字符串超限;写入失败保留上次完整缓存,过大的旧缓存自动重建。
- 修复超过 800 万字符的生成文件导致索引取消的问题,已验证工程中约 17 MB 的解析器源码。
- 索引失败日志带上文件路径,并同步到 Hornet 主输出通道。
0.0.5 更新
- 补齐类和结构体成员关系图,覆盖构造初始化、类外成员函数、嵌套
this 访问和静态成员;静态成员声明与定义归入同一张图。
- 关系图和层次树统一使用变量读写引用:左写右读,复合赋值及自增自减同时显示在两侧;函数参数、局部和全局变量、数组、函数指针、枚举及联合体使用同一视图。
- 修复命名空间及 extern 变量绑定,兼容语义后端返回单个定义位置,并修复 Windows 短路径导致的旧数据库清理误判。
0.0.4 更新
- 单张关系图的节点上限由 250 提高到 1024,包含中心节点。
- 选中变量或函数名称,或将光标放在名称上,按 F6 打开对应关系图;支持通过 VS Code 键盘快捷方式修改绑定。
0.0.3 更新
C_Cpp.intelliSenseEngine 默认为 default,Hornet 不再强制设置为 disabled。
- 右键结构体成员变量或全局变量,选择 Hornet Show Graph:左侧显示写引用,右侧显示读引用;复合赋值、自增自减同时显示在两侧。双击节点跳转引用位置。优先使用语义后端的读写标记,语法后备分析不追踪别名和引用参数副作用。
- 当前模式独立保存
.vscode/hornet/index/<mode>/index.json 源码及头文件符号清单。已打开文件也会使用已保存的磁盘内容写入缓存。Hybrid 的两套内置索引分别保存;四种模式均不需要 clangd,显式排除设置仍然生效。
- 变量关系按声明身份区分函数、嵌套块、文件、普通变量和不同结构体成员;中心节点标明类别、所属结构体或函数、文件和声明行号。Tag、Flyweight 使用语法作用域和简单接收对象类型,无法确认的成员访问会省略;复杂 C++ 类型解析不在内置语法解析器的支持范围内。
- 关系图直接定位光标对应的符号,不再弹出候选选择框。自动生成的索引、托管编译数据库和默认构建目录统一放在
.vscode/hornet/,旧版 Hornet 索引自动迁移,其他扩展的文件和 VS Code 配置保留原位。显式自定义存储路径仍然有效。
市场版使用 VS Code 的 Auto Update 从扩展市场更新;下面的插件内“检查更新”独立检查 GitHub Releases。已经发布的 GitHub 0.0.2 附件保留原来的 hornet 发布者,不能用作市场版迁移安装包。
执行 Hornet C/C++: 检查更新,或在 Hornet 状态菜单中选择 Check for Updates。插件从公开发布仓检查正式版本,并按工作区主机选择安装包,包括 SSH、WSL 和容器。选择下载并安装后,插件会验证 SHA-256,再交给 VS Code 安装;完成后重新加载窗口。也可以选择打开发布页自行下载。
启动检查最多每天一次,同一可用版本仅提醒一次。将 hornet-cpp.updates.checkOnStartup 设置为 false 可仅保留手动检查。检查和下载支持 VS Code HTTP 代理及 HTTPS_PROXY / HTTP_PROXY。后台失败记入 Open Logs,手动检查失败时还可打开发布页。
当前版本: 本发布渠道的 0.0.12 承接 0.0.11。若旧安装包无法检查更新,请手动安装当前 VSIX 并重新加载 VS Code。
使用指南与分步引导
在命令面板中执行 Hornet C/C++: 开始使用(分步引导),按五个步骤完成上手;执行 Hornet C/C++: 打开用户使用指南 阅读离线手册。Hornet 状态菜单也提供 Get Started 和 User Guide。引导随 VS Code 显示语言切换并保存进度,手册附带中英文版本。安装时的引导展示由 VS Code 管理。
首次打开项目
- 打开并信任 C/C++ 项目文件夹。
- 四种模式均使用内置 C/C++ 解析器离线工作,默认选择 Tag。均不发现、下载或启动 clangd,无需编译数据库。
- 扩展建立项目索引。状态栏以持续旋转图标显示正在索引,旁边显示当前扫描阶段的百分比和文件数量;悬停查看详细进度;完成后显示 Hornet C/C++: idle。
- 在函数上右键选择 Hornet Show Graph 查看调用图。
安装包按平台生成,不代表该平台会附带 clangd 或编译器。交叉编译项目仍需配置实际工具链、头文件路径和宏定义。
主要功能
- 补全、悬停说明、跳转定义/声明、查找引用。
- 内置格式化、大纲和符号搜索。
- 调用层次、变量读写关系图和交互式函数调用图。
- 编译数据库导入、合并、校验、配置发现和项目索引刷新。
- 每个工作区文件夹独立配置和独立语言服务。
四种模式均使用内置语法解析器和格式化器,不提供完整编译器语义、类型层次、重命名、重构或编译器诊断。
函数调用图
在 C/C++ 函数上右键执行 Hornet Show Graph,图形显示在底部 Hornet Graph 面板。
也可以在 C/C++ 或 CUDA 编辑器中选中变量、函数名称,或将光标放在名称上,按 F6 查看关系图。自定义或取消快捷键:执行 首选项: 打开键盘快捷方式,搜索 @command:hornet-cpp.showCallGraph,修改对应绑定。
- 函数框两侧的加减按钮展开或折叠调用关系。操作时该函数保持原来的屏幕位置和缩放比例,新增内容向四周排布;需要查看全图时点击适应窗口按钮。
- 工具栏支持一键展开全部、一键折叠全部;展开受当前图的节点上限约束。
- 将鼠标移到连线上或点击连线,可显示沿调用方向移动的高亮短线。
- 点击空白处或按 Esc 取消已选择的连线。
- 右侧按每次调用分别显示节点,同一函数被重复调用时也分别列出。节点标明调用文件、行号和列号,并按源码位置从上到下排列;双击直接跳转到对应的那次调用。
- 拖动空白区域平移,鼠标滚轮或工具栏缩放。
- 使用“设为中心”从另一个函数继续浏览。
每张图最多加载 1024 个函数。大型调用链可切换中心分段浏览。布局为跨列调用预留连线路径,并将箭头连接到目标函数框的端口中心。
编译配置与索引
扩展读取 .vscode/hornet/compile-db/compile_commands.json 中的编译命令。可以执行 Hornet C/C++: Import Compilation Database 导入现有 compile_commands.json,或使用已配置的 CMake 构建目录。
四种模式均使用内置语法解析器,提供导航、引用、符号、补全和调用图;同名符号可能有歧义。不计算宏、条件编译、模板实例化或完整 C++ 类型,不声明支持语义重命名、重构、嵌入提示、语义着色或编译器诊断。
手动刷新索引:命令面板执行 Hornet Build Index,或点击状态栏索引项。索引不等同于编译或链接程序。
设置示例:
{
"hornet-cpp.languageProvider": "Tag",
"hornet-cpp.cpuUsage": "Medium",
"hornet-cpp.syntaxColor.enable": true
}
解析模式
点击底部模式名称或执行 Hornet C/C++: Switch Parsing Mode:
| 模式 |
工作方式 |
所需配置 |
| Hybrid |
组合内置语法树解析器和 Tag/Flyweight 索引,按编译命令覆盖范围路由 |
无需原生语言服务器,编译数据库可选 |
| Flyweight |
后台线程运行 Tree-sitter C/C++ WebAssembly 解析器,近期文件使用增量语法树 |
无须安装编译器、clangd 或生成数据库 |
| Compiler |
保留模式名称,使用内置 C/C++ 语法树解析器 |
无需 clangd、原生语言服务器、工具链或编译数据库 |
| Tag(默认) |
后台线程建立词法标签,并通过语法作用域和接收对象类型绑定变量 |
无额外工具要求 |
四种模式均使用内置语法解析器,提供导航、引用、符号、补全和调用图;同名符号可能有歧义。不计算宏、条件编译、模板实例化或完整 C++ 类型,不声明支持语义重命名、重构、嵌入提示、语义着色或编译器诊断。
内置索引采用小型 JSON 清单和按文件分片,并将每条记录限制为分块写入,避免整库字符串超过 V8 长度上限;写入失败时保留上次完整缓存。建立和重建索引均不需要启动、下载或重启 clangd。递归扫描支持大写扩展名,不受 .gitignore、files.exclude 或 search.exclude 影响;索引范围由 Hornet 全局及模式专属排除项决定,Tag 和 Flyweight 默认排除 build/output 等目录。读取或解析失败会在日志中列出。解析器和格式化器的 WebAssembly 文件随 VSIX 附带,无须联网下载。
在 Hornet C/C++ → 齿轮 → 扩展设置 中配置,或搜索 @ext:codehubcloud.hornet-cpp。设置说明、选项标签和顶部扩展简介随 VS Code 显示语言切换,JSON 配置键及保存值保持不变。原生详情正文固定读取一份 README,因此本页采用默认英文、中文说明可展开的形式。
使用自己的格式文件时,将 hornet-cpp.clangd.formatFilePath 设置为绝对路径或 ${workspaceFolder}/config/.clang-format 这样的工作区相对路径。指定文件优先;找不到项目格式文件且启用 clangd.forceFormatStyle 时,使用本项目定义的 Hornet 样式:LLVM 基础、4 空格缩进、120 列。内置数据库和符号搜索也属于本项目实现,与原版定制服务器的区别已在相关设置中说明。
状态与维护
悬停 Hornet C/C++: idle 显示 Hornet C/C++ Status、Activated、实际安装版本、模式、CPU Usage;点击状态栏可打开相同操作的菜单。VS Code 的状态栏右键菜单由编辑器管理,因此 Hornet 使用悬停链接和左键菜单提供这些操作。
- Open Extension Logs / Open Parser Logs / Open Hornet-DB Logs:分别查看扩展、编译服务和 Tag/Flyweight 索引日志。
- Open Settings:打开 Hornet 设置。点击模式或 CPU Usage 可直接修改;CPU 默认 Maximum,可改为 High、Medium、Low。
- Update Index:更新内置索引;Rebuild Index:清空内存清单,使用内置解析器重新扫描项目;两者均无需 clangd。
- Reload window:重新加载 VS Code 窗口。
- Clear Errors:清除 Hornet 当前诊断;下一次解析产生的错误会再次显示。
- FAQ:打开下方常见问题。
CPU 设置控制 内置解析器的线程数量和工作占比,并非操作系统级 CPU 使用率硬上限。Hornet-DB 是 Hornet 轻量索引日志的名称。
FAQ
旧版 clangd 配置错误? 四种模式均已改用内置解析器。安装当前修复包、重载窗口并执行 Rebuild Index 即可,无需配置语言服务器。
索引或调用关系不完整: 检查 Hornet 排除项、源码读取和解析错误,通过 Open Hornet-DB Logs 查看详情。四种内置模式提供语法关系,不执行完整 C++ 语义分析。
补全或诊断重复: 检查是否同时启用了其他提供相同功能的 C/C++ 语言扩展。
查看日志: 执行 Hornet C/C++: Open Logs,确认当前扩展版本和 内置解析器启动状态。
反馈
请在 Issues 提交问题,附上操作系统、CPU 架构、VS Code/插件版本和复现步骤。日志中可能包含本地项目路径,提交前请自行检查。
第三方声明
插件安装包内保留 LICENSE.txt 和 ThirdPartyNotices.txt。Hornet C/C++ 是独立工具,不是微软官方 C/C++ 扩展。