转到中文描述
clangd
clangd helps developers write, understand and
improve C/C++ code by providing:
- code completion
- compile errors and warnings
- go-to-definition and cross references
- hover information and inlay hints
- include management
- code formatting
- simple refactorings
Full documentation for clangd is at clangd.llvm.org.
Modified based on the commit_log:c0375489682e331ad06c25b60df86e4f102a6407 of llvm-vs-code-extensions.vscode-clangd
In order to accommodate KylinOS, the extension does some work on the commit log:c0375489682e331ad06c25b60df86e4f102a6407,and semantic highlighting has been reintroduced to support clangd8.
Requirements
Please install clangd 9 or later
Setup
clangd
server
The extension requires the clangd
language server.
You will be prompted to download it if it's not found on your PATH.
(Automatic installation is possible on x86-64 Linux, Windows, and Mac).
If you have an old version of clangd installed on your system already, you can
run "Check for clangd language server update" from the command palette.
Project setup
clangd is based on the clang C++ compiler, and understands even complex C++
code. However, you must tell clangd how your project is built (compile flags).
A compile_commands.json
file
can usually be generated by your build system
(e.g. with CMake, by setting -DCMAKE_EXPORT_COMPILE_COMMANDS=1
).
See Project Setup
in the clangd documentation for details and alternatives.
Features
Code completion
Suggestions will appear as you type names, or after .
or ->
.
Because clangd uses a full C++ parser, code completion has access to precise
type information.
Errors, warnings, and clang-tidy
Code errors are shown as you type (both as red squiggle underlines, and in the
"Problems" panel). These are the same as produced by the clang compiler, and
suggested fixes can automatically be applied.
Most clang-tidy checks are supported (these can be enabled using a .clang-tidy
file).
Cross-references
Go-to-definition and find-references work across your code, using a project-wide
index.
Press Ctrl-P #
to quickly navigate to a symbol by name.
Hover and inlay hints
Clangd can describe almost any entity if you hover the mouse (or press Ctrl-KI).
Inlay hints for parameters and deduced types can be shown temporarily or
permanently (the editor.inlayHints.enabled
setting controls this).
Include management
Code completion works across your codebase and adds #include
directives where
needed. The •
shows includes that will be inserted.
clangd can suggest inserting missing #includes, where they cause errors.
It can warn on unused includes.
clangd uses the clang-format
engine. You can format a file or the selection.
When "Format on Type" is enabled in the settings, pressing enter will cause
clangd to format the old line and semantically reindent.
The style used for formatting (and certain other operations) is controlled by the project's
.clang-format file.
Refactoring
clangd supports some local refactorings. When you select an expression or
declaration, the lightbulb menu appears and you can choose a code action.
Current refactorings include:
- extract variable/function
- expand
auto
types and macros
- use raw strings
- rename (bound to
<F2>
, rather than a contextual code action)
Bugs/contributing
clangd is part of the LLVM project.
If you'd like to help out, reach out to clangd-dev@lists.llvm.org.
If you've found a bug in this extension, please file it at https://gitee.com/openkylin/ide-vscode-clangd/issues.
If you've found a bug in clangd, please file at https://gitee.com/openkylin/ide-vscode-clangd/issues.
english
clangd(中文描述)
clangd 帮助开发人员编写、理解和改进C/C++代码,提供以下功能:
- 代码补全
- 编译错误和警告
- 转到定义和交叉引用
- 悬停信息和嵌入提示
- 包括管理
- 代码格式化
- 简单的重构
clangd的完整文档在 clangd.llvm.org.
根据llvm-vs-code-extensions.vscode-clangd的commit_log:c0375489682e331ad06c25b60df86e4f102a6407修改
为了适配KylinOS,该插件在提交日志上做了一些工作c0375489682e331ad06c25b60df86e4f102a6407,并且重新引入了语义高亮以支持clangd8。
依赖
需要安装clangd 9 以上软件包
设置
clangd
服务
扩展需要“clangd”语言服务器。
如果在PATH中没有找到,系统会提示您下载它。
(在x86-64 Linux、Windows和Mac上可以自动安装)。
如果您的系统上已经安装了旧版本的clangd,您可以
从命令面板中运行“检查clangd语言服务器更新”。
项目设置
clangd基于clang C++编译器,甚至可以理解复杂的C++代码。但是,您必须告诉clangd您的项目是如何构建的(编译标志)。
A compile_commands.json
file通常可以由你的构建系统生成(例如使用CMake,通过设置-DCMAKE_EXPORT_COMPILE_COMMANDS=1
)。
参考项目设置
在clangd文档中了解详细信息和备选方案。
特性
代码补全
Suggestions will appear as you type names, or after .
or ->
.
Because clangd uses a full C++ parser, code completion has access to precise
type information.
建议将出现在您键入的名称或.
、->
之后。因为clangd使用完整的C++解析器,所以代码完成可以访问精确的类型信息。
错误、警告和clang-tidy
代码错误会在您输入时显示出来(红色下划线和“问题”面板)。这些与clang编译器生成的相同,并且建议的修复可以自动应用。
支持大多数clang-tidy检查(这些可以使用.clang-tidy
file启用)。
交叉引用
Go-to-definition和find-references使用项目范围的索引在整个代码中工作。
点击Ctrl-P #
快速导航到符号。
悬停和嵌入提示
如果你将鼠标悬停(或按Ctrl-KI), Clangd几乎可以描述任何对象。
参数和推断类型的嵌入提示可以临时或永久地显示(通过设置editor.inlayHints.enabled
控制这一点)。
包括管理
代码完成可以在整个代码库中工作,并在需要的地方添加“#include”指令。•
表示将includes 被插入。
它可以对未使用的组件发出警告
格式化
Clangd使用“clang-format”引擎。您可以格式化文件或格式化选择的内容。
当在设置中启用“按类型格式化”时,按enter将导致clangd格式化旧行并在语义上重新缩进。
项目可控制格式化样式(和某些其他操作)
.clang-format file.
重构
Clangd支持一些局部重构。当您选择表达式或声明时,将出现灯泡菜单,您可以选择代码操作。
当前的重构包括:
- 提取变量/函数
- 扩展
auto
类型和宏
- 使用原始字符串
- 重命名(绑定到' ',而不是上下文代码操作)
错误/贡献
clangd是LLVM 项目的一部分。
如果你想帮忙,请联系clangd-dev@lists.llvm.org。
如果你在这个扩展中发现了一个bug,请把它提交到https://gitee.com/openkylin/ide-vscode-clangd/issues。
如果你在clangd中发现了一个bug,请在https://gitee.com/openkylin/ide-vscode-clangd/issues 上提交。