Add some util for neovim developing, and switch default compile toolchain#47
Add some util for neovim developing, and switch default compile toolchain#47creeper5820 merged 2 commits intomainfrom
Conversation
概览该改动调整开发环境配置,删除了环境变量中的 Neovim 目录,更新了 Docker Compose 挂载点,优化了构建脚本,并添加了新的容器管理脚本用于快速启动开发环境和 Neovim 编辑器。 变更
序列图sequenceDiagram
participant User
participant rmcs_nvim as rmcs (nvim)
participant Docker as Docker Compose
participant Container
participant Neovim
participant Neovide
User->>rmcs_nvim: 执行 rmcs nvim 命令
rmcs_nvim->>Docker: 启动容器服务
Docker->>Container: 容器启动
rmcs_nvim->>rmcs_nvim: 从基础端口开始扫描可用端口
loop 端口探测
rmcs_nvim->>Container: 尝试连接端口
end
rmcs_nvim->>Container: 在可用端口启动 Neovim (headless)
Container->>Neovim: Neovim 启动并监听端口
rmcs_nvim->>rmcs_nvim: 等待端口就绪 (最长10秒)
rmcs_nvim->>Neovide: 连接到 Neovim 端口
Neovide->>User: 显示 Neovim UI
代码审查工作量评估🎯 3 (中等) | ⏱️ ~20 分钟 建议审查人员
诗
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @.script/launch/rmcs:
- Around line 35-38: 当前从 NVIM_PORT 起循环探测端口(在 while nc -z "$NVIM_HOST" "$port"
... 中)没有上限,会在连续被占用时无限循环;为修复,添加一个上限检查(例如 MAX_PORT 或 MAX_ATTEMPTS)并在每次循环判断 port <=
MAX_PORT 或尝试次数未超出,若超出则打印错误(包括试图的起始端口和最大尝试数)并退出非零;修改涉及的标识符为 NVIM_PORT / NVIM_HOST
/ port / while nc -z 循环及相应的退出处理逻辑。
In `@docker-compose.yml`:
- Line 9: The docker-compose volume currently mounts the entire host ~/.config/
into the container via the line "~/.config/:${CONTAINER_HOME}/.config/:bind",
which is too broad and exposes sensitive host configs; replace that broad mount
with explicit per-app mounts (e.g., use the existing ${HOST_NVIM_DIR} for Neovim
-> "${HOST_NVIM_DIR}:${CONTAINER_HOME}/.config/nvim:bind") and add other
specific mounts only as needed (for example lazygit config) instead of mounting
~/.config/ wholesale; update the volume entry that contains
"~/.config/:${CONTAINER_HOME}/.config/:bind" to the targeted mounts.
🧹 Nitpick comments (3)
.script/build-rmcs (1)
1-16: 整体改进合理,脚本更加健壮。 👍路径引用、条件编译器检测、Ninja 生成器切换都处理得当。
一个小建议:
CC和CXX是独立检测的,理论上可能出现只有其中一个可用的情况,导致混合编译器配置。可以考虑将两者作为一组来设置:♻️ 可选改进
-command -v clang &>/dev/null && - export CC=clang - -command -v clang++ &>/dev/null && - export CXX=clang++ +if command -v clang &>/dev/null && command -v clang++ &>/dev/null; then + export CC=clang + export CXX=clang++ +fi.script/launch/rmcs (2)
41-42: Neovim headless 监听地址建议使用0.0.0.0或确认 host 网络模式。当前脚本在容器内让 Neovim 监听
localhost:$port。这依赖于docker-compose.yml中network_mode: host的配置才能从宿主机连接。如果将来网络模式改变,宿主机上的 neovide 将无法连接到容器内的 Neovim。建议在脚本中添加注释说明此依赖关系,或考虑监听0.0.0.0。
18-23:rmcs_zsh在退出 zsh 后容器仍在后台运行。
docker compose up -d启动容器后,用户退出zsh后容器不会自动停止。如果这是有意为之(允许多个会话连接),建议在帮助信息中说明如何手动停止容器。
|
@qzhhhi REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW |
qzhhhi
left a comment
There was a problem hiding this comment.
neovim 的相关代码和切换默认工具链不应该在单个 commit 里一起提交。
拆成两个 commit。
另:用一下约定式提交吧,可以参考 librmcs
qzhhhi
left a comment
There was a problem hiding this comment.
neovim 的相关代码和切换默认工具链不应该在单个 commit 里一起提交。
拆成两个 commit。 <<< 这个还没做
另外,.script/launch/rmcs 这个文件的位置很尴尬,对于使用者来说,launch-rmcs 和 launch/rmcs 是两个看不出区别的指令。
7881d5d to
a8dd7a6
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (4)
.script/host/rmcs (2)
18-23:rmcs_zsh未指定-u用户,与rmcs_nvim行为不一致。
rmcs_nvim(Line 41)使用了-u "$DEVELOPER_NAME"以ubuntu用户执行命令,但rmcs_zsh中的docker compose exec没有指定用户,将以容器默认用户(通常是 root)进入 shell。如果这是有意为之可以忽略,否则建议统一:♻️ 建议修改
function rmcs_zsh() { local service="$1" echo "Starting and entering container..." docker compose up -d - docker compose exec "$service" zsh + docker compose exec -u "$DEVELOPER_NAME" "$service" zsh }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.script/host/rmcs around lines 18 - 23, The rmcs_zsh function starts and enters the container without specifying a user, unlike rmcs_nvim which uses -u "$DEVELOPER_NAME"; update rmcs_zsh to pass -u "$DEVELOPER_NAME" to docker compose exec so the shell runs as the same developer user (reference functions rmcs_zsh and rmcs_nvim and the DEVELOPER_NAME variable).
63-78:main函数参数解析和目录校验逻辑清晰。通过
-d判断首参是否为目录来区分路径参数和命令参数,并校验docker-compose.yml存在性,逻辑合理。不过 Line 76 只检查了
docker-compose.yml,如果项目使用的是compose.yaml(Docker Compose V2 同样支持的文件名),则会误报。视项目实际情况可忽略。🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.script/host/rmcs around lines 63 - 78, The script's main function currently only checks for "docker-compose.yml" which fails for projects using alternate Compose filenames; update the existence check in main to consider all common Compose filenames (e.g., "docker-compose.yml", "docker-compose.yaml", "compose.yml", "compose.yaml") and proceed if any one exists, otherwise print the same error and exit; adjust the test referencing docker-compose.yml so functions/classes/logic around main and the directory validation use the combined check..script/build-rmcs (2)
16-16:"$@"放在--cmake-args之前,用户传入的 cmake 参数可能被拆分。当前
"$@"位于--cmake-args前面。如果用户调用时传入--cmake-args -DFOO=bar,colcon 会将其视为独立的一组 cmake 参数,与脚本末尾的-G Ninja分开累积,行为上可以工作。但如果用户期望直接追加额外参数到--cmake-args后面(如-DCMAKE_BUILD_TYPE=Release),则需要在调用时显式加上--cmake-args前缀。考虑将
"$@"移到命令末尾以获得更直观的行为:♻️ 建议修改
-colcon build --symlink-install --merge-install "$@" --cmake-args -G Ninja +colcon build --symlink-install --merge-install --cmake-args -G Ninja "$@"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.script/build-rmcs at line 16, The colcon invocation puts "$@" before --cmake-args which prevents user-supplied CMake flags from being appended to the script's --cmake-args list; update the command in the .script/build-rmcs file (the colcon build invocation) to place "$@" at the end of the argument list so that user-provided flags are appended after --cmake-args -G Ninja (preserve quoting of "$@" when moving it).
10-14:CC和CXX独立检测可能导致编译器不匹配。如果系统中只安装了
clang而没有clang++(或反之),会导致 C 和 C++ 编译器不配对(例如CC=clang+CXX=g++),可能引发难以排查的构建问题。建议将两者作为一组进行检测:♻️ 建议修改
-command -v clang &>/dev/null && - export CC=clang - -command -v clang++ &>/dev/null && - export CXX=clang++ +if command -v clang &>/dev/null && command -v clang++ &>/dev/null; then + export CC=clang + export CXX=clang++ +fi🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.script/build-rmcs around lines 10 - 14, The script currently checks clang and clang++ independently which can leave CC and CXX mismatched; update the detection so you probe pairs and set both together: if both `clang` and `clang++` exist, export `CC=clang` and `CXX=clang++`; else if both `gcc` and `g++` exist, export `CC=gcc` and `CXX=g++`; otherwise fall back to a single-tool check that warns or exits. Modify the logic around the `CC`/`CXX` exports in the existing block that currently calls `command -v clang` and `command -v clang++` so the pairwise check replaces the independent checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In @.script/host/rmcs:
- Around line 35-38: 循环使用 nc -z 检查端口的 while loop 没有上限保护,可能导致无限循环; add a maximum
guard by introducing a MAX_PORT (or MAX_ATTEMPTS) and an attempts counter, then
change the loop condition to while nc -z "$NVIM_HOST" "$port" 2>/dev/null && [
"$port" -le "$MAX_PORT" ] (or increment attempts and check attempts -lt
MAX_ATTEMPTS), and when the limit is reached emit a clear error message and exit
non‑zero instead of continuing; update references to port, the while loop, and
the exit path accordingly.
---
Nitpick comments:
In @.script/build-rmcs:
- Line 16: The colcon invocation puts "$@" before --cmake-args which prevents
user-supplied CMake flags from being appended to the script's --cmake-args list;
update the command in the .script/build-rmcs file (the colcon build invocation)
to place "$@" at the end of the argument list so that user-provided flags are
appended after --cmake-args -G Ninja (preserve quoting of "$@" when moving it).
- Around line 10-14: The script currently checks clang and clang++ independently
which can leave CC and CXX mismatched; update the detection so you probe pairs
and set both together: if both `clang` and `clang++` exist, export `CC=clang`
and `CXX=clang++`; else if both `gcc` and `g++` exist, export `CC=gcc` and
`CXX=g++`; otherwise fall back to a single-tool check that warns or exits.
Modify the logic around the `CC`/`CXX` exports in the existing block that
currently calls `command -v clang` and `command -v clang++` so the pairwise
check replaces the independent checks.
In @.script/host/rmcs:
- Around line 18-23: The rmcs_zsh function starts and enters the container
without specifying a user, unlike rmcs_nvim which uses -u "$DEVELOPER_NAME";
update rmcs_zsh to pass -u "$DEVELOPER_NAME" to docker compose exec so the shell
runs as the same developer user (reference functions rmcs_zsh and rmcs_nvim and
the DEVELOPER_NAME variable).
- Around line 63-78: The script's main function currently only checks for
"docker-compose.yml" which fails for projects using alternate Compose filenames;
update the existence check in main to consider all common Compose filenames
(e.g., "docker-compose.yml", "docker-compose.yaml", "compose.yml",
"compose.yaml") and proceed if any one exists, otherwise print the same error
and exit; adjust the test referencing docker-compose.yml so
functions/classes/logic around main and the directory validation use the
combined check.
Switch toolchain to clang with Ninja for supporting cxx module
摘要
此PR切换了构建系统的默认工具链为 Clang + Ninja,并添加了 Neovim 开发相关的实用工具脚本。
主要变更
构建系统优化
.script/build-rmcs):#! /bin/bash→#!/bin/bash)/opt/cmake/bin加入 PATHclang和clang++时,自动设置CC=clang和CXX=clang++colcon build现在使用--cmake-args -G NinjaNeovim 开发工具
.script/host/rmcs):rmcs_zsh命令:启动 Docker 容器并打开 zsh shellrmcs_nvim命令:启动容器内的无头 Neovim 实例,自动检测可用端口,通过 Neovide 客户端连接配置调整
.env):移除HOST_NVIM_DIR变量docker-compose.yml):修改卷挂载策略,从指定的环境变量路径改为用户主目录下的.config目录(~/.config/:${CONTAINER_HOME}/.config/)影响范围
此变更影响开发工作流程,特别是本地开发环境的构建配置和 Neovim 集成体验。新增的脚本提供了便捷的容器化开发环境管理方案。