Skip to content

Commit 6e69f75

Browse files
#12 添加clangd的支持 (#23)
* 添加clangd支持 * 更新README * 更新README * 删除.clangd * Revert "更新README" This reverts commit fb5ef13. * Revert "更新README" This reverts commit f7b1f7f. * docs: update chapter_1 in EN and CN versions * docs: update chapter_1 in EN and CN version * 更新config.xlings * 更新文档 * add support for nvim and zed * optimize editor config to support nvim and zed --------- Co-authored-by: SPeak <[email protected]>
1 parent 507e780 commit 6e69f75

File tree

5 files changed

+71
-5
lines changed

5 files changed

+71
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ __pycache__
4242
llm.config.xlings
4343
media
4444
build
45+
.cache/
46+
dslings/compile_commands.json

book/en/src/base/chapter_1.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ dslings/hello-mcpp.cpp -->> Current detected file
149149
Homepage: https://github.com/d2learn/xlings
150150
```
151151

152-
## 3. Configure Project Language
152+
## 3. Configure Project (Optional)
153+
154+
### Configure Language
153155

154156
Edit the `lang` attribute in the project configuration file `config.xlings`. `zh` corresponds to Chinese, and `en` corresponds to English.
155157

@@ -165,6 +167,31 @@ Edit the `lang` attribute in the project configuration file `config.xlings`. `zh
165167
}
166168
```
167169

170+
### Custom Editor - Using nvim as Example
171+
172+
If you prefer to use Neovim as your editor with LSP (clangd) support, you can configure it as follows:
173+
174+
**1. Edit the `editor` attribute in the project configuration file `config.xlings` and set it to `nvim` (or `zed`)**
175+
176+
```bash
177+
d2x = {
178+
checker = {
179+
name = "dslings",
180+
editor = "nvim", -- option: vscode, nvim, zed
181+
},
182+
```
183+
184+
**2. Run the one-click dependency installation and environment configuration command in the project root directory**
185+
186+
```bash
187+
xlings install
188+
```
189+
190+
**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**
191+
192+
> 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.
193+
194+
168195
## 4. Resources and Communication
169196
170197
**Communication Group (Q):** 167535744

book/src/base/chapter_1.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ dslings/hello-mcpp.cpp -->> 当前检测的文件
147147
Homepage: https://github.com/d2learn/xlings
148148
```
149149

150-
## 3.配置项目语言
150+
## 3.配置项目(可选)
151+
152+
### 配置语言
151153

152154
编辑项目配置文件`config.xlings`中的`lang`属性, `zh`对应中文, `en`对应英文
153155

@@ -163,6 +165,30 @@ Homepage: https://github.com/d2learn/xlings
163165
}
164166
```
165167

168+
### 自定义编辑器 - 以nvim编辑器为例
169+
170+
如果你希望使用 Neovim 编辑器并获得 LSP(clangd)支持, 可以按如下步骤进行配置
171+
172+
**1.编辑项目配置文件`config.xlings`中的`editor`属性, 设置为`nvim` (或`zed`)**
173+
174+
```bash
175+
d2x = {
176+
checker = {
177+
name = "dslings",
178+
editor = "nvim", -- option: vscode, nvim, zed
179+
},
180+
```
181+
182+
**2.在项目根目录运行一键依赖安装和环境配置命令**
183+
184+
```bash
185+
xlings install
186+
```
187+
188+
**3.在项目目录, 重新运行检测命令 `d2x checker` 就会使用nvim打开对应练习文件, 并具备练习自动跳转/切换功能**
189+
190+
> 注: nvim编辑器下的"实时检测功能"的触发时机, 将会对应到 `:w` 命令. 即修改代码后, 在nvim的命令行模式对文件进行保存(`:w`)时, d2x就会更新检测结果
191+
166192
## 4.资源于交流
167193
168194
**交流群(Q):** 167535744

config.xlings

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
-- https://xlings.d2learn.org
2+
13
xname = "mcpp-standard" -- project name
24

35
-- xim-deps
46
xim = {
5-
vscode = "",
7+
vscode = "", -- config by checker.editor
68
cpp = "", -- language:[windows:mingw], [linux:gcc], [macos:clang]
79
mdbook = "0.4.43", -- for d2x book
10+
xppcmds = {
11+
"xmake project -k compile_commands --project=dslings"
12+
}
813
}
914

1015
d2x = {
1116
checker = {
1217
name = "dslings",
13-
editor = "vscode",
18+
editor = "vscode", -- option: vscode, nvim, zed
1419
},
1520

1621
commands = {
@@ -29,4 +34,5 @@ d2x = {
2934
},
3035
}
3136

37+
xim[d2x.checker.editor or "vscode"] = "" -- config deps(default version
3238
--xlings_llm_config = "llm.config.xlings"

dslings/xmake.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ if is_host("windows") then
44
add_ldflags("-static")
55
end
66

7-
if d2x.private.mcpp.lang == "zh" then
7+
local lang = "en"
8+
if d2x and d2x.private and d2x.private.mcpp then
9+
lang = d2x.private.mcpp.lang or "en"
10+
end
11+
12+
if lang == "zh" then
813
add_includedirs(".")
914

1015
target("00-0-hello-mcpp")

0 commit comments

Comments
 (0)