参考链接:
- https://josephpei.github.io/2018/05/04/VSCode-cquery-lsp-实现-C-C-补全/
- https://blog.coderzh.com/2018/10/14/cquery/
- https://github.com/cquery-project/cquery/wiki/Building-cquery
- https://code.visualstudio.com/docs/getstarted/settings#_default-settings
1. build cquery
参考官网教程,先安装依赖:

安装cmake:
brew install cmake
clang已经安装上了,不知道为什么之后还会下载7.0版本,可以在这里查看一下版本信息:
clang --version
gcc --version

之后,按照官网教程进行配置:
git clone --recursive https://github.com/cquery-project/cquery.git cd cquery git submodule update --init mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=release -DCMAKE_EXPORT_COMPILE_COMMANDS=YES cmake --build . cmake --build . --target install
在进行到 cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=release -DCMAKE_EXPORT_COMPILE_COMMANDS=YES
这一步的时候,会下载很久(久到令人怀疑是不是已经断掉了),可以将链接复制到浏览器中进行下载(https://releases.llvm.org/6.0.0/clang+llvm-6.0.0-x86_64-apple-darwin.tar.xz ),然后将下载后的文件解压放到build
文件夹下,再进行之后的build
和install
,即可完成cquery的安装。(参照参考文件2)
注意安装完成后会给出build文件的目录,记录下来以便之后进行配置。

2.Vscode配置
参考:
- vscode基本设置与配置详解:https://blog.csdn.net/u013304372/article/details/78917536
a. 在extension中输入cquery进行查找安装。

b. 在VScode中按Command+Shift+P
,输入Open User Settings
打开配置面板(或者Code->Preferences->Settings
)。按右上角的{ }
可以进入打开settings.json
文件进行编辑(注意刚安装的vscode该文件为空,直接在$HOME/Library/Application Support/Code/User/settings.json
目录下找可能还找不到该文件)。

配置信息参考cquery官网,下面是我的配置信息(第二个配置研究了半天,感觉应该是制定一个存放cache的路径就可以了)。

加上官网一个高亮信息,总体配置如下:
{ "cquery.launch.command": "绝对路径/build/release/bin/cquery", "cquery.cacheDirectory": "/home/.cquery-cache/", "cquery.completion.include.blacklist": [ ".*/.vscache/.*", "/tmp.*", "build/.*" ], "editor.fontSize": 18, "cquery.highlighting.enabled.types": true, "cquery.highlighting.enabled.freeStandingFunctions": true, "cquery.highlighting.enabled.memberFunctions": true, "cquery.highlighting.enabled.freeStandingVariables": true, "cquery.highlighting.enabled.memberVariables": true, "cquery.highlighting.enabled.namespaces": true, "cquery.highlighting.enabled.macros": true, "cquery.highlighting.enabled.enums": true, "cquery.highlighting.enabled.typeAliases": true, "cquery.highlighting.enabled.enumConstants": true, "cquery.highlighting.enabled.staticMemberFunctions": true, "cquery.highlighting.enabled.parameters": true, "cquery.highlighting.enabled.templateParameters": true, "cquery.highlighting.enabled.staticMemberVariables": true, "cquery.highlighting.enabled.globalVariables": true }
c. 在生成的build目录下,可以找到一个compile_commands.json
文件,将其复制到项目根目录下。(参考链接2)
文章来源: https://blog.csdn.net/sanra123/article/details/91399204