Skip to content
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ __pycache__
llm.config.xlings
media
build
.cache/
dslings/compile_commands.json
29 changes: 28 additions & 1 deletion book/en/src/base/chapter_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -165,6 +167,31 @@ 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, 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

**Communication Group (Q):** 167535744
Expand Down
28 changes: 27 additions & 1 deletion book/src/base/chapter_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ dslings/hello-mcpp.cpp -->> 当前检测的文件
Homepage: https://github.com/d2learn/xlings
```

## 3.配置项目语言
## 3.配置项目(可选)

### 配置语言

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

Expand All @@ -163,6 +165,30 @@ Homepage: https://github.com/d2learn/xlings
}
```

### 自定义编辑器 - 以nvim编辑器为例

如果你希望使用 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.资源于交流

**交流群(Q):** 167535744
Expand Down
10 changes: 8 additions & 2 deletions config.xlings
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
-- 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 = {
"xmake project -k compile_commands --project=dslings"
}
}

d2x = {
checker = {
name = "dslings",
editor = "vscode",
editor = "vscode", -- option: vscode, nvim, zed
},

commands = {
Expand All @@ -29,4 +34,5 @@ d2x = {
},
}

xim[d2x.checker.editor or "vscode"] = "" -- config deps(default version
--xlings_llm_config = "llm.config.xlings"
7 changes: 6 additions & 1 deletion dslings/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down