Skip to content

feat: implement note mode for general codebase commenting#19

Merged
hay-kot merged 12 commits into
mainfrom
feat/note-mode
Feb 11, 2026
Merged

feat: implement note mode for general codebase commenting#19
hay-kot merged 12 commits into
mainfrom
feat/note-mode

Conversation

@hay-kot
Copy link
Copy Markdown
Collaborator

@hay-kot hay-kot commented Feb 9, 2026

Summary

Implements note mode (#5) - a feature for adding comments to any files in the codebase without requiring diff or review context.

Features

  • Multiple note sets: Organize notes for different purposes (security audit, refactoring, etc.)
  • Persistent storage: Auto-saves to .diff-review/notes/ with JSON format
  • Session restore: Automatically restores note mode state on Neovim startup
  • Works anywhere: Comment during normal editing, no special layout required
  • Consistent UI: Reuses existing keymaps and visual styling from diff review

Implementation

Core Modules (5 new files)

  • notes.lua - In-memory storage with set management
  • note_persistence.lua - JSON persistence layer
  • note_mode.lua - Mode state management and auto-commands
  • note_ui.lua - Virtual text rendering with separate namespace
  • note_actions.lua - User interaction handlers (add/edit/delete)

Commands (6 new)

  • :DiffReviewNoteEnter [set_name] - Enter note mode
  • :DiffReviewNoteExit - Exit note mode
  • :DiffReviewNoteToggle [set_name] - Toggle mode
  • :DiffReviewNoteClear - Clear all notes in current set
  • :DiffReviewNoteList - List and switch note sets
  • :DiffReviewNoteSwitch <set_name> - Switch to different set

Configuration

require('diff-review').setup({
  notes = {
    default_set = "default",
    auto_restore = true,
  },
})

Testing

  • 30 unit tests (21 for notes module, 9 for persistence)
  • All tests passing
  • Covers CRUD operations, persistence, and set management

Documentation

  • Added comprehensive README section
  • Usage examples and workflows
  • Storage structure documentation
  • Configuration examples

Changes

  • 10 files changed, 1909 insertions(+)
  • No breaking changes
  • Fully isolated from existing diff review functionality

Demo Workflow

" Start note mode for security audit
:DiffReviewNoteEnter security-audit

" Navigate files and add comments
<leader>c " Add comment at cursor
<leader>v " View all comments

" Switch to different note set
:DiffReviewNoteSwitch refactoring

" Notes auto-save and persist across sessions

Closes #5

Add note mode that allows commenting on any files without requiring
diff/review context. Implements all core functionality:

Core modules:
- notes.lua: In-memory note storage with set management
- note_persistence.lua: JSON persistence to .diff-review/notes/
- note_mode.lua: Mode state management and auto-commands
- note_ui.lua: Virtual text rendering with separate namespace
- note_actions.lua: User interaction handlers

Features:
- Multiple named note sets for different purposes
- Automatic save on changes
- Session persistence and auto-restore
- Works in normal buffers without special layout
- Reuses existing keymaps and UI styling
- 6 new user commands for note management

Commands added:
- :DiffReviewNoteEnter [set_name]
- :DiffReviewNoteExit
- :DiffReviewNoteToggle [set_name]
- :DiffReviewNoteClear
- :DiffReviewNoteList
- :DiffReviewNoteSwitch <set_name>

Related to #5
All 21 tests passing for core note CRUD operations
Add comprehensive documentation for note mode feature including:
- Feature overview and benefits
- All available commands
- Usage workflow
- Storage structure
- Configuration options
- Example workflows
- Coexistence with diff review
9 tests covering save/load, list, delete, and auto-save operations
- Save notes explicitly when exiting note mode
- Save notes before saving session state on VimLeavePre
- Add comprehensive persistence integration tests (6 tests)

Fixes issue where notes would disappear when reopening Vim
Adds :DiffReviewNoteCopy command with two export modes:
- notes: Simple markdown with line numbers
- full: Includes code context around notes

Features:
- Exports notes grouped by file
- Supports both single and range notes
- Includes metadata header with set name and date
- Sorts files alphabetically and notes by line number
- Copy to clipboard via multiple backends (pbcopy, xclip, wl-copy)

Includes 9 comprehensive tests covering all export scenarios
- Guard against nil config in setup_buffer_keymaps
- Make list_sets test more resilient to concurrent test runs
- Initialize config in export tests before entering note mode

All 45 tests now passing
BREAKING CHANGE: Command structure simplified

Before (15+ commands):
- DiffReview, DiffReviewClose, DiffReviewToggle, DiffReviewList, etc.
- DiffReviewNoteEnter, DiffReviewNoteExit, DiffReviewNoteClear, etc.

After (2 main commands + 1 shortcut):
- :DiffReview [subcommand] - all diff review operations
- :DiffNote [subcommand] - all note mode operations
- :DiffReviewToggle - shortcut for most common operation

Subcommands:
  DiffReview: close, toggle, list, copy, submit, health
  DiffNote: enter, exit, toggle, clear, list, switch, copy

Benefits:
- Cleaner namespace (2 commands vs 15+)
- Better discoverability via tab completion
- Matches patterns from popular plugins (Telescope, Lazy)
- Groups related functionality logically

Documentation updated throughout README
Now correctly handles refs like 'main', 'develop', 'origin/main'
by checking against known subcommands instead of pattern matching.

Fixes error: 'Unknown subcommand: main'
- Create shared utility modules (git_utils, storage_utils, clipboard_utils)
- Add comprehensive error handling for all file I/O operations
- Fix silent pcall failures in note_ui (5 locations)
- Wrap auto-save hooks with error handling in notes module
- Migrate note_persistence to use new storage utilities
- Replace git command calls with git_utils in note_mode and note_actions
- Fix API inconsistency: use linehl instead of line_hl_group with hl_mode=combine
- Extract magic numbers to constants (sign and extmark priorities)
- Add line number validation in notes.add()
- Replace emoji with markdown quote style (💬 -> >)
- Consolidate clipboard operations using shared utility

Test coverage:
- Add 20 new tests for utility modules
- Add line validation tests for notes module
- Update note_export test for emoji change
- All critical functionality tests passing (74 tests)

Note: One pre-existing flaky test in note_persistence remains
- Rename shadowing variables (notes -> notes_api, state -> note_state)
- Simplify restore_session control flow with early returns
- Add proper test cleanup in note_export_spec
- Fix list_sets verification in note_persistence_spec
- Add edge case test files for note_mode and storage
@hay-kot hay-kot merged commit e483ac9 into main Feb 11, 2026
2 checks passed
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.

Feature: General codebase commenting mode (non-diff)

1 participant