Skip to content

refactor: rename to code-preview, split backend modules, add layout + visible_only tests (#13)#34

Merged
Cannon07 merged 1 commit intomainfrom
refactor/rename_codepreview
Apr 11, 2026
Merged

refactor: rename to code-preview, split backend modules, add layout + visible_only tests (#13)#34
Cannon07 merged 1 commit intomainfrom
refactor/rename_codepreview

Conversation

@Cannon07
Copy link
Copy Markdown
Owner

@Cannon07 Cannon07 commented Apr 11, 2026

Summary

  • Rename plugin from claude-preview to code-preview across all Lua modules, shell scripts, TypeScript, commands, and tests
  • Split monolithic hooks.lua into dedicated backends/claudecode.lua and backends/opencode.lua modules
  • Relocate adapter scripts into backends/claudecode/ and backends/opencode/ directories
  • Add deprecated aliases for all old :ClaudePreview* commands so existing users aren't broken
  • Add tests for diff layout variants (tab / vsplit / inline) and visible_only mode

Changes

Rename: claude-previewcode-preview

  • lua/code-preview/ (renamed from lua/claude-preview/) — all modules updated
  • All require("claude-preview.*")require("code-preview.*") throughout Lua, shell scripts, and TypeScript
  • Commands renamed: :CodePreviewInstallClaudeCodeHooks, :CodePreviewUninstallClaudeCodeHooks, :CodePreviewCloseDiff, :CodePreviewStatus, :CodePreviewToggleVisibleOnly, :CodePreviewInstallOpenCodeHooks, :CodePreviewUninstallOpenCodeHooks
  • Deprecated aliases — all old :ClaudePreview* commands still work but emit a deprecation warning pointing to the new command name
  • bin/nvim-send.shmktemp prefix updated to code-preview-nvim-cmd
  • tests/minimal_init.lua and all spec files updated

Backend restructure

  • lua/code-preview/backends/claudecode.lua (new, replaces hooks.lua Claude Code logic) — install(), uninstall(), dual-marker uninstall ("code-preview" and "claude-preview") so users with old hooks can cleanly uninstall after upgrading
  • lua/code-preview/backends/opencode.lua (new, replaces hooks.lua OpenCode logic) — install(), uninstall()
  • lua/code-preview/hooks.lua — deleted (split into the two backend modules above)
  • backends/claudecode/code-preview-diff.sh (moved from bin/claude-preview-diff.sh) — sets CODE_PREVIEW_BACKEND=claudecode, execs bin/core-pre-tool.sh
  • backends/claudecode/code-close-diff.sh (moved from bin/claude-close-diff.sh) — execs bin/core-post-tool.sh
  • backends/opencode/ (moved from opencode-plugin/) — index.ts env var updated CLAUDE_PREVIEW_BACKENDCODE_PREVIEW_BACKEND; package name updated to code-preview-opencode
  • bin/core-pre-tool.sh / bin/core-post-tool.sh — all requires and env var references updated

Health check

  • lua/code-preview/health.lua — dual-marker hook detection: reports OK for new marker, warns with migration hint for legacy claude-preview marker, and fails if neither is found

Tests

  • tests/plugin/diff_lifecycle_spec.lua — new "diff layouts" describe block with 3 tests: tab opens a new tab with 2 windows, vsplit stays in the current tab, inline opens a new tab with 1 window
  • tests/backends/claudecode/test_edit.sh — new test_visible_only: verifies diff opens for a buffer visible in Neovim and is skipped for a file not open in any window
  • tests/backends/claudecode/ (renamed from tests/backends/claude/) — all test scripts updated
  • tests/helpers.sh — hook script paths updated to backends/claudecode/

Documentation

  • README.md — fully updated: new module paths, command names, architecture diagram, testing commands, migration guide for users upgrading from older versions

Migration guide (for existing users)

  1. Update require("claude-preview")require("code-preview") in your Neovim config
  2. Re-run :CodePreviewInstallClaudeCodeHooks (or OpenCode equivalent) to update hook script paths
  3. Old :ClaudePreview* commands still work with a deprecation warning

Test plan

  • All 39 tests pass (bash tests/run.sh) — 17 plugin + 22 backend
  • tab / vsplit / inline layouts each produce the correct window structure
  • visible_only skips diff for files not open in Neovim, shows diff for visible files
  • Hook install writes new backends/claudecode/ paths to .claude/settings.local.json
  • Hook uninstall removes both new and legacy markers (dual-marker transition)
  • All old :ClaudePreview* commands work with deprecation warning
  • Claude Code: edit / write / bash rm / sequential edits all work end-to-end
  • OpenCode: edit / write / bash rm / multi-file queue / relative paths all work end-to-end
  • visible_only, defer_claude_permissions, neo-tree reveal/indicators work on both backends
  • Stale socket recovery works after Neovim restart

Issue:

#13

@Cannon07 Cannon07 merged commit f775e1e into main Apr 11, 2026
2 checks passed
@Cannon07 Cannon07 deleted the refactor/rename_codepreview branch April 11, 2026 11:33
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