当前位置:网站首页>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

边栏推荐
猜你喜欢

golang之GMP调度模型

cmake配置libtorch报错Failed to compute shorthash for libnvrtc.so

Mapreduce环境详细搭建和案例实现

FP7195降压恒流PWM转模拟调光零压差大功率驱动方案原理图

PyTorch③---torchvision中数据集的使用

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

【使用Pytorch实现ResNet网络模型:ResNet50、ResNet101和ResNet152】

PyTorch⑦---卷积神经网络_非线性激活

深入理解Golang之Map

Win7 encounters an error and cannot boot into the desktop normally, how to solve it?
随机推荐
Actual combat Meituan Nuxt +Vue family bucket, server-side rendering, mailbox verification, passport authentication service, map API reference, mongodb, redis and other technical points
Mysql连接错误解决
Win11 system cannot find dll file how to fix
casbin模型
win10无法直接用照片查看器打开图片怎么办
pygame绘制弧线
Binder机制(下篇)
STM32LL库使用——SPI通信
jest test, component test
FP6296锂电池升压 5V9V12V内置 MOS 大功率方案原理图
How to reinstall Win7 system with U disk?How to reinstall win7 using u disk?
PyTorch⑤---卷积神经网络_卷积层
Tensorflow常用函数
Binder机制(中篇)
Please make sure you have the correct access rights and the repository exists.问题解决
PHY6222蓝牙5.2支持MESH组网M0内核超低功耗
对疫情期间量化策略表现的看法
如何用硬币模拟1/3的概率,以及任意概率?
What should I do if I install a solid-state drive in Win10 and still have obvious lags?
FP5139电池与适配器供电DC-DC隔离升降压电路反激电路电荷泵电路原理图