feat: add restore diagnostics command for previous code reviews#19
feat: add restore diagnostics command for previous code reviews#19
Conversation
|
Caution Review failedAn error occurred during the review process. Please try again later. 📝 WalkthroughWalkthroughThis pull request introduces a new restore feature enabling users to re-apply diagnostics from previously saved code reviews via the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Command as Command Handler
participant Review as Review Module
participant Storage as Storage
participant Diagnostics as Diagnostics
participant Notify as vim.notify
User->>Command: :CodeRabbitRestore [id]
Command->>Review: restore(id)
Review->>Storage: list saved reviews
Storage-->>Review: review entries
Review->>Review: select by id or most recent
Review->>Storage: load(selected_id)
Storage-->>Review: review findings
Review->>Diagnostics: clear existing diagnostics
Review->>Diagnostics: set diagnostic for each finding
Diagnostics-->>Review: diagnostics applied
Review->>Notify: success message (count, id)
Notify-->>User: notification displayed
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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
🧹 Nitpick comments (1)
tests/coderabbit/restore_spec.lua (1)
22-30: Track and clean temporary directories created bymake_findings.
make_findings()creates per-test temp directories that are never removed, so repeated runs can leak files under/tmp.💡 Suggested fix
local test_dir = vim.fn.tempname() .. "/coderabbit_restore_test" +local temp_dirs = {} storage._set_base_dir(test_dir) @@ local function cleanup() vim.fn.delete(test_dir, "rf") + for _, dir in ipairs(temp_dirs) do + vim.fn.delete(dir, "rf") + end + temp_dirs = {} diagnostics.clear() end @@ local function make_findings(n) local tmpdir = vim.fn.tempname() vim.fn.mkdir(tmpdir, "p") + table.insert(temp_dirs, tmpdir) local findings = {}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/coderabbit/restore_spec.lua` around lines 22 - 30, make_findings currently creates a temp dir (tmpdir) and returns findings but never removes the tmpdir; change make_findings to return the tmpdir along with the findings (e.g., return findings, tmpdir) and update callers/tests to remove the directory in their teardown using vim.fn.rmdir(tmpdir, "rf"); alternatively, have make_findings register the temp dir for cleanup by exposing a helper (or calling a provided cleanup function) so tmpdir is removed after each test—refer to the tmpdir local in make_findings and the tests' teardown/after_each to perform vim.fn.rmdir(tmpdir, "rf").
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lua/coderabbit/review.lua`:
- Around line 250-253: Guard against nil or malformed review.findings before
iterating: after loading the review (the value referenced as review used inside
vim.schedule) ensure review and review.findings are tables (or coerce to an
empty table) before calling ipairs; update the scheduled block that loops over
review.findings to check type(review) == "table" and type(review.findings) ==
"table" (or set local findings = review and review.findings or {} and iterate
that), then call diagnostics.set(finding.filepath, { finding.diagnostic }) only
for valid entries to avoid runtime errors when storage.load returned a malformed
review.
In `@plugin/coderabbit.lua`:
- Around line 53-54: The current handler silently treats non-numeric restore IDs
as nil and calls require("coderabbit").restore(id), which unintentionally
restores the latest review; change it to validate the argument: check
args.fargs[1] and run tonumber(args.fargs[1]) and if that returns nil, surface
an error to the user (e.g., via a user-visible error/notification) and return
early instead of calling restore; only call require("coderabbit").restore(id)
when tonumber produced a valid numeric id.
---
Nitpick comments:
In `@tests/coderabbit/restore_spec.lua`:
- Around line 22-30: make_findings currently creates a temp dir (tmpdir) and
returns findings but never removes the tmpdir; change make_findings to return
the tmpdir along with the findings (e.g., return findings, tmpdir) and update
callers/tests to remove the directory in their teardown using
vim.fn.rmdir(tmpdir, "rf"); alternatively, have make_findings register the temp
dir for cleanup by exposing a helper (or calling a provided cleanup function) so
tmpdir is removed after each test—refer to the tmpdir local in make_findings and
the tests' teardown/after_each to perform vim.fn.rmdir(tmpdir, "rf").
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0a776c10-afd8-4acd-80d0-37b4131f4bea
📒 Files selected for processing (6)
README.mddoc/coderabbit.txtlua/coderabbit/init.lualua/coderabbit/review.luaplugin/coderabbit.luatests/coderabbit/restore_spec.lua
Description
Add way to restore previous diagnostics from code review (useful if neovim is closed, etc)
Screenshots/Images
Summary by CodeRabbit
Release Notes
New Features
:CodeRabbitRestore [id], defaulting to the most recent review when no ID is provided.Documentation
Tests