当前位置:网站首页>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
边栏推荐
猜你喜欢
FP6195耐压60V电流降压3.3V5V模块供电方案
How to add a one-key shutdown option to the right-click menu in Windows 11
机器学习和深度学习中的梯度下降及其类型
2020-02-06-快速搭建个人博客
Win10 Settings screen out from lack of sleep?Win10 set the method that never sleep
win10无法直接用照片查看器打开图片怎么办
win10 system update error code 0x80244022 how to do
Win11怎么在右键菜单添加一键关机选项
Makefile容易犯错的语法
flink+sklearn——使用jpmml实现flink上的机器学习模型部署
随机推荐
【深度学习中的损失函数整理与总结】
【使用Pytorch实现VGG16网络模型】
FP6296锂电池升压 5V9V12V内置 MOS 大功率方案原理图
机器学习---监督学习、无监督学习
Binder机制(中篇)
Fast advanced TypeScript
Do Windows 10 computers need antivirus software installed?
编译error D8021 :无效的数值参数“/Wextra” cl command line error d8021 invalid numeric argument ‘/wextra‘
jest测试,组件测试
FP7128内置MOS降压恒流调光深度0.01%高辉共阳调光方案
13.56MHZ刷卡芯片CI521兼容cv520/ci520支持A卡B卡MIFARE协议
jest test, component test
Makefile容易犯错的语法
DP1101兼容CC1101是SUB1GHz无线收发芯片应用于智能家居
5. Use RecyclerView to elegantly achieve waterfall effect
arm ldr系列指令
How to update Win11 sound card driver?Win11 sound card driver update method
图像配置分类及名词解释
【我的电赛日记(完结)---2021全国大学生电子设计竞赛全国一等奖】A题:信号失真度测量装置
PyTorch②---transforms结构及用法