Skip to content

Commit 1f736fd

Browse files
committed
docs: Provide CN translation for clangd_cdt_support.rst
1 parent 3ae9b40 commit 1f736fd

File tree

2 files changed

+136
-39
lines changed

2 files changed

+136
-39
lines changed

docs/en/additionalfeatures/clangd_cdt_support.rst

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,55 @@
33
Espressif-IDE LSP Support for C/C++ Editor
44
==========================================
55

6-
The Espressif-IDE 3.0.0 (and higher) now includes the `Eclipse CDT-LSP <https://github.com/eclipse-cdt/cdt-lsp/>`, enabling support for the latest C/C++ standards and providing an LSP-based C/C++ Editor. This editor, powered by the `LLVM <https://clangd.llvm.org/>` clangd C/C++ language server, offers advanced functionality for ESP-IDF developers.
6+
:link_to_translation:`zh_CN:[中文]`
77

8-
In line with this enhancement, we've discontinued support for the standard CDT Editor/Indexer, as it only offers support for up to C++ 14. This has been replaced with a new LSP editor, especially considering that ESP-IDF now utilizes C++ 20 (with GCC 11.2) in v5.0.x, transitions to C++ 23 (with GCC 12.1) in v5.1, and to C++ 23 with GCC 13.1 in v5.2.
8+
The Espressif-IDE 3.0.0 or later now includes the `Eclipse CDT-LSP <https://github.com/eclipse-cdt/cdt-lsp/>`_, enabling support for the latest C/C++ standards and providing an LSP-based C/C++ Editor. This editor, powered by the `LLVM <https://clangd.llvm.org/>`_ clangd C/C++ language server, offers advanced functionality for ESP-IDF developers.
9+
10+
In line with this enhancement, we have discontinued support for the standard CDT Editor/Indexer, as it only supports up to C++ 14. This has been replaced with a new LSP editor, especially considering that ESP-IDF now utilizes C++ 20 (with GCC 11.2) in v5.0.x, transitions to C++ 23 (with GCC 12.1) in v5.1, and to C++ 23 with GCC 13.1 in v5.2.
911

1012
The LSP powered C/C++ editor greatly benefits ESP-IDF developers by aligning with the latest language standards and compiler versions, enhancing productivity, and improving code quality.
1113

12-
You can find more details on the LSP based C/C++ Editor features in the `Eclipse CDT-LSP documentation <https://github.com/eclipse-cdt/cdt-lsp/>`_.
14+
You can find more details on the LSP based C/C++ editor features in the `Eclipse CDT-LSP documentation <https://github.com/eclipse-cdt/cdt-lsp/>`_.
1315

1416
Prerequisites
1517
-------------
16-
* You need to have Espressif-IDE 3.0.0 (and higher) to have access to the LSP powered C/C++ editor.
18+
19+
* You need Espressif-IDE 3.0.0 or later to access the LSP-powered C/C++ editor.
1720
* If you are updating Eclipse CDT or Espressif-IDE via the update site, you need to select the ESP-IDF Eclipse Plugin and its dependencies, as shown below:
1821

1922
.. image:: ../../../media/clangd/cdtlsp_updatesite.png
2023

2124
Clangd Configuration
2225
--------------------
2326

24-
By default, the esp-clang toolchain is installed as a part of the ESP-IDF tools installation process, and clangd **Path** is configured in the preferences.
27+
By default, the esp-clang toolchain is installed as a part of the ESP-IDF tools installation process, and clangd ``Path`` is configured in the preferences.
2528

26-
The **Drivers** path and **--compile-commands-dir** path will be configured based on the selected target (esp32, esp32c6 etc.) and the project you're building.
29+
The ``Drivers`` path and ``--compile-commands-dir`` path will be configured based on the selected target (esp32, esp32c6, etc.) and the project being built.
2730

2831
However, if there are any issues in configuration, this can be configured in the following way:
2932

