2024-12-16 V1 31826
IDE #
插件 #
- C/C++ IntelliSense, debugging, and code browsing.
- C/C++ Extension Pack Popular extensions for C++ development in Visual Studio Code.
Formatter & Linter #
-
.clang-format :只格式化代码,不去理解代码意图。
-
.clang-tidy :不只优化格式,还能识别错误实践。
clang-tidy is a clang-based C++ “linter” tool. Its purpose is to provide an extensible framework for diagnosing and fixing typical programming errors, like style violations, interface misuse, or bugs that can be deduced via static analysis. clang-tidy is modular and provides a convenient interface for writing new checks.
.clang-format #
来源:Android Studio 导出(Editor -> Code Style -> C/C++ -> … -> Export -> clang-format
File)。
插件配置:
设置名称 | 类型 | 值 | 说明 |
---|---|---|---|
C_Cpp.clang_format_style | String | file | 寻找项目根目录的 .clang-format 文件,文件不存在时,则使用 C_Cpp.clang_format_fallbackStyle 中的默认配置。 |
C_Cpp.clang_format_fallbackStyle | String | LLVM | 找不到 .clang-format 文件时的缺省配置。 |
运行:
- 使用快捷键:Shift + Alt + F。
- 使用命令: Ctrl + Shift + P 搜索并运行 Format Document。
格式:key: value
,如 IndentWidth: 4
代表四个空格缩进。
- BasedOnStyle 可以设置基础风格。
- sortincludes 控制如何排序头文件。
.clang-tidy #
来源:Google cloud 项目。
插件配置:
设置名称 | 类型 | 值 | 说明 |
---|---|---|---|
C_Cpp.codeAnalysis.clangTidy.enabled | Boolean | True | 是否开启 clangTidy。 |
C_Cpp.codeAnalysis.runAutomatically | Boolean | True | 是否自动执行代码分析,勾选后保存和打开文件时会自动分析文件。 |
运行:
- 自动运行。
- 使用命令: Ctrl + Shift + P 搜索并运行 Run Code Analysis on Active File。
格式:
# 控制开关,`-` 代表不检查
Checks:
-*,
readability-identifier-naming
# key-value pair,配置具体的 Options
CheckOptions:
- { key: readability-identifier-naming.VariableCase, value: lower_case }
readability-identifier-naming 可以设置命名规范。
如果 Quick fix 不提示修复方法(
v1.22.11
),升级插件到C/C++ v1.23.2 (pre-release)
。
找不到头文件时也报告错误的方法: Extentions -> C/C++ -> IntelliScene -> Error Squiggles: enabled
编辑器竖线 #
// settings.json
"editor.rulers": [
{
"column": 80,
"color": "#14c50e"
},
100, // a ruler with the default or editorRuler.foreground color at column 100
{
"column": 120,
"color": "#ff0000"
},
]
资源 #
- Clang-Format Style Options
- Clang-Tidy Checks
- Google C++ Style Guide
- Visual Studio Code C++ December 2021 Update: clang-tidy
- Diff clang-formant and clang-tidy
- Android Studio 导出 .clang-tidy:
Editor -> Inspections -> Clang-Tidy
- C/C++ extension tag:
@ext:ms-vscode.cpptools
- 推荐插件
- Codeium
- Git Graph
- Bookmarks
- Todo Tree
- Remote - SSH
- Output Colorizer: Syntax highlighting for log files