在本页中

Clangd

Clang 项目拥有用于解析 C 语言族源文件并为您提供详细诊断的库。clangd索引可为代码补全等服务提供准确、完整的结果。

要为 clangd 设置首选项,请访问Preferences >C++ >Clangd 并选择Use clangd

C++ 偏好设置中的 Clangd 选项卡

下表描述了可用的首选项。

首选项说明
Path to executable指定 clangd 14 或更高版本的路径。
Background indexing选择Off 可使用速度更快但精确度较低的内置索引器。在全局符号搜索时,根据准确性还是速度更重要来设置索引优先级。
Per-project index location为每个项目指定存储索引文件的文件夹。compile-commands.json 文件也存储在此处。
Per-session index location指定为每个会话存储索引文件的文件夹。
Header/source switch mode选择用于在头文件和源文件之间切换的 C/C++ 后端。如果内置代码模型未找到任何内容,Try Both 使用 clangd。
Worker thread count设置要使用的固定内核数。默认情况下,clangd 会使用所有未使用的内核。
Insert header files on completion在完成符号时插入头文件。
Update dependent sources在编辑包含头文件的源文件时,重新解析该文件。清除此选项后,只有在保存头文件时才会重新解析。
Completion results完成结果的最大数量。设为 0 可取消限制。
Completion ranking model选择用于排列完成建议的 clangd 模型。 Decision Forest (默认)使用机器学习。Heuristic 是手工创建的。
Document update thresholdQt Creator 向服务器发送文件更改前的等待时间。
Ignore files greater than解析文件的最大大小。启用后解析速度会更快。
Diagnostic configuration要执行的 Clang 检查。选择以编辑检查。
Sessions with a Single Clangd Instance添加应使用单个 clangd 进程进行索引的会话。

Clang 检查

选择Diagnostic configuration 字段的值可打开Diagnostic Configurations 对话框,在此可选择和编辑要执行的检查。

诊断配置对话框

除了使用内置检查外,还可以选择Copy 来创建检查副本,并根据需要对副本进行编辑。

  • Build-system warnings 显示构建系统指定的警告。
  • Checks for questionable constructs 结合-Wall-Wextra 检查容易避免的可疑结构和一些其他问题。

Clang 检查以-W 开始。每个检查都有一个以-Wno 开头的否定版本。

请注意,某些选项会开启其他选项。更多信息,请参阅 "请求或抑制警告的选项"或 GCC 或 Clang 手册页面。

另请参阅 指定 clangd 设置Clang 代码模型代码模型

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.