当前位置:网站首页>Configure clangd for vscode
Configure clangd for vscode
2022-08-02 15:26:00 【Hongyao】
目录
clangdCan provide better completions and hints,Bring your own checkswarning的问题,It can reduce everyone's future looking for existencewarning的时间.After configuration can be inunittest和timetestAutocompletion is also implemented in ,平均速度比vscode c/c++Plugins are faster.
安装clangd 后端
sudo apt-get install clangd
安装clangd 前端
在插件市场搜索clangd.安装即可.注意c/c++可以不用卸载,Otherwise debugging might be a bit problematic.
修改基础配置
在project folder下建立.vscode文件夹,创建settings.json文件.如下图

settings.json内容如下(Note that local configuration may also be requiredclangd.arguments否则可能会有问题,Chen Tianhao has this problem)
{
"files.associations": {
"iostream": "cpp",
"intrinsics.h": "c",
"ostream": "cpp",
"vector": "cpp"
},
// Turn on paste save auto format
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"C_Cpp.errorSquiggles": "Disabled",
"C_Cpp.intelliSenseEngineFallback": "Disabled",
"C_Cpp.intelliSenseEngine": "Disabled",
"C_Cpp.autocomplete": "Disabled", // So you don't get autocomplete from both extensions.
"clangd.path": "/usr/bin/clangd",
// Clangd 运行参数(在终端/命令行输入 clangd --help-list-hidden 可查看更多)
"clangd.arguments": [
// 让 Clangd Generate more detailed logs
"--log=verbose",
// 输出的 JSON The files are more beautiful
"--pretty",
// 全局补全(Suggestions that pop up as you type will be provided CMakeLists.txt possible symbols in all files configured in ,会自动补充头文件)
"--all-scopes-completion",
// Suggested style:打包(Overloaded functions will only give a suggestion)
// Instead it can be set to detailed
"--completion-style=bundled",
// Rename variables across files
"--cross-file-rename",
// Supplemental header files are allowed
"--header-insertion=iwyu",
// Enter suggestions,Items that already contain a header file are distinguished from items that do not yet contain a header file by a dot
"--header-insertion-decorators",
// 在后台自动分析文件(基于 complie_commands,我们用CMake生成)
"--background-index",
// 启用 Clang-Tidy 以提供「静态检查」
"--clang-tidy",
// Clang-Tidy Statically checked parameters,Indicates which rules are used for static checking,详情见「and configured according to the official documentation VSCode advantage over having」
// the part after the parameter*表示通配符
// added before the parameter-,如-modernize-use-trailing-return-type,A rule will be disabled
"--clang-tidy-checks=cppcoreguidelines-*,performance-*,bugprone-*,portability-*,modernize-*,google-*",
// Default formatting style: Google Open Source Project Code Guidelines
// "--fallback-style=file",
// 同时开启的任务数量
"-j=2",
// pch优化的位置(memory 或 disk,选择memory会增加内存开销,But it will improve performance) Recommended for use on boardsdisk
"--pch-storage=disk",
// When this is enabled,When completing a function,Placeholders will be provided for parameters,press after typing Tab You can switch to the next placeholder,to the end of the function
// I choose to disable
"--function-arg-placeholders=false",
// compelie_commands.json 文件的目录位置(relative to the workspace,由于 CMake This file is generated by default build 文件夹中,故设置为 build)
"--compile-commands-dir=build"
],
}
生成compile_commands.json文件
Make sure that the project can be compiled normally
cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .. -G 'Unix Makefiles'
之后在build目录下就会生成对应的compile_commands.json,格式如下.Just make sure it's therecompile_commands.json文件,这是clangd补全依赖文件,否则会失效.
[
{
"directory": "",
"command": "",
"file": "",
},
]
It may need to be started manually after the build is completereload window或者使用manually activate extension.之后每次打开projectUsually it starts automatically.


可以通过ps -ef | grep clang查看是否存在进程

基本效果
补全

warning提醒

There is a problem with automatic modification


注意事项
- It is best to use the image below after useclose remote关闭,Otherwise, there may be processes in the background that are not closed

- when the process is compiled,clangdThe cache is automatically regenerated,It will take up a lot of hard disk space and may need to be cleaned regularly

边栏推荐
- PyTorch⑥---卷积神经网络_池化层
- yolov5官方代码解读——前向传播
- Do Windows 10 computers need antivirus software installed?
- 用U盘怎么重装Win7系统?如何使用u盘重装系统win7?
- 【深度学习中的损失函数整理与总结】
- General syntax and usage instructions of SQL (picture and text)
- 2020-02-06-快速搭建个人博客
- Tensorflow张量生成
- Win10 Settings screen out from lack of sleep?Win10 set the method that never sleep
- Mysql的锁
猜你喜欢

pygame绘制弧线

推开机电的大门《电路》(二):功率计算与判断

Binder ServiceManager解析

FP7195芯片PWM转模拟调光至0.1%低亮度时恒流一致性的控制原理

What is Win10 God Mode for?How to enable God Mode in Windows 10?

win10无法直接用照片查看器打开图片怎么办

ARMv8虚拟化

PyTorch(12)---损失函数和反向传播

How to reinstall Win7 system with U disk?How to reinstall win7 using u disk?

PyTorch④---DataLoader的使用
随机推荐
GICv3/v4-软件概述
PyTorch①---加载数据、tensorboard的使用
win10 system update error code 0x80244022 how to do
【使用Pytorch实现VGG16网络模型】
win11一直弹出用户账户控制怎么解决
Win11怎么在右键菜单添加一键关机选项
2.4G无线小模块CI24R1超低成本
DP1332E内置c8051的mcu内核NFC刷卡芯片国产兼容NXP
define #使用
Win11电脑一段时间不操作就断网怎么解决
PyTorch④---DataLoader的使用
Win7怎么干净启动?如何只加载基本服务启动Win7系统
编译error D8021 :无效的数值参数“/Wextra” cl command line error d8021 invalid numeric argument ‘/wextra‘
基于51单片机和物联网的智能家居系统(ESP8266物联网模块)
【我的电赛日记(一)】HMI USART串口屏
How to set the win10 taskbar does not merge icons
SQL的通用语法和使用说明(图文)
设备驱动框架简介
Win10系统设置application identity自动提示拒绝访问怎么办
Win7 encounters an error and cannot boot into the desktop normally, how to solve it?