一、配置
{
"clangd.path": "/home/xxx/.local/clangd_12.0.1/bin/clangd",
"clangd.arguments": [
"--background-index",
"--header-insertion=never",
"--limit-results=0",
"--compile-commands-dir=${workspaceFolder}/out",
"--completion-style=detailed",
"-log=info"
],
}
二、使用scripts/gen_compile_commands.py生成compile_commands.json
./scripts/gen_compile_commands.py -d out
三、解决解析过程中的报错
1.方法一
修改gen_compile_commands.py脚本,去掉报错的参数,添加如下代码:
_FILTER_PATTERN = r'\-mabi=lp64|\-fno-var-tracking-assignments|\-fconserve-stack|\-mstack-protector-guard=sysreg|\-mstack-protector-guard-reg=sp_el0|\-mstack-protector-guard-offset=1240'
prefix = re.sub(_FILTER_PATTERN, "", prefix)
重新生成compile_commands.json
2.方法二
将报错的选项添加到根目录下的.clangd文件中,添加如下内容:
CompileFlags: # Tweak the parse settings
Remove: [-mabi=lp64,-fno-var-tracking-assignments, -fconserve-stack, -mstack-protector-guard=sysreg, -mstack-protector-guard-reg=sp_el0, -mstack-protector-guard-offset=1240]
更新:使用新版本的clangd,需要添加"--enable-config",.clangd好像只有在${workspaceFolder}当前目录下起作用。
可以使用kill杀掉当前的clangd进程重启服务。或者关闭vscode关闭文件夹再打开重启。
{
"clangd.arguments": [
"--background-index",
"--header-insertion=never",
"--limit-results=0",
"--compile-commands-dir=${workspaceFolder}",
"--completion-style=detailed",
"--enable-config",
"-log=info"
],
"clangd.path": "/opt/clangd_14.0.3/bin/clangd",
}
更新,去掉clang-tidy的错误告警,命令行添加以下参数,禁止clang-tidy的所有检测。
"--clang-tidy",
"--clang-tidy-checks=-*"