30-
1. Go to `Window` > `Preferences` > `C/C++` > `Editor(LSP)`
31-
2. Navigate to `clangd` node
32-
3. Provide `Drivers` path as shown in the screenshot.
33-
4. Set `--compile-commands-dir=/project/build` in the additional argument section.
34-
5. Click on `Apply and Close`.
33+
1. Go to ``Window`` > ``Preferences`` > ``C/C++`` > ``Editor(LSP)``.
34+
2. Navigate to ``clangd`` node.
35+
3. Provide ``Drivers`` path as shown in the screenshot.
36+
4. Set ``--compile-commands-dir=/project/build`` in the additional argument section.
37+
5. Click on ``Apply and Close``.
3538

36-
.. image:: ../../../media/clangd/clangd_config.png
39+
.. image:: ../../../media/clangd/clangd_config.png
3740

38-
By default, when you create a new project, a `.clangd` configuration file is created with the following arguments.
41+
By default, when you create a new project, a ``.clangd`` configuration file is created with the following arguments.
3942

40-
However, if you are dealing with an existing project, please create a `.clangd` file at the root of the project and add the following content.
43+
However, if you are dealing with an existing project, please create a ``.clangd`` file at the root of the project and add the following content.
4144

4245
.. code-block:: yaml
4346
4447
CompileFlags:
45-
CompilationDatabase: build
46-
Remove: [-m*, -f*]
48+
CompilationDatabase: build
49+
Remove: [-m*, -f*]
4750
48-
How to fix Unknown argument error when navigating to the esp-idf components
49-
----------------------------------------------------------------------------------------
51+
How to Fix the "Unknown Argument" Error When Navigating to ESP-IDF Components
52+
-----------------------------------------------------------------------------
5053

51-
If you are seeing the following error markers while navigating to the esp-idf components source code:
54+
If you see the following error markers while navigating to the ESP-IDF component source code:
5255

5356
.. code-block:: none
5457
@@ -59,34 +62,34 @@ If you are seeing the following error markers while navigating to the esp-idf co
5962
6063
Please follow the steps below to fix it:
6164

62-
1. Download the script for `fix_compile_commands.py <https://github.com/espressif/idf-eclipse-plugin/tree/master/resources/fix_compile_commands/fix_compile_commands.py>`_.
65+
1. Download the script for `fix_compile_commands.py <https://github.com/espressif/idf-eclipse-plugin/tree/master/resources/fix_compile_commands/fix_compile_commands.py>`_.
6366

64-
2. Invoke the script from the project post build step. Here is example for `CMakeLists.txt <https://github.com/espressif/idf-eclipse-plugin/blob/master/resources/fix_compile_commands/CMakeLists.txt>`_:
67+
2. Invoke the script from the project post build step. Here is example for `CMakeLists.txt <https://github.com/espressif/idf-eclipse-plugin/blob/master/resources/fix_compile_commands/CMakeLists.txt>`_:
6568

66-
.. code-block:: cmake
69+
.. code-block:: cmake
6770
68-
if(EXISTS "${CMAKE_SOURCE_DIR}/fix_compile_commands.py")
69-
add_custom_target(
70-
fix_clangd ALL
71-
COMMAND ${CMAKE_COMMAND} -E echo "Running fix_compile_commands.py..."
72-
COMMAND ${CMAKE_COMMAND} -E env python3 ${CMAKE_SOURCE_DIR}/fix_compile_commands.py
73-
COMMENT "Cleaning compile_commands.json for clangd"
74-
VERBATIM
75-
)
76-
endif()
71+
if(EXISTS "${CMAKE_SOURCE_DIR}/fix_compile_commands.py")
72+
add_custom_target(
73+
fix_clangd ALL
74+
COMMAND ${CMAKE_COMMAND} -E echo "Running fix_compile_commands.py..."
75+
COMMAND ${CMAKE_COMMAND} -E env python3 ${CMAKE_SOURCE_DIR}/fix_compile_commands.py
76+
COMMENT "Cleaning compile_commands.json for clangd"
77+
VERBATIM
78+
)
79+
endif()
7780
78-
3. Now run the build, the script will remove the -m* and -f* flags from the compile_commands.json file which are unknown to clangd.
81+
3. Run the build, the script will remove the ``-m*`` and ``-f*`` flags from the ``compile_commands.json`` file which are unknown to clangd.
7982

80-
4. Now, you can navigate to the esp-idf components source code without any errors.
83+
4. Now, you can navigate to the ESP-IDF components source code without any errors.
8184

8285
Disable CDT Indexer
8386
-------------------
8487

85-
With Espressif-IDE 3.0.0 (and higher), the CDT Indexer is disabled by default; instead, the LSP Indexer server will be used for code analysis.
88+
With Espressif-IDE 3.0.0 or later, the CDT Indexer is disabled by default; instead, the LSP Indexer server is used for code analysis.
8689

87-
If, for some reason, it is not disabled, please follow the steps below to disable it.
90+
If, for any reason, it is not disabled, follow the steps below to disable it.
8891

89-
1. Go to `Window` > `Preferences` > `C/C++` > `Indexer`
90-
2. Uncheck `Enable Indexer` option and then click on `Apply and Close`.
92+
1. Go to ``Window`` > ``Preferences`` > ``C/C++`` > ``Indexer``.
93+
2. Uncheck ``Enable Indexer`` option and then click on ``Apply and Close``.
9194

92-
.. image:: ../../../media/clangd/cdt_indexer_disable.png
95+
.. image:: ../../../media/clangd/cdt_indexer_disable.png
Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,95 @@
1-
.. include:: ../../en/additionalfeatures/clangd_cdt_support.rst
1+
.. _clangd_cdt_support:
2+
3+
Espressif-IDE 对 C/C++ 编辑器的 LSP 支持
4+
========================================
5+
6+
:link_to_translation:`en:[English]`
7+
8+
Espressif-IDE 3.0.0 及更高版本现已内置 `Eclipse CDT-LSP <https://github.com/eclipse-cdt/cdt-lsp/>`_,支持最新的 C/C++ 标准并提供基于 LSP 的 C/C++ 编辑器。该编辑器由 `LLVM <https://clangd.llvm.org/>`_ clangd C/C++ 语言服务器驱动,为 ESP-IDF 开发者提供更强大的功能。
9+
10+
为配合本次功能增强,我们已停止支持标准的 CDT 编辑器/索引器,因为其仅支持至 C++ 14。我们用全新的 LSP 编辑器取而代之,尤其考虑到 ESP-IDF 现已在 v5.0.x 中使用 C++ 20(配合 GCC 11.2),在 v5.1 过渡到 C++ 23(配合 GCC 12.1),并在 v5.2 使用 GCC 13.1 的 C++ 23。
11+
12+
基于 LSP 的 C/C++ 编辑器与最新的语言标准和编译器版本保持一致,可极大提升 ESP-IDF 开发者的效率并改进代码质量。
13+
14+
关于基于 LSP 的 C/C++ 编辑器功能的更多信息,请参阅 `Eclipse CDT-LSP 文档 <https://github.com/eclipse-cdt/cdt-lsp/>`_。
15+
16+
准备工作
17+
--------
18+
19+
* 需要 Espressif-IDE 3.0.0 及更高版本才能使用基于 LSP 的 C/C++ 编辑器。
20+
* 如果通过更新站点升级 Eclipse CDT 或 Espressif-IDE,需要选择 ESP-IDF Eclipse 插件及其依赖项,如下图所示。
21+
22+
.. image:: ../../../media/clangd/cdtlsp_updatesite.png
23+
24+
Clangd 配置
25+
-----------
26+
27+
默认情况下,esp-clang 工具链会在 ESP-IDF 工具的安装过程中自动安装,并且会在偏好设置中配置好 clangd 的 ``Path``。
28+
29+
``Drivers`` 路径和 ``--compile-commands-dir`` 路径会根据所选目标(esp32、esp32c6 等)以及当前正在构建的项目自动配置。
30+
31+
如果自动配置有问题,可按以下方式手动配置:
32+
33+
1. 前往 ``Window`` > ``Preferences`` > ``C/C++`` > ``Editor(LSP)``。
34+
2. 定位到 ``clangd`` 节点。
35+
3. 按截图所示填写 ``Drivers`` 路径。
36+
4. 在附加参数区域设置 ``--compile-commands-dir=/project/build``。
37+
5. 点击 ``Apply and Close``。
38+
39+
.. image:: ../../../media/clangd/clangd_config.png
40+
41+
创建新项目时,会默认生成一个 ``.clangd`` 配置文件,并带有如下参数。
42+
43+
如果处理的是现有项目,请在项目根目录处创建 ``.clangd`` 文件并添加如下内容。
44+
45+
.. code-block:: yaml
46+
47+
CompileFlags:
48+
CompilationDatabase: build
49+
Remove: [-m*, -f*]
50+
51+
如何解决在浏览 ESP-IDF 组件时出现的 "Unknown Argument" 错误
52+
-----------------------------------------------------------
53+
54+
如果在浏览 ESP-IDF 组件源码时看到如下错误标记:
55+
56+
.. code-block:: none
57+
58+
Multiple markers at this line
59+
- Unknown argument: '-fno-tree-switch-conversion' [drv_unknown_argument]
60+
- Unknown argument: '-fno-shrink-wrap' [drv_unknown_argument]
61+
- Unknown argument: '-fstrict-volatile-bitfields' [drv_unknown_argument]
62+
63+
请按以下步骤修复:
64+
65+
1. 下载脚本 `fix_compile_commands.py <https://github.com/espressif/idf-eclipse-plugin/tree/master/resources/fix_compile_commands/fix_compile_commands.py>`_。
66+
67+
2. 在项目的构建后步骤中调用该脚本。以下为 `CMakeLists.txt <https://github.com/espressif/idf-eclipse-plugin/blob/master/resources/fix_compile_commands/CMakeLists.txt>`_ 示例:
68+
69+
.. code-block:: cmake
70+
71+
if(EXISTS "${CMAKE_SOURCE_DIR}/fix_compile_commands.py")
72+
add_custom_target(
73+
fix_clangd ALL
74+
COMMAND ${CMAKE_COMMAND} -E echo "Running fix_compile_commands.py..."
75+
COMMAND ${CMAKE_COMMAND} -E env python3 ${CMAKE_SOURCE_DIR}/fix_compile_commands.py
76+
COMMENT "Cleaning compile_commands.json for clangd"
77+
VERBATIM
78+
)
79+
endif()
80+
81+
3. 运行构建,该脚本会从 ``compile_commands.json`` 文件中移除 clangd 无法识别的 ``-m*`` 和 ``-f*`` 标志。
82+
83+
4. 现在浏览 ESP-IDF 组件源码将不会出现报错。
84+
85+
禁用 CDT 索引器
86+
---------------
87+
88+
在 Espressif-IDE 3.0.0 及更高版本中,默认禁用 CDT 索引器,代码分析由 LSP 索引器服务器执行。
89+
90+
如果 CDT 索引器因为某些原因未被自动禁用,可参照下列步骤手动将其禁用。
91+
92+
1. 前往 ``Window`` > ``Preferences`` > ``C/C++`` > ``Indexer``。
93+
2. 取消勾选 ``Enable Indexer`` 选项,然后点击 ``Apply and Close``。
94+
95+
.. image:: ../../../media/clangd/cdt_indexer_disable.png

0 commit comments

Comments
 (0)