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/book/en/src/base/chapter_1.md b/book/en/src/base/chapter_1.md index 267fdf2..51fe36c 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,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 diff --git a/book/src/base/chapter_1.md b/book/src/base/chapter_1.md index d38cc44..1af941f 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,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 diff --git a/config.xlings b/config.xlings index b9596b2..b42e6cf 100644 --- a/config.xlings +++ b/config.xlings @@ -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 = { @@ -29,4 +34,5 @@ d2x = { }, } +xim[d2x.checker.editor or "vscode"] = "" -- config deps(default version --xlings_llm_config = "llm.config.xlings" 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")