ccls
vscode的ccls插件需要配置ccls.misc.compilationDatabaseDirectory
才能让它正常识别自定义header,需要根据cmake插件的build目录来设定,不过一般都是${workspaceRoot}/build
。
wrapper
根据wiki添加include,做个wrapper。
"clang++ -xc++ -fsyntax-only -v /dev/null"
提取出关键路径(注意,最后一个不包含括号的内容):
1
2
3
4
5
6
|
/usr/local/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1
/Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/Library/Developer/CommandLineTools/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks
|
写成wrapper放到PATH包含的路径里:
1
2
3
4
5
6
7
8
9
|
#!/bin/sh
exec /opt/homebrew/bin/ccls --init='{"clang":{"extraArgs":[
"-isystem/usr/local/include",
"-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
"-isystem/Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/include",
"-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
"-isystem/Library/Developer/CommandLineTools/usr/include",
"-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
]}}' "$@"
|
vscode-ccls插件配置
vscode的相关配置:https://github.com/MaskRay/ccls/wiki/Visual-Studio-Code。
-
ccls.launch.command
,可以直接设置成wrapper的路径。
-
高亮:将以下内容直接粘贴到settings.json里:
1
2
3
|
"ccls.highlight.function.face": ["enabled"],
"ccls.highlight.type.face": ["enabled"],
"ccls.highlight.variable.face": ["enabled"]
|
-
与微软官方的C++插件同时使用,也是粘贴到settings.json里:
1
2
3
4
|
"C_Cpp.autocomplete": "Disabled",
"C_Cpp.formatting": "Disabled",
"C_Cpp.errorSquiggles": "Disabled",
"C_Cpp.intelliSenseEngine": "Disabled"
|
lint
brew安装cpplint和cppcheck。
vscode安装cppcheck插件,检查类型cpp-check-lint.cppcheck.--enable=
改成all
,同时设置cpp-check-lint.cppcheck.--suppressions-list=
为missingInclude(真找不到header的话ccls会报错,不需要static linter们报错)。
debug
用cmake来debug,要么在GUI中点击新建launch.js,要么自己在项目根目录新增文件夹.vscode,里面新建launch.json,然后就可以自定义什么运行参数之类的了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/adblock2mosdns",
"args": [
"--skip-download"
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
|