From 4a864b677d481b440a9ca67fd1e6b4003d6a3797 Mon Sep 17 00:00:00 2001 From: ExquisiteCore Date: Tue, 18 Nov 2025 00:10:23 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0clangd=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ dslings/.clangd | 18 ++++++++++++++++++ dslings/xmake.lua | 7 ++++++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 dslings/.clangd diff --git a/.gitignore b/.gitignore index 5610391..21461c5 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ __pycache__ llm.config.xlings media build +.cache/ +dslings/compile_commands.json diff --git a/dslings/.clangd b/dslings/.clangd new file mode 100644 index 0000000..a764e5e --- /dev/null +++ b/dslings/.clangd @@ -0,0 +1,18 @@ +CompileFlags: + Add: + - "-I." + Remove: + - "-W*" + +Diagnostics: + ClangTidy: + Add: [] + Remove: ["*"] + +Index: + Background: Build + +InlayHints: + Enabled: Yes + ParameterNames: Yes + DeducedTypes: Yes diff --git a/dslings/xmake.lua b/dslings/xmake.lua index 9e617f0..14d69f7 100644 --- a/dslings/xmake.lua +++ b/dslings/xmake.lua @@ -4,7 +4,12 @@ if is_host("windows") then add_ldflags("-static") end -if d2x.private.mcpp.lang == "zh" then +local lang = "en" +if d2x and d2x.private and d2x.private.mcpp then + lang = d2x.private.mcpp.lang or "en" +end + +if lang == "zh" then add_includedirs(".") target("00-0-hello-mcpp") From f7b1f7ff0d639b754f994a944459cf2226285263 Mon Sep 17 00:00:00 2001 From: ExquisiteCore Date: Tue, 18 Nov 2025 00:29:24 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 20 ++++++++++++++++++++ README.zh.hant.md | 20 ++++++++++++++++++++ README.zh.md | 20 ++++++++++++++++++++ book/en/src/README.md | 20 ++++++++++++++++++++ book/src/README.md | 20 ++++++++++++++++++++ 5 files changed, 100 insertions(+) diff --git a/README.md b/README.md index a780575..b43e973 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,26 @@ cd mcpp-standard d2x checker ``` +#### Using Neovim Editor + +If you prefer to use Neovim as your editor with LSP support: + +```bash +# After cloning the project, navigate to dslings directory +cd mcpp-standard/dslings + +# Generate compile_commands.json for clangd +xmake project -k compile_commands + +# Open the directory with nvim +nvim . +``` + +Inside Neovim: +1. Open a terminal with `:terminal` +2. Navigate to project root: `cd ..` +3. Run the checker: `d2x checker` + **👉 [more details...](https://sunrisepeak.github.io/mcpp-standard/base/chapter_1.html)** ## Community diff --git a/README.zh.hant.md b/README.zh.hant.md index 02b0eb9..ef1629b 100644 --- a/README.zh.hant.md +++ b/README.zh.hant.md @@ -72,6 +72,26 @@ cd mcpp-standard d2x checker ``` +#### 使用Neovim編輯器 + +如果你希望使用Neovim編輯器並獲得LSP支援: + +```bash +# 複製專案後,進入dslings目錄 +cd mcpp-standard/dslings + +# 為clangd生成compile_commands.json +xmake project -k compile_commands + +# 使用nvim打開整個目錄 +nvim . +``` + +在Neovim中: +1. 使用 `:terminal` 打開終端 +2. 返回專案根目錄:`cd ..` +3. 執行檢測器:`d2x checker` + **👉 [更多細節...](https://sunrisepeak.github.io/mcpp-standard/base/chapter_1.html)** ## 社區 diff --git a/README.zh.md b/README.zh.md index d9caed5..dd854e0 100644 --- a/README.zh.md +++ b/README.zh.md @@ -72,6 +72,26 @@ cd mcpp-standard d2x checker ``` +#### 使用Neovim编辑器 + +如果你希望使用Neovim编辑器并获得LSP支持: + +```bash +# 克隆项目后,进入dslings目录 +cd mcpp-standard/dslings + +# 为clangd生成compile_commands.json +xmake project -k compile_commands + +# 使用nvim打开整个目录 +nvim . +``` + +在Neovim中: +1. 使用 `:terminal` 打开终端 +2. 返回项目根目录:`cd ..` +3. 运行检测器:`d2x checker` + **👉 [更多细节...](https://sunrisepeak.github.io/mcpp-standard/base/chapter_1.html)** ## 社区 diff --git a/book/en/src/README.md b/book/en/src/README.md index bb1cf1b..f0131cc 100644 --- a/book/en/src/README.md +++ b/book/en/src/README.md @@ -68,6 +68,26 @@ cd mcpp-standard d2x checker ``` +#### Using Neovim Editor + +If you prefer to use Neovim as your editor with LSP support: + +```bash +# After cloning the project, navigate to dslings directory +cd mcpp-standard/dslings + +# Generate compile_commands.json for clangd +xmake project -k compile_commands + +# Open the directory with nvim +nvim . +``` + +Inside Neovim: +1. Open a terminal with `:terminal` +2. Navigate to project root: `cd ..` +3. Run the checker: `d2x checker` + **👉 [more details...](https://sunrisepeak.github.io/mcpp-standard/en/base/chapter_1.html)** ## Community diff --git a/book/src/README.md b/book/src/README.md index 8677bbe..71d214e 100644 --- a/book/src/README.md +++ b/book/src/README.md @@ -68,6 +68,26 @@ cd mcpp-standard d2x checker ``` +#### 使用Neovim编辑器 + +如果你希望使用Neovim编辑器并获得LSP支持: + +```bash +# 克隆项目后,进入dslings目录 +cd mcpp-standard/dslings + +# 为clangd生成compile_commands.json +xmake project -k compile_commands + +# 使用nvim打开整个目录 +nvim . +``` + +在Neovim中: +1. 使用 `:terminal` 打开终端 +2. 返回项目根目录:`cd ..` +3. 运行检测器:`d2x checker` + **👉 [更多细节...](https://sunrisepeak.github.io/mcpp-standard/base/chapter_1.html)** ## 社区 From fb5ef1315fc17011f4c413f0efed127fc6dca3a4 Mon Sep 17 00:00:00 2001 From: ExquisiteCore Date: Tue, 18 Nov 2025 00:34:55 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ README.zh.hant.md | 3 +++ README.zh.md | 3 +++ book/en/src/README.md | 3 +++ book/src/README.md | 3 +++ 5 files changed, 15 insertions(+) diff --git a/README.md b/README.md index b43e973..7cbc344 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,9 @@ cd mcpp-standard/dslings # Generate compile_commands.json for clangd xmake project -k compile_commands +# Comment out the editor line in config.xlings +# Open mcpp-standard/config.xlings and comment out: editor = "vscode", + # Open the directory with nvim nvim . ``` diff --git a/README.zh.hant.md b/README.zh.hant.md index ef1629b..42d2916 100644 --- a/README.zh.hant.md +++ b/README.zh.hant.md @@ -83,6 +83,9 @@ cd mcpp-standard/dslings # 為clangd生成compile_commands.json xmake project -k compile_commands +# 註解掉config.xlings中的editor設定 +# 開啟mcpp-standard/config.xlings並註解掉:editor = "vscode", + # 使用nvim打開整個目錄 nvim . ``` diff --git a/README.zh.md b/README.zh.md index dd854e0..6127754 100644 --- a/README.zh.md +++ b/README.zh.md @@ -83,6 +83,9 @@ cd mcpp-standard/dslings # 为clangd生成compile_commands.json xmake project -k compile_commands +# 注释掉config.xlings中的editor配置 +# 打开mcpp-standard/config.xlings并注释掉:editor = "vscode", + # 使用nvim打开整个目录 nvim . ``` diff --git a/book/en/src/README.md b/book/en/src/README.md index f0131cc..44f1084 100644 --- a/book/en/src/README.md +++ b/book/en/src/README.md @@ -79,6 +79,9 @@ cd mcpp-standard/dslings # Generate compile_commands.json for clangd xmake project -k compile_commands +# Comment out the editor line in config.xlings +# Open mcpp-standard/config.xlings and comment out: editor = "vscode", + # Open the directory with nvim nvim . ``` diff --git a/book/src/README.md b/book/src/README.md index 71d214e..bd355f4 100644 --- a/book/src/README.md +++ b/book/src/README.md @@ -79,6 +79,9 @@ cd mcpp-standard/dslings # 为clangd生成compile_commands.json xmake project -k compile_commands +# 注释掉config.xlings中的editor配置 +# 打开mcpp-standard/config.xlings并注释掉:editor = "vscode", + # 使用nvim打开整个目录 nvim . ``` From 279bbb3f83c5a464e1cfeaaab8080a8184b15b68 Mon Sep 17 00:00:00 2001 From: ExquisiteCore Date: Tue, 18 Nov 2025 08:40:14 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E5=88=A0=E9=99=A4.clangd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dslings/.clangd | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 dslings/.clangd diff --git a/dslings/.clangd b/dslings/.clangd deleted file mode 100644 index a764e5e..0000000 --- a/dslings/.clangd +++ /dev/null @@ -1,18 +0,0 @@ -CompileFlags: - Add: - - "-I." - Remove: - - "-W*" - -Diagnostics: - ClangTidy: - Add: [] - Remove: ["*"] - -Index: - Background: Build - -InlayHints: - Enabled: Yes - ParameterNames: Yes - DeducedTypes: Yes From 38e44e2966c66f8565f39ac4ecef79ed5da53d59 Mon Sep 17 00:00:00 2001 From: ExquisiteCore Date: Tue, 18 Nov 2025 08:49:51 +0800 Subject: [PATCH 05/12] =?UTF-8?q?Revert=20"=E6=9B=B4=E6=96=B0README"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit fb5ef1315fc17011f4c413f0efed127fc6dca3a4. --- README.md | 3 --- README.zh.hant.md | 3 --- README.zh.md | 3 --- book/en/src/README.md | 3 --- book/src/README.md | 3 --- 5 files changed, 15 deletions(-) diff --git a/README.md b/README.md index 7cbc344..b43e973 100644 --- a/README.md +++ b/README.md @@ -83,9 +83,6 @@ cd mcpp-standard/dslings # Generate compile_commands.json for clangd xmake project -k compile_commands -# Comment out the editor line in config.xlings -# Open mcpp-standard/config.xlings and comment out: editor = "vscode", - # Open the directory with nvim nvim . ``` diff --git a/README.zh.hant.md b/README.zh.hant.md index 42d2916..ef1629b 100644 --- a/README.zh.hant.md +++ b/README.zh.hant.md @@ -83,9 +83,6 @@ cd mcpp-standard/dslings # 為clangd生成compile_commands.json xmake project -k compile_commands -# 註解掉config.xlings中的editor設定 -# 開啟mcpp-standard/config.xlings並註解掉:editor = "vscode", - # 使用nvim打開整個目錄 nvim . ``` diff --git a/README.zh.md b/README.zh.md index 6127754..dd854e0 100644 --- a/README.zh.md +++ b/README.zh.md @@ -83,9 +83,6 @@ cd mcpp-standard/dslings # 为clangd生成compile_commands.json xmake project -k compile_commands -# 注释掉config.xlings中的editor配置 -# 打开mcpp-standard/config.xlings并注释掉:editor = "vscode", - # 使用nvim打开整个目录 nvim . ``` diff --git a/book/en/src/README.md b/book/en/src/README.md index 44f1084..f0131cc 100644 --- a/book/en/src/README.md +++ b/book/en/src/README.md @@ -79,9 +79,6 @@ cd mcpp-standard/dslings # Generate compile_commands.json for clangd xmake project -k compile_commands -# Comment out the editor line in config.xlings -# Open mcpp-standard/config.xlings and comment out: editor = "vscode", - # Open the directory with nvim nvim . ``` diff --git a/book/src/README.md b/book/src/README.md index bd355f4..71d214e 100644 --- a/book/src/README.md +++ b/book/src/README.md @@ -79,9 +79,6 @@ cd mcpp-standard/dslings # 为clangd生成compile_commands.json xmake project -k compile_commands -# 注释掉config.xlings中的editor配置 -# 打开mcpp-standard/config.xlings并注释掉:editor = "vscode", - # 使用nvim打开整个目录 nvim . ``` From 1f1736fbaa2fd95589090e9874de10c48699060f Mon Sep 17 00:00:00 2001 From: ExquisiteCore Date: Tue, 18 Nov 2025 08:50:19 +0800 Subject: [PATCH 06/12] =?UTF-8?q?Revert=20"=E6=9B=B4=E6=96=B0README"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f7b1f7ff0d639b754f994a944459cf2226285263. --- README.md | 20 -------------------- README.zh.hant.md | 20 -------------------- README.zh.md | 20 -------------------- book/en/src/README.md | 20 -------------------- book/src/README.md | 20 -------------------- 5 files changed, 100 deletions(-) diff --git a/README.md b/README.md index b43e973..a780575 100644 --- a/README.md +++ b/README.md @@ -72,26 +72,6 @@ cd mcpp-standard d2x checker ``` -#### Using Neovim Editor - -If you prefer to use Neovim as your editor with LSP support: - -```bash -# After cloning the project, navigate to dslings directory -cd mcpp-standard/dslings - -# Generate compile_commands.json for clangd -xmake project -k compile_commands - -# Open the directory with nvim -nvim . -``` - -Inside Neovim: -1. Open a terminal with `:terminal` -2. Navigate to project root: `cd ..` -3. Run the checker: `d2x checker` - **👉 [more details...](https://sunrisepeak.github.io/mcpp-standard/base/chapter_1.html)** ## Community diff --git a/README.zh.hant.md b/README.zh.hant.md index ef1629b..02b0eb9 100644 --- a/README.zh.hant.md +++ b/README.zh.hant.md @@ -72,26 +72,6 @@ cd mcpp-standard d2x checker ``` -#### 使用Neovim編輯器 - -如果你希望使用Neovim編輯器並獲得LSP支援: - -```bash -# 複製專案後,進入dslings目錄 -cd mcpp-standard/dslings - -# 為clangd生成compile_commands.json -xmake project -k compile_commands - -# 使用nvim打開整個目錄 -nvim . -``` - -在Neovim中: -1. 使用 `:terminal` 打開終端 -2. 返回專案根目錄:`cd ..` -3. 執行檢測器:`d2x checker` - **👉 [更多細節...](https://sunrisepeak.github.io/mcpp-standard/base/chapter_1.html)** ## 社區 diff --git a/README.zh.md b/README.zh.md index dd854e0..d9caed5 100644 --- a/README.zh.md +++ b/README.zh.md @@ -72,26 +72,6 @@ cd mcpp-standard d2x checker ``` -#### 使用Neovim编辑器 - -如果你希望使用Neovim编辑器并获得LSP支持: - -```bash -# 克隆项目后,进入dslings目录 -cd mcpp-standard/dslings - -# 为clangd生成compile_commands.json -xmake project -k compile_commands - -# 使用nvim打开整个目录 -nvim . -``` - -在Neovim中: -1. 使用 `:terminal` 打开终端 -2. 返回项目根目录:`cd ..` -3. 运行检测器:`d2x checker` - **👉 [更多细节...](https://sunrisepeak.github.io/mcpp-standard/base/chapter_1.html)** ## 社区 diff --git a/book/en/src/README.md b/book/en/src/README.md index f0131cc..bb1cf1b 100644 --- a/book/en/src/README.md +++ b/book/en/src/README.md @@ -68,26 +68,6 @@ cd mcpp-standard d2x checker ``` -#### Using Neovim Editor - -If you prefer to use Neovim as your editor with LSP support: - -```bash -# After cloning the project, navigate to dslings directory -cd mcpp-standard/dslings - -# Generate compile_commands.json for clangd -xmake project -k compile_commands - -# Open the directory with nvim -nvim . -``` - -Inside Neovim: -1. Open a terminal with `:terminal` -2. Navigate to project root: `cd ..` -3. Run the checker: `d2x checker` - **👉 [more details...](https://sunrisepeak.github.io/mcpp-standard/en/base/chapter_1.html)** ## Community diff --git a/book/src/README.md b/book/src/README.md index 71d214e..8677bbe 100644 --- a/book/src/README.md +++ b/book/src/README.md @@ -68,26 +68,6 @@ cd mcpp-standard d2x checker ``` -#### 使用Neovim编辑器 - -如果你希望使用Neovim编辑器并获得LSP支持: - -```bash -# 克隆项目后,进入dslings目录 -cd mcpp-standard/dslings - -# 为clangd生成compile_commands.json -xmake project -k compile_commands - -# 使用nvim打开整个目录 -nvim . -``` - -在Neovim中: -1. 使用 `:terminal` 打开终端 -2. 返回项目根目录:`cd ..` -3. 运行检测器:`d2x checker` - **👉 [更多细节...](https://sunrisepeak.github.io/mcpp-standard/base/chapter_1.html)** ## 社区 From f24dcd6122980554fe04c02c1f9451ae076a29e4 Mon Sep 17 00:00:00 2001 From: ExquisiteCore Date: Tue, 18 Nov 2025 09:01:35 +0800 Subject: [PATCH 07/12] docs: update chapter_1 in EN and CN versions --- book/en/src/base/chapter_1.md | 51 ++++++++++++++++++++++++++++++++++- book/src/base/chapter_1.md | 51 ++++++++++++++++++++++++++++++++++- 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/book/en/src/base/chapter_1.md b/book/en/src/base/chapter_1.md index 267fdf2..a9f38c2 100644 --- a/book/en/src/base/chapter_1.md +++ b/book/en/src/base/chapter_1.md @@ -149,7 +149,9 @@ dslings/hello-mcpp.cpp -->> Current detected file Homepage: https://github.com/d2learn/xlings ``` -## 3. Configure Project Language +## 3. Configure Project (Optional) + +### Configure Language Edit the `lang` attribute in the project configuration file `config.xlings`. `zh` corresponds to Chinese, and `en` corresponds to English. @@ -165,6 +167,53 @@ Edit the `lang` attribute in the project configuration file `config.xlings`. `zh } ``` +### Custom Editor - Using nvim as Example + +The project includes a `.clangd` configuration file in the root directory, supporting code editing and completion with nvim + clangd. + +**Configuration Details:** + +The `.clangd` configuration in the project root directory: + +```yaml +CompileFlags: + Add: + - "-Idslings" # Add dslings as include path + - "-std=c++20" # Use C++20 standard + Remove: + - "-W*" # Remove warning flags + +Diagnostics: + ClangTidy: + Add: [] + Remove: ["*"] +``` + +**Usage:** + +1. Open files directly from the project root directory: + ```bash + cd mcpp-standard + nvim dslings/hello-mcpp.cpp + ``` + +2. If clangd fails to recognize code properly, restart LSP in nvim: + ```vim + :LspRestart + ``` + +3. Check LSP status: + ```vim + :LspInfo " Check if clangd is running properly + :LspLog " View detailed logs + ``` + +**Benefits:** + +- No need to manually generate `compile_commands.json` +- Unified project configuration, set once and work everywhere +- Support for code completion, go to definition, error diagnostics, and more + ## 4. Resources and Communication **Communication Group (Q):** 167535744 diff --git a/book/src/base/chapter_1.md b/book/src/base/chapter_1.md index d38cc44..479a499 100644 --- a/book/src/base/chapter_1.md +++ b/book/src/base/chapter_1.md @@ -147,7 +147,9 @@ dslings/hello-mcpp.cpp -->> 当前检测的文件 Homepage: https://github.com/d2learn/xlings ``` -## 3.配置项目语言 +## 3.配置项目(可选) + +### 配置语言 编辑项目配置文件`config.xlings`中的`lang`属性, `zh`对应中文, `en`对应英文 @@ -163,6 +165,53 @@ Homepage: https://github.com/d2learn/xlings } ``` +### 自定义编辑器 - 以nvim编辑器为例 + +项目已在根目录配置了 `.clangd` 文件,支持使用 nvim + clangd 进行代码编辑和补全。 + +**配置说明:** + +项目根目录的 `.clangd` 配置如下: + +```yaml +CompileFlags: + Add: + - "-Idslings" # 添加 dslings 为包含路径 + - "-std=c++20" # 使用 C++20 标准 + Remove: + - "-W*" # 移除警告标志 + +Diagnostics: + ClangTidy: + Add: [] + Remove: ["*"] +``` + +**使用方法:** + +1. 直接在项目根目录打开文件: + ```bash + cd mcpp-standard + nvim dslings/hello-mcpp.cpp + ``` + +2. 如果 clangd 未能正确识别代码,在 nvim 中重启 LSP: + ```vim + :LspRestart + ``` + +3. 检查 LSP 状态: + ```vim + :LspInfo " 查看 clangd 是否正常启动 + :LspLog " 查看详细日志 + ``` + +**优势:** + +- 无需手动生成 `compile_commands.json` +- 统一的项目配置,一次设置全局生效 +- 支持代码补全、跳转定义、错误提示等功能 + ## 4.资源于交流 **交流群(Q):** 167535744 From d44700c1f242bc8f5d6f56fcbaca1c7f6a28b625 Mon Sep 17 00:00:00 2001 From: ExquisiteCore Date: Tue, 18 Nov 2025 09:01:56 +0800 Subject: [PATCH 08/12] docs: update chapter_1 in EN and CN version --- book/en/src/base/chapter_1.md | 49 +++++++++++------------------------ book/src/base/chapter_1.md | 49 +++++++++++------------------------ 2 files changed, 30 insertions(+), 68 deletions(-) diff --git a/book/en/src/base/chapter_1.md b/book/en/src/base/chapter_1.md index a9f38c2..94f8366 100644 --- a/book/en/src/base/chapter_1.md +++ b/book/en/src/base/chapter_1.md @@ -169,50 +169,31 @@ Edit the `lang` attribute in the project configuration file `config.xlings`. `zh ### Custom Editor - Using nvim as Example -The project includes a `.clangd` configuration file in the root directory, supporting code editing and completion with nvim + clangd. +If you prefer to use Neovim as your editor with LSP (clangd) support: -**Configuration Details:** +**Usage Steps:** -The `.clangd` configuration in the project root directory: - -```yaml -CompileFlags: - Add: - - "-Idslings" # Add dslings as include path - - "-std=c++20" # Use C++20 standard - Remove: - - "-W*" # Remove warning flags - -Diagnostics: - ClangTidy: - Add: [] - Remove: ["*"] -``` - -**Usage:** - -1. Open files directly from the project root directory: +1. From the project root directory, navigate to dslings and generate compilation database: ```bash - cd mcpp-standard - nvim dslings/hello-mcpp.cpp + cd dslings + xmake project -k compile_commands + cd .. ``` -2. If clangd fails to recognize code properly, restart LSP in nvim: - ```vim - :LspRestart +2. Open the entire project with nvim from the project root directory: + ```bash + nvim . ``` -3. Check LSP status: +3. Open a terminal inside nvim and run the code checker: ```vim - :LspInfo " Check if clangd is running properly - :LspLog " View detailed logs + :terminal ``` -**Benefits:** - -- No need to manually generate `compile_commands.json` -- Unified project configuration, set once and work everywhere -- Support for code completion, go to definition, error diagnostics, and more + In the terminal, execute: + ```bash + d2x checker + ``` ## 4. Resources and Communication diff --git a/book/src/base/chapter_1.md b/book/src/base/chapter_1.md index 479a499..34e2ef5 100644 --- a/book/src/base/chapter_1.md +++ b/book/src/base/chapter_1.md @@ -167,50 +167,31 @@ Homepage: https://github.com/d2learn/xlings ### 自定义编辑器 - 以nvim编辑器为例 -项目已在根目录配置了 `.clangd` 文件,支持使用 nvim + clangd 进行代码编辑和补全。 +如果你希望使用 Neovim 编辑器并获得 LSP(clangd)支持: -**配置说明:** +**使用步骤:** -项目根目录的 `.clangd` 配置如下: - -```yaml -CompileFlags: - Add: - - "-Idslings" # 添加 dslings 为包含路径 - - "-std=c++20" # 使用 C++20 标准 - Remove: - - "-W*" # 移除警告标志 - -Diagnostics: - ClangTidy: - Add: [] - Remove: ["*"] -``` - -**使用方法:** - -1. 直接在项目根目录打开文件: +1. 在项目根目录,进入 dslings 目录生成编译数据库: ```bash - cd mcpp-standard - nvim dslings/hello-mcpp.cpp + cd dslings + xmake project -k compile_commands + cd .. ``` -2. 如果 clangd 未能正确识别代码,在 nvim 中重启 LSP: - ```vim - :LspRestart +2. 在项目根目录使用 nvim 打开整个项目: + ```bash + nvim . ``` -3. 检查 LSP 状态: +3. 在 nvim 中打开终端并运行代码检测: ```vim - :LspInfo " 查看 clangd 是否正常启动 - :LspLog " 查看详细日志 + :terminal ``` -**优势:** - -- 无需手动生成 `compile_commands.json` -- 统一的项目配置,一次设置全局生效 -- 支持代码补全、跳转定义、错误提示等功能 + 在终端中执行: + ```bash + d2x checker + ``` ## 4.资源于交流 From 04feee9fff76cfa1124a6f854eb0691d98a8f805 Mon Sep 17 00:00:00 2001 From: ExquisiteCore Date: Tue, 18 Nov 2025 18:56:43 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0config.xlings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.xlings | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config.xlings b/config.xlings index b9596b2..f7f96be 100644 --- a/config.xlings +++ b/config.xlings @@ -5,6 +5,9 @@ xim = { vscode = "", cpp = "", -- language:[windows:mingw], [linux:gcc], [macos:clang] mdbook = "0.4.43", -- for d2x book + xppcmds = { + "xmake project -k compile_commands --project=dslings" + } } d2x = { From 9a4976c22a78fd69c1b3d9759c6d269fbc340032 Mon Sep 17 00:00:00 2001 From: ExquisiteCore Date: Tue, 18 Nov 2025 18:57:45 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- book/en/src/base/chapter_1.md | 2 +- book/src/base/chapter_1.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/book/en/src/base/chapter_1.md b/book/en/src/base/chapter_1.md index 94f8366..1b47901 100644 --- a/book/en/src/base/chapter_1.md +++ b/book/en/src/base/chapter_1.md @@ -173,7 +173,7 @@ If you prefer to use Neovim as your editor with LSP (clangd) support: **Usage Steps:** -1. From the project root directory, navigate to dslings and generate compilation database: +1. The compilation database will be automatically generated during project installation (via `xlings install` command). To manually regenerate: ```bash cd dslings xmake project -k compile_commands diff --git a/book/src/base/chapter_1.md b/book/src/base/chapter_1.md index 34e2ef5..a8640c1 100644 --- a/book/src/base/chapter_1.md +++ b/book/src/base/chapter_1.md @@ -171,7 +171,7 @@ Homepage: https://github.com/d2learn/xlings **使用步骤:** -1. 在项目根目录,进入 dslings 目录生成编译数据库: +1. 编译数据库会在项目安装时自动生成(通过 `xlings install` 命令)。如需手动重新生成: ```bash cd dslings xmake project -k compile_commands From 7b82b532378c16cb67d54d3690432c09b6a827e6 Mon Sep 17 00:00:00 2001 From: SPeak Date: Wed, 19 Nov 2025 01:21:43 +0800 Subject: [PATCH 11/12] add support for nvim and zed --- config.xlings | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/config.xlings b/config.xlings index f7f96be..b42e6cf 100644 --- a/config.xlings +++ b/config.xlings @@ -1,8 +1,10 @@ +-- https://xlings.d2learn.org + xname = "mcpp-standard" -- project name -- xim-deps xim = { - vscode = "", + vscode = "", -- config by checker.editor cpp = "", -- language:[windows:mingw], [linux:gcc], [macos:clang] mdbook = "0.4.43", -- for d2x book xppcmds = { @@ -13,7 +15,7 @@ xim = { d2x = { checker = { name = "dslings", - editor = "vscode", + editor = "vscode", -- option: vscode, nvim, zed }, commands = { @@ -32,4 +34,5 @@ d2x = { }, } +xim[d2x.checker.editor or "vscode"] = "" -- config deps(default version --xlings_llm_config = "llm.config.xlings" From da733119a5215244aa8d5b7dc6dd4aba7ea86fc8 Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Wed, 19 Nov 2025 02:53:29 +0800 Subject: [PATCH 12/12] optimize editor config to support nvim and zed --- book/en/src/base/chapter_1.md | 47 ++++++++++++++++------------------- book/src/base/chapter_1.md | 46 ++++++++++++++++------------------ 2 files changed, 43 insertions(+), 50 deletions(-) diff --git a/book/en/src/base/chapter_1.md b/book/en/src/base/chapter_1.md index 1b47901..51fe36c 100644 --- a/book/en/src/base/chapter_1.md +++ b/book/en/src/base/chapter_1.md @@ -169,31 +169,28 @@ Edit the `lang` attribute in the project configuration file `config.xlings`. `zh ### Custom Editor - Using nvim as Example -If you prefer to use Neovim as your editor with LSP (clangd) support: - -**Usage Steps:** - -1. The compilation database will be automatically generated during project installation (via `xlings install` command). To manually regenerate: - ```bash - cd dslings - xmake project -k compile_commands - cd .. - ``` - -2. Open the entire project with nvim from the project root directory: - ```bash - nvim . - ``` - -3. Open a terminal inside nvim and run the code checker: - ```vim - :terminal - ``` - - In the terminal, execute: - ```bash - d2x checker - ``` +If you prefer to use Neovim as your editor with LSP (clangd) support, you can configure it as follows: + +**1. Edit the `editor` attribute in the project configuration file `config.xlings` and set it to `nvim` (or `zed`)** + +```bash +d2x = { + checker = { + name = "dslings", + editor = "nvim", -- option: vscode, nvim, zed + }, +``` + +**2. Run the one-click dependency installation and environment configuration command in the project root directory** + +```bash +xlings install +``` + +**3. In the project directory, rerun the detection command `d2x checker` to open the corresponding exercise file with Neovim, which will support automatic exercise navigation/switching** + +> Note: In Neovim, the "real-time detection feature" is triggered by the `:w` command. That is, after modifying the code, saving the file in Neovim's command-line mode (`:w`) will prompt `d2x` to update the detection results. + ## 4. Resources and Communication diff --git a/book/src/base/chapter_1.md b/book/src/base/chapter_1.md index a8640c1..1af941f 100644 --- a/book/src/base/chapter_1.md +++ b/book/src/base/chapter_1.md @@ -167,31 +167,27 @@ Homepage: https://github.com/d2learn/xlings ### 自定义编辑器 - 以nvim编辑器为例 -如果你希望使用 Neovim 编辑器并获得 LSP(clangd)支持: - -**使用步骤:** - -1. 编译数据库会在项目安装时自动生成(通过 `xlings install` 命令)。如需手动重新生成: - ```bash - cd dslings - xmake project -k compile_commands - cd .. - ``` - -2. 在项目根目录使用 nvim 打开整个项目: - ```bash - nvim . - ``` - -3. 在 nvim 中打开终端并运行代码检测: - ```vim - :terminal - ``` - - 在终端中执行: - ```bash - d2x checker - ``` +如果你希望使用 Neovim 编辑器并获得 LSP(clangd)支持, 可以按如下步骤进行配置 + +**1.编辑项目配置文件`config.xlings`中的`editor`属性, 设置为`nvim` (或`zed`)** + +```bash +d2x = { + checker = { + name = "dslings", + editor = "nvim", -- option: vscode, nvim, zed + }, +``` + +**2.在项目根目录运行一键依赖安装和环境配置命令** + +```bash +xlings install +``` + +**3.在项目目录, 重新运行检测命令 `d2x checker` 就会使用nvim打开对应练习文件, 并具备练习自动跳转/切换功能** + +> 注: nvim编辑器下的"实时检测功能"的触发时机, 将会对应到 `:w` 命令. 即修改代码后, 在nvim的命令行模式对文件进行保存(`:w`)时, d2x就会更新检测结果 ## 4.资源于交流