Skip to content

feat: add restore diagnostics command for previous code reviews#19

Merged
smnatale merged 5 commits intomainfrom
feat/restore-diagnostics
Apr 14, 2026
Merged

feat: add restore diagnostics command for previous code reviews#19
smnatale merged 5 commits intomainfrom
feat/restore-diagnostics

Conversation

@smnatale
Copy link
Copy Markdown
Owner

@smnatale smnatale commented Apr 14, 2026

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

    • Added restore functionality to reapply diagnostics from previously saved reviews using :CodeRabbitRestore [id], defaulting to the most recent review when no ID is provided.
  • Documentation

    • Updated user guide with restore command documentation and programmatic API reference.
  • Tests

    • Added test coverage for restore functionality.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 14, 2026

Caution

Review failed

An error occurred during the review process. Please try again later.

📝 Walkthrough

Walkthrough

This pull request introduces a new restore feature enabling users to re-apply diagnostics from previously saved code reviews via the :CodeRabbitRestore [id] command and corresponding Lua API, with comprehensive documentation and test coverage.

Changes

Cohort / File(s) Summary
Documentation
README.md, doc/coderabbit.txt
Documented the new :CodeRabbitRestore [id] user command and require("coderabbit").restore({id}) Lua function with behaviour for handling saved review identifiers and defaults.
Core implementation
lua/coderabbit/init.lua, lua/coderabbit/review.lua
Implemented restoration logic: wrapper function in init.lua delegates to review module; review.lua contains core functionality to list saved reviews, select by provided or most recent ID, load stored findings, clear existing diagnostics, and apply restored diagnostics with user notifications.
User command
plugin/coderabbit.lua
Exposed :CodeRabbitRestore command with optional ID argument and completion function sourcing available review IDs from storage.
Test suite
tests/coderabbit/restore_spec.lua
Added comprehensive test coverage verifying restore behaviour including empty history, unknown IDs, specific ID restoration, most-recent-by-default selection, and diagnostic clearing before restoration.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new restore diagnostics command for accessing previous code reviews.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@smnatale smnatale changed the title feat: add restore diagnostics command feat: add restore diagnostics command for previous code reviews Apr 14, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/coderabbit/restore_spec.lua (1)

22-30: Track and clean temporary directories created by make_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

📥 Commits

Reviewing files that changed from the base of the PR and between c9744f3 and a768339.

📒 Files selected for processing (6)
  • README.md
  • doc/coderabbit.txt
  • lua/coderabbit/init.lua
  • lua/coderabbit/review.lua
  • plugin/coderabbit.lua
  • tests/coderabbit/restore_spec.lua

Comment thread lua/coderabbit/review.lua
Comment thread plugin/coderabbit.lua Outdated
@smnatale smnatale merged commit 9813da0 into main Apr 14, 2026
4 checks passed
@smnatale smnatale deleted the feat/restore-diagnostics branch April 14, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant