94 lines
2.8 KiB
Markdown
94 lines
2.8 KiB
Markdown
# .vscode/
|
||
|
||
VS Code 的工作区配置(只影响编辑器体验,**删掉不影响仿真运行**)。
|
||
|
||
| 文件 | 说明 |
|
||
|---|---|
|
||
| `settings.json` | clangd 设成唯一的 C++ 智能感知引擎;`xacro/urdf/sdf` 关联成 XML |
|
||
| `c_cpp_properties.json` | cpptools 的兜底配置(当前被禁用,留着备用) |
|
||
|
||
> 注意:这里**没有** `cmake.sourceDirectory`。本工程不使用 CMake / colcon,
|
||
> 那行配置已随迁移删除;如果 CMake Tools 插件又把它写回来,可以忽略。
|
||
|
||
## C++ 智能感知怎么工作
|
||
|
||
用 **clangd**,它读工作区根的 `compile_commands.json`(真实编译命令),
|
||
所以 include 路径、宏定义、C++ 标准全部**自动**跟构建保持一致,不用手写。
|
||
|
||
```
|
||
xmake(仓库根)
|
||
↓ plugin.compile_commands.autoupdate 规则自动触发
|
||
compile_commands.json(工作区根,每次构建后重写)
|
||
↓
|
||
clangd 读取
|
||
```
|
||
|
||
**没有手工生成步骤** —— 以前那个 `tools/gen_compdb.sh`(合并 colcon 的分包产物)
|
||
已经随去 colcon 一起删掉了。
|
||
|
||
## ⚠️ 最常踩的坑:报「xxx.hpp file not found」
|
||
|
||
**现象**:
|
||
|
||
```
|
||
'sentry_nav/waypoint_sequencer.hpp' file not found
|
||
Too many errors emitted, stopping now [-ferror-limit=]
|
||
```
|
||
|
||
**原因**:`compile_commands.json` 是**旧的**。clangd 只读它,不会自己去看 `xmake.lua`。
|
||
只要做过下面任何一件事,这个文件就过期了:
|
||
|
||
- 新增 / 重命名 / 删除 `.cpp`
|
||
- 改 `xmake.lua` 的 `add_files` / `add_includedirs` / `set_languages`
|
||
- 新增 `#include` 指向一个新的目录
|
||
- 换 C++ 标准
|
||
|
||
**修复**(两步,缺一不可):
|
||
|
||
```bash
|
||
cd ~/Gazebo_projects/sentry_nav_dev
|
||
xmake # 构建 + 自动重写根 compile_commands.json
|
||
```
|
||
|
||
然后在 VS Code 里:
|
||
|
||
```
|
||
Ctrl+Shift+P → clangd: Restart language server
|
||
```
|
||
|
||
> 只 `clangd: Restart` 不跑 `xmake` 是**不够的** —— 文件本身没变,clangd 读到的还是旧路径。
|
||
|
||
## 验证 compdb 是否正确
|
||
|
||
```bash
|
||
# 看根 compdb 里有哪些编译单元(应该是 6 个:2 节点 + 2 核心 + 2 测试)
|
||
python3 -c "
|
||
import json
|
||
for e in json.load(open('compile_commands.json')):
|
||
print(e['file'].split('sentry_nav_dev/')[-1])
|
||
"
|
||
|
||
# 更彻底:直接用 clangd 解析一遍(应该输出 All checks completed, 0 errors)
|
||
clangd --check=src/sentry_nav/src/patrol.cpp --compile-commands-dir=.
|
||
```
|
||
|
||
## 兜底配置(`clangd.fallbackFlags`)
|
||
|
||
只在你**单独打开一个头文件**、而它不在任何编译单元里时才生效:
|
||
|
||
```json
|
||
"-std=c++23",
|
||
"-I/opt/ros/lyrical/include",
|
||
"-I${workspaceFolder}/src/sentry_nav/include"
|
||
```
|
||
|
||
## 真正的构建仍然用命令行
|
||
|
||
```bash
|
||
cd ~/Gazebo_projects/sentry_nav_dev
|
||
xmake # 编译
|
||
xmake test # 单元测试
|
||
```
|
||
|
||
> `sentry_sim` 里没有 C/C++ 源码,编辑器对它只剩 SDF/XML 高亮,不涉及编译。
|