25 Commits

Author SHA1 Message Date
Valdemar Lorenzen 2368091d93 fix: simplify revision diff selection into a flat list
Revisions still used ancestry lanes and placed author/date/bookmark metadata before the summary. Show short change IDs and summaries first, move metadata to a dimmed detail row, and remove the obsolete picker graph projection.
2026-11-05 15:59:09 +01:00
Valdemar Lorenzen 1afc896cab fix: make bookmark diff selection a name-first list
Bookmarks shared revision-graph rendering, allowing ancestry lanes and revision metadata to crowd out reference names. Restrict graph projection to Revisions and reuse flat bookmark rows with commit summaries.
2026-11-05 15:59:09 +01:00
Valdemar Lorenzen e3d44f24c0 feat: show jj ancestry in the floating diff picker 2026-11-02 10:17:33 +01:00
hl-valdemar 496c93774f fix: render theme-aware software cursors and mode banners 2026-10-26 16:29:17 +01:00
hl-valdemar c6901eaaa6 fix: synchronize cursor and bar mode colors 2026-10-26 16:14:41 +01:00
hl-valdemar ce434a1c17 feat: configure cursor appearance by editing mode 2026-10-26 16:14:41 +01:00
hl-valdemar 846803a3e2 fix: hide commentless reviews from CLI listings 2026-10-25 21:34:45 +01:00
hl-valdemar 448c3bf477 feat: scope local reviews to comparisons 2026-10-25 01:18:25 +02:00
hl-valdemar 815fcccbe8 feat: fence review excerpts with language tags 2026-10-25 00:19:06 +02:00
hl-valdemar c1bff63111 feat: show base-relative changes in conflict panes 2026-10-25 00:11:40 +02:00
hl-valdemar c88582f2ba feat: resolve review comments through the CLI 2026-10-24 13:29:18 +02:00
hl-valdemar 6b04b6f0ac fix: keep explorer selections readable on light terminals 2026-10-23 12:07:43 +02:00
hl-valdemar c12d98e348 refactor: remove legacy diff review command aliases 2026-10-22 23:21:53 +02:00
hl-valdemar e6d94dcb41 feat: support comments in ordinary source buffers 2026-10-22 23:21:53 +02:00
hl-valdemar ac5c64981d fix: display diff totals as plain status text 2026-10-22 19:29:04 +02:00
hl-valdemar 8f4e0fa7fb fix: exempt configuration blocks from length lint 2026-10-22 11:35:07 +02:00
hl-valdemar 03931496bf feat: add Typst syntax and Tinymist defaults 2026-10-22 11:35:07 +02:00
Valdemar Lorenzen ea7c240eb6 fix: keep pull request filters session-local 2026-10-21 15:18:47 +02:00
Valdemar Lorenzen fbcb519e13 feat: add persistent pull request sort and filter menus 2026-10-21 13:39:27 +02:00
Valdemar Lorenzen 37b47ebc8a feat: sort and filter pull requests by review state 2026-10-21 12:53:22 +02:00
Valdemar Lorenzen 5c08aa0a67 chore: isolate tests from external services 2026-10-21 11:44:32 +02:00
Valdemar Lorenzen 0202644efa feat: configure personal pull request review indicators 2026-10-21 11:28:55 +02:00
Valdemar Lorenzen bd71d463a4 feat: mark pull requests approved by the authenticated user 2026-10-21 11:14:01 +02:00
Valdemar Lorenzen 6a359cc351 feat: separate draft pull requests into their own tab 2026-10-21 10:46:14 +02:00
Valdemar Lorenzen cce3b1e469 feat: show line counts in pull request picker 2026-10-21 10:24:43 +02:00
46 changed files with 7489 additions and 1346 deletions
+5
View File
@@ -7,3 +7,8 @@ Style/StringLiterals:
Style/StringLiteralsInInterpolation: Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes EnforcedStyle: double_quotes
Metrics/BlockLength:
AllowedMethods:
- refine
- Vamp.configure
Generated
+11
View File
@@ -151,6 +151,16 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
[[package]]
name = "codebook-tree-sitter-typst"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f785ad90ce80edd9e8b3d00890af0bc163e9a2c38f03daa18aede98d343d093"
dependencies = [
"cc",
"tree-sitter-language",
]
[[package]] [[package]]
name = "compact_str" name = "compact_str"
version = "0.9.1" version = "0.9.1"
@@ -2003,6 +2013,7 @@ dependencies = [
name = "vamp" name = "vamp"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"codebook-tree-sitter-typst",
"crossterm", "crossterm",
"ignore", "ignore",
"ratatui", "ratatui",
+1
View File
@@ -27,6 +27,7 @@ tree-sitter-python = "0.25.0"
tree-sitter-ruby = "0.23.1" tree-sitter-ruby = "0.23.1"
tree-sitter-rust = "0.24.2" tree-sitter-rust = "0.24.2"
tree-sitter-toml-ng = "0.7.0" tree-sitter-toml-ng = "0.7.0"
tree-sitter-typst = { package = "codebook-tree-sitter-typst", version = "=0.12.1" }
tree-sitter-typescript = "0.23.2" tree-sitter-typescript = "0.23.2"
tree-sitter-yaml = "0.7.2" tree-sitter-yaml = "0.7.2"
tree-sitter-zig = "1.1.2" tree-sitter-zig = "1.1.2"
+9 -2
View File
@@ -21,15 +21,22 @@ vamp --review list --repo . --json
vamp --review show 1 --repo . --json vamp --review show 1 --repo . --json
vamp --review show 1 --repo . --all vamp --review show 1 --repo . --all
vamp --review delete 1 3 --repo . # Delete comment 3 from review 1 vamp --review delete 1 3 --repo . # Delete comment 3 from review 1
vamp --review resolve 1 3 --repo . # Mark comment 3 resolved, preserving its feedback
``` ```
The review CLI discovers the Git/Jujutsu checkout from `--repo` (default: current directory). It uses the same default configuration, `--config PATH`, `--no-config`, and `review_directory` as the editor, but starts no editor workers or terminal UI. Missing storage lists no reviews without creating a database; incompatible storage is rejected and preserved. The review CLI discovers the Git/Jujutsu checkout from `--repo` (default: current directory). It uses the same default configuration, `--config PATH`, `--no-config`, and `review_directory` as the editor, but starts no editor workers or terminal UI. Missing storage lists no reviews without creating a database; incompatible storage is rejected and preserved.
Local reviews are scoped to the canonical checkout and ordered, resolved Before/After pair. Opening a different comparison selects its own review; reopening the same pair resumes its feedback and progress. In-place Working refreshes retain the active review. Ordinary source-buffer comments use separate source reviews. CLI listings identify each review's scope; JSON exposes it as `comparison` (an endpoint pair, or `null` for source reviews).
Review storage now uses SQLite schema 4 and JSON export version 5. Older formats are rejected and preserved without migration or reset.
Use the persistent **Review ID** printed by `list`, not a list position. IDs are shared across repositories; listing filters them to the selected checkout, so its first review need not be ID 1. Human-readable listings include a command to show each review. The internal save revision is omitted from text but remains in JSON; it is not a Git/Jujutsu revision. `show all` is not supported: use `show ID --all` to include resolved comments in that review. Use the persistent **Review ID** printed by `list`, not a list position. IDs are shared across repositories; listing filters them to the selected checkout, so its first review need not be ID 1. Human-readable listings include a command to show each review. The internal save revision is omitted from text but remains in JSON; it is not a Git/Jujutsu revision. `show all` is not supported: use `show ID --all` to include resolved comments in that review.
`show` includes unresolved comments by default; `--all` includes resolved comments too. Human-readable output is the default. JSON includes the canonical repository root, storage review ID/revision, summary/verdict, total/resolved/unresolved counts, and comments with exact zero-based, end-exclusive grapheme anchors and selected source excerpts—not whole source files. `list --json` returns the repository and review metadata/counts without comments. Explicit editor JSON exports still contain complete anchor source text. `show` includes unresolved comments by default; `--all` includes resolved comments too. Human-readable output is the default, with source excerpts in language-tagged Markdown code blocks. JSON includes the canonical repository root, storage review ID/revision, summary/verdict, total/resolved/unresolved counts, and comments with exact zero-based, end-exclusive grapheme anchors and raw selected source excerpts—not whole source files or Markdown fences. `list --json` returns the repository and review metadata/counts without comments. Explicit editor JSON exports still contain complete anchor source text.
`list` and `show` are read-only. `delete REVIEW_ID COMMENT_ID` immediately commits deletion of one resolved or unresolved comment, then prints the updated review with its remaining unresolved comments (`--json` is supported). Both IDs are required; missing reviews/comments and repository mismatches fail without changing stored reviews or creating missing storage. Deleting the last comment keeps the review, summary, and verdict. Concurrent saves use the same revision-conflict protection as the editor; an already-open editor must reload before saving after a CLI deletion. Existing JSON exports are not modified. `list` omits reviews with no comments in both text and JSON output. Reviews containing only resolved comments remain listed. Commentless reviews remain stored to preserve file checkmarks, summaries, and verdicts; the editor can still resume them, and `show ID` can inspect them directly.
`list` and `show` are read-only. `delete REVIEW_ID COMMENT_ID` immediately commits deletion of one resolved or unresolved comment. `resolve REVIEW_ID COMMENT_ID` instead marks that comment resolved, preserving its body and original anchor. Repeating resolution succeeds without writing or advancing the review revision. Both commands print the updated review with its remaining unresolved comments (`--json` is supported); use `show REVIEW_ID --all` to verify resolved feedback. Both IDs are required; missing reviews/comments and repository mismatches fail without changing stored reviews or creating missing storage. Deleting the last comment keeps the review, summary, and verdict. Concurrent saves use the same revision-conflict protection as the editor; an already-open editor must reload before saving after a CLI change. Existing JSON exports are not modified.
`vamp review` still opens a file named `review`; `vamp -- --review` opens a file named `--review`. `vamp review` still opens a file named `review`; `vamp -- --review` opens a file named `--review`.
+3
View File
@@ -1,3 +1,6 @@
- [x] improve: diff picker - if jj managed, present as jj log.
- this makes it much easier to determine which revisions to actually pick for before/after
- the bookmarks only view could simply filter out unbookmarked revisions but otherwise display in the same way
- [ ] feature: diff view - GitHub code review integration after the local review UX is usable. - [ ] feature: diff view - GitHub code review integration after the local review UX is usable.
- publish local reviews explicitly: general PR comments, inline line/range comments, review summaries, approval, and requests for changes. - publish local reviews explicitly: general PR comments, inline line/range comments, review summaries, approval, and requests for changes.
- preserve explicit PR identity and reviewed commit IDs; validate anchors against GitHub's PR diff and recheck the PR head before submission. - preserve explicit PR identity and reviewed commit IDs; validate anchors against GitHub's PR diff and recheck the PR head before submission.
+8 -7
View File
@@ -17,10 +17,11 @@ One editor crate; the workspace also includes its patched Crossterm dependency.
Virtual diff leaves retain their original catalog input index for caller-owned annotations. Normal scanned leaves accept optional repository status and old-path metadata without filtering unchanged files; missing tracked deletions add virtual leaves and required directories. Metadata-only updates preserve query, selection, expansion, and view without rebuilding the catalog. Virtual diff leaves retain their original catalog input index for caller-owned annotations. Normal scanned leaves accept optional repository status and old-path metadata without filtering unchanged files; missing tracked deletions add virtual leaves and required directories. Metadata-only updates preserve query, selection, expansion, and view without rebuilding the catalog.
- `diff`: owns searchable Before/After selection, category, focus and explorer visibility, request freshness, read-only comparison DTOs, aligned rows with cached grapheme-level change ranges, and shared vertical/independent horizontal offsets. Changed paths form a virtual `files::FilePicker` catalog, reusing the normal tree projection, filtering, and navigation without scanning disk. It has no subprocess or terminal dependencies. - `diff`: owns searchable Before/After selection, category, focus and explorer visibility, request freshness, read-only comparison DTOs, aligned rows with cached grapheme-level change ranges, and shared vertical/independent horizontal offsets. Changed paths form a virtual `files::FilePicker` catalog, reusing the normal tree projection, filtering, and navigation without scanning disk. It has no subprocess or terminal dependencies.
- `repository`: discovers jj/Git repositories and local/advertised remote revisions, builds disk snapshots and changed-file hunks, and owns isolated temporary comparison repositories with bounded, cancellable subprocesses. It never saves editor buffers or modifies active refs/checkouts. - `repository`: discovers jj/Git repositories and local/advertised remote revisions, builds disk snapshots and changed-file hunks, and owns isolated temporary comparison repositories with bounded, cancellable subprocesses. It never saves editor buffers or modifies active refs/checkouts.
- `review`: owns the validated local review model, exact immutable anchors, persisted file checkmarks, SQLite storage through bundled rusqlite, and atomic JSON import/export with external-change protection. Schema 3 stores review identity, repository, revision, summary, and verdict in `reviews`; `comments` stores ordered comment IDs, bodies, resolution states, and explicit immutable anchor fields. `reviewed_files` stores revision pairs, paths, optional old paths, and optional exact live After text. Foreign keys, unique keys, and checks enforce relationships and scalar invariants. Full `u64` comment IDs use checked decimal text because SQLite integers are signed. No JSON documents are stored in SQLite. - `review`: owns the validated local review model, exact immutable anchors, persisted file checkmarks, SQLite storage through bundled rusqlite, and atomic JSON import/export with external-change protection. Schema 4 stores review identity, repository, revision, summary, verdict, and nullable ordered comparison endpoints in `reviews`; null endpoints identify source reviews. `comments` stores ordered comment IDs, bodies, resolution states, and explicit immutable anchor fields. `reviewed_files` stores revision pairs, paths, optional old paths, and optional exact live After text. Foreign keys, unique keys, and checks enforce relationships and scalar invariants. Full `u64` comment IDs use checked decimal text because SQLite integers are signed. No JSON documents are stored in SQLite.
`Store` retains compare-and-swap review revisions and atomic whole-review saves: metadata and replacement comment/checkmark rows commit together. Read transactions reconstruct validated reviews from one consistent snapshot, including when listing in descending ID order. Stored text is bounded to 64 MiB per review, including a fixed per-comment/checkmark overhead. JSON version 4 is an independent import/export format. Incompatible databases, including schemas 1 and 2, are rejected and preserved without migration or reset. CLI metadata, sole-review restoration, and selector labels reuse loaded reviews; selector choices live only in the displayed buffer. `Store` retains compare-and-swap review revisions and atomic whole-review saves: metadata and replacement comment/checkmark rows commit together. A stored review cannot be reassigned to another scope. Read transactions reconstruct validated reviews from one consistent snapshot, including when listing in descending ID order. Stored text is bounded to 64 MiB per review, including a fixed per-comment/checkmark overhead. JSON version 5 is an independent import/export format. Incompatible databases, including schema 3, are rejected and preserved without migration or reset. CLI metadata and selectors reuse loaded reviews; selector choices live only in the displayed buffer.
The review CLI keeps `list`/`show` read-only. Comment deletion validates the explicit review/comment IDs through an existing read-only store before opening it for a compare-and-swap save; absent storage and invalid targets do not create reviews or a database. The review CLI keeps `list`/`show` read-only. Comment deletion and resolution validate the explicit review/comment IDs through an existing read-only store before opening it for a compare-and-swap save; absent storage and invalid targets do not create reviews or a database. Resolution preserves comment bodies and immutable anchors; already-resolved comments succeed without writing or advancing the revision.
`editor_review` commits native comment/summary buffers on dismissal or switching, and verdicts/deletions immediately. It restores a sole stored review or opens the floating selector for multiple reviews. Exports retain their own file baseline and do not become automatic persistence targets; imports get fresh database identities. Review editors remain tab-owned native panes outside the workspace `PaneTree`. Storage opens lazily when a comparison is ready; the session supplies the configured or XDG default directory. Direct `Editor` callers inject a directory with `set_review_directory` to enable persistence. CLI listings exclude reviews with zero comments, not reviews with zero unresolved comments. Filtering stays at the CLI boundary: storage listing and editor restoration retain commentless reviews and their file checkmarks, summaries, and verdicts.
`editor_review` owns tab-local review state selected by canonical repository root and ordered resolved comparison identities, or a separate source scope for ordinary repository buffers. A sole scope-matching review restores automatically; multiple matches open the floating selector. `diff` freezes initial review endpoints through in-place Working refreshes; explicit comparisons and moved bookmark endpoints resolve their own scope. Source and comparison panes share the comment editor, immutable anchors, storage, and review commands, not their review documents. Dirty drafts block scope changes, and stored/JSON opens reject mismatched scopes before replacing state. Comment/summary text saves explicitly; dismissing discards that editor's unsaved text, while switching may retain hidden drafts. Verdicts/deletions/resolution changes commit immediately without saving drafts. Exports retain their own file baseline and do not become automatic persistence targets; imports get fresh database identities. Review editors remain tab-owned native panes outside the workspace `PaneTree`. The session supplies the configured or XDG default directory; direct `Editor` callers inject a directory with `set_review_directory` to enable persistence.
Successful SQLite autosaves and JSON-only saves share one acknowledgement operation: clear review dirtiness and advance the owning tab's native draft saved baselines only after persistence succeeds. Failed writes retain unsaved state; JSON exports do not acknowledge a pending SQLite save. Successful SQLite autosaves and JSON-only saves share one acknowledgement operation: clear review dirtiness and advance the owning tab's native draft saved baselines only after persistence succeeds. Failed writes retain unsaved state; JSON exports do not acknowledge a pending SQLite save.
Review replacement and comment deletion are private editor-owned operations. Replacement loads and validates its Stored/JSON/New source before retiring old bindings, installing the document, and resetting selection/navigation. Deletion retires and acknowledges only the matching comment drafts, preventing stale text from overwriting reused IDs. Both persist before opening the overview; a post-mutation save failure retains the applied, unsaved identity change. Native text/undo and general transition guards remain unchanged. Review replacement and comment deletion are private editor-owned operations. Replacement loads and validates its Stored/JSON/New source before retiring old bindings, installing the document, and resetting selection/navigation. Deletion retires and acknowledges only the matching comment drafts, preventing stale text from overwriting reused IDs. Both persist before opening the overview; a post-mutation save failure retains the applied, unsaved identity change. Native text/undo and general transition guards remain unchanged.
- `clipboard`: owns native plain-text provider selection and bounded subprocess I/O; it never computes selections or editing offsets. - `clipboard`: owns native plain-text provider selection and bounded subprocess I/O; it never computes selections or editing offsets.
@@ -64,7 +65,7 @@ Frontends inspect `file_picker()` for query, presentation, view, explorer-local
Frontends inspect `diagnostics()` and `diagnostic_at_cursor()` for validated active-buffer annotations. Diagnostics are owned by core LSP or a plugin and buffer revision; text changes clear them. Native server retirement removes only that server's contribution, preserving sibling diagnostics. The TUI underlines annotated text, colors affected gutter numbers by severity, and displays the primary caret's diagnostic message without replacing search/selection backgrounds. Frontends inspect `diagnostics()` and `diagnostic_at_cursor()` for validated active-buffer annotations. Diagnostics are owned by core LSP or a plugin and buffer revision; text changes clear them. Native server retirement removes only that server's contribution, preserving sibling diagnostics. The TUI underlines annotated text, colors affected gutter numbers by severity, and displays the primary caret's diagnostic message without replacing search/selection backgrounds.
Frontends borrow `semantic_tokens()` for sorted, single-line grapheme spans from the active buffer. Immutable `Arc` slices are shared by native LSP and buffer storage; painting does not copy tokens. Text replacements retain tokens outside the changed range and shift following positions using whole graphemes, including newline changes. Tokens overlapping the changed range are dropped; disjoint edits conservatively invalidate the range between their first and last changes. This applies to typing, undo/redo, completion, plugin replacements, and disk reloads. Path changes discard overlays. Native updates validate the whole applicable annotation batch before mutation. The TUI merges semantic styling into its existing glyph pass above syntax foregrounds but below diagnostic/search/selection/caret styling. Frontends borrow `semantic_tokens()` for sorted, single-line grapheme spans from the active buffer. Immutable `Arc` slices are shared by native LSP and buffer storage; painting does not copy tokens. Text replacements retain tokens outside the changed range and shift following positions using whole graphemes, including newline changes. Tokens overlapping the changed range are dropped; disjoint edits conservatively invalidate the range between their first and last changes. This applies to typing, undo/redo, completion, plugin replacements, and disk reloads. Path changes discard overlays. Native updates validate the whole applicable annotation batch before mutation. The TUI merges semantic styling into its existing glyph pass above syntax foregrounds but below diagnostic/search/selection/caret styling.
Frontends inspect `hover()` for optional read-only content and logical-line/grapheme scroll offsets. Popup request eligibility, dismissal, and scrolling stay editor/session-owned; the TUI clips the panel inside the full editor area without changing the primary cursor or viewport. Its hover-local syntax cache treats content as Markdown, including named fenced-code injections, and rebuilds only when content changes. The popup shares the document syntax palette and preserves raw Markdown text and logical scroll coordinates. Frontends inspect `hover()` for optional read-only content and logical-line/grapheme scroll offsets. Popup request eligibility, dismissal, and scrolling stay editor/session-owned; the TUI clips the panel inside the full editor area without changing the primary cursor or viewport. Its hover-local syntax cache treats content as Markdown, including named fenced-code injections, and rebuilds only when content changes. The popup shares the document syntax palette and preserves raw Markdown text and logical scroll coordinates.
Frontends borrow `completion()` for the read-only item list and selected index: zero is Original text, and other indices select `items[selected - 1]`. The editor owns the immutable original document/carets, atomic candidate transactions, cycling/dismissal, pending Insert undo, and final-only repeat recording. It changes only the primary completion target and translates secondary carets through all edits. The TUI places a windowed list near the current caret, bounded by the full editor rather than its pane, sanitizes/clips labels and detail by grapheme, and preserves hardware cursor ownership; wheel input over the list is consumed without dispatching edits. Frontends borrow `completion()` for the read-only item list and selected index: zero is Original text, and other indices select `items[selected - 1]`. The editor owns the immutable original document/carets, atomic candidate transactions, cycling/dismissal, pending Insert undo, and final-only repeat recording. It changes only the primary completion target and translates secondary carets through all edits. The TUI places a windowed list near the current caret, bounded by the full editor rather than its pane, sanitizes/clips labels and detail by grapheme, and preserves logical cursor ownership; wheel input over the list is consumed without dispatching edits.
Frontends borrow `snippet_selections()` for the active argument's end-exclusive grapheme ranges, including mirrors and empty tabstops. The editor caches those ranges after previews, argument edits, and navigation; rendering adds no snippet allocation. Template edits stay primary-only, translate other carets, and fold resolved replacement text and caret placement into the pending completion repeat step. Per-occurrence ancestry distinguishes nested arguments from adjacent empty stops, allowing enclosing replacements to retire only overwritten descendants. Frontends borrow `snippet_selections()` for the active argument's end-exclusive grapheme ranges, including mirrors and empty tabstops. The editor caches those ranges after previews, argument edits, and navigation; rendering adds no snippet allocation. Template edits stay primary-only, translate other carets, and fold resolved replacement text and caret placement into the pending completion repeat step. Per-occurrence ancestry distinguishes nested arguments from adjacent empty stops, allowing enclosing replacements to retire only overwritten descendants.
## Terminal lifecycle and layout ## Terminal lifecycle and layout
@@ -73,13 +74,13 @@ The terminal guard owns raw mode, alternate-screen state, bracketed paste, mouse
`tui::TerminalSession::run(inherited_screen, body)` scopes this ownership; `tui::run(&mut session, inherited_screen)` renders inside that active guard. On Unix, a fresh alternate screen pushes disambiguated keyboard flags so Ctrl+i stays distinct from Tab; final cleanup pops them. `TerminalSession::prepare_restart()` resets process-local input state without leaving the alternate screen or popping its keyboard flags. The replacement process inherits that stack entry rather than pushing another, and the guard stays armed if relaunch fails. `tui::TerminalSession::run(inherited_screen, body)` scopes this ownership; `tui::run(&mut session, inherited_screen)` renders inside that active guard. On Unix, a fresh alternate screen pushes disambiguated keyboard flags so Ctrl+i stays distinct from Tab; final cleanup pops them. `TerminalSession::prepare_restart()` resets process-local input state without leaving the alternate screen or popping its keyboard flags. The replacement process inherits that stack entry rather than pushing another, and the guard stays armed if relaunch fails.
Redraws stage Ratatui's buffer diff, cursor placement, and DEC synchronized-update commands (mode 2026) in a reusable byte buffer, then write and flush the complete frame to the terminal. Frame computation never suspends terminal presentation; synchronization covers transmitted painting rather than layout/highlighting work. The hardware cursor is hidden before painting even when synchronization is unsupported. Terminal cleanup releases synchronization before leaving the alternate screen or invoking caller panic diagnostics. Backend-writer access is enabled solely for this staging seam. Redraws stage Ratatui's buffer diff, logical cursor placement, and DEC synchronized-update commands (mode 2026) in a reusable byte buffer, then write and flush the complete frame to the terminal. Frame computation never suspends terminal presentation; synchronization covers transmitted painting rather than layout/highlighting work. `WheelPanels::cursor` records the final focused cursor position; the software cursor is painted after overlays, using the same named ANSI mode palette as the bars. `SoftwareCursorBackend` delegates drawing and cursor coordinates but suppresses hardware-cursor visibility, retaining input-method placement without a second cursor or OSC 12 dependency. The hardware cursor stays hidden even when synchronization is unsupported. Terminal cleanup releases synchronization before leaving the alternate screen, then restores cursor visibility before returning or invoking caller panic diagnostics. Backend-writer access is enabled solely for this staging seam.
`terminal_colors` intercepts crossterm's key-shaped OSC 11/4 replies before editor dispatch, assembles a bounded RGB background/red/green triple, and preserves unrelated events and opaque bracketed paste. Queries never block input and start after painting, so syntax initialization does not spend their reply deadline. Startup, color-scheme notifications, and focus-regain queries replace cached diff tints atomically. While any rendered pane shows a diff, a one-second fallback probes for silent palette changes or missed notifications; ordinary editor views do not poll. Its injected-time deadline prevents overlapping periodic requests. An unanswered/partial query expires after 250 ms and removes stale tints rather than assuming a dark theme. Valid late replies are consumed without becoming editing commands. The frontend precomputes rounded RGB blends from the original background (18% row, 38% character), propagating them to active, parked, and newly created panes. `terminal_colors` intercepts crossterm's key-shaped OSC 11/4 replies before editor dispatch, assembles a bounded RGB background/red/green triple, and preserves unrelated events and opaque bracketed paste. Queries never block input and start after painting, so syntax initialization does not spend their reply deadline. Startup, color-scheme notifications, and focus-regain queries replace cached diff tints atomically. While any rendered pane shows a diff, a one-second fallback probes for silent palette changes or missed notifications; ordinary editor views do not poll. Its injected-time deadline prevents overlapping periodic requests. An unanswered/partial query expires after 250 ms and removes stale tints rather than assuming a dark theme. Valid late replies are consumed without becoming editing commands. The frontend precomputes rounded RGB blends from the original background (18% row, 38% character), propagating them to active, parked, and newly created panes.
`vendor/crossterm` retains Crossterm 0.29.0's upstream source and MIT license, with a small Unix decoder patch exposing `Event::ColorSchemeChanged` for `CSI ? 997 ; 1/2 n`. The report signals a palette refresh, not a choice of hard-coded light/dark colors. Valid fragmented reports and malformed color reports leave following keys intact. Cargo patches both direct and Ratatui dependency paths to this one copy; remove the patch/workspace member once upstream supports these notifications. `vendor/crossterm` retains Crossterm 0.29.0's upstream source and MIT license, with a small Unix decoder patch exposing `Event::ColorSchemeChanged` for `CSI ? 997 ; 1/2 n`. The report signals a palette refresh, not a choice of hard-coded light/dark colors. Valid fragmented reports and malformed color reports leave following keys intact. Cargo patches both direct and Ratatui dependency paths to this one copy; remove the patch/workspace member once upstream supports these notifications.
The TUI allocates a flexible buffer viewport and optional one-row top/bottom bars, with no reserved prompt/message footer. Both bars derive visibility from configured content: empty content takes no row, and tabs-only content is hidden with a single tab in either position. Both render across ordinary, split, diff, and selector views. Ordered left/center/right groups use full-row centering, active-tab collision priority, internal padding, and independent styled edges. Floating Command/Search input owns the hardware cursor; non-focusable operation/diagnostic notifications anchor bottom-right inside the chrome-free workspace and hide obscured document carets. Higher-priority modal overlays suppress them without changing input state. Wheel hit regions clear each frame and consume reports over these popups. Zero-sized terminals render nothing; minimal-height input never reserves another row. Layout and terminal-cell text mapping remain frontend-owned. The TUI allocates a flexible buffer viewport and optional one-row top/bottom bars, with no reserved prompt/message footer. Both bars derive visibility from configured content: empty content takes no row, and tabs-only content is hidden with a single tab in either position. Both render across ordinary, split, diff, and selector views. Ordered left/center/right groups use full-row centering, active-tab collision priority, internal padding, and independent styled edges; accented content and edges share the focused mode's ANSI palette colors. Floating Command/Search input owns the software cursor; non-focusable operation/diagnostic notifications anchor bottom-right inside the chrome-free workspace and hide obscured document carets. Higher-priority modal overlays suppress them without changing input state. Wheel hit regions clear each frame and consume reports over these popups. Zero-sized terminals render nothing; minimal-height input never reserves another row. Layout and terminal-cell text mapping remain frontend-owned.
Comparison views reserve no separate metadata header or native-buffer help footer. Revision labels render bottom-left in pane borders (combined on single-pane views), with per-side editability top-right and focus indicated by border styling. Dock and document geometry use the reclaimed workspace rows; conditional loading/error/file notices remain separate from the border metadata. Comparison views reserve no separate metadata header or native-buffer help footer. Revision labels render bottom-left in pane borders (combined on single-pane views), with per-side editability top-right and focus indicated by border styling. Dock and document geometry use the reclaimed workspace rows; conditional loading/error/file notices remain separate from the border metadata.
+50 -14
View File
@@ -15,6 +15,8 @@ Vamp.configure do |config|
config.clipboard_mode = "system" config.clipboard_mode = "system"
config.git_blame = true # false disables current-line attribution config.git_blame = true # false disables current-line attribution
config.git_gutter = "bar" # or "symbols", "line_numbers", "none" config.git_gutter = "bar" # or "symbols", "line_numbers", "none"
config.cursor = {} # mode colors enabled; all modes use a block cursor
# config.cursor = { mode_colors: false, insert: :bar, visual: :underline }
config.scroll_distance = 0 # nonnegative edge distance, or nil to center config.scroll_distance = 0 # nonnegative edge distance, or nil to center
config.scroll_step_lines = nil # Ctrl+u/d: half viewport, or a positive screen-row count config.scroll_step_lines = nil # Ctrl+u/d: half viewport, or a positive screen-row count
config.highlight_trailing_whitespace = false # true marks line-end whitespace in red config.highlight_trailing_whitespace = false # true marks line-end whitespace in red
@@ -30,6 +32,8 @@ Vamp.configure do |config|
config.diff_view_mode = "split" # or "unified" config.diff_view_mode = "split" # or "unified"
config.diff_split_orientation = "vertical" # or "horizontal" config.diff_split_orientation = "vertical" # or "horizontal"
config.diff_follow_working_copy = true config.diff_follow_working_copy = true
config.pull_request_review_requested_symbol = "🙏"
config.pull_request_approved_symbol = "👍"
config.resolve_history_layout = "columns" # or "base_below" config.resolve_history_layout = "columns" # or "base_below"
config.review_directory = nil # XDG data directory; override with an absolute or config-relative path config.review_directory = nil # XDG data directory; override with an absolute or config-relative path
config.bind "ctrl+h", config.core.left, mode: config.modes.tree config.bind "ctrl+h", config.core.left, mode: config.modes.tree
@@ -56,6 +60,12 @@ Plugin paths resolve relative to the config file, not the shell's working direct
`config.file_explorer_side` defaults to `"right"`; other choices are `"left"`, `"top"`, and `"bottom"`. Independent `file_explorer_view` / `file_picker_view` preferences both default to `"tree"` and accept `"list"` as an alternative. Invalid preference strings report notices and retain defaults while valid bindings still install. Non-string/empty values disable the whole configuration like other Ruby type errors. `config.file_explorer_side` defaults to `"right"`; other choices are `"left"`, `"top"`, and `"bottom"`. Independent `file_explorer_view` / `file_picker_view` preferences both default to `"tree"` and accept `"list"` as an alternative. Invalid preference strings report notices and retain defaults while valid bindings still install. Non-string/empty values disable the whole configuration like other Ruby type errors.
`config.clipboard_mode` accepts `"system"` (default) or `"separate"`. An invalid policy string reports a notice and retains System while valid bindings still install; non-string/empty values reject the whole Ruby configuration. `config.clipboard_mode` accepts `"system"` (default) or `"separate"`. An invalid policy string reports a notice and retains System while valid bindings still install; non-string/empty values reject the whole Ruby configuration.
`config.cursor` accepts a partial hash. `mode_colors` defaults to `true`: the primary software cursor and secondary text carets use the terminal's ANSI cyan in Normal, green in Insert, magenta in Visual (including Visual Line), yellow in Command, and blue in Search. These are palette entries from the current terminal color scheme, not fixed RGB colors. Set `config.cursor = { mode_colors: false }` for a neutral reverse-video block cursor (default text color for bar/underline); secondary carets retain their magenta highlight.
The `normal`, `insert`, `visual`, `command`, and `search` keys select software cursor shapes: `:block`, `:bar`, or `:underline` (strings also work). Every mode defaults to a steady block. Block and underline preserve the displayed grapheme; the bar draws `▏` over the hovered character until the cursor moves. For example, `config.cursor = { insert: :bar, visual: :underline }` changes those two shapes without disabling mode colors. Each assignment replaces the cursor configuration; omitted keys retain built-in defaults. Unknown keys, nonboolean `mode_colors`, unsupported shapes, and non-hash values reject the configuration.
Shapes apply to the primary cursor, including command/search prompts, pickers, and historical/diff text; secondary carets remain cell highlights. The cursor is painted after the focused view's overlays, takes precedence over syntax/search/selection colors, and disappears when its position is offscreen or covered by a notification. The hardware cursor stays hidden during editing; its logical position is retained for input methods, and normal exit/errors/panics restore its visibility. Vamp does not change terminal cursor color or shape settings, so multiplexers need no native cursor-color support. File contents and cursor positions remain unchanged.
`config.scroll_distance` defaults to `0`: keep the viewport still until its primary cursor or selected picker entry would leave it. A nonnegative integer reserves that many visible rows above/below the cursor, and terminal-cell columns left/right in unwrapped text. `nil` keeps it centered; integers at least half the current viewport dimension behave the same way until resizing makes that margin usable. The start of content limits centering, while trailing blank space allows centering near the end. Whole two-row picker entries stay aligned, using the nearest entry to the center when exact margins cannot fit. `config.scroll_distance` defaults to `0`: keep the viewport still until its primary cursor or selected picker entry would leave it. A nonnegative integer reserves that many visible rows above/below the cursor, and terminal-cell columns left/right in unwrapped text. `nil` keeps it centered; integers at least half the current viewport dimension behave the same way until resizing makes that margin usable. The start of content limits centering, while trailing blank space allows centering near the end. Whole two-row picker entries stay aligned, using the nearest entry to the center when exact margins cannot fit.
The setting applies to ordinary and historical buffers, split/unified diff panes, file pickers and explorers, command/buffer palettes, completion lists, and revision selectors. Wrapped text measures visual rows, not source lines; picker distances use result rows, excluding borders, search fields, and help. Manual mouse-wheel scrolling remains detached until keyboard navigation resumes. Only `nil` or integers from `0` through the platform's Rust `usize` maximum (`18446744073709551615` on 64-bit systems) are accepted; other values reject the configuration. The setting applies to ordinary and historical buffers, split/unified diff panes, file pickers and explorers, command/buffer palettes, completion lists, and revision selectors. Wrapped text measures visual rows, not source lines; picker distances use result rows, excluding borders, search fields, and help. Manual mouse-wheel scrolling remains detached until keyboard navigation resumes. Only `nil` or integers from `0` through the platform's Rust `usize` maximum (`18446744073709551615` on 64-bit systems) are accepted; other values reject the configuration.
@@ -103,7 +113,23 @@ Indicators compare the current editor text (including unsaved edits) against Git
`config.diff_view_mode` selects the initial view for each new comparison: `"split"` (default) or `"unified"`. `config.diff_split_orientation` selects `"vertical"` (left/right, default) or `"horizontal"` (above/below) for split views. Invalid values reject the configuration. Normal-mode **Space v** cycles split/unified; **Space s** flips split orientation. These controls affect the current comparison, not startup defaults, and retain their choices across file switches and tabs. Orientation changes apply only in split view. `config.diff_view_mode` selects the initial view for each new comparison: `"split"` (default) or `"unified"`. `config.diff_split_orientation` selects `"vertical"` (left/right, default) or `"horizontal"` (above/below) for split views. Invalid values reject the configuration. Normal-mode **Space v** cycles split/unified; **Space s** flips split orientation. These controls affect the current comparison, not startup defaults, and retain their choices across file switches and tabs. Orientation changes apply only in split view.
`config.diff_follow_working_copy` defaults to `true`. A Working-checkout After follows descendant checkouts automatically, including in inactive tabs; `false` disables endpoint following without disabling ordinary live-buffer editing or reload. Only literal booleans are accepted. Pinned After endpoints never move, but their checkout-aware editability checks remain enabled regardless of this setting. See [repository diff](editing.md#repository-diff) for ancestry and refresh behavior. `config.diff_follow_working_copy` defaults to `true`. The After picker calls its live-files choice **Follow checkout** when enabled, otherwise **Checkout snapshot**. Following advances to descendant checkouts automatically, including in inactive tabs; `false` disables endpoint following without disabling ordinary live-buffer editing or reload. Only literal booleans are accepted. Before is always frozen. Pinned After endpoints never move, but their checkout-aware editability checks remain enabled regardless of this setting. See [repository diff](editing.md#repository-diff) for ancestry and refresh behavior.
`config.pull_request_review_requested_symbol` and `config.pull_request_approved_symbol` control the markers before PR numbers in the pull-request picker. Defaults are `"🙏"` for an outstanding personal review request and `"👍"` for your active approval, using the API-authenticated account. Requests take precedence over approvals when both apply. Each option accepts a string without control characters; multi-character and wide Unicode symbols are supported. Set either to `""` to hide that state, or both to `""` to remove the marker gutter. PR numbers and metadata stay aligned by terminal-cell width, including rows without a marker. Non-strings and strings containing tabs, newlines, or other control characters reject the configuration.
`config.pull_request_sort` optionally overrides saved sorting: `nil` or an omitted option uses saved sorting, then built-in defaults. A configured sort section replaces that entire saved section; omitted criteria use built-in defaults. `config.pull_request_filters` sets the session's initial filter buckets; `nil` or omission includes all buckets. UI filter changes are shared across tabs and picker reopenings for this vamp session only. Restart restores the configured filters or includes all buckets; previously saved filters are ignored.
```ruby
config.pull_request_sort = {
updated_at: { precedence: 1, direction: :desc },
created_at: { direction: :asc }
}
config.pull_request_filters = [:requested, :approved]
```
Sort fields are `requested`, `updated_at`, `approved`, and `created_at`, in that default precedence order. Default direction is `desc`; timestamp criteria support `asc` for oldest first. `precedence` is `nil` (unnumbered default position) or a unique integer in `1..4`. Filters are any subset of `requested` (Requested from me), `approved` (Approved by me without an outstanding personal request), and `other` (Other / unavailable). `[]` excludes all requests; `{}` resets sorting to built-in defaults. Unknown fields/options, duplicate ranks/filters, and invalid types or directions reject configuration.
Enter Apply in the sort menu saves changed sorting to `$XDG_STATE_HOME/vamp/pull_requests.json`, or `~/.local/state/vamp/pull_requests.json` if XDG state is unset or relative. Applying filters never writes this file, and subsequent sort saves exclude filters. This also works with `--no-config`. Configuration remains a startup override, not a lock: UI edits work for the session, but explicitly configured settings win again next startup. Sort save failures report session-only changes. Corrupt, incompatible, or non-regular storage is reported and preserved rather than reset or overwritten.
`config.resolve_history_layout` controls the read-only conflict inputs opened by `:resolve.history`: `"columns"` (default) places left/base/right side by side; `"base_below"` places left/right above a full-width base. Both layouts share aligned rows and synchronized vertical scrolling. Tab/Shift+Tab follows layout order (left/base/right or left/right/base); directional pane actions follow the displayed geometry. Narrow terminals show the focused source only; the base-below layout does the same when there is insufficient height. This setting does not change the editable Resolution view or ordinary diffs. Invalid values reject the configuration. `config.resolve_history_layout` controls the read-only conflict inputs opened by `:resolve.history`: `"columns"` (default) places left/base/right side by side; `"base_below"` places left/right above a full-width base. Both layouts share aligned rows and synchronized vertical scrolling. Tab/Shift+Tab follows layout order (left/base/right or left/right/base); directional pane actions follow the displayed geometry. Narrow terminals show the focused source only; the base-below layout does the same when there is insufficient height. This setting does not change the editable Resolution view or ordinary diffs. Invalid values reject the configuration.
@@ -117,6 +143,8 @@ config.bind "leader s", config.core.diff.orientation.toggle
`config.bar.top` and `config.bar.bottom` each accept ordered `left`, `center`, and `right` arrays of segment names. Both bars accept every builtin and custom segment, with the same anchors, title templates, margins, padding, styled edges, and collision handling. Left and right groups anchor to their respective edges; the center group is centered on the whole row, not on the gap remaining between the other groups. Array order is display order within each group. Omitted groups and segment options retain that bar's defaults; an empty array removes that group. `config.bar.top` and `config.bar.bottom` each accept ordered `left`, `center`, and `right` arrays of segment names. Both bars accept every builtin and custom segment, with the same anchors, title templates, margins, padding, styled edges, and collision handling. Left and right groups anchor to their respective edges; the center group is centered on the whole row, not on the gap remaining between the other groups. Array order is display order within each group. Omitted groups and segment options retain that bar's defaults; an empty array removes that group.
Accented segments (including active tabs, mode, position, and custom labels), their padding, and decorative edge colors follow the focused editing mode using the same ANSI palette as the software cursor. Both bars change together; inactive tabs, neutral text, separators, and margins retain their existing styling. Setting `config.cursor = { mode_colors: false }` affects cursors only, not the bars.
The renderer inserts one unstyled blank column between visible items in each group, including tab titles. Hidden items contribute no separator; there is no separator before the first or after the last item. Separator widths count toward anchoring and collision handling. Plain-text segments default to no padding or margins, so adjacent labels do not double their spacing. The renderer inserts one unstyled blank column between visible items in each group, including tab titles. Hidden items contribute no separator; there is no separator before the first or after the last item. Separator widths count toward anchoring and collision handling. Plain-text segments default to no padding or margins, so adjacent labels do not double their spacing.
Use the two setters independently; a combined `config.bar = { ... }` assignment is not supported. Use the two setters independently; a combined `config.bar = { ... }` assignment is not supported.
@@ -154,7 +182,7 @@ Each segment's `title` is a literal template supporting only `{index}`, `{view}`
`margin` adds unstyled space outside both edges of a segment, unlike the styled internal `padding`. `leading_margin` and `trailing_margin` override their respective sides. All accept integers from `0` through `64`; all margins default to zero. Explicit margins are additional to the renderer's one-column separator, so leave them at zero for normal inter-item spacing. Margins count toward anchor placement and collision handling; empty segments consume no margin, and margins yield along with padding and edges when only clipped content fits. `margin` adds unstyled space outside both edges of a segment, unlike the styled internal `padding`. `leading_margin` and `trailing_margin` override their respective sides. All accept integers from `0` through `64`; all margins default to zero. Explicit margins are additional to the renderer's one-column separator, so leave them at zero for normal inter-item spacing. Margins count toward anchor placement and collision handling; empty segments consume no margin, and margins yield along with padding and edges when only clipped content fits.
`padding` adds spaces inside the segment's styling, on both sides of its title, and accepts integers from `0` through `64`. It defaults to `0` for plain-text and custom segments and `1` for tabs, mode, position, battery, diff totals, shell status, and LSP indicators. Internal padding is separate from the inter-item separator; explicit padding can deliberately add more whitespace. `leading_edge` and `trailing_edge` are separate styled glyph strings, not padding; `""` removes an edge. Tabs, diff totals, and shell status default to `"░▓"` / `"▓░"` edges; mode has only the trailing `"▓░"` edge, position and battery only the leading `"░▓"` edge, and other segments have none. `first_leading_edge` optionally overrides the first occurrence's leading glyphs: for tabs this is the actual first tab, not the first tab remaining after clipping; other segments have one occurrence. Tabs default this override to `""`, suppressing the first tab's left fade. Unicode widths are measured in terminal cells. Edge strings must be single-line and contain no control characters. Unknown style keys, invalid templates, and wrong types reject configuration. `padding` adds spaces inside the segment's styling, on both sides of its title, and accepts integers from `0` through `64`. It defaults to `0` for plain-text and custom segments and `1` for tabs, mode, position, battery, shell status, and LSP indicators. Diff totals use plain text without a filled background, padding, or edges by default. Internal padding is separate from the inter-item separator; explicit padding can deliberately add more whitespace. `leading_edge` and `trailing_edge` are separate styled glyph strings, not padding; `""` removes an edge. Tabs and shell status default to `"░▓"` / `"▓░"` edges; mode has only the trailing `"▓░"` edge, position and battery only the leading `"░▓"` edge, and other segments have none. `first_leading_edge` optionally overrides the first occurrence's leading glyphs: for tabs this is the actual first tab, not the first tab remaining after clipping; other segments have one occurrence. Tabs default this override to `""`, suppressing the first tab's left fade. Unicode widths are measured in terminal cells. Edge strings must be single-line and contain no control characters. Unknown style keys, invalid templates, and wrong types reject configuration.
Any other segment name is a custom named value, such as `:build_status`. Set initial strings with `config.labels`; an empty value hides the custom segment, including its title override, margins, padding, and edges. Names match `[A-Za-z_][A-Za-z0-9_]*`. Labels are plain text: control characters are replaced rather than interpreted as terminal escapes. The same named value can appear in either bar. Any other segment name is a custom named value, such as `:build_status`. Set initial strings with `config.labels`; an empty value hides the custom segment, including its title override, margins, padding, and edges. Names match `[A-Za-z_][A-Za-z0-9_]*`. Labels are plain text: control characters are replaced rather than interpreted as terminal escapes. The same named value can appear in either bar.
@@ -241,8 +269,8 @@ Normal and Visual Ctrl+u/Ctrl+d invoke `config.core.scroll_step_up` / `config.co
| Normal | `edit`, `buffers`, `buffer`, `buffer_next`, `buffer_previous`, `buffer_delete`, `buffer_force_delete` | | Normal | `edit`, `buffers`, `buffer`, `buffer_next`, `buffer_previous`, `buffer_delete`, `buffer_force_delete` |
| Normal | `follow_link` | | Normal | `follow_link` |
| Normal | `diff`, `diff.mode.toggle`, `diff.view.toggle`, `diff.orientation.toggle`, `diff.review.toggle` | | Normal | `diff`, `diff.mode.toggle`, `diff.view.toggle`, `diff.orientation.toggle`, `diff.review.toggle` |
| Normal, Visual | `diff.comment` | | Normal, Visual | `comment` |
| Normal | `diff.review.edit`, `diff.review.delete`, `diff.review.resolve`, `diff.review.unresolve`, `diff.review.next`, `diff.review.previous`, `diff.review.overview`, `diff.review.copy`, `diff.review.summary`, `diff.review.verdict`, `diff.review.save`, `diff.review.open`, `diff.review.new` | | Normal | `review.edit`, `review.delete`, `review.resolve`, `review.unresolve`, `review.next`, `review.previous`, `review.overview`, `review.copy`, `review.summary`, `review.verdict`, `review.save`, `review.open`, `review.new` |
| Normal, Insert, Visual, Command, Search | `diff.close` | | Normal, Insert, Visual, Command, Search | `diff.close` |
| Normal | `resolve`, `resolve.next`, `resolve.previous`, `resolve.use_source`, `resolve.source`, `resolve.base`, `resolve.next_file`, `resolve.previous_file`, `resolve.files`, `resolve.draft`, `resolve.history`, `resolve.view.toggle`, `resolve.close` | | Normal | `resolve`, `resolve.next`, `resolve.previous`, `resolve.use_source`, `resolve.source`, `resolve.base`, `resolve.next_file`, `resolve.previous_file`, `resolve.files`, `resolve.draft`, `resolve.history`, `resolve.view.toggle`, `resolve.close` |
| Normal, Insert, Visual, Command, Search | `word_wrap.toggle` | | Normal, Insert, Visual, Command, Search | `word_wrap.toggle` |
@@ -324,20 +352,20 @@ config.bind "ctrl+h", nil, mode: config.modes.tree
The diff's changed-file explorer and floating picker use these same tree and selection contexts, including remaps and disabled keys. Enter opens the selected file's comparison; writable After reuses its live buffer. The catalog contains only changed paths, with A/M/D/R status markers, rather than a disk scan. The diff's changed-file explorer and floating picker use these same tree and selection contexts, including remaps and disabled keys. Enter opens the selected file's comparison; writable After reuses its live buffer. The catalog contains only changed paths, with A/M/D/R status markers, rather than a disk scan.
Ordinary `config.core.file_picker` and `config.core.file_explorer` bindings work inside comparisons. Ctrl+w closes a focused picker/explorer, retaining its query, selection, and expansion state; the panes use the reclaimed width. Ctrl+e has no reserved diff behavior. Escape closes the revision selector in either stage, but an opened comparison still closes explicitly through `:diff.close`, its palette action, or the generated action value below. `config.core.diff` remains the opening action and exposes immutable `close`, `mode.toggle`, `view.toggle`, and `orientation.toggle` children. New comparisons default to Branch changes (merge base → selected After); Normal-mode Ctrl+b, `:diff.mode.toggle`, or the palette toggles to direct Snapshots and back, preserving the selected endpoints. Selecting Working checkout on either side forces Snapshots. Ordinary `config.core.file_picker` and `config.core.file_explorer` bindings work inside comparisons. Ctrl+w closes a focused picker/explorer, retaining its query, selection, and expansion state; the panes use the reclaimed width. Ctrl+e has no reserved diff behavior. Escape closes the revision selector in either stage, but an opened comparison still closes explicitly through `:diff.close`, its palette action, or the generated action value below. `config.core.diff` remains the opening action and exposes immutable `close`, `mode.toggle`, `view.toggle`, and `orientation.toggle` children. New comparisons default to Branch changes (merge base → selected After); Normal-mode Ctrl+b, `:diff.mode.toggle`, or the palette toggles to direct Snapshots and back, preserving the selected endpoints. Selecting Checkout snapshot or Follow checkout forces Snapshots.
`config.core.diff.review.toggle` is a non-mutating Normal-mode action, also available as `:diff.review.toggle` and in the palette. It marks/unmarks the highlighted changed-file leaf when the comparison's explorer is focused, or the current comparison file from a text pane. Read-only snapshots permit review marks. The default `c` shortcut applies only while browsing the diff's changed-file tree; explicit bindings and disabled keys override it. For example, `config.bind "ctrl+g", config.core.diff.review.toggle`; use the palette or a control-key binding while filtering, including List view, so printable input stays in the query. `config.core.diff.review.toggle` is a non-mutating Normal-mode action, also available as `:diff.review.toggle` and in the palette. It marks/unmarks the highlighted changed-file leaf when the comparison's explorer is focused, or the current comparison file from a text pane. Read-only snapshots permit review marks. The default `c` shortcut applies only while browsing the diff's changed-file tree; explicit bindings and disabled keys override it. For example, `config.bind "ctrl+g", config.core.diff.review.toggle`; use the palette or a control-key binding while filtering, including List view, so printable input stays in the query.
Local comments use `config.core.diff.comment` in Normal or Visual mode; the remaining `config.core.diff.review` actions in the table above use Normal mode. They have no default bindings and are available through the palette and canonical Ex commands. `edit`, `delete`, `resolve`, `unresolve`, `verdict`, `save`, and `open` open argument prompts when selected as actions. Comment IDs are optional and default to the overview entry under the caret or selected comment. For example: Local comments use `config.core.comment` in Normal or Visual mode in ordinary repository source buffers and diff text panes; the remaining `config.core.review` actions in the table above use Normal mode. File checkmarks use `config.core.diff.review.toggle`. These actions have no default bindings and are available through the palette and Ex commands. `edit`, `delete`, `resolve`, `unresolve`, `verdict`, `save`, and `open` open argument prompts when selected as actions. Comment IDs are optional and default to the overview entry under the caret or selected comment. For example:
```ruby ```ruby
config.bind "leader r c", config.core.diff.comment config.bind "leader r c", config.core.comment
config.bind "leader r c", config.core.diff.comment, mode: config.modes.visual config.bind "leader r c", config.core.comment, mode: config.modes.visual
config.bind "leader r o", config.core.diff.review.overview config.bind "leader r o", config.core.review.overview
config.bind "leader r n", config.core.diff.review.next config.bind "leader r n", config.core.review.next
``` ```
Review editing uses a floating window without adding workspace splits. Dismissing or switching editors commits text to local SQLite; verdicts, deletions, and resolution changes commit immediately. `:w` commits explicitly; `:diff.review.save path` exports JSON without redirecting autosaves. `config.review_directory` defaults to `nil`, selecting `$XDG_DATA_HOME/vamp/reviews/` (absolute XDG path only), otherwise `~/.local/share/vamp/reviews/`. String overrides are resolved relative to the configuration file; empty/NUL-containing strings and non-string/non-nil values are rejected. These actions do not contact a forge. See [local review behavior](editing.md#repository-diff). Review editing uses a floating window without adding workspace splits. `:w` or `:review.save` commits comment/summary text, including hidden drafts; dismissing an editor discards its unsaved text, and switching editors does not save it. Verdicts, deletions, and resolution changes commit immediately without saving drafts. `:review.save path` additionally exports JSON without redirecting autosaves. `config.review_directory` defaults to `nil`, selecting `$XDG_DATA_HOME/vamp/reviews/` (absolute XDG path only), otherwise `~/.local/share/vamp/reviews/`. String overrides are resolved relative to the configuration file; empty/NUL-containing strings and non-string/non-nil values are rejected. These actions do not contact a forge. See [local review behavior](editing.md#repository-diff).
`config.core.pane.close` and `config.core.pane.force_close` close a focused **docked** file list instead of its editor pane, without discarding buffers or exiting the comparison. A floating picker does not intercept these actions: normal close still protects underlying dirty buffers, while force-close retains its existing discard semantics. For example, bind `config.bind "ctrl+x", config.core.pane.close`; focused tree/selection overrides and printable filter input retain priority. Palette-originated close actions retain the originating dock target through force confirmation. `config.core.pane.close` and `config.core.pane.force_close` close a focused **docked** file list instead of its editor pane, without discarding buffers or exiting the comparison. A floating picker does not intercept these actions: normal close still protects underlying dirty buffers, while force-close retains its existing discard semantics. For example, bind `config.bind "ctrl+x", config.core.pane.close`; focused tree/selection overrides and printable filter input retain priority. Palette-originated close actions retain the originating dock target through force confirmation.
@@ -382,6 +410,7 @@ Vamp.configure do |config|
config.lsp["rust"] = true # rust-analyzer, extensions: ["rs"] config.lsp["rust"] = true # rust-analyzer, extensions: ["rs"]
config.lsp["ruby"] = true # solargraph stdio, extensions: ["rb"] config.lsp["ruby"] = true # solargraph stdio, extensions: ["rb"]
config.lsp["python"] = true # ty server + ruff server, extensions: ["py"] config.lsp["python"] = true # ty server + ruff server, extensions: ["py"]
config.lsp["typst"] = true # tinymist lsp, extensions: ["typ"]
config.lsp["my-language"] = { config.lsp["my-language"] = {
command: ["my-language-server", "--stdio"], command: ["my-language-server", "--stdio"],
@@ -396,13 +425,15 @@ Vamp.configure do |config|
end end
``` ```
Keys are arbitrary nonempty strings, used as the protocol's `languageId`; they need no Tree-sitter grammar or hardcoded language enum. Absent/`false` entries are disabled. `true` enables a built-in preset: `"rust"` uses `rust-analyzer`/`rs`, `"python"` uses `ty server` plus `ruff server`/`py`, and `"ruby"` uses `solargraph stdio`/`rb`. Unknown keys need a configuration object with nonempty `command` argv or a `servers` list, plus `extensions` (without leading dots). Objects also explicitly enable servers; known presets supply omitted command/extensions. An explicit `command` replaces the entire preset with one server: `config.lsp["rust"] = { command: ["/custom/path/rust-analyzer"] }` retains `rs`, while a Python command override does not also launch Ruff. Keys are arbitrary nonempty strings, used as the protocol's `languageId`; they need no Tree-sitter grammar or hardcoded language enum. Absent/`false` entries are disabled. `true` enables a built-in preset: `"rust"` uses `rust-analyzer`/`rs`, `"python"` uses `ty server` plus `ruff server`/`py`, `"ruby"` uses `solargraph stdio`/`rb`, and `"typst"` uses `tinymist lsp`/`typ`. Unknown keys need a configuration object with nonempty `command` argv or a `servers` list, plus `extensions` (without leading dots). Objects also explicitly enable servers; known presets supply omitted command/extensions. An explicit `command` replaces the entire preset with one server: `config.lsp["rust"] = { command: ["/custom/path/rust-analyzer"] }` retains `rs`, while a Python command override does not also launch Ruff.
Only `command`, `extensions`, `initialization_options`, `settings`, and `servers` are accepted. Options/settings must be JSON-compatible objects. Without an explicit command/list, options apply to every default server; explicit `initialization_options` replaces preset defaults. `servers` must be a nonempty ordered list of objects with explicit `command` and optional per-server `initialization_options`/`settings`; it shares language-level extensions and cannot be combined with top-level command/options/settings. Invalid declarations reject configuration with a notice rather than activating a guessed server. Commands are executable/argument arrays, never shell commands; use an absolute path if the executable is not on PATH. No server installation or restart is automatic. Only `command`, `extensions`, `initialization_options`, `settings`, and `servers` are accepted. Options/settings must be JSON-compatible objects. Without an explicit command/list, options apply to every default server; explicit `initialization_options` replaces preset defaults. `servers` must be a nonempty ordered list of objects with explicit `command` and optional per-server `initialization_options`/`settings`; it shares language-level extensions and cannot be combined with top-level command/options/settings. Invalid declarations reject configuration with a notice rather than activating a guessed server. Commands are executable/argument arrays, never shell commands; use an absolute path if the executable is not on PATH. No server installation or restart is automatic.
Install Solargraph yourself with `gem install solargraph` in the project's Ruby environment. The Ruby preset launches `["solargraph", "stdio"]`, following [Solargraph's stdio integration](https://solargraph.org/guides/language-server), and uses [YARD annotations](https://solargraph.org/guides/yard) for type information. Explicit `command` overrides replace the entire argv: for a bundled installation, use `config.lsp["ruby"] = { command: ["bundle", "exec", "solargraph", "stdio"] }`; Vamp retains the `rb` extension but does not append `stdio` to your override. Install Solargraph yourself with `gem install solargraph` in the project's Ruby environment. The Ruby preset launches `["solargraph", "stdio"]`, following [Solargraph's stdio integration](https://solargraph.org/guides/language-server), and uses [YARD annotations](https://solargraph.org/guides/yard) for type information. Explicit `command` overrides replace the entire argv: for a bundled installation, use `config.lsp["ruby"] = { command: ["bundle", "exec", "solargraph", "stdio"] }`; Vamp retains the `rb` extension but does not append `stdio` to your override.
**Config-file lint style:** Solargraph's RuboCop reporter discovers `.rubocop.yml` from the Ruby file's directory, not Vamp's workspace. A config under `~/.config/vamp/` therefore does not inherit this repository's policy. To keep double quotes, multiline trailing argument commas, commented-out settings without a space after `#`, and no required frozen-string header, place this `.rubocop.yml` beside `config.rb` (also for a custom `--config` path): Install [Tinymist](https://github.com/Myriad-Dreamin/tinymist#installation) separately and enable `config.lsp["typst"] = true` for `.typ` files. The preset launches `["tinymist", "lsp"]` with language ID `typst`; it does not enable preview or add export settings. Tinymist builds that return overlapping semantic tokens despite Vamp advertising no overlap support retain Tree-sitter highlighting and report the rejected tokens; hover and other LSP requests remain available. This occurs with the installed Typst 0.14.2-based build (`tinymist/v0.14.6-rc2`).
**Config-file lint style:** Solargraph's RuboCop reporter discovers `.rubocop.yml` from the Ruby file's directory, not Vamp's workspace. A config under `~/.config/vamp/` therefore does not inherit this repository's policy. To keep double quotes, multiline trailing argument commas, commented-out settings without a space after `#`, no required frozen-string header, and no block-length limit on `Vamp.configure`, place this `.rubocop.yml` beside `config.rb` (also for a custom `--config` path):
```yaml ```yaml
Style/StringLiterals: Style/StringLiterals:
@@ -416,9 +447,14 @@ Style/FrozenStringLiteralComment:
Layout/LeadingCommentSpace: Layout/LeadingCommentSpace:
Enabled: false Enabled: false
Metrics/BlockLength:
AllowedMethods:
- refine
- Vamp.configure
``` ```
Syntax errors and other lint checks remain enabled. Restart Vamp after changing the policy so Solargraph reloads it; the Ruby config itself need not change. Syntax errors and other lint checks remain enabled. The block-length exemption applies only to `Vamp.configure`, alongside RuboCop's default `refine` exemption; ordinary blocks still have the normal limit. Restart Vamp after changing the policy so Solargraph reloads it; the Ruby config itself need not change.
**Python (Astral):** install [ty](https://docs.astral.sh/ty/editors/) and [Ruff](https://docs.astral.sh/ruff/editors/setup/) yourself, for example with `uv tool install ty` and `uv tool install ruff`. The Python preset sends the same documents to both servers, uses ty for hover/definition, and merges type errors with Ruff lint diagnostics. Clearing or losing one server preserves the other's diagnostics. Formatting and code actions remain unsupported by Vamp. **Python (Astral):** install [ty](https://docs.astral.sh/ty/editors/) and [Ruff](https://docs.astral.sh/ruff/editors/setup/) yourself, for example with `uv tool install ty` and `uv tool install ruff`. The Python preset sends the same documents to both servers, uses ty for hover/definition, and merges type errors with Ruff lint diagnostics. Clearing or losing one server preserves the other's diagnostics. Formatting and code actions remain unsupported by Vamp.
+39 -4
View File
@@ -23,6 +23,8 @@ The default workspace member is the editor. `vendor/crossterm` is included to te
`vendor/tree-sitter-honey` contains a minimal Rust binding plus the unchanged generated parser, parser header, and highlight query from [`valdemar/tree-sitter-honey`](https://github.com/valdemar/tree-sitter-honey), revision `10f1ff746fe57736ae7d7c8c402f7b265680b26c` (MIT). Builds do not depend on a sibling checkout or an installed Tree-sitter CLI. To update, copy `src/parser.c`, `src/tree_sitter/parser.h`, and `queries/highlights.scm` from the same grammar revision, update the revision recorded here, and run `cargo test --lib syntax::tests`. `vendor/tree-sitter-honey` contains a minimal Rust binding plus the unchanged generated parser, parser header, and highlight query from [`valdemar/tree-sitter-honey`](https://github.com/valdemar/tree-sitter-honey), revision `10f1ff746fe57736ae7d7c8c402f7b265680b26c` (MIT). Builds do not depend on a sibling checkout or an installed Tree-sitter CLI. To update, copy `src/parser.c`, `src/tree_sitter/parser.h`, and `queries/highlights.scm` from the same grammar revision, update the revision recorded here, and run `cargo test --lib syntax::tests`.
Typst uses the published [`codebook-tree-sitter-typst` 0.12.1 grammar](https://docs.rs/codebook-tree-sitter-typst/0.12.1/codebook_tree_sitter_typst/), aliased as `tree-sitter-typst` and pinned because the crate does not export queries. `src/syntax/languages.rs` supplies supported highlight captures and standard raw-code injection captures against that grammar's AST. After changing the grammar or query, run `cargo test --lib syntax::`; coverage includes Typst markup/code, incremental edits, Markdown fences, and embedded Rust. Live network-denied PTY smoke verifies heading/keyword/string/function colors, the opt-in Tinymist status, an unknown-variable diagnostic, and a `text()` hover signature with unchanged source bytes.
## Ruby types ## Ruby types
Use YARD `@param`, `@return`, and `@yieldparam` annotations for Ruby APIs, and `@type` for locals where inference needs help. Examples annotate DSL block parameters before the call, without adding runtime assignments or dependencies. `Vamp::Action` / `Vamp::Mode` field types and the dynamically defined mode methods use Solargraph-supported directives. Use YARD `@param`, `@return`, and `@yieldparam` annotations for Ruby APIs, and `@type` for locals where inference needs help. Examples annotate DSL block parameters before the call, without adding runtime assignments or dependencies. `Vamp::Action` / `Vamp::Mode` field types and the dynamically defined mode methods use Solargraph-supported directives.
@@ -41,11 +43,31 @@ Rust tests live under [`tests/`](../tests/). Private unit tests are in [`tests/u
`cargo test` runs both groups; `cargo test --lib` and `cargo test --bin vamp` select the library and CLI unit suites. Do not name a unit file `tests/unit/main.rs`: Cargo would discover it as a separate integration target. `cargo test` runs both groups; `cargo test --lib` and `cargo test --bin vamp` select the library and CLI unit suites. Do not name a unit file `tests/unit/main.rs`: Cargo would discover it as a separate integration target.
### External-service isolation
Tests must not contact real websites or APIs. Forge tests inject JSON responses through `page_with`, `metadata_with`, and `resolve_with`; listing workers inject fetch closures. Repository remotes are temporary local repositories (including missing local paths for failure cases). LSP servers, Ruby plugins, and shell commands are local fixture subprocesses. The SSH alias check uses `ssh -G` with a temporary config to inspect configuration without connecting.
On macOS, verify external-service isolation with networking denied for Cargo and all descendants:
```sh
sandbox-exec -p '(version 1) (allow default) (deny network*)' \
cargo test --offline --no-fail-fast -- --test-threads=1 \
--skip shell::tests::completed_shell_does_not_leave_background_jobs_holding_output_open \
--skip shell::tests::dropping_shell_kills_and_reaps_group_with_pipe_inheriting_descendant
cargo test --offline --lib shell::tests:: -- --test-threads=1
```
Dependencies must already be cached. `--offline` prevents Cargo downloads; it does not block networking by tests or subprocesses. The sandbox supplies that boundary, including for real Git/jj operations and fixture programs; do not replace those local integration checks with mocks.
The two skipped shell cleanup checks execute `/bin/ps`, which macOS refuses to launch even under an allow-all sandbox profile; run them outside the sandbox as shown. Serial execution avoids contention in subprocess fixtures with production deadlines.
### Coverage
- Editor checks cover Unicode editing, multi-target state, undo/redo, saving failures, and modal paste acceptance and rejection atomicity. - Editor checks cover Unicode editing, multi-target state, undo/redo, saving failures, and modal paste acceptance and rejection atomicity.
- Prompt-history checks cover separate session-wide command/search entries, Unicode draft restoration, editable recalls, clamped/empty/bounded history, duplicate/empty/cancelled submissions, remapped/disabled keys, and preserved Visual/read-only diff targets. Live PTY smoke exercises arrows and raw Ctrl+k/j, restores drafts, accepts a recalled search with Enter, and checks command/search isolation and unchanged source bytes. - Prompt-history checks cover separate session-wide command/search entries, Unicode draft restoration, editable recalls, clamped/empty/bounded history, duplicate/empty/cancelled submissions, remapped/disabled keys, and preserved Visual/read-only diff targets. Live PTY smoke exercises arrows and raw Ctrl+k/j, restores drafts, accepts a recalled search with Enter, and checks command/search isolation and unchanged source bytes.
- Command-completion checks cover forward/backward alphabetical cycling/wrap across core names, aliases and live plugin registrations, reverse-first completion and direction changes retaining the prefix, explicit execution, edits/history/cancel resets, empty/unknown/Unicode prefixes, untouched arguments, remapped/disabled keys, and preserved Visual/read-only diff targets and literal search tabs. Live PTY smoke cycles `tab.*` in both directions through wraparound, submits a completed `tab.new`, and exits with unchanged source bytes. - Command-completion checks cover forward/backward alphabetical cycling/wrap across core names, aliases and live plugin registrations, reverse-first completion and direction changes retaining the prefix, explicit execution, edits/history/cancel resets, empty/unknown/Unicode prefixes, untouched arguments, remapped/disabled keys, and preserved Visual/read-only diff targets and literal search tabs. Live PTY smoke cycles `tab.*` in both directions through wraparound, submits a completed `tab.new`, and exits with unchanged source bytes.
- Shell-command checks use file-gated subprocesses to prove editing remains live, stdout/stderr/status and cwd handling, null stdin, output bounds, launch/worker errors, and process-group cleanup on completion/drop. Spinner timing uses an injected `Instant`; render checks cover scrolling, dismissal, hidden source caret, and tiny/offset windows. Live PTY smoke gates completion, saves an edit while pending, then observes both output streams and exit status and dismisses the popup. - Shell-command checks use file-gated subprocesses to prove editing remains live, stdout/stderr/status and cwd handling, null stdin, output bounds, launch/worker errors, and process-group cleanup on completion/drop. Spinner timing uses an injected `Instant`; render checks cover scrolling, dismissal, hidden source caret, and tiny/offset windows. Live PTY smoke gates completion, saves an edit while pending, then observes both output streams and exit status and dismisses the popup.
- Visual-command checks preserve directed characterwise/linewise ranges and multiple carets through command cancellation and plugin dispatch, exercise remapped command entry, and submit `:diff.comment` on either historical side. Live PTY smoke selects lines, cancels a prompt, then runs `:diff.comment` directly and verifies the saved original range without using the palette. - Visual-command checks preserve directed characterwise/linewise ranges and multiple carets through command cancellation and plugin dispatch, exercise remapped command entry, and submit `:comment` on either historical side. Live PTY smoke selects lines, cancels a prompt, then runs `:comment` directly and verifies the saved original range without using the palette.
- Presentation regressions render retained characterwise/linewise highlights during command entry in ordinary, split-diff, and unified views. Floating-review checks preserve source rectangles and the workspace layout, place the caret inside the overlay, retain explicitly saved text across tab switches, and restore source focus on Escape or pane close. - Presentation regressions render retained characterwise/linewise highlights during command entry in ordinary, split-diff, and unified views. Floating-review checks preserve source rectangles and the workspace layout, place the caret inside the overlay, retain explicitly saved text across tab switches, and restore source focus on Escape or pane close.
- Review prose checks render long comments and summaries with wrapping enabled by default in split/unified views, preserve exact single-line text and source wrapping, and retain an explicit wrap toggle on reopening. Live PTY smoke displays a long comment across continuation rows, saves it, verifies exact text through the review CLI, and reopens it still wrapped. - Review prose checks render long comments and summaries with wrapping enabled by default in split/unified views, preserve exact single-line text and source wrapping, and retain an explicit wrap toggle on reopening. Live PTY smoke displays a long comment across continuation rows, saves it, verifies exact text through the review CLI, and reopens it still wrapped.
- Precise-range checks cover forward/reversed characterwise and partial-multiline selections on both sides, linewise and caret/empty-line fallbacks, source-column navigation, Unicode grapheme bounds, invalid schemas, and preserved save-conflict checks. Render checks cover exact text/newline cells, wrapping, horizontal clipping, shared unified context, stale suppression, and native Visual precedence. Live PTY smoke saves and reopens a selection containing a wide and combining grapheme. - Precise-range checks cover forward/reversed characterwise and partial-multiline selections on both sides, linewise and caret/empty-line fallbacks, source-column navigation, Unicode grapheme bounds, invalid schemas, and preserved save-conflict checks. Render checks cover exact text/newline cells, wrapping, horizontal clipping, shared unified context, stale suppression, and native Visual precedence. Live PTY smoke saves and reopens a selection containing a wide and combining grapheme.
@@ -57,7 +79,8 @@ Rust tests live under [`tests/`](../tests/). Private unit tests are in [`tests/u
- Battery checks inject samples and refresh gates, use temporary Linux sysfs fixtures, and validate native value types/bounds without depending on the machine's charge or clock. Unit sessions do not automatically read hardware. Live smoke should compare the default indicator with OS telemetry and observe a production refresh; no-battery, explicit overrides, and disabled anchors must not fabricate values. - Battery checks inject samples and refresh gates, use temporary Linux sysfs fixtures, and validate native value types/bounds without depending on the machine's charge or clock. Unit sessions do not automatically read hardware. Live smoke should compare the default indicator with OS telemetry and observe a production refresh; no-battery, explicit overrides, and disabled anchors must not fabricate values.
- Status redesign checks cover component-aware home abbreviation without save-path changes; floating command/search submit/cancel, Unicode/tiny/offset clipping and wheel isolation; footer-row reclamation; notification Escape/modal/prefix priority and covered-caret visibility; and ready-server metadata using real framed subprocess fixtures, including stacks, initialization gates, failure, and focus changes. - Status redesign checks cover component-aware home abbreviation without save-path changes; floating command/search submit/cancel, Unicode/tiny/offset clipping and wheel isolation; footer-row reclamation; notification Escape/modal/prefix priority and covered-caret visibility; and ready-server metadata using real framed subprocess fixtures, including stacks, initialization gates, failure, and focus changes.
- Unix terminal-hook checks use isolated child processes and real PTYs to keep process-global hooks out of the parallel runner. They cover raw/alternate-screen/mouse-capture cleanup on entry failure, normal return, I/O errors, and panics during frame construction, including original panic-payload propagation. - Unix terminal-hook checks use isolated child processes and real PTYs to keep process-global hooks out of the parallel runner. They cover raw/alternate-screen/mouse-capture cleanup on entry failure, normal return, I/O errors, and panics during frame construction, including original panic-payload propagation.
- Redraw checks inspect actual Crossterm output during repeated scrolling: supporting terminals receive synchronized frames, terminals ignoring synchronization never paint with a visible hardware cursor, and the final caret remains visible. A protocol-state regression verifies that the terminal is not left in synchronized-output mode while the next frame is computed. - Redraw checks inspect actual Crossterm output during repeated scrolling: supporting terminals receive synchronized frames, terminals ignoring synchronization never paint with a visible hardware cursor, and the final software caret remains visible. A protocol-state regression verifies that the terminal is not left in synchronized-output mode while the next frame is computed.
- Cursor checks render software block/bar/underline shapes, wide/combining graphemes, cell restoration after motion, neutral reverse-video blocks, and shared ANSI mode accents on both banners through Normal, Insert, Visual, Command, and Search. The production backend preserves logical cursor coordinates without showing the hardware cursor. Live PTY screen parsing and an isolated Herdr 0.9.5 full-client smoke verify that mode-colored cells survive multiplexing, match both banners, avoid OSC 12, leave source bytes unchanged, and restore hardware visibility on exit. Document-layer fixtures exclude the final cursor overlay; complete-frame checks use `BufferViewports` with the production backend adapter.
- Wheel checks render document/panel views and cover three-row scrolling, unchanged carets/selections/text, first/last-page clamping, offscreen cursor hiding, no-op/custom-bound navigation reveal, manual persistence through idle/resize/palette updates, and floating/unfocused-docked explorer selection and focus preservation. Queued-input checks verify that the next frame shows ordered wheel steps without crossing a key or resize boundary. - Wheel checks render document/panel views and cover three-row scrolling, unchanged carets/selections/text, first/last-page clamping, offscreen cursor hiding, no-op/custom-bound navigation reveal, manual persistence through idle/resize/palette updates, and floating/unfocused-docked explorer selection and focus preservation. Queued-input checks verify that the next frame shows ordered wheel steps without crossing a key or resize boundary.
- Queued-navigation checks cover counted ordered motions through short rows, Normal/Visual ranges, remapped press/repeat keys, rendered caret visibility, edit/layout/prefix and non-key barriers, and the 64-key fairness bound. Burst smoke must verify the final cursor position as well as frame count; batching reduces queued redraws without increasing the OS/terminal repeat rate. - Queued-navigation checks cover counted ordered motions through short rows, Normal/Visual ranges, remapped press/repeat keys, rendered caret visibility, edit/layout/prefix and non-key barriers, and the 64-key fairness bound. Burst smoke must verify the final cursor position as well as frame count; batching reduces queued redraws without increasing the OS/terminal repeat rate.
- Native LSP integration checks launch framed-protocol fixture subprocesses, covering initialization/settings, opt-in startup, synchronization, UTF-16/file-URI conversion, dirty targets, stale requests/diagnostics, and transport failures. Stack checks cover independent initialization, diagnostic merging/clearing, sibling failure isolation in active/parked buffers, same-revision rename/close identity, aggregate limits, first-server position routing, and both shutdowns. Semantic ordering uses protocol/file gates; elapsed deadlines only bound stuck subprocesses. - Native LSP integration checks launch framed-protocol fixture subprocesses, covering initialization/settings, opt-in startup, synchronization, UTF-16/file-URI conversion, dirty targets, stale requests/diagnostics, and transport failures. Stack checks cover independent initialization, diagnostic merging/clearing, sibling failure isolation in active/parked buffers, same-revision rename/close identity, aggregate limits, first-server position routing, and both shutdowns. Semantic ordering uses protocol/file gates; elapsed deadlines only bound stuck subprocesses.
@@ -68,17 +91,26 @@ Clipboard checks use isolated providers rather than reading or overwriting the d
Diff checks cover staged category/filter navigation, stale request cancellation, row alignment, read-only buffer isolation, and rendered panes. Repository integration fixtures exercise Git and Git-backed jj, advertised but unfetched remote branches/bookmarks/tags, imported historical commit/change IDs, conflicts, unusual paths, binary/mode/link/submodule changes, and unchanged active metadata. Remote fixtures are local bare copies; they never push. Git fixture identities and commit dates are fixed. Diff checks cover staged category/filter navigation, stale request cancellation, row alignment, read-only buffer isolation, and rendered panes. Repository integration fixtures exercise Git and Git-backed jj, advertised but unfetched remote branches/bookmarks/tags, imported historical commit/change IDs, conflicts, unusual paths, binary/mode/link/submodule changes, and unchanged active metadata. Remote fixtures are local bare copies; they never push. Git fixture identities and commit dates are fixed.
Pull-request checks cover ranked sort menus, rank collisions/default slots, timestamp directions, independent personal review flags, checkbox unions, Apply/Cancel, category/query composition, streamed updates, and selection identity. Storage and session checks cover restart persistence, config section overrides, corrupt/incompatible-file preservation, and failed writes with isolated paths. Live PTY smoke at 100×24 and 44×16 exercises checkbox Apply/Cancel, restart restoration, creation-rank movement and ascending direction, and a config filter override. All forge responses come from a disposable curl fixture; the editor and descendants run with networking denied.
Session-filter regressions verify no file creation on filter Apply, retention across picker reopenings, restart reset, and saved sorting without filter data. Previously saved filters, including invalid legacy values, are ignored without altering valid sorting or changing the file on load. Live network-denied PTY smoke checks these transitions plus configured filter restoration and the active-filter indicator.
Diff-stat checks cover unopened frozen files, additions/deletions/renames, binary/mode changes, CRLF/EOF, refresh, oversized-file laziness, filtering, live edits/undo, and inactive tabs. Live PTY smoke opens a two-file Git Working comparison, observes selected-file `+2 -1` alongside whole-diff `+2 -2` before opening the second file, edits and undoes text, switches to an ordinary tab, and exits with source bytes and HEAD unchanged. Diff-stat checks cover unopened frozen files, additions/deletions/renames, binary/mode changes, CRLF/EOF, refresh, oversized-file laziness, filtering, live edits/undo, and inactive tabs. Live PTY smoke opens a two-file Git Working comparison, observes selected-file `+2 -1` alongside whole-diff `+2 -2` before opening the second file, edits and undoes text, switches to an ordinary tab, and exits with source bytes and HEAD unchanged.
Local review checks cover native comment/summary composition and undo, Visual ranges on either side, verdicts, JSON save/reopen, external-write refusal, hidden drafts and teardown guards, immutable Working identities in Git/jj, renamed paths, live EOF, and stale anchors. Render checks cover selected/range markers, split/unified context, wrapped continuations, and narrow gutters. Live PTY smoke creates and saves a comment/summary/verdict, closes and reopens the review, edits the reopened comment, changes the reviewed source, and observes stale status without altering the saved anchor. Fixtures are local repositories; no forge writes. Local review checks cover native comment/summary composition and undo, Visual ranges on either side, verdicts, JSON save/reopen, external-write refusal, hidden drafts and teardown guards, immutable Working identities in Git/jj, renamed paths, live EOF, and stale anchors. Render checks cover selected/range markers, split/unified context, wrapped continuations, and narrow gutters. Live PTY smoke creates and saves a comment/summary/verdict, closes and reopens the review, edits the reopened comment, changes the reviewed source, and observes stale status without altering the saved anchor. Fixtures are local repositories; no forge writes.
Ordinary-source review checks cover unsaved Unicode selections, line/empty-line anchors, no storage creation on initialization, explicit save/discard, optimistic conflicts, tab/pane guards, JSON round-trips, stale read-only snapshots, and rendered exact-range markers. Review selection separates source and comparison scopes even within one tab; dirty drafts guard transitions, and mismatched stored/JSON opens cannot reassign feedback. Review state remains tab-owned, with the selected document scoped to its source or comparison.
Review clipboard checks cover System/Separate routing with isolated providers, exact Unicode excerpts, resolved/stale comments across files, retained unsaved drafts, unchanged storage revisions, and empty/invalid/failed-copy preservation. Live PTY smoke imports a review, copies it, pastes into an empty buffer, and verifies the saved bytes exactly match CLI `show --all`; default CLI output still excludes resolved comments. Review clipboard checks cover System/Separate routing with isolated providers, exact Unicode excerpts, resolved/stale comments across files, retained unsaved drafts, unchanged storage revisions, and empty/invalid/failed-copy preservation. Live PTY smoke imports a review, copies it, pastes into an empty buffer, and verifies the saved bytes exactly match CLI `show --all`; default CLI output still excludes resolved comments.
SQLite review checks cover exact anchors across restarts and revision changes, repository isolation, independent connections and optimistic conflicts, locked/unwritable stores, incompatible schema preservation, relational constraints, full unsigned comment IDs, stable comment order, bounded/corrupt rows, rollback after partial comment insertion, private file permissions, and XDG/config path resolution. Schema 1 document storage is rejected without modification. Editor checks require explicit writes for comment/summary text, discard unsaved text on dismissal without retaining discarded undo history, prevent metadata autosaves from committing hidden drafts, persist verdicts/deletions, restore a sole review, choose among multiple reviews, and keep exports independent from autosaves. Test fixtures use isolated review directories. Live PTY smoke verifies that Escape leaves no new stored comment, `:w` persists exact text, and pane close discards a later edit; reopening and writing again preserves the saved body. Review text-format checks cover language-tagged excerpts, Honey's `hon` fence alias, special filenames and frozen shebang detection, unknown languages, Unicode, trailing-newline preservation, and nested backtick fences. Live PTY/CLI smoke imports `.hon` and nested Markdown comments, copies/pastes them into a saved buffer, compares its exact bytes with `show --all`, and verifies unresolved filtering, raw JSON excerpts, unchanged source bytes and an unchanged stored review revision.
SQLite review checks cover exact anchors, ordered comparison-scope round-trips and immutable scope saves, repository isolation, independent connections and optimistic conflicts, locked/unwritable stores, incompatible schema preservation, relational constraints, full unsigned comment IDs, stable comment order, bounded/corrupt rows, rollback after partial comment insertion, private file permissions, and XDG/config path resolution. SQLite schemas through 3 and JSON versions through 4 are rejected without modification. Editor checks cover automatic selection for different endpoint pairs, restoration of the same pair, stable in-place Working refreshes, moved-bookmark scope changes, separate source feedback, per-scope selectors, and explicit draft-save/discard behavior. Live PTY/CLI smoke saves feedback on two immutable pairs, reopens the first to restore only its feedback, retains Working feedback through refresh, saves a separate source comment, and inspects all scopes through SQLite and CLI JSON. Fixtures use isolated repositories and review directories; no forge writes.
Manual-resolution checks cover immediate persistence, reopen/export/import, independent stale status, conflict-retained drafts, and incompatible version preservation. CLI checks cover filename-safe dispatch, Unicode excerpts, unresolved filtering/counts, absent storage, read-only access and permissions, symlink rejection, and incompatible schema preservation. Manual-resolution checks cover immediate persistence, reopen/export/import, independent stale status, conflict-retained drafts, and incompatible version preservation. CLI checks cover filename-safe dispatch, Unicode excerpts, unresolved filtering/counts, absent storage, read-only access and permissions, symlink rejection, and incompatible schema preservation.
Live PTY/CLI smoke composes and explicitly saves a comment, resolves it in the editor, observes an empty default CLI comment list with explicit counts, retrieves the resolved comment and exact excerpt with `--all`, and unresolves it. Each transition advances the same stored review revision; listing absent storage creates no data directory. Live PTY/CLI smoke composes and explicitly saves a comment, resolves it in the editor, observes an empty default CLI comment list with explicit counts, retrieves the resolved comment and exact excerpt with `--all`, and unresolves it. Each transition advances the same stored review revision; listing absent storage creates no data directory.
CLI deletion checks exercise explicit review/comment IDs, resolved-comment deletion, repository isolation, preserved summaries/verdicts/other comments, last-comment deletion, missing targets/storage, and stale-save conflicts through the executable. CLI smoke verifies persisted deletion and rejects a repeated deletion without advancing the review revision. CLI deletion checks exercise explicit review/comment IDs, resolved-comment deletion, repository isolation, preserved summaries/verdicts/other comments, last-comment deletion, missing targets/storage, and stale-save conflicts through the executable. CLI smoke verifies persisted deletion and rejects a repeated deletion without advancing the review revision.
CLI resolution checks exercise positive review/comment IDs, preserved bodies/immutable anchors and other review metadata, unresolved filtering/full counts, `show --all`, repository isolation, missing/invalid targets and absent storage, idempotent repeats without revision changes, and stale-save rejection through the executable. CLI smoke: show a review as JSON, resolve one comment with `--repo PATH --json`, confirm counts and default filtering, show it again with `--all` to compare the original body/anchor/excerpt, and repeat resolution to confirm an unchanged storage revision.
Relational-storage smoke inspects typed review/comment columns, round-trips exact Unicode anchors through the store and JSON export/import, deletes through the real CLI, and confirms the stored review and existing export remain intact. Relational-storage smoke inspects typed review/comment columns, round-trips exact Unicode anchors through the store and JSON export/import, deletes through the real CLI, and confirms the stored review and existing export remain intact.
Reviewed-file checks cover SQLite/JSON round-trips, unmarking, exact revision pairs and rename paths across catalog reordering, lazy loading, live text/final-newline mismatch, edit-triggered invalidation, selected-review isolation, hidden-draft isolation, conflicts, and transactional rollback. Live PTY smoke marks a file in a real Git comparison, verifies the SQLite row, restarts the editor, observes the restored checkmark, unmarks it, and verifies row removal with unchanged source bytes. Reviewed-file checks cover SQLite/JSON round-trips, unmarking, exact revision pairs and rename paths across catalog reordering, lazy loading, live text/final-newline mismatch, edit-triggered invalidation, selected-review isolation, hidden-draft isolation, conflicts, and transactional rollback. Live PTY smoke marks a file in a real Git comparison, verifies the SQLite row, restarts the editor, observes the restored checkmark, unmarks it, and verifies row removal with unchanged source bytes.
Per-file persistence also exercises a real Git Working comparison: mark two lazy files, save/reload the review, edit one file, refresh the snapshot, and retain only the unchanged file's mark through detail loading. Per-file persistence also exercises a real Git Working comparison: mark two lazy files, save/reload the review, edit one file, refresh the snapshot, and retain only the unchanged file's mark through detail loading.
@@ -88,9 +120,11 @@ Conflicted-revision regressions preserve unchanged symlinks, defer oversized uns
Resolver checks use isolated real jj repositories: read-only discovery, marker-free all-side/base projections preserving outside edits and EOF, initial seed undo, hunk choice/undo, retained resolved files, jj-authoritative status, checkout/external-write refusal, cancellation, nontext bytes/types/modes/deletion, and directory-child protection. Render checks cover aligned gaps/highlights, context folding, native Draft focus/search/selection, separate History, hidden/on-demand explorer, viewport retention and narrow layouts. Live PTY smoke exercises frozen marker-free alternatives, History/Draft switching, hunk choice and guarded save confirmation without touching user repositories. Resolver checks use isolated real jj repositories: read-only discovery, marker-free all-side/base projections preserving outside edits and EOF, initial seed undo, hunk choice/undo, retained resolved files, jj-authoritative status, checkout/external-write refusal, cancellation, nontext bytes/types/modes/deletion, and directory-child protection. Render checks cover aligned gaps/highlights, context folding, native Draft focus/search/selection, separate History, hidden/on-demand explorer, viewport retention and narrow layouts. Live PTY smoke exercises frozen marker-free alternatives, History/Draft switching, hunk choice and guarded save confirmation without touching user repositories.
Base-relative resolver regressions cover red display-only removals and green native additions on both sides, deletion/replacement gaps, add/add without a base, native-coordinate round trips and EOF rows. The rendered workspace check exercises both split orientations and unified mode, native edits, hunk choice/undo, and both History layouts. Live PTY smoke checks actual red `-` and green `+` cells on both candidates, opens columns/base-below History, verifies browsing leaves conflict bytes untouched, and takes/saves an Alternative with exact output bytes and jj confirmation.
Conflict History layout checks load `resolve_history_layout` through the real Ruby configuration and render both left/base/right columns and left/right over base. They cover source contents, full-width base geometry, Tab/directional focus, synchronized wheel scrolling, read-only base protection, narrow/short fallbacks and preserved Draft text. Live PTY smoke opens both layouts, focuses/scrolls the base, returns to Resolution, takes a hunk and saves; jj confirms the checkout is no longer conflicted. Conflict History layout checks load `resolve_history_layout` through the real Ruby configuration and render both left/base/right columns and left/right over base. They cover source contents, full-width base geometry, Tab/directional focus, synchronized wheel scrolling, read-only base protection, narrow/short fallbacks and preserved Draft text. Live PTY smoke opens both layouts, focuses/scrolls the base, returns to Resolution, takes a hunk and saves; jj confirms the checkout is no longer conflicted.
Shared-workspace parity checks compare ordinary and resolver diff geometry/content under identical chrome, focus and source cursors. Cover native picker selection/remaps, Tree/List and dock/floating actions, excerpt initialization, folded search, focus transfer on wheel, layout controls, loading/History/pane-rebuild transitions, and preserved per-file viewport state. Live PTY smoke uses Space e, Down/Enter file selection and guarded saving through the same explorer path. Shared-workspace checks exercise ordinary and resolver diffs with native chrome, focus and source cursors. Cover native picker selection/remaps, Tree/List and dock/floating actions, excerpt initialization, folded search, focus transfer on wheel, layout controls, loading/History/pane-rebuild transitions, and preserved per-file viewport state. Live PTY smoke uses Space e, Down/Enter file selection and guarded saving through the same explorer path.
Repository gutter checks cover LF/CRLF normalization, additions/replacements/deletion anchors, staged/disk/unsaved Git text, unborn and missing named files, ignored/unsupported paths, read-only colocated/non-colocated jj queries, stale results and per-buffer isolation, plus rendered modes, colors, current-line precedence, wrap/scroll and narrow/split geometry. Live PTY smoke verifies all four modes, edit/undo refresh, external Git HEAD changes, and jj parent changes without editor restart. Repository gutter checks cover LF/CRLF normalization, additions/replacements/deletion anchors, staged/disk/unsaved Git text, unborn and missing named files, ignored/unsupported paths, read-only colocated/non-colocated jj queries, stale results and per-buffer isolation, plus rendered modes, colors, current-line precedence, wrap/scroll and narrow/split geometry. Live PTY smoke verifies all four modes, edit/undo refresh, external Git HEAD changes, and jj parent changes without editor restart.
@@ -103,6 +137,7 @@ Diff LSP integration checks reuse the real framed-protocol subprocess with test-
Changed-file explorer checks cover reuse of the compact directory tree, removed/historical paths, file-to-directory transitions, remapped tree/selection bindings, filter/open/focus transitions, right-dock geometry, and wheel routing without edits to the underlying document. Changed-file explorer checks cover reuse of the compact directory tree, removed/historical paths, file-to-directory transitions, remapped tree/selection bindings, filter/open/focus transitions, right-dock geometry, and wheel routing without edits to the underlying document.
Visibility checks preserve browsing and pane state across Ctrl+e, exclude hidden explorers from focus/wheel routing, and verify full-width review. Status checks preserve catalog associations through sorting, compaction, duplicate inputs, and file/directory collisions, and cover colored A/M/D/R markers, selected/unfocused rows, Tree/List filtering, and sanitized rename paths. Visibility checks preserve browsing and pane state across Ctrl+e, exclude hidden explorers from focus/wheel routing, and verify full-width review. Status checks preserve catalog associations through sorting, compaction, duplicate inputs, and file/directory collisions, and cover colored A/M/D/R markers, selected/unfocused rows, Tree/List filtering, and sanitized rename paths.
Light-terminal explorer selection checks render focused/unfocused rows through theme changes, require readable filename/status/directory contrast on Pumpkin Light, and retain dark/unknown-terminal fallbacks. A live PTY check answers native OSC color queries, opens the explorer with Space e, and observes the pale truecolor selection without changing source bytes.
Diff styling checks cover independent snapshot language/shebang/injection detection, accepted/stale snapshot identity, real-parser cache freshness/reuse/release, syntax foreground over changed backgrounds, real empty rows versus missing counterparts, scrolling-stable diagonal hatching, and tab/wide/combining/control-character clipping. TestBackend omits wide-glyph continuation cells; terminal smoke verifies their actual styling. Diff styling checks cover independent snapshot language/shebang/injection detection, accepted/stale snapshot identity, real-parser cache freshness/reuse/release, syntax foreground over changed backgrounds, real empty rows versus missing counterparts, scrolling-stable diagonal hatching, and tab/wide/combining/control-character clipping. TestBackend omits wide-glyph continuation cells; terminal smoke verifies their actual styling.
## Performance and process limits ## Performance and process limits
+74 -35
View File
@@ -74,7 +74,7 @@ With an enabled server that provides completion, Ctrl+n in Insert requests candi
Every candidate is applied from that same immutable original document, not on top of the previous candidate. A candidate's primary replacement and additional text edits are one atomic change. Other keys close the list without accepting it: plain-text completion retains ordinary typing, newline, and configured Tab insertion; snippet completion keeps its argument navigation described below. Escape returns to Normal retaining the displayed text. There is no automatic popup. Empty, unsupported, or invalid results leave the document unchanged and report a message. Every candidate is applied from that same immutable original document, not on top of the previous candidate. A candidate's primary replacement and additional text edits are one atomic change. Other keys close the list without accepting it: plain-text completion retains ordinary typing, newline, and configured Tab insertion; snippet completion keeps its argument navigation described below. Escape returns to Normal retaining the displayed text. There is no automatic popup. Empty, unsupported, or invalid results leave the document unchanged and report a message.
Cycling creates no separate undo entries. Only the final chosen edits join the existing Insert undo group; choosing Original text adds no completion edit. Undo restores that group, and dot repeats the final resolved completion edits rather than requests or intermediate candidates. The list stays inside the document text workspace, does not cover the gutter or explorer, and never takes the hardware cursor. Wheel input over it is consumed without choosing a candidate. Cycling creates no separate undo entries. Only the final chosen edits join the existing Insert undo group; choosing Original text adds no completion edit. Undo restores that group, and dot repeats the final resolved completion edits rather than requests or intermediate candidates. The list stays inside the document text workspace, does not cover the gutter or explorer, and never takes the primary cursor. Wheel input over it is consumed without choosing a candidate.
Snippet candidates expand the full template immediately, including parentheses and argument defaults. The first numbered argument is highlighted; typing replaces it, then continues within that argument. Repeated occurrences of the same argument update together, without broadcasting to secondary carets. Backspace/Delete stay within the active argument; Enter can insert a newline there. **Tab** moves forward and **Shift+Tab** backward in ascending tabstop order. Replacing an enclosing argument removes its nested arguments, not adjacent independent ones. Reaching the final `$0` position ends navigation, so subsequent Tab uses the configured spaces-or-tab insertion. Escape, ordinary cursor motion, paste, commands, and focus/buffer changes also end navigation without removing the expanded text. Snippet candidates expand the full template immediately, including parentheses and argument defaults. The first numbered argument is highlighted; typing replaces it, then continues within that argument. Repeated occurrences of the same argument update together, without broadcasting to secondary carets. Backspace/Delete stay within the active argument; Enter can insert a newline there. **Tab** moves forward and **Shift+Tab** backward in ascending tabstop order. Replacing an enclosing argument removes its nested arguments, not adjacent independent ones. Reaching the final `$0` position ends navigation, so subsequent Tab uses the configured spaces-or-tab insertion. Escape, ordinary cursor motion, paste, commands, and focus/buffer changes also end navigation without removing the expanded text.
@@ -126,7 +126,7 @@ System clipboard publication must succeed before any deletion. Failure preserves
## Selections and multi-caret editing ## Selections and multi-caret editing
Editing uses an ordered selection set with one primary target. Cursor and word motions apply to every target; Visual motions keep each target's anchor and move its active endpoint. Whole combining sequences and ZWJ emoji remain intact. `v` selects characterwise, inclusive of endpoints; `V` selects every complete row touched by the endpoints, including blank and empty final rows. Switching between `v` and `V` retains endpoints; pressing the current shape's selector again cancels. Read-only ranges are end-exclusive. Characterwise `$`/End can select the newline after a non-final row; selected newlines appear as a blue blank cell after the line. Linewise highlighting covers the copied text, including trailing whitespace, plus one blank cell for each copied newline; unused viewport space and the gutter remain unhighlighted. The status reads VISUAL LINE. Blue highlighting overrides yellow search highlighting; secondary carets are magenta, including on empty lines and at line ends. Only the primary owns the hardware cursor and viewport. The status line counts all targets, including offscreen targets. Editing uses an ordered selection set with one primary target. Cursor and word motions apply to every target; Visual motions keep each target's anchor and move its active endpoint. Whole combining sequences and ZWJ emoji remain intact. `v` selects characterwise, inclusive of endpoints; `V` selects every complete row touched by the endpoints, including blank and empty final rows. Switching between `v` and `V` retains endpoints; pressing the current shape's selector again cancels. Read-only ranges are end-exclusive. Characterwise `$`/End can select the newline after a non-final row; selected newlines appear as a blue blank cell after the line. Linewise highlighting covers the copied text, including trailing whitespace, plus one blank cell for each copied newline; unused viewport space and the gutter remain unhighlighted. The status reads VISUAL LINE. Blue highlighting overrides yellow search highlighting; secondary carets follow the mode palette (magenta in Visual), including on empty lines and at line ends. The primary software cursor overlays these text colors and alone drives the viewport; its shape and mode colors are [configurable](configuration.md#preferences). The status line counts all targets, including offscreen targets.
Ctrl+k/Ctrl+e clone each target to the adjacent row, preserving preferred terminal-cell columns (tabs use four-cell stops); Visual cloning preserves both endpoints. Duplicate carets and truly overlapping selections merge; adjacent ranges remain distinct. Visual Ctrl+l creates one Normal caret at the first nonblank of each touched row. Visual `I`/`A` similarly create one Insert caret per touched row at first nonblank/end. Occurrence actions use the primary selection as a literal, potentially multiline, grapheme-aligned query: Ctrl+n adds the next non-overlapping occurrence and wraps; Ctrl+s moves only the primary to that occurrence; Ctrl+a selects all occurrences. Ctrl+k/Ctrl+e clone each target to the adjacent row, preserving preferred terminal-cell columns (tabs use four-cell stops); Visual cloning preserves both endpoints. Duplicate carets and truly overlapping selections merge; adjacent ranges remain distinct. Visual Ctrl+l creates one Normal caret at the first nonblank of each touched row. Visual `I`/`A` similarly create one Insert caret per touched row at first nonblank/end. Occurrence actions use the primary selection as a literal, potentially multiline, grapheme-aligned query: Ctrl+n adds the next non-overlapping occurrence and wraps; Ctrl+s moves only the primary to that occurrence; Ctrl+a selects all occurrences.
@@ -196,7 +196,7 @@ Up/Ctrl+k recalls older entries; Down/Ctrl+j recalls newer entries and restores
Tab replaces the command-name prefix with the first case-sensitive match in alphabetical order; repeated presses cycle forward through the same matches and wrap. Shift+Tab cycles backward, starting at the last match when no cycle is active. Switching direction retains the original prefix. Candidates include canonical core commands, shorthand aliases, and commands from currently enabled plugins. Empty input cycles all command names. Typing, deleting, or browsing history starts a fresh completion cycle. Completion only changes the prompt: Enter still executes, and Escape cancels. Arguments (including paths) are not completed; Tab and Shift+Tab leave them unchanged. Search-mode Tab remains literal text. Rebind or disable forward/backward completion with `config.core.command_complete` / `config.core.command_complete_previous` in Command mode. Tab replaces the command-name prefix with the first case-sensitive match in alphabetical order; repeated presses cycle forward through the same matches and wrap. Shift+Tab cycles backward, starting at the last match when no cycle is active. Switching direction retains the original prefix. Candidates include canonical core commands, shorthand aliases, and commands from currently enabled plugins. Empty input cycles all command names. Typing, deleting, or browsing history starts a fresh completion cycle. Completion only changes the prompt: Enter still executes, and Escape cancels. Arguments (including paths) are not completed; Tab and Shift+Tab leave them unchanged. Search-mode Tab remains literal text. Rebind or disable forward/backward completion with `config.core.command_complete` / `config.core.command_complete_previous` in Command mode.
Command input works in both Normal and Visual modes, including read-only diff panes. The original selection stays highlighted while typing. Enter dispatches with its ranges, direction, and linewise shape intact; individual commands decide whether to consume or retain them. Escape returns to the original Visual selection without executing. For example, select lines with `V`, then type `:diff.comment` and press Enter—no command palette is needed. `config.core.command` can also be bound in Visual mode. Command input works in both Normal and Visual modes, including read-only diff panes. The original selection stays highlighted while typing. Enter dispatches with its ranges, direction, and linewise shape intact; individual commands decide whether to consume or retain them. Escape returns to the original Visual selection without executing. For example, select lines with `V`, then type `:comment` and press Enter—no command palette is needed. `config.core.command` can also be bound in Visual mode.
Use `:!COMMAND` (for example `:!pwd` or `:!echo "$PATH"`) to run shell commands asynchronously while continuing to edit. Vamp runs `$SHELL -c COMMAND`, falling back to `/bin/sh`, in the editor's project directory with the inherited environment and closed stdin. Shell quoting, pipes, and redirection work normally; interactive terminal programs are not supported. Commands have the same permissions as Vamp, including file and network access. Submit additional `:!` commands while others are running to execute them concurrently. Use `:!COMMAND` (for example `:!pwd` or `:!echo "$PATH"`) to run shell commands asynchronously while continuing to edit. Vamp runs `$SHELL -c COMMAND`, falling back to `/bin/sh`, in the editor's project directory with the inherited environment and closed stdin. Shell quoting, pipes, and redirection work normally; interactive terminal programs are not supported. Commands have the same permissions as Vamp, including file and network access. Submit additional `:!` commands while others are running to execute them concurrently.
@@ -297,6 +297,9 @@ Pane-focus bindings also work while the ordinary file explorer or picker has foc
Floating windows overlay the entire editor, above all workspace panes. File pickers, revision selectors, hover documentation, and completion lists are not clipped to the focused pane; completion remains anchored to its caret. Docked exploration reserves space at the editor edge before the remaining workspace is split into panes. The changed-file explorer follows the same layout, on the editor's right edge. Floating windows overlay the entire editor, above all workspace panes. File pickers, revision selectors, hover documentation, and completion lists are not clipped to the focused pane; completion remains anchored to its caret. Docked exploration reserves space at the editor edge before the remaining workspace is split into panes. The changed-file explorer follows the same layout, on the editor's right edge.
On light terminals that answer color queries, selected explorer rows use a pale shade of the terminal background, preserving filename, directory and repository-status foregrounds when focused or unfocused. Dark terminals and unavailable color reports retain the ANSI blue/dark-gray selection backgrounds. Theme changes update visible and parked panes.
Diff comparisons reuse the split geometry and directional-focus engine. Option/Alt navigation moves between Before, After, and Files first, then to a neighboring workspace pane when there is no internal target in that direction. Splitting a diff text view creates an ordinary sibling showing the same buffer; historical snapshots remain read-only, including after the comparison closes. Diff comparisons reuse the split geometry and directional-focus engine. Option/Alt navigation moves between Before, After, and Files first, then to a neighboring workspace pane when there is no internal target in that direction. Splitting a diff text view creates an ordinary sibling showing the same buffer; historical snapshots remain read-only, including after the comparison closes.
## Tabs ## Tabs
@@ -387,16 +390,20 @@ The project root is the working directory captured at startup. Scanning uses the
Run `:diff` in Normal mode, choose **Before**, then **After**, and press Enter to compare. The command palette also exposes **Diff**; there is no default keybinding. Repository discovery starts at the active file's directory, or the startup project root for an unnamed buffer, and prefers jj over Git. Run `:diff` in Normal mode, choose **Before**, then **After**, and press Enter to compare. The command palette also exposes **Diff**; there is no default keybinding. Repository discovery starts at the active file's directory, or the startup project root for an unnamed buffer, and prefers jj over Git.
The floating selector has **Revisions / Bookmarks** tabs for jj, or **Commits / Branches / Tags** for Git. Both Before and After support case-insensitive fuzzy search by revision/change ID, commit ID, reference name, or description: `f1205pas` can find `sm/fin-1205-pilot-assignment-schema`. Space-separated tokens must all match, but can match different fields in any order; a single token cannot span unrelated fields. Exact, prefix, and contiguous matches rank ahead of scattered subsequences; otherwise equal matches favor names/IDs over descriptions, word boundaries, and tighter spans. Ties retain catalogue order, and an empty or whitespace-only query restores the original order. **Working checkout** stays first in every category, even when it does not match the query. As Before it is a disk snapshot, including eligible untracked files. As After it includes unsaved regular-text buffers and enables live editing; opening a comparison never saves them. The floating selector has **Revisions / Bookmarks** tabs for jj, or **Commits / Branches / Tags** for Git. Both jj tabs use flat lists without ancestry lanes. **Revisions** puts the short change ID and commit description on the first line; bookmarks, author, date, commit ID, and textual **[checkout]** / **[immutable]** badges appear on a dimmed second line. **Bookmarks** puts the name first, with the commit description underneath. Local and remote-tracking bookmarks remain individually selectable, including multiple names on one revision, preserving their symbolic follow behavior. Narrow windows omit revision metadata and use compact single-line entries.
New comparisons default to **Branch changes**: Before becomes the unique merge base of the selected Before and After revisions, and After stays the selected tip. Changes exclusive to the Before branch are excluded. The Before border identifies both selected names and the immutable merge-base commit ID. **Snapshots** compares the two selected snapshots directly. **Ctrl+b** toggles the mode, also available as **`:diff.mode.toggle`**, the palette action, and remappable **`config.core.diff.mode.toggle`**. Toggling an opened comparison recomputes using the original selected endpoints. Selecting **Working checkout** on either side immediately forces **Snapshots**; Branch changes is unavailable while it is selected. Missing or multiple merge bases produce an explicit, recoverable selector error rather than silently falling back; choose Snapshots to compare such histories. jj's synthetic root is the empty ancestor of every jj history. Both stages support case-insensitive fuzzy search by revision/change ID, commit ID, reference name, or description: `f1205pas` can find `sm/fin-1205-pilot-assignment-schema`. Space-separated tokens must all match, but can match different fields; a token cannot span unrelated fields. jj keeps catalogue order while filtering. Git ranks exact, prefix, and contiguous matches ahead of scattered subsequences, with names/IDs ahead of descriptions and catalogue order breaking ties. An empty query restores catalogue order. After choosing Before, its revision carries a **[Before]** badge instead of a separate summary row. It remains included through search and category changes, but scrolls normally.
The separate checkout choice stays first in every category regardless of the query. It is **Checkout snapshot** during Before selection: a frozen disk snapshot including eligible untracked files. During After selection it is **Follow checkout** when `config.diff_follow_working_copy` is enabled, otherwise **Checkout snapshot**. Either After choice includes unsaved regular-text buffers and enables live editing; opening a comparison never saves them. Unlike this live-files choice, selecting the recorded checkout revision in Revisions pins that revision.
New comparisons default to **Branch changes**: Before becomes the unique merge base of the selected Before and After revisions, and After stays the selected tip. Changes exclusive to the Before branch are excluded. The Before border identifies both selected names and the immutable merge-base commit ID. **Snapshots** compares the two selected snapshots directly. **Ctrl+b** toggles the mode, also available as **`:diff.mode.toggle`**, the palette action, and remappable **`config.core.diff.mode.toggle`**. Toggling an opened comparison recomputes using the original selected endpoints. Selecting **Checkout snapshot** or **Follow checkout** immediately forces **Snapshots**; Branch changes is unavailable while either is selected. Missing or multiple merge bases produce an explicit, recoverable selector error rather than silently falling back; choose Snapshots to compare such histories. jj's synthetic root is the empty ancestor of every jj history.
| Selector input | Effect | | Selector input | Effect |
| --- | --- | | --- | --- |
| Tab / Shift+Tab | Next / previous category | | Tab / Shift+Tab | Next / previous category |
| Up / Down, Ctrl+k / Ctrl+j | Previous / next entry | | Up / Down, Ctrl+k / Ctrl+j | Previous / next entry |
| Backspace / Ctrl+u | Remove a query grapheme / clear query | | Backspace / Ctrl+u | Remove a query grapheme / clear query |
| Ctrl+b | Toggle Branch changes / Snapshots (Working checkout requires Snapshots) | | Ctrl+b | Toggle Branch changes / Snapshots (checkout choices require Snapshots) |
| Enter | Choose the entry | | Enter | Choose the entry |
| Esc | Close either selector stage, cancel outstanding work, and restore the source buffer without discarding edits | | Esc | Close either selector stage, cancel outstanding work, and restore the source buffer without discarding edits |
@@ -404,7 +411,23 @@ Printable input belongs to the focused query, including `:`, `_`, and `|`; Norma
The selector initially lists local revisions and known tracking refs **without contacting remotes**. **Load refs from origin** (or another configured remote) in Bookmarks/Branches/Tags lists advertised references, including refs never fetched locally, without advancing the selection stage. Selecting a reference such as `some-bookmark@origin` reuses available content or fetches the missing selected reference into a temporary comparison repository. **Load history from origin** in Revisions/Commits explicitly imports searchable remote history. Network operations use the repository's existing credentials; errors stay in the selector. They do not update active refs, snapshot jj's working copy, or change the checkout. The selector initially lists local revisions and known tracking refs **without contacting remotes**. **Load refs from origin** (or another configured remote) in Bookmarks/Branches/Tags lists advertised references, including refs never fetched locally, without advancing the selection stage. Selecting a reference such as `some-bookmark@origin` reuses available content or fetches the missing selected reference into a temporary comparison repository. **Load history from origin** in Revisions/Commits explicitly imports searchable remote history. Network operations use the repository's existing credentials; errors stay in the selector. They do not update active refs, snapshot jj's working copy, or change the checkout.
**Pull requests:** run **`:pull_requests [remote]`**, use the palette's `pull_requests` action, or bind **`config.core.pull_requests`**. The floating picker has **Open / Closed / All** tabs; Closed includes merged requests. Tab/Shift+Tab changes category, typing fuzzy-searches its number, title, author, state, and branches, and Enter immediately opens the selected request in **Branch changes** mode using its immutable head and merge base. Escape restores the source buffer. A failed list can be retried with Enter. The default remote is `origin`, or the sole configured remote; specify a name when there are multiple remotes without `origin`. **Pull requests:** run **`:pull_requests [remote]`**, use the palette's `pull_requests` action, or bind **`config.core.pull_requests`**. The floating picker has **Open / Closed / Drafts / All** tabs. Open excludes drafts; Drafts contains open draft requests; Closed includes merged requests and closed drafts. Tab/Shift+Tab changes category, typing fuzzy-searches its number, title, author, state, and branches, and Enter immediately opens the selected request in **Branch changes** mode using its immutable head and merge base. Escape restores the source buffer. A failed list can be retried with Enter. The default remote is `origin`, or the sole configured remote; specify a name when there are multiple remotes without `origin`.
Each pull request's metadata shows added/deleted line counts after its state, before the branch names: `author · open · +123 -45 · topic → main`. Zero counts are shown explicitly; missing, denied, or failed statistics show `size unavailable` without preventing selection. Counts come from one batched read-only statistics query per nonempty GitHub/GitLab page ([GitHub](https://docs.github.com/en/graphql/reference/pulls), [GitLab](https://docs.gitlab.com/api/graphql/reference/#diffstatssummary)); [Gitea](https://docs.gitea.com/api/operations/repo-list-pull-requests/) supplies them directly in its list response. GitHub statistics require API authentication even for public repositories. Listing does not fetch source diffs.
Immediately before `#number`, **🙏 marks an outstanding personal review request** and **👍 marks your active approval**, separately from the `>` selection arrow. A review request takes precedence when both apply, including a re-review request after an earlier approval. “You” means the account authenticated to that forge's API—not the repository's Git author or SSH identity. Other users' and team-only requests do not count; completed or removed requests lose 🙏.
A later request for changes or dismissal removes 👍; comment-only and pending reviews do not replace an existing approval. The mark is not the PR's overall approval decision or a guarantee that you reviewed its current head; the forge controls approval resets after new commits. Customize either symbol with [`config.pull_request_review_requested_symbol` and `config.pull_request_approved_symbol`](configuration.md); an empty string hides that symbol. Multi-cell symbols remain aligned, and decorations are not part of searchable PR labels.
**Ctrl+s** opens sorting settings in the floating picker. The default comparison order is **Requested from me → Updated at → Approved by me → Created at**, with true statuses and newest timestamps first. Up/Down or the configured selection bindings navigate. Press **1–4** to assign the highlighted criterion an absolute precedence; it moves to that position and stays highlighted. Occupied explicit ranks shift forward (wrapping to a free slot); unnumbered criteria fill the remaining slots in their default relative order. Only explicitly assigned ranks display numbers. **Backspace** clears an explicit rank; **Left/Right** toggles oldest/newest first for timestamp criteria. Comparisons are lexicographic, with higher PR number as the final tie-breaker. Fuzzy text still determines which requests match; these settings determine their order.
**Ctrl+f** opens review filter checkboxes. **Space** toggles the highlighted bucket: **Requested from me**, **Approved by me**, or **Other / unavailable**. Checked buckets combine with OR, then intersect with the category and text query. All checked includes every review state; none checked produces no matches. These are personal states, not the PR's team approval threshold: teammates' outstanding requests do not cancel your approval. A new request for your own review takes precedence over your earlier approval. Unavailable metadata remains Other, not a claim that the PR has never been reviewed.
**Enter** applies either settings view; **Escape** discards its draft and returns to the PR list. Applied settings preserve the selected request where possible and carry across tabs and picker reopenings. Sorting persists across sessions; filters are session-local and restart from `config.pull_request_filters` or all buckets when unset. Previously saved filters are ignored. The picker displays its active review buckets whenever any are excluded. Category counts remain loaded-category totals, and partial-search notices still apply. Settings use already-loaded metadata without additional API requests. Explicit [configuration overrides](configuration.md#preferences) win again at startup; the settings view indicates when this applies.
Review-state reads reuse the same API credentials as listing. GitHub matches the current list's [requested reviewers](https://docs.github.com/en/rest/pulls/review-requests#list-requested-reviewers-for-a-pull-request) and filters published [reviews by author and decision state](https://docs.github.com/en/graphql/reference/pulls#pullrequest). GitLab filters approvals by the authenticated approver and reads individual reviewer [interaction states](https://docs.gitlab.com/api/graphql/reference/) in separate bounded, paginated batches; unsupported or denied reviewer-state fields do not discard known approvals or size metadata. Gitea reuses [paginated review reads per PR](https://docs.gitea.com/api/operations/repo-list-pull-reviews/) for both states, so its pages can take longer to load.
Anonymous, denied, missing, or failed state lookups leave the corresponding indicator unavailable without preventing browsing. A blank is not proof that no request or approval exists. Reopen the picker to fetch current review state. No approval, review request, or other remote write is performed.
GitHub, GitLab merge requests, and Gitea are supported. API reads require `curl`; public repositories work anonymously. Authentication uses `GH_TOKEN`/`GITHUB_TOKEN` for github.com, `GH_ENTERPRISE_TOKEN`/`GITHUB_ENTERPRISE_TOKEN` for GitHub Enterprise, `GITLAB_TOKEN` for GitLab, and `GITEA_TOKEN` for Gitea. With no matching environment token, GitHub/GitLab reuse `gh auth token --hostname HOST` / `glab auth token --hostname HOST` when available. Tokens are supplied to curl on stdin, not in subprocess arguments, and sent only to the HTTPS API; redirects are not followed. Git object fetching uses the configured remote's existing Git/SSH credentials separately. GitHub, GitLab merge requests, and Gitea are supported. API reads require `curl`; public repositories work anonymously. Authentication uses `GH_TOKEN`/`GITHUB_TOKEN` for github.com, `GH_ENTERPRISE_TOKEN`/`GITHUB_ENTERPRISE_TOKEN` for GitHub Enterprise, `GITLAB_TOKEN` for GitLab, and `GITEA_TOKEN` for Gitea. With no matching environment token, GitHub/GitLab reuse `gh auth token --hostname HOST` / `glab auth token --hostname HOST` when available. Tokens are supplied to curl on stdin, not in subprocess arguments, and sent only to the HTTPS API; redirects are not followed. Git object fetching uses the configured remote's existing Git/SSH credentials separately.
@@ -412,9 +435,9 @@ Standard GitHub/GitLab/Gitea hosts and Codeberg are detected from HTTPS or SSH r
SSH aliases are resolved with `ssh -G` before provider detection and API authentication, honoring the effective `HostName` and user-specific `Match` settings. SSH ports do not become HTTPS API ports. Git fetches retain the original remote URL, alias, and SSH identity configuration. A failed API load shows its error without also claiming that the search has no matches; the empty-result message appears only after a successful load. SSH aliases are resolved with `ssh -G` before provider detection and API authentication, honoring the effective `HostName` and user-specific `Match` settings. SSH ports do not become HTTPS API ports. Git fetches retain the original remote URL, alias, and SSH identity configuration. A failed API load shows its error without also claiming that the search has no matches; the empty-result message appears only after a successful load.
Open and Closed fetch their first pages concurrently, newest-first, and display each page immediately. Subsequent pages load in the background, with the active category dispatched first; loaded rows remain selectable. Pages request 50 entries. GitLab Closed combines separate closed and merged requests (up to 100 entries per batch). All merges the two catalogs without a third fetch stream, deduplicates requests, and sorts by creation time; background updates preserve the selected PR's identity. Open (including drafts) and Closed fetch their first pages concurrently, newest-first, and display each page immediately. Open and Drafts filter the same catalog, sharing its loading, completion, and retry state without extra requests. Subsequent pages load in the background, with the active category's stream dispatched first; loaded rows remain selectable. Pages request 50 entries. GitLab Closed combines separate closed and merged requests (up to 100 entries per batch). All includes open, draft, closed, and merged requests from the two streams, deduplicates requests, and sorts by creation time; background updates preserve the selected PR's identity.
Search filters loaded entries locally and explicitly indicates partial results while more pages remain. A later-page error retains loaded rows; **Ctrl+r** retries failed categories (the active category, or both from All). Enter selects a loaded row; in an empty failed category it retries loading. Escape cancels outstanding work. Selection stops listing and only then retrieves that PR's historical metadata and preserved head reference, so GitLab detail reads and Gitea ref lookups do not delay the catalog. Search filters loaded entries locally and explicitly indicates partial results while more pages remain. A later-page error retains loaded rows; **Ctrl+r** retries failed fetch streams (the active category's stream, or both from All). Enter selects a loaded row; in an empty failed category it retries loading. Escape cancels outstanding work. Selection stops listing and only then retrieves that PR's historical metadata and preserved head reference, so GitLab detail reads and Gitea ref lookups do not delay the catalog.
Fork heads are fetched through the target repository's PR refs into the existing private comparison store, without changing active refs, jj operations, or checkout files. Closed/merged requests retain historical bases and heads rather than comparing against today's branch tips. If the server no longer retains the required commits, opening the request reports an error instead of displaying a different diff. Review submission and comments are separate, not part of this picker. Fork heads are fetched through the target repository's PR refs into the existing private comparison store, without changing active refs, jj operations, or checkout files. Closed/merged requests retain historical bases and heads rather than comparing against today's branch tips. If the server no longer retains the required commits, opening the request reports an error instead of displaying a different diff. Review submission and comments are separate, not part of this picker.
@@ -424,9 +447,9 @@ Comparison discovery builds the changed-path/status catalog first. File text, no
Conflicted jj revisions also discover files without reading every blob. Ordinary files and symbolic links retain their Git contents; selected conflicted files show jj's rendered conflict projection. Unchanged links and jj's internal merge-tree metadata do not appear as changes. Viewing a conflict does not resolve it or modify the revision. Conflicted jj revisions also discover files without reading every blob. Ordinary files and symbolic links retain their Git contents; selected conflicted files show jj's rendered conflict projection. Unchanged links and jj's internal merge-tree metadata do not appear as changes. Viewing a conflict does not resolve it or modify the revision.
**Working checkout After follows forward checkouts automatically**, checked asynchronously once per second, including inactive tabs. A descendant jj change or Git HEAD rebuilds the changed-file catalog and captures current working bytes plus eligible unsaved buffers, while keeping the original Before frozen. jj tracking uses change IDs, so snapshot/description rewrites of the same change do not advance the endpoint or prevent following its later descendants. Same, backward, and unrelated checkouts do not rebuild the catalog; live-buffer editing and external reload still work normally. Historical After never follows. Set `config.diff_follow_working_copy = false` to disable following. **Follow checkout After follows descendant checkouts automatically**, checked asynchronously once per second, including inactive tabs. A descendant jj change or Git HEAD rebuilds the changed-file catalog and captures current working bytes plus eligible unsaved buffers, while keeping the original Before frozen. jj tracking uses change IDs, so snapshot/description rewrites of the same change do not advance the endpoint or prevent following its later descendants. Same, backward, and unrelated checkouts do not rebuild the catalog; live-buffer editing and external reload still work normally. Historical After never follows. Set `config.diff_follow_working_copy = false` to disable following; the picker then calls this choice **Checkout snapshot**.
**Selected jj bookmarks follow their locally known targets automatically**, checked on the same one-second interval, including inactive tabs and with `config.diff_follow_working_copy = false`. Local bookmarks and known remote-tracking bookmarks retain their names; explicit revision selections remain pinned. A changed commit ID, including an amendment of the same change ID, rebuilds the comparison. Branch changes also recomputes the merge base. Unrelated endpoints stay frozen, except for the existing Working After forward-follow behavior. Deleted or conflicted bookmarks keep the last successful comparison visible with an error; a later successful check clears the error. These checks never fetch, contact remotes, or snapshot jj's working copy; privately loaded remote history and advertised remote selections remain frozen. **Selected jj bookmarks follow their locally known targets automatically**, checked on the same one-second interval, including inactive tabs and with `config.diff_follow_working_copy = false`. Local bookmarks and known remote-tracking bookmarks retain their names; explicit revision selections remain pinned. A changed commit ID, including an amendment of the same change ID, rebuilds the comparison. Branch changes also recomputes the merge base. Unrelated endpoints stay frozen, except for the existing Follow checkout After behavior. Deleted or conflicted bookmarks keep the last successful comparison visible with an error; a later successful check clears the error. These checks never fetch, contact remotes, or snapshot jj's working copy; privately loaded remote history and advertised remote selections remain frozen.
Deleted or conflicted bookmarks unrelated to the selected endpoints do not block opening or refreshing a comparison. Deleted or conflicted bookmarks unrelated to the selected endpoints do not block opening or refreshing a comparison.
@@ -434,7 +457,7 @@ Deleted or conflicted bookmarks unrelated to the selected endpoints do not block
Refresh retains the selected path when still present, explorer query/view/visibility, logical text-side focus, and split/unified/orientation/wrap choices; moving a Working or bookmark endpoint clears review marks, while pinned checkout-only transitions retain them. Removed selections fall back to the first changed file. Bookmark replacements preserve/clamp cursor and scroll positions as replacement content loads. Failed refreshes keep the previous comparison visible. Superseded file loads and LSP navigation cannot apply to the new comparison; snapshots still displayed in other panes or tabs remain read-only. Refresh retains the selected path when still present, explorer query/view/visibility, logical text-side focus, and split/unified/orientation/wrap choices; moving a Working or bookmark endpoint clears review marks, while pinned checkout-only transitions retain them. Removed selections fall back to the first changed file. Bookmark replacements preserve/clamp cursor and scroll positions as replacement content loads. Failed refreshes keep the previous comparison visible. Superseded file loads and LSP navigation cannot apply to the new comparison; snapshots still displayed in other panes or tabs remain read-only.
The changed-file explorer is **docked on the right**. In the default split layout, modified files show Before on the left and After on the right. Added files show only After, using the full text workspace; deleted files show only Before. Rename-only files show one empty pane, with the old and new paths in the explorer; renames with text or final-newline changes retain both source sides. Before and unmatched pinned After snapshots are read-only. **Working checkout** or a checkout-matched pinned After binds eligible regular UTF-8 files to normal editor buffers, reusing already-open dirty buffers and their undo history. Editable After supports native edits, completion, undo/redo, and `:w`. Removed files, rename-only files, binary files, symlinks, and submodules remain read-only. Closing the diff keeps its buffers and unsaved edits. The changed-file explorer is **docked on the right**. In the default split layout, modified files show Before on the left and After on the right. Added files show only After, using the full text workspace; deleted files show only Before. Rename-only files show one empty pane, with the old and new paths in the explorer; renames with text or final-newline changes retain both source sides. Before and unmatched pinned After snapshots are read-only. A **Follow checkout / Checkout snapshot After** or a checkout-matched pinned After binds eligible regular UTF-8 files to normal editor buffers, reusing already-open dirty buffers and their undo history. Editable After supports native edits, completion, undo/redo, and `:w`. Removed files, rename-only files, binary files, symlinks, and submodules remain read-only. Closing the diff keeps its buffers and unsaved edits.
Comparisons start in **split, vertical (left/right)** view by default. In Normal mode, **Space v** cycles split/unified; **Space s** switches a split between vertical (left/right) and horizontal (above/below, Before above After). Canonical commands are `:diff.view.toggle` and `:diff.orientation.toggle`; both are available in the palette and as remappable `config.core.diff.view.toggle` / `config.core.diff.orientation.toggle` actions. Configure new-comparison defaults with `config.diff_view_mode = "split"` or `"unified"` and `config.diff_split_orientation = "vertical"` or `"horizontal"`. Current choices survive file and tab switches; closing and reopening uses the configured defaults. Orientation stays unchanged while unified is active. Comparisons start in **split, vertical (left/right)** view by default. In Normal mode, **Space v** cycles split/unified; **Space s** switches a split between vertical (left/right) and horizontal (above/below, Before above After). Canonical commands are `:diff.view.toggle` and `:diff.orientation.toggle`; both are available in the palette and as remappable `config.core.diff.view.toggle` / `config.core.diff.orientation.toggle` actions. Configure new-comparison defaults with `config.diff_view_mode = "split"` or `"unified"` and `config.diff_split_orientation = "vertical"` or `"horizontal"`. Current choices survive file and tab switches; closing and reopening uses the configured defaults. Orientation stays unchanged while unified is active.
@@ -464,47 +487,57 @@ Mark or unmark a diff file with **`c` while browsing the changed-file tree**, **
Collapsed folders show a green **`✓`** when every changed file beneath them is reviewed, including nested files and descendants hidden by filtering. Expanded folders stay unmarked. Folder marks update automatically when a descendant's review mark or the changed-file catalog changes. Collapsed folders show a green **`✓`** when every changed file beneath them is reviewed, including nested files and descendants hidden by filtering. Expanded folders stay unmarked. Folder marks update automatically when a descendant's review mark or the changed-file catalog changes.
Review marks are saved with the selected local review and restored by immutable per-file Before/After identities and file paths. Changes to unrelated files or commit metadata do not clear them; changes to either side's bytes, final newline, file mode, or rename paths require re-review. They survive filtering, file navigation, lazy loading, tabs, split/unified/orientation changes, and pinned checkout-only transitions. Editing a writable After file clears only that file's mark and saves the removal; unchanged refreshes and saves preserve it. Marks on live text also retain its exact contents, including the final newline, so different unsaved text cannot inherit a checkmark. Marks do not change document text, undo history, or repository state. Without configured SQLite storage, use `:diff.review.save path` to save them as JSON. Older revision-pair-scoped marks remain stored but must be marked again to acquire per-file identities; comments, summaries, and verdicts are unaffected. Review marks are saved with the selected local review and restored by immutable per-file Before/After identities and file paths. Changes to unrelated files or commit metadata do not clear them; changes to either side's bytes, final newline, file mode, or rename paths require re-review. They survive filtering, file navigation, lazy loading, tabs, split/unified/orientation changes, and pinned checkout-only transitions. Editing a writable After file clears only that file's mark and saves the removal; unchanged refreshes and saves preserve it. Marks on live text also retain its exact contents, including the final newline, so different unsaved text cannot inherit a checkmark. Marks do not change document text, undo history, or repository state. Without configured SQLite storage, use `:review.save path` to save them as JSON. Older revision-pair-scoped marks remain stored but must be marked again to acquire per-file identities; comments, summaries, and verdicts are unaffected.
**Local review comments** share local storage with the file-reviewed checkmarks above; neither feature publishes to GitHub. Focus either diff text pane and run **`:diff.comment`** to comment on the current line. A characterwise Visual selection (`v`) anchors its exact text, including partial lines and multiline spans; Visual Line (`V`) anchors whole selected lines. Type **`:diff.comment`** and press Enter, or use the palette/a configured binding. Multiple independent carets/ranges must be reviewed separately. **Local review comments** work in ordinary repository source buffers and diff text panes; they share storage with file-reviewed checkmarks and never publish to GitHub. Run **`:comment`** to comment on the current line. A characterwise Visual selection (`v`) anchors its exact text, including partial lines and multiline spans; Visual Line (`V`) anchors whole selected lines. Multiple independent carets/ranges must be reviewed separately.
Comments, summaries, and the review overview open in a focused floating editor over the whole diff text workspace, not a source-side split. The source layout, file explorer, and viewports stay unchanged. Normal editing, selections, and undo/redo work in editable review buffers. Escape in Normal mode or `:pane.close` dismisses the window and returns to the diff, discarding that editor's unsaved text. An unsaved new comment is not attached to the review; an existing comment or summary reopens with its last saved text and no discarded undo history. Insert/Visual/Command Escape first retains its usual modal behavior. Source rows are never replaced with comment text. Magenta **`○`** gutter markers identify saved comment ranges; **`●`** identifies the selected comment. Its exact current text range has a magenta background, including wrapped continuations and selected newline cells; native Visual selections take precedence. Stale comments have neither markers nor text highlighting. Markers preserve addition/deletion signs, appear only on the first wrapped segment, and also work in unified view. Comments, summaries, and the review overview open in a focused floating editor over the source workspace, not a source-side split. The source layout, file explorer, and viewports stay unchanged. Normal editing, selections, and undo/redo work in editable review buffers. Escape in Normal mode or `:pane.close` dismisses the window and returns to the source, discarding that editor's unsaved text. An unsaved new comment is not attached to the review; an existing comment or summary reopens with its last saved text and no discarded undo history. Insert/Visual/Command Escape first retains its usual modal behavior. Source rows are never replaced with comment text. Magenta **`○`** gutter markers identify saved comment ranges; **`●`** identifies the selected comment. Its exact current text range has a magenta background, including wrapped continuations and selected newline cells; native Visual selections take precedence. Stale comments have neither markers nor text highlighting. Markers preserve addition/deletion signs, appear only on the first wrapped segment, and also work in unified view.
Local review buffers (comments, summaries, overview, and stored-review selector) soft-wrap by default without inserting newlines into saved text. Use `:word_wrap.toggle` to disable wrapping for the focused review buffer; reopening it retains that choice for the session. Source diff wrapping remains independent. Local review buffers (comments, summaries, overview, and stored-review selector) soft-wrap by default without inserting newlines into saved text. Use `:word_wrap.toggle` to disable wrapping for the focused review buffer; reopening it retains that choice for the session. Source diff wrapping remains independent.
| Command | Effect | | Command | Effect |
| --- | --- | | --- | --- |
| `:diff.comment` | Add a comment on the current line or exact selected text range, on the focused side | | `:comment` | Add a comment on the current source line or exact selected text range |
| `:diff.review.edit [id]` | Edit an existing comment; defaults to the overview entry under the caret or selected comment | | `:review.edit [id]` | Edit an existing comment; defaults to the overview entry under the caret or selected comment |
| `:diff.review.delete [id]` | Delete that draft comment | | `:review.delete [id]` | Delete that draft comment |
| `:diff.review.resolve [id]` / `:diff.review.unresolve [id]` | Mark a comment resolved/unresolved; uses the same default selection as edit/delete | | `:review.resolve [id]` / `:review.unresolve [id]` | Mark a comment resolved/unresolved; uses the same default selection as edit/delete |
| `:diff.review.next` / `:diff.review.previous` | Cycle comments, opening their text and revealing a matching source anchor | | `:review.next` / `:review.previous` | Cycle comments, opening their text and revealing a matching source anchor |
| `:diff.review.overview` | Refresh/open a read-only summary and comment list; Enter edits the entry under the caret | | `:review.overview` | Refresh/open a read-only summary and comment list; Enter edits the entry under the caret |
| `:diff.review.copy` | Copy all saved comments in the selected review to the configured clipboard, using the CLI text format | | `:review.copy` | Copy all saved comments in the selected review to the configured clipboard, using the CLI text format |
| `:diff.review.summary` | Compose the review summary | | `:review.summary` | Compose the review summary |
| `:diff.review.verdict looks_good` | Record **Looks good** | | `:review.verdict looks_good` | Record **Looks good** |
| `:diff.review.verdict changes_requested` | Record **Changes requested**; `none` clears the verdict | | `:review.verdict changes_requested` | Record **Changes requested**; `none` clears the verdict |
| `:diff.review.save [path]` | Commit to SQLite; with a path, also export JSON for sharing | | `:review.save [path]` | Commit to SQLite; with a path, also export JSON for sharing |
| `:diff.review.open [id or path]` | Show stored reviews, open a stored review ID, or import a JSON review as a new review | | `:review.open [id or path]` | Show reviews for the current scope, open a matching stored review ID, or import matching JSON as a new review |
| `:diff.review.new` | Create a separate stored review for the current repository | | `:review.new` | Create another stored review for the current comparison or ordinary-source scope |
Comment and summary text is committed only by **`:w`** or **`:diff.review.save`**, which saves the entire review, including hidden drafts. Dismissing an editor discards its unsaved text; switching between review editors can retain hidden drafts but does not save them. File checkmarks, verdicts, deletions, and manual resolution changes commit immediately to local SQLite without committing draft text. `:diff.review.save path` or `:w path` additionally exports JSON; later metadata autosaves still go to SQLite and leave that export unchanged. Imports create a new stored review identity rather than overwriting another review. File checkmarks remain diff-specific (`:diff.review.toggle`).
`:diff.review.copy` copies the same text as `vamp --review show ID --all`: repository, summary, verdict, counts, and every saved comment with its anchor and exact excerpt. Resolved and stale comments are included, across all files in the selected review. `clipboard_mode` chooses the system clipboard or Separate-mode internal register. Copying does not save or include unsaved comment/summary drafts. No comments or a clipboard write failure reports an error without replacing the register. Comment and summary text is committed only by **`:w`** or **`:review.save`**, which saves the entire review, including hidden drafts. Dismissing an editor discards its unsaved text; switching between review editors can retain hidden drafts but does not save them. File checkmarks, verdicts, deletions, and manual resolution changes commit immediately to local SQLite without committing draft text. `:review.save path` or `:w path` additionally exports JSON; later metadata autosaves still go to SQLite and leave that export unchanged. Imports create a new stored review identity rather than overwriting another review.
`:review.copy` copies the same text as `vamp --review show ID --all`: repository, summary, verdict, counts, and every saved comment with its anchor and exact excerpt. Resolved and stale comments are included, across all files in the selected review. `clipboard_mode` chooses the system clipboard or Separate-mode internal register. Copying does not save or include unsaved comment/summary drafts. No comments or a clipboard write failure reports an error without replacing the register.
CLI text output and `:review.copy` wrap each source excerpt in a Markdown code block, with its detected language tag (`hon` for `.hon`, `rust` for `.rs`, and so on). Detection uses the frozen source path and first-line shebang, not current disk contents; unknown languages use an untagged block. Fences grow beyond any backtick run in the excerpt, so nested Markdown cannot end the block early. Feedback follows outside the code block. Exact excerpt text, including existing final newlines, is preserved; a missing final newline gains only the separator required before the closing fence. JSON excerpts and stored anchors remain raw and unchanged.
From the shell, use `vamp --review delete REVIEW_ID COMMENT_ID [--repo PATH] [--json]` to delete a stored comment immediately without opening the editor. Find IDs with `vamp --review list` and `vamp --review show REVIEW_ID --all`. The repository defaults to the current checkout. Both resolved and unresolved comments can be deleted; the review and any JSON exports remain intact. An editor holding the old review revision must reload before saving. From the shell, use `vamp --review delete REVIEW_ID COMMENT_ID [--repo PATH] [--json]` to delete a stored comment immediately without opening the editor. Find IDs with `vamp --review list` and `vamp --review show REVIEW_ID --all`. The repository defaults to the current checkout. Both resolved and unresolved comments can be deleted; the review and any JSON exports remain intact. An editor holding the old review revision must reload before saving.
Storage defaults to `$XDG_DATA_HOME/vamp/reviews/reviews.sqlite3`, or `~/.local/share/vamp/reviews/reviews.sqlite3` when XDG_DATA_HOME is unset or relative. Configure `review_directory` to override its directory; relative configuration paths resolve against the config file. Repository identity is the canonical checkout root. Each review has a persistent database ID independent of comparison revisions, so reopening changed revisions retains stale comments. Opening a comparison automatically restores the repository's sole review. Multiple reviews open a floating selector: move to an entry and press Enter, or use `:diff.review.open id`. Use `:diff.review.new` for another independent review. Use `vamp --review resolve REVIEW_ID COMMENT_ID [--repo PATH] [--json]` after addressing and verifying feedback to mark it resolved without changing its body or original anchor. The command prints the updated review's remaining unresolved comments and full counts; `show REVIEW_ID --all` still includes the resolved original. Repeating resolution succeeds without a write or revision bump. Both IDs must be positive and refer to the selected repository; invalid targets and absent storage fail without creating or changing stored data. Like deletion, resolution rejects stale saves from an editor holding the previous review revision.
Storage defaults to `$XDG_DATA_HOME/vamp/reviews/reviews.sqlite3`, or `~/.local/share/vamp/reviews/reviews.sqlite3` when XDG_DATA_HOME is unset or relative. Configure `review_directory` to override its directory; relative configuration paths resolve against the config file. Review scope is the canonical checkout root plus the ordered, resolved Before/After identities, not branch/bookmark labels. Opening a different pair selects its existing review or starts an empty one; reopening the same pair restores its feedback, verdict, and file progress. A sole matching review restores automatically; multiple reviews for that scope open a floating selector. Move to an entry and press Enter, or use `:review.open id`. `:review.new` creates another review within the same scope. Opening or importing a review from a different scope is rejected rather than reassigning its feedback.
Working edits and in-place checkout refreshes retain the comparison's initial review scope. Explicitly opening a comparison resolves its endpoints again: changed Working contents or moved bookmarks can therefore select a different review. Ordinary source-buffer comments use a separate repository-local source scope, never the last comparison's review. Unsaved review drafts block scope changes until saved or discarded. Opening an empty scope does not write storage until a review change is committed.
Write errors, locked databases, incompatible schemas, and conflicting edits from another editor instance retain dirty drafts and report the failure. Failed text saves leave the committed review unchanged; unrelated metadata autosaves cannot commit those drafts. Normal destructive closes remain guarded until drafts are explicitly saved or discarded. `:w!` does not bypass database revision conflicts; export your draft before reopening the current stored review. JSON exports retain external-file-change protection. Only the current database schema is accepted; existing incompatible databases are preserved rather than reset or migrated. Write errors, locked databases, incompatible schemas, and conflicting edits from another editor instance retain dirty drafts and report the failure. Failed text saves leave the committed review unchanged; unrelated metadata autosaves cannot commit those drafts. Normal destructive closes remain guarded until drafts are explicitly saved or discarded. `:w!` does not bypass database revision conflicts; export your draft before reopening the current stored review. JSON exports retain external-file-change protection. Only the current database schema is accepted; existing incompatible databases are preserved rather than reset or migrated.
The current SQLite format is schema 3: typed `reviews`, `comments`, and `reviewed_files` tables, not serialized JSON documents. Older databases are incompatible and are left untouched; there is no migration or automatic reset. JSON version 4 is the sharing format, independent of the database schema. The current SQLite format is schema 4: typed `reviews`, `comments`, and `reviewed_files` tables, not serialized JSON documents. Review rows store nullable Before/After identities; both are null for source reviews. Older databases, including schema 3, are incompatible and are left untouched; there is no migration or automatic reset. JSON version 5 is the sharing format, independent of the database schema.
Version 4 JSON is the agent-readable sharing format: repository root, summary, optional verdict, comments, and a required `reviewed_files` array. Each reviewed file stores its immutable per-file `revisions` pair (`file:` identities encoding mode, Git object ID or exact data, and notices), relative `path`, optional rename `old_path`, and optional exact live `after` text. Comments have stable IDs, bodies, required boolean `resolved` states, and anchors. New comments are unresolved. Database review IDs and optimistic storage revisions stay internal. Each anchor retains its immutable comparison revision, side, relative path (old path for renamed Before files), and exact whole-file text including the final newline. `start` and `end` contain zero-based source `row` and extended-grapheme `column` coordinates; `end` is exclusive. Columns count complete Unicode graphemes, not bytes, code points, UTF-16 units, or screen cells. Overview/window labels display one-based rows and columns. Older JSON formats are rejected and preserved without migration. Working comparisons use content-addressed snapshot IDs; captured text additionally freezes live unsaved edits. Stored reviews have a 64 MiB aggregate text budget including 64 bytes of overhead per comment and reviewed file; imported/exported JSON files have a separate 64 MiB serialized-size limit. Version 5 JSON is the agent-readable sharing format: repository root, `comparison` (an ordered Before/After identity pair, or `null` for source reviews), summary, optional verdict, comments, and a required `reviewed_files` array. Each reviewed file stores its immutable per-file `revisions` pair (`file:` identities encoding mode, Git object ID or exact data, and notices), relative `path`, optional rename `old_path`, and optional exact live `after` text. Comments have stable IDs, bodies, required boolean `resolved` states, and anchors. New comments are unresolved. Database review IDs and optimistic storage revisions stay internal. Each anchor retains its immutable comparison revision, side, relative path (old path for renamed Before files), and exact whole-file text including the final newline. `start` and `end` contain zero-based source `row` and extended-grapheme `column` coordinates; `end` is exclusive. Columns count complete Unicode graphemes, not bytes, code points, UTF-16 units, or screen cells. Overview/window labels display one-based rows and columns. Older JSON formats are rejected and preserved without migration. Working comparisons use content-addressed snapshot IDs; captured text additionally freezes live unsaved edits. Stored reviews have a 64 MiB aggregate text budget including 64 bytes of overhead per comment and reviewed file; imported/exported JSON files have a separate 64 MiB serialized-size limit.
Reopening requires the same repository root. Unchanged comment ranges follow edits elsewhere in the file, including inserted/deleted lines above and column shifts before a partial-line selection. Working-snapshot refreshes can retain these attachments; unrelated immutable revisions and paths do not match. Mapping requires an unchanged, unambiguous text region containing the selection. Modified/deleted selections or ambiguous repeated regions are **stale**: comments remain available through the overview and next/previous navigation, with original snapshot coordinates and no current-source marker or jump. Saved anchors and exported excerpts remain unchanged. Unloaded files are shown as **not checked** until visited; refresh the overview to update its statuses. There is no server, authentication, or review-publishing operation. Reopening requires the same repository root. Unchanged comment ranges follow edits elsewhere in the file, including inserted/deleted lines above and column shifts before a partial-line selection. Working-snapshot refreshes can retain these attachments; unrelated immutable revisions and paths do not match. Mapping requires an unchanged, unambiguous text region containing the selection. Modified/deleted selections or ambiguous repeated regions are **stale**: comments remain available through the overview and next/previous navigation, with original snapshot coordinates and no current-source marker or jump. Saved anchors and exported excerpts remain unchanged. Unloaded files are shown as **not checked** until visited; refresh the overview to update its statuses. There is no server, authentication, or review-publishing operation.
Resolution is a manual human decision, independent of anchor freshness: a comment can be both resolved and stale. Overview entries and comment titles label resolved/unresolved status. Resolved comments remain in the overview and next/previous navigation, and can still be edited or reopened. Resolving never changes an anchor or deletes feedback. Ordinary source comments use an immutable content snapshot identity and capture the current buffer, including unsaved text; they do not require a commit or a diff. They retain the same SQLite/JSON formats. Opening a source comment navigates to its file and mapped selection; if that text is stale or the file is unavailable, it opens the preserved original text read-only instead of attaching feedback to different code.
Resolution is an explicit reviewer or agent decision, independent of anchor freshness: a comment can be both resolved and stale. Overview entries and comment titles label resolved/unresolved status. Resolved comments remain in the overview and next/previous navigation, and can still be edited or reopened. Resolving never changes an anchor or deletes feedback.
Text panes show change excerpts with **10 unchanged lines above and below** each change, preserving original file line numbers. Overlapping or touching excerpts merge; omitted stretches show an unchanged-line count in both panes. Files with only metadata changes show their notice or “No text changes” rather than unrelated source. Text panes show change excerpts with **10 unchanged lines above and below** each change, preserving original file line numbers. Overlapping or touching excerpts merge; omitted stretches show an unchanged-line count in both panes. Files with only metadata changes show their notice or “No text changes” rather than unrelated source.
@@ -548,6 +581,8 @@ Run **`:resolve`** in Normal mode for the current jj working copy. It opens a de
The resolver shows the editable **Resolution** on the left and a read-only **Other version** on the right, with aligned rows, line/character highlighting, context folds and synchronized scrolling. Both are projected from the current working buffer, including pre-existing unsaved edits: only conflict-marker regions are replaced by their selected alternatives. Already-merged text and edits outside those regions appear on both sides. The initial output is seeded from the first side as a normal undoable buffer change; opening never writes it to disk. References remain frozen while later edits change only the output. The resolver shows the editable **Resolution** on the left and a read-only **Other version** on the right, with aligned rows, line/character highlighting, context folds and synchronized scrolling. Both are projected from the current working buffer, including pre-existing unsaved edits: only conflict-marker regions are replaced by their selected alternatives. Already-merged text and edits outside those regions appear on both sides. The initial output is seeded from the first side as a normal undoable buffer change; opening never writes it to disk. References remain frozen while later edits change only the output.
Both panes show their own changes **against the selected base**, not a left-to-right removal/addition comparison: removed base lines are red with `-`, and added candidate lines are green with `+`, on either side. Replacements show the removed base text followed by the candidate text; unchanged text stays neutral. Removed base lines are display-only, with no candidate line number, caret, or editable selection. With no base (an add/add conflict), both candidates are additions against empty text. The Resolution baseline uses the same frozen working-text projection as its alternatives, preserving already-merged text and pre-existing outside edits. `resolve.base` selects the baseline through History; returning to Resolution uses that selection. Hunk navigation and `resolve.use_source` still operate on differences between the actual Draft and Alternative.
Pane borders label the editable output **Resolution** and its frozen reference **Other version**. Paths and branch-comparison metadata are omitted from these titles; unsaved state belongs only to the output, and source identity appears with the reference. Explorer **C** marks files jj still considers conflicted, including while edited/checking or confirmation is unavailable; it clears only when jj confirms resolution. Pane borders label the editable output **Resolution** and its frozen reference **Other version**. Paths and branch-comparison metadata are omitted from these titles; unsaved state belongs only to the output, and source identity appears with the reference. Explorer **C** marks files jj still considers conflicted, including while edited/checking or confirmation is unavailable; it clears only when jj confirms resolution.
| Command | Behavior | | Command | Behavior |
@@ -563,6 +598,8 @@ Pane borders label the editable output **Resolution** and its frozen reference *
**History** is separate from editing: it compares the original inputs and their base, with all sides and bases selectable for multi-sided conflicts. `config.resolve_history_layout = "columns"` (default) shows left/base/right; `"base_below"` shows left/right above a full-width base. Both layouts retain aligned changes and synchronized vertical scrolling. Tab/Shift+Tab cycles in layout order; directional pane actions follow the displayed geometry. Narrow History shows the focused source, as does base-below History when too short to display both rows of panes. Draft text, undo, caret and viewport survive view switches. Resolution uses the ordinary diff workspace, including its configured explorer, split/unified/orientation controls, source-line navigation, excerpts, focus and scrolling. Read-only Alternatives and History reject edits and saves. **History** is separate from editing: it compares the original inputs and their base, with all sides and bases selectable for multi-sided conflicts. `config.resolve_history_layout = "columns"` (default) shows left/base/right; `"base_below"` shows left/right above a full-width base. Both layouts retain aligned changes and synchronized vertical scrolling. Tab/Shift+Tab cycles in layout order; directional pane actions follow the displayed geometry. Narrow History shows the focused source, as does base-below History when too short to display both rows of panes. Draft text, undo, caret and viewport survive view switches. Resolution uses the ordinary diff workspace, including its configured explorer, split/unified/orientation controls, source-line navigation, excerpts, focus and scrolling. Read-only Alternatives and History reject edits and saves.
Each outer History pane uses the same red-removal/green-addition presentation against the selected base. The base pane highlights original text changed by either input; addition-only rows leave a gap there. This applies to both History layouts.
Input indexes are one-based and include bases. Conflict-specific actions appear in the palette and through corresponding `config.core.resolve` methods. File navigation uses the existing picker/explorer actions: Space o opens floating search, Space e focuses the dock, Ctrl+t switches Tree/List, Ctrl+w closes it, and configured tree/selection bindings apply unchanged. Enter selects a relevant conflict file and focuses the editable Draft. Normal-mode Tab/Shift+Tab, native motions/search, context expansion and layout actions follow normal diff behavior. The complete seeded Draft can be saved even when intentional differences remain against the Alternative: those differences are not unresolved conflict markers. There is no automatic “accept both”. Input indexes are one-based and include bases. Conflict-specific actions appear in the palette and through corresponding `config.core.resolve` methods. File navigation uses the existing picker/explorer actions: Space o opens floating search, Space e focuses the dock, Ctrl+t switches Tree/List, Ctrl+w closes it, and configured tree/selection bindings apply unchanged. Enter selects a relevant conflict file and focuses the editable Draft. Normal-mode Tab/Shift+Tab, native motions/search, context expansion and layout actions follow normal diff behavior. The complete seeded Draft can be saved even when intentional differences remain against the Alternative: those differences are not unresolved conflict markers. There is no automatic “accept both”.
**`:w` saves and checks jj**, asynchronously. Before writing, the resolver locks the working copy and validates the frozen checkout and exact on-disk file state. Checkout changes, external writes and unsafe filesystem ancestors refuse the write, including force-save. Successful writes trigger jj's normal snapshot operation, which may capture other on-disk changes. The list distinguishes unresolved, unsaved, checking, resolved and unconfirmed states. jj—not marker scanning or a manual checkbox—confirms resolution. A failed confirmation keeps saved contents and reports unconfirmed status. Resolved files remain in the session for review. Dirty drafts prevent destructive resolver/pane/tab closes. **`:w` saves and checks jj**, asynchronously. Before writing, the resolver locks the working copy and validates the frozen checkout and exact on-disk file state. Checkout changes, external writes and unsafe filesystem ancestors refuse the write, including force-save. Successful writes trigger jj's normal snapshot operation, which may capture other on-disk changes. The list distinguishes unresolved, unsaved, checking, resolved and unconfirmed states. jj—not marker scanning or a manual checkbox—confirms resolution. A failed confirmation keeps saved contents and reports unconfirmed status. Resolved files remain in the session for review. Dirty drafts prevent destructive resolver/pane/tab closes.
@@ -613,7 +650,7 @@ config.bind "leader f", config.core.follow_link
## Syntax highlighting ## Syntax highlighting
Buffers highlight automatically using [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) and compiled-in grammar/query packages. The selected language set is Rust, Ruby, Python, JSON, Bash, Makefile, Markdown, JavaScript/JSX, TypeScript/TSX, HTML, CSS, YAML, TOML, C, C++, Go, Zig (`.zig`), and Honey (`.hon`). Detection uses filename/extension or the in-memory first-line shebang, including common special filenames such as Makefile, Gemfile, and Cargo.lock; no file reread occurs. Unsupported formats use the normal foreground. The detected language appears in status, and save-as redetects it. Buffers highlight automatically using [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) and compiled-in grammar/query packages. The selected language set is Rust, Ruby, Python, JSON, Bash, Makefile, Markdown, JavaScript/JSX, TypeScript/TSX, HTML, CSS, YAML, TOML, C, C++, Go, Zig (`.zig`), Honey (`.hon`), and Typst (`.typ`). Detection uses filename/extension or the in-memory first-line shebang, including common special filenames such as Makefile, Gemfile, and Cargo.lock; no file reread occurs. Unsupported formats use the normal foreground. The detected language appears in status, and save-as redetects it.
Files remain editable above the syntax budget: sources over 1 MiB, or with any line over 64 KiB, use plain text and show the reason in the language status. Syntax highlighting resumes automatically after shrinking below both limits. This avoids building a full parse tree for huge generated files; navigation, search, selections, undo/redo, and saving remain available. Files remain editable above the syntax budget: sources over 1 MiB, or with any line over 64 KiB, use plain text and show the reason in the language status. Syntax highlighting resumes automatically after shrinking below both limits. This avoids building a full parse tree for huge generated files; navigation, search, selections, undo/redo, and saving remain available.
@@ -621,6 +658,8 @@ Colors retain the terminal palette: comments dark gray, strings green, keywords
Honey uses its bundled grammar and highlight queries, including declarations, primitive types, literals, and comments. Markdown fences accept `honey`, `honeylang`, or `hon`; the language ID is `honey`. Honey uses its bundled grammar and highlight queries, including declarations, primitive types, literals, and comments. Markdown fences accept `honey`, `honeylang`, or `hon`; the language ID is `honey`.
Typst highlights headings, emphasis, references, raw code, comments, strings, numbers, keywords, and function calls without an LSP. Markdown fences accept `typst` or `typ`; named raw-code blocks inside Typst use the same bundled language registry. The language ID is `typst`. Native [Tinymist configuration](configuration.md#native-lsp) is opt-in.
Markdown heading markers (`#` through `######`, or Setext underlines) share the heading text's markup color. List markers (`-`, `+`, `*`, and ordered prefixes such as `1.` or `1)`) also use cyan markup, including nested and blockquoted lists. Plain-text hashes and other punctuation keep their existing styling. Markdown heading markers (`#` through `######`, or Setext underlines) share the heading text's markup color. List markers (`-`, `+`, `*`, and ordered prefixes such as `1.` or `1)`) also use cyan markup, including nested and blockquoted lists. Plain-text hashes and other punctuation keep their existing styling.
An enabled supporting LSP server supplies semantic tokens automatically, overriding syntax colors only on recognized spans. Semantic colors also use the terminal palette: namespaces neutral gray, types cyan, variables/parameters light cyan, and properties blue. Readonly variables/parameters/properties keep those role colors and add italics; declarations/definitions are bold, documentation comments italic, and deprecated symbols struck through. Italic emphasis depends on terminal support. Edits retain semantic colors outside the changed range and shift them with the text until updated tokens arrive, avoiding whole-buffer flashes. Tree-sitter fills gaps, including edited ranges whose semantic tokens were discarded. Search, Visual selections, diagnostics, and carets keep their existing precedence. See [native LSP configuration](configuration.md#native-lsp) for provider support and server-stack routing. An enabled supporting LSP server supplies semantic tokens automatically, overriding syntax colors only on recognized spans. Semantic colors also use the terminal palette: namespaces neutral gray, types cyan, variables/parameters light cyan, and properties blue. Readonly variables/parameters/properties keep those role colors and add italics; declarations/definitions are bold, documentation comments italic, and deprecated symbols struck through. Italic emphasis depends on terminal support. Edits retain semantic colors outside the changed range and shift them with the text until updated tokens arrive, avoiding whole-buffer flashes. Tree-sitter fills gaps, including edited ranges whose semantic tokens were discarded. Search, Visual selections, diagnostics, and carets keep their existing precedence. See [native LSP configuration](configuration.md#native-lsp) for provider support and server-stack routing.
+5
View File
@@ -5,6 +5,8 @@ Vamp.configure do |config|
config.leader = "space" config.leader = "space"
config.clipboard_mode = "system" # "separate" keeps ordinary y/d/c/p/P internal config.clipboard_mode = "system" # "separate" keeps ordinary y/d/c/p/P internal
config.git_blame = true # false disables current-line inline blame config.git_blame = true # false disables current-line inline blame
config.cursor = {} # mode colors enabled; block cursor in every mode
# config.cursor = { mode_colors: false, insert: :bar, visual: :underline }
config.scroll_distance = 0 # nonnegative edge distance, or nil to center config.scroll_distance = 0 # nonnegative edge distance, or nil to center
config.scroll_step_lines = nil # Ctrl+u/d: half viewport, or a positive screen-row count config.scroll_step_lines = nil # Ctrl+u/d: half viewport, or a positive screen-row count
config.highlight_trailing_whitespace = false # true marks line-end whitespace in red config.highlight_trailing_whitespace = false # true marks line-end whitespace in red
@@ -18,6 +20,8 @@ Vamp.configure do |config|
config.diff_view_mode = "split" # or "unified" config.diff_view_mode = "split" # or "unified"
config.diff_split_orientation = "vertical" # or "horizontal" config.diff_split_orientation = "vertical" # or "horizontal"
config.diff_follow_working_copy = true # false keeps the selected Working After endpoint config.diff_follow_working_copy = true # false keeps the selected Working After endpoint
config.pull_request_review_requested_symbol = "🙏"
config.pull_request_approved_symbol = "👍"
config.resolve_history_layout = "columns" # or "base_below" for left/right above the base config.resolve_history_layout = "columns" # or "base_below" for left/right above the base
# config.popup.command = { anchor: :bottom_left } # config.popup.command = { anchor: :bottom_left }
# config.popup.search = { anchor: :center } # config.popup.search = { anchor: :center }
@@ -43,6 +47,7 @@ Vamp.configure do |config|
# config.lsp["rust"] = true # built-in rust-analyzer preset # config.lsp["rust"] = true # built-in rust-analyzer preset
# config.lsp["ruby"] = true # built-in Solargraph stdio preset (gem install solargraph) # config.lsp["ruby"] = true # built-in Solargraph stdio preset (gem install solargraph)
# config.lsp["python"] = true # built-in ty + Ruff stack (install both separately) # config.lsp["python"] = true # built-in ty + Ruff stack (install both separately)
# config.lsp["typst"] = true # built-in Tinymist LSP preset (install tinymist separately)
# config.lsp["my-language"] = { # config.lsp["my-language"] = {
# command: ["my-language-server", "--stdio"], extensions: ["myl"], # command: ["my-language-server", "--stdio"], extensions: ["myl"],
# initialization_options: {}, settings: {} # initialization_options: {}, settings: {}
+3 -3
View File
@@ -195,15 +195,15 @@ impl ChromeLine {
fn default_segment(name: &str) -> SegmentConfig { fn default_segment(name: &str) -> SegmentConfig {
let mut segment = SegmentConfig::default(); let mut segment = SegmentConfig::default();
if matches!(name, "tabs" | "position" | "battery" | "shell" | "diff") { if matches!(name, "tabs" | "position" | "battery" | "shell") {
segment.leading_edge = "░▓".into(); segment.leading_edge = "░▓".into();
} }
if matches!(name, "tabs" | "mode" | "shell" | "diff") { if matches!(name, "tabs" | "mode" | "shell") {
segment.trailing_edge = "▓░".into(); segment.trailing_edge = "▓░".into();
} }
if matches!( if matches!(
name, name,
"tabs" | "mode" | "position" | "battery" | "shell" | "diff" | "lsp" "tabs" | "mode" | "position" | "battery" | "shell" | "lsp"
) { ) {
segment.padding = 1; segment.padding = 1;
} }
+46
View File
@@ -0,0 +1,46 @@
use crate::editor::Mode;
use serde::Deserialize;
#[derive(Clone, Copy, Debug, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub(crate) struct CursorConfig {
pub(crate) mode_colors: bool,
pub(crate) normal: CursorShape,
pub(crate) insert: CursorShape,
pub(crate) command: CursorShape,
pub(crate) search: CursorShape,
pub(crate) visual: CursorShape,
}
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub(crate) enum CursorShape {
Block,
Bar,
Underline,
}
impl Default for CursorConfig {
fn default() -> Self {
Self {
mode_colors: true,
normal: CursorShape::Block,
insert: CursorShape::Block,
command: CursorShape::Block,
search: CursorShape::Block,
visual: CursorShape::Block,
}
}
}
impl CursorConfig {
pub(crate) fn shape(self, mode: Mode) -> CursorShape {
match mode {
Mode::Normal => self.normal,
Mode::Insert => self.insert,
Mode::Command => self.command,
Mode::Search => self.search,
Mode::Visual => self.visual,
}
}
}
+655 -142
View File
File diff suppressed because it is too large Load Diff
+189 -54
View File
@@ -990,96 +990,91 @@ core_actions![
true, true,
), ),
( (
"core.diff.comment", "core.comment",
Action::DiffComment, Action::Comment,
&[Mode::Normal, Mode::Visual], &[Mode::Normal, Mode::Visual],
true true
), ),
( (
"core.diff.review.edit", "core.review.edit",
Action::ReviewEdit, Action::ReviewEdit,
&[Mode::Normal], &[Mode::Normal],
true, true,
true true
), ),
( (
"core.diff.review.delete", "core.review.delete",
Action::ReviewDelete, Action::ReviewDelete,
&[Mode::Normal], &[Mode::Normal],
true, true,
true true
), ),
( (
"core.diff.review.resolve", "core.review.resolve",
Action::ReviewResolve, Action::ReviewResolve,
&[Mode::Normal], &[Mode::Normal],
true, true,
true true
), ),
( (
"core.diff.review.unresolve", "core.review.unresolve",
Action::ReviewUnresolve, Action::ReviewUnresolve,
&[Mode::Normal], &[Mode::Normal],
true, true,
true true
), ),
( (
"core.diff.review.next", "core.review.next",
Action::ReviewNext, Action::ReviewNext,
&[Mode::Normal], &[Mode::Normal],
true true
), ),
( (
"core.diff.review.previous", "core.review.previous",
Action::ReviewPrevious, Action::ReviewPrevious,
&[Mode::Normal], &[Mode::Normal],
true true
), ),
( (
"core.diff.review.overview", "core.review.overview",
Action::ReviewOverview, Action::ReviewOverview,
&[Mode::Normal], &[Mode::Normal],
true true
), ),
( (
"core.diff.review.copy", "core.review.copy",
Action::ReviewCopy, Action::ReviewCopy,
&[Mode::Normal], &[Mode::Normal],
true true
), ),
( (
"core.diff.review.summary", "core.review.summary",
Action::ReviewSummary, Action::ReviewSummary,
&[Mode::Normal], &[Mode::Normal],
true true
), ),
( (
"core.diff.review.verdict", "core.review.verdict",
Action::ReviewVerdict, Action::ReviewVerdict,
&[Mode::Normal], &[Mode::Normal],
true, true,
true true
), ),
( (
"core.diff.review.save", "core.review.save",
Action::ReviewSave, Action::ReviewSave,
&[Mode::Normal], &[Mode::Normal],
true, true,
true true
), ),
( (
"core.diff.review.open", "core.review.open",
Action::ReviewOpen, Action::ReviewOpen,
&[Mode::Normal], &[Mode::Normal],
true, true,
true true
), ),
( ("core.review.new", Action::ReviewNew, &[Mode::Normal], true),
"core.diff.review.new",
Action::ReviewNew,
&[Mode::Normal],
true
),
( (
"core.word_wrap.toggle", "core.word_wrap.toggle",
Action::WordWrapToggle, Action::WordWrapToggle,
@@ -1699,7 +1694,7 @@ pub struct ResolverFile {
pub seed_source: usize, pub seed_source: usize,
projection: Option<crate::resolve::Projection>, projection: Option<crate::resolve::Projection>,
diff: DiffState, diff: DiffState,
comparison_key: Option<(u64, usize)>, comparison_key: Option<(u64, usize, Option<usize>)>,
} }
impl ResolverFile { impl ResolverFile {
@@ -1893,6 +1888,7 @@ struct Tab {
pane_id: usize, pane_id: usize,
pane_layout: PaneTree, pane_layout: PaneTree,
review_pane: Option<usize>, review_pane: Option<usize>,
local_review: crate::review::ReviewState,
file_picker: Option<FilePicker>, file_picker: Option<FilePicker>,
diff: Option<DiffState>, diff: Option<DiffState>,
parked_diff: Option<DiffState>, parked_diff: Option<DiffState>,
@@ -2200,6 +2196,7 @@ pub struct Editor {
panes: BTreeMap<usize, Pane>, panes: BTreeMap<usize, Pane>,
pane_layout: PaneTree, pane_layout: PaneTree,
review_pane: Option<usize>, review_pane: Option<usize>,
pub(crate) local_review: crate::review::ReviewState,
tab_id: usize, tab_id: usize,
next_tab_id: usize, next_tab_id: usize,
tab_order: Vec<usize>, tab_order: Vec<usize>,
@@ -2231,6 +2228,7 @@ pub struct Editor {
bottom_bar: ChromeLine, bottom_bar: ChromeLine,
popup: PopupConfig, popup: PopupConfig,
labels: BTreeMap<String, String>, labels: BTreeMap<String, String>,
pub(crate) cursor_config: crate::cursor::CursorConfig,
scroll_distance: Option<usize>, scroll_distance: Option<usize>,
scroll_step_lines: Option<NonZeroUsize>, scroll_step_lines: Option<NonZeroUsize>,
highlight_trailing_whitespace: bool, highlight_trailing_whitespace: bool,
@@ -2284,6 +2282,12 @@ pub struct Editor {
diff_return_buffer: Option<usize>, diff_return_buffer: Option<usize>,
diff_context_options: (usize, usize), diff_context_options: (usize, usize),
diff_display_options: (ViewMode, SplitAxis), diff_display_options: (ViewMode, SplitAxis),
pub(crate) diff_follow_working_copy: bool,
pub(crate) pull_request_review_requested_symbol: String,
pub(crate) pull_request_approved_symbol: String,
pub(crate) pull_request_preferences: crate::pull_requests::Preferences,
pub(crate) pull_request_preferences_changed: bool,
pub(crate) pull_request_configured: [bool; 2],
next_diff_request: u64, next_diff_request: u64,
outstanding_diff_request: Option<u64>, outstanding_diff_request: Option<u64>,
pending_lsp_navigation: Option<PendingLspNavigation>, pending_lsp_navigation: Option<PendingLspNavigation>,
@@ -2308,6 +2312,7 @@ impl Editor {
)]), )]),
pane_layout: PaneTree::new(1), pane_layout: PaneTree::new(1),
review_pane: None, review_pane: None,
local_review: Default::default(),
tab_id: 1, tab_id: 1,
next_tab_id: 2, next_tab_id: 2,
tab_order: vec![1], tab_order: vec![1],
@@ -2350,6 +2355,7 @@ impl Editor {
bottom_bar: ChromeLine::bottom(), bottom_bar: ChromeLine::bottom(),
popup: PopupConfig::default(), popup: PopupConfig::default(),
labels: BTreeMap::new(), labels: BTreeMap::new(),
cursor_config: crate::cursor::CursorConfig::default(),
scroll_distance: Some(0), scroll_distance: Some(0),
scroll_step_lines: None, scroll_step_lines: None,
highlight_trailing_whitespace: false, highlight_trailing_whitespace: false,
@@ -2424,6 +2430,12 @@ impl Editor {
diff_return_buffer: None, diff_return_buffer: None,
diff_context_options: (10, 15), diff_context_options: (10, 15),
diff_display_options: (ViewMode::Split, SplitAxis::Vertical), diff_display_options: (ViewMode::Split, SplitAxis::Vertical),
diff_follow_working_copy: false,
pull_request_review_requested_symbol: "🙏".into(),
pull_request_approved_symbol: "👍".into(),
pull_request_preferences: Default::default(),
pull_request_preferences_changed: false,
pull_request_configured: [false; 2],
next_diff_request: 0, next_diff_request: 0,
outstanding_diff_request: None, outstanding_diff_request: None,
pending_lsp_navigation: None, pending_lsp_navigation: None,
@@ -3080,11 +3092,34 @@ impl Editor {
let Some(buffer) = self.buffer(draft_buffer) else { let Some(buffer) = self.buffer(draft_buffer) else {
return; return;
}; };
let key = (buffer.text_revision, source); let base_index = resolver.selected_base;
let key = (buffer.text_revision, source, base_index);
let changed = file.comparison_key != Some(key); let changed = file.comparison_key != Some(key);
let first_comparison = file.diff.comparison_id.is_none(); let first_comparison = file.diff.comparison_id.is_none();
if changed { if changed {
if file.comparison_key.is_none_or(|(_, index)| index != source) { let base = match base_index {
Some(index) => match &file.projection {
Some(projection) => projection.alternative(index),
None => file
.sources
.get(index)
.map(|source| source.text.as_str())
.ok_or_else(|| "No such conflict base".into()),
},
None => Ok(""),
};
let base = match base {
Ok(text) => split_lines(text),
Err(error) => {
self.resolvers.get_mut(&self.tab_id).unwrap().files[file_index].error =
Some(error);
return;
}
};
if file
.comparison_key
.is_none_or(|(_, index, _)| index != source)
{
let alternative = match &file.projection { let alternative = match &file.projection {
Some(projection) => projection.alternative(source), Some(projection) => projection.alternative(source),
None => Ok(file None => Ok(file
@@ -3133,7 +3168,7 @@ impl Editor {
.set_context_options(self.diff_context_options.0, self.diff_context_options.1); .set_context_options(self.diff_context_options.0, self.diff_context_options.1);
let previous_id = file.diff.comparison_id; let previous_id = file.diff.comparison_id;
file.diff file.diff
.set_resolver_text(&draft.lines, &alternative.lines); .set_resolver_text(&draft.lines, &alternative.lines, Some(&base));
if file.diff.comparison_id != previous_id { if file.diff.comparison_id != previous_id {
self.next_diff_request = self self.next_diff_request = self
.next_diff_request .next_diff_request
@@ -3653,6 +3688,7 @@ impl Editor {
pane_id: std::mem::replace(&mut self.pane_id, next.pane_id), pane_id: std::mem::replace(&mut self.pane_id, next.pane_id),
pane_layout: std::mem::replace(&mut self.pane_layout, next.pane_layout), pane_layout: std::mem::replace(&mut self.pane_layout, next.pane_layout),
review_pane: std::mem::replace(&mut self.review_pane, next.review_pane), review_pane: std::mem::replace(&mut self.review_pane, next.review_pane),
local_review: std::mem::replace(&mut self.local_review, next.local_review),
file_picker: std::mem::replace(&mut self.file_picker, next.file_picker), file_picker: std::mem::replace(&mut self.file_picker, next.file_picker),
diff: std::mem::replace(&mut self.diff, next.diff), diff: std::mem::replace(&mut self.diff, next.diff),
parked_diff: std::mem::replace(&mut self.parked_diff, next.parked_diff), parked_diff: std::mem::replace(&mut self.parked_diff, next.parked_diff),
@@ -3702,6 +3738,7 @@ impl Editor {
pane_id, pane_id,
pane_layout: PaneTree::new(pane_id), pane_layout: PaneTree::new(pane_id),
review_pane: None, review_pane: None,
local_review: Default::default(),
file_picker: None, file_picker: None,
diff: None, diff: None,
parked_diff: None, parked_diff: None,
@@ -3804,11 +3841,6 @@ impl Editor {
// No input dispatch or document copies: source documents stay unique in active/parked. // No input dispatch or document copies: source documents stay unique in active/parked.
fn select_pane(&mut self, id: usize) { fn select_pane(&mut self, id: usize) {
let id = if self.review_pane == Some(id) && self.workspace_diff().is_none() {
self.panes[&id].origin.unwrap_or(id)
} else {
id
};
if id == self.pane_id { if id == self.pane_id {
return; return;
} }
@@ -4213,7 +4245,12 @@ impl Editor {
return; return;
} }
self.finish_pane_interaction(); self.finish_pane_interaction();
if self.diff_owner == Some(id) && !force && self.local_review_close_blocked() { let review_source =
self.review_pane.and_then(|panel| self.panes[&panel].origin) == Some(id);
if (self.diff_owner == Some(id) || review_source)
&& !force
&& self.local_review_close_blocked()
{
return; return;
} }
if self.diff_owner == Some(id) { if self.diff_owner == Some(id) {
@@ -4226,6 +4263,9 @@ impl Editor {
} }
let next = self.pane_layout.close(id).expect("another pane exists"); let next = self.pane_layout.close(id).expect("another pane exists");
self.select_pane(next); self.select_pane(next);
if review_source && let Some(panel) = self.review_pane {
self.panes.get_mut(&panel).unwrap().origin = Some(next);
}
self.panes.remove(&id); self.panes.remove(&id);
for buffer in buffers { for buffer in buffers {
self.forget_buffer(buffer); self.forget_buffer(buffer);
@@ -4557,6 +4597,16 @@ impl Editor {
.as_mut() .as_mut()
.is_some_and(|diff| diff.apply_result(id, result)); .is_some_and(|diff| diff.apply_result(id, result));
} }
let result = if let Ok(Outcome::BookmarkRefresh(comparison)) = &result
&& self.current_review_dirty()
&& self
.workspace_diff()
.is_some_and(|diff| diff.review_comparison.as_ref() != Some(&comparison.revisions))
{
Err("Save the local review before changing comparison endpoints".into())
} else {
result
};
self.outstanding_diff_request = None; self.outstanding_diff_request = None;
if self.diff.as_ref().is_some_and(DiffState::refresh_pending) if self.diff.as_ref().is_some_and(DiffState::refresh_pending)
&& !matches!(&result, Ok(Outcome::CheckoutRefresh(None))) && !matches!(&result, Ok(Outcome::CheckoutRefresh(None)))
@@ -4617,11 +4667,16 @@ impl Editor {
view.clamp(&self.active.lines); view.clamp(&self.active.lines);
self.active.view = view; self.active.view = view;
} }
if let Err(error) = self.initialize_local_review() { if self.resolver().is_none()
&& self
.workspace_diff()
.is_some_and(|diff| diff.phase == Phase::View)
&& let Err(error) = self.initialize_local_review()
{
self.set_message(format!("Local review: {error}")); self.set_message(format!("Local review: {error}"));
} }
if restore_reviewed && let Some(diff) = &mut self.diff { if restore_reviewed && let Some(diff) = &mut self.diff {
diff.restore_reviewed_files(); diff.restore_reviewed_files(&self.local_review);
} }
let reviewed = self.diff.as_mut().and_then(|diff| { let reviewed = self.diff.as_mut().and_then(|diff| {
(refresh (refresh
@@ -4711,6 +4766,7 @@ impl Editor {
diff.word_wrap = self.active.view.word_wrap; diff.word_wrap = self.active.view.word_wrap;
diff.view_mode = self.diff_display_options.0; diff.view_mode = self.diff_display_options.0;
diff.split_axis = self.diff_display_options.1; diff.split_axis = self.diff_display_options.1;
diff.follow_working_copy = self.diff_follow_working_copy;
diff.set_context_options(self.diff_context_options.0, self.diff_context_options.1); diff.set_context_options(self.diff_context_options.0, self.diff_context_options.1);
self.diff = Some(diff); self.diff = Some(diff);
} }
@@ -5180,16 +5236,19 @@ impl Editor {
pub(crate) fn refresh_live_diff(&mut self) { pub(crate) fn refresh_live_diff(&mut self) {
self.refresh_resolver_comparison(); self.refresh_resolver_comparison();
for diff in self for (diff, parked, review) in std::iter::once((
.diff &mut self.diff,
.iter_mut() &mut self.parked_diff,
.chain(self.parked_diff.iter_mut()) &mut self.local_review,
))
.chain( .chain(
self.tabs self.tabs
.values_mut() .values_mut()
.flat_map(|tab| tab.diff.iter_mut().chain(tab.parked_diff.iter_mut())), .map(|tab| (&mut tab.diff, &mut tab.parked_diff, &mut tab.local_review)),
) ) {
{ let Some(diff) = diff.as_mut().or(parked.as_mut()) else {
continue;
};
let buffer = diff.live_buffer.and_then(|id| { let buffer = diff.live_buffer.and_then(|id| {
if id == self.active.id { if id == self.active.id {
Some(&self.active) Some(&self.active)
@@ -5201,7 +5260,7 @@ impl Editor {
&& diff.live_after_available() && diff.live_after_available()
&& diff.live_revision != Some(buffer.text_revision) && diff.live_revision != Some(buffer.text_revision)
{ {
diff.refresh_after(&buffer.lines, buffer.text_revision); diff.refresh_after(&buffer.lines, buffer.text_revision, review);
diff.follow_caret = true; diff.follow_caret = true;
} }
} }
@@ -5314,6 +5373,47 @@ impl Editor {
let phase = self.picker_diff().expect("active diff").phase; let phase = self.picker_diff().expect("active diff").phase;
let files_focused = let files_focused =
phase == Phase::View && self.picker_diff().unwrap().focus == Focus::Files; phase == Phase::View && self.picker_diff().unwrap().focus == Focus::Files;
if phase != Phase::View
&& self.picker_diff().unwrap().pull_request_remote.is_some()
&& (self.picker_diff().unwrap().pull_request_menu.is_some()
|| matches!(input, Input::Ctrl('s' | 'f')))
{
if !matches!(
input,
Input::Char('0'..='9' | ' ')
| Input::Ctrl('s' | 'f')
| Input::Escape
| Input::Enter
| Input::Left
| Input::Right
) && BackspaceKind::from_input(&input).is_none()
&& self.handle_selection_binding(&input)
{
return None;
}
let diff = self.picker_diff_mut().unwrap();
diff.handle(input);
if std::mem::take(&mut diff.pull_request_preferences_changed) {
let preferences = diff.pull_request_preferences.clone();
self.pull_request_preferences_changed |=
self.pull_request_preferences.sort != preferences.sort;
self.pull_request_preferences = preferences.clone();
for diff in self
.diff
.iter_mut()
.chain(self.parked_diff.iter_mut())
.chain(
self.tabs
.values_mut()
.flat_map(|tab| tab.diff.iter_mut().chain(tab.parked_diff.iter_mut())),
)
.filter(|diff| diff.pull_request_remote.is_some())
{
diff.set_pull_request_preferences(preferences.clone());
}
}
return None;
}
if phase != Phase::View && input == Input::Escape { if phase != Phase::View && input == Input::Escape {
return self.execute_action(Action::DiffClose.entry(), ""); return self.execute_action(Action::DiffClose.entry(), "");
} }
@@ -5434,7 +5534,7 @@ impl Editor {
| Action::DiffViewToggle | Action::DiffViewToggle
| Action::DiffOrientationToggle | Action::DiffOrientationToggle
| Action::DiffReviewToggle | Action::DiffReviewToggle
| Action::DiffComment | Action::Comment
| Action::ReviewEdit | Action::ReviewEdit
| Action::ReviewDelete | Action::ReviewDelete
| Action::ReviewResolve | Action::ReviewResolve
@@ -8866,7 +8966,7 @@ impl Editor {
| Action::DiffViewToggle | Action::DiffViewToggle
| Action::DiffOrientationToggle | Action::DiffOrientationToggle
| Action::DiffReviewToggle | Action::DiffReviewToggle
| Action::DiffComment | Action::Comment
| Action::ReviewEdit | Action::ReviewEdit
| Action::ReviewDelete | Action::ReviewDelete
| Action::ReviewResolve | Action::ReviewResolve
@@ -9508,8 +9608,7 @@ impl Editor {
.map(|buffer| buffer.id); .map(|buffer| buffer.id);
if let Some(id) = loaded { if let Some(id) = loaded {
self.switch_buffer(id); self.switch_buffer(id);
return Ok(()); } else {
}
let buffer = Buffer::open( let buffer = Buffer::open(
self.next_buffer_id, self.next_buffer_id,
Some(path), Some(path),
@@ -9517,6 +9616,14 @@ impl Editor {
allow_missing, allow_missing,
)?; )?;
self.add_buffer(buffer); self.add_buffer(buffer);
}
if self.review_directory.is_some()
&& self.workspace_diff().is_none()
&& self.resolver().is_none()
&& let Err(error) = self.initialize_local_review()
{
self.set_message(format!("Local review: {error}"));
}
Ok(()) Ok(())
} }
@@ -9694,7 +9801,7 @@ impl Editor {
fn restart(&mut self, force: bool) { fn restart(&mut self, force: bool) {
if !force && self.local_reviews_dirty() { if !force && self.local_reviews_dirty() {
self.set_message("Unsaved local review; use :diff.review.save <path>"); self.set_message("Unsaved local review; use :review.save <path>");
return; return;
} }
if force || !self.any_dirty() { if force || !self.any_dirty() {
@@ -9825,7 +9932,7 @@ impl Editor {
} }
if matches!( if matches!(
entry.action, entry.action,
Action::DiffComment Action::Comment
| Action::ReviewEdit | Action::ReviewEdit
| Action::ReviewDelete | Action::ReviewDelete
| Action::ReviewResolve | Action::ReviewResolve
@@ -10039,6 +10146,9 @@ impl Editor {
self.active.view.mode = Mode::Normal; self.active.view.mode = Mode::Normal;
} }
if entry.action == Action::DiffModeToggle { if entry.action == Action::DiffModeToggle {
if self.local_review_close_blocked() {
return None;
}
let Some(diff) = self.diff.as_mut() else { let Some(diff) = self.diff.as_mut() else {
self.set_message("No comparison is open"); self.set_message("No comparison is open");
return None; return None;
@@ -10051,15 +10161,28 @@ impl Editor {
self.diff_return_buffer = Some(self.active.id); self.diff_return_buffer = Some(self.active.id);
return None; return None;
} }
let Some(diff) = self if entry.action == Action::DiffReviewToggle {
.picker_diff_mut() if self
.filter(|diff| diff.phase == Phase::View) .picker_diff()
else { .is_none_or(|diff| diff.phase != Phase::View)
{
self.set_message("No comparison is open"); self.set_message("No comparison is open");
return None; return None;
}; }
if entry.action == Action::DiffReviewToggle { if self.resolver().is_none()
match diff.toggle_reviewed() { && let Err(error) = self.initialize_local_review()
{
self.set_message(format!("Local review: {error}"));
return None;
}
let mut review = std::mem::take(&mut self.local_review);
let result = self
.picker_diff_mut()
.filter(|diff| diff.phase == Phase::View)
.ok_or("No comparison is open")
.and_then(|diff| diff.toggle_reviewed(&mut review));
self.local_review = review;
match result {
Ok(reviewed) => { Ok(reviewed) => {
if self.resolver().is_none() if self.resolver().is_none()
&& let Err(error) = self.autosave_local_review() && let Err(error) = self.autosave_local_review()
@@ -10077,6 +10200,13 @@ impl Editor {
} }
return None; return None;
} }
let Some(diff) = self
.picker_diff_mut()
.filter(|diff| diff.phase == Phase::View)
else {
self.set_message("No comparison is open");
return None;
};
if entry.action == Action::DiffViewToggle { if entry.action == Action::DiffViewToggle {
diff.set_view_mode(match diff.view_mode { diff.set_view_mode(match diff.view_mode {
ViewMode::Split => ViewMode::Unified, ViewMode::Split => ViewMode::Unified,
@@ -10154,6 +10284,9 @@ impl Editor {
self.active.view.command_line.clear(); self.active.view.command_line.clear();
self.active.view.mode = Mode::Normal; self.active.view.mode = Mode::Normal;
} }
if let Err(error) = self.initialize_local_review() {
self.set_message(format!("Local review: {error}"));
}
} else { } else {
self.set_message("The diff.close command takes no arguments"); self.set_message("The diff.close command takes no arguments");
} }
@@ -10168,7 +10301,9 @@ impl Editor {
if args.split_whitespace().count() > 1 { if args.split_whitespace().count() > 1 {
self.set_message("Usage: pull_requests [remote]"); self.set_message("Usage: pull_requests [remote]");
} else { } else {
self.open_diff(DiffState::pull_requests(args.into())); let mut diff = DiffState::pull_requests(args.into());
diff.set_pull_request_preferences(self.pull_request_preferences.clone());
self.open_diff(diff);
} }
} else if args.is_empty() { } else if args.is_empty() {
self.open_diff(DiffState::new()); self.open_diff(DiffState::new());
+320 -176
View File
@@ -25,58 +25,114 @@ pub(super) struct ReviewBuffer {
impl Editor { impl Editor {
pub fn set_review_directory(&mut self, directory: PathBuf) { pub fn set_review_directory(&mut self, directory: PathBuf) {
self.review_directory = Some(directory); self.review_directory = Some(directory);
if self.review_root().is_ok()
&& let Err(error) = self.initialize_local_review()
{
self.set_message(format!("Local review: {error}"));
}
} }
pub(super) fn initialize_local_review(&mut self) -> Result<(), String> { pub(super) fn initialize_local_review(&mut self) -> Result<(), String> {
let Some(directory) = self.review_directory.as_ref() else { let root = self.review_root()?;
return Ok(()); let comparison = self.review_comparison();
}; if self.local_review.document.root == root
let Some(diff) = self && self.local_review.document.comparison == comparison
.workspace_diff() {
.filter(|diff| diff.phase == Phase::View) self.local_review.initialized = true;
else {
return Ok(());
};
if diff.local_review.initialized {
return Ok(()); return Ok(());
} }
let root = diff if self.current_review_dirty() {
.comparison return Err("Save the current review before changing review scopes".into());
.as_ref() }
.ok_or("Comparison is loading")? let reviews = match self.review_directory.as_deref() {
.root Some(directory) => crate::review::Store::open_read_only(directory)?
.clone(); .map(|store| store.list(&root))
let directory = directory.clone(); .transpose()?
self.review_diff_mut().unwrap().local_review.initialized = true; .unwrap_or_default(),
self.review_diff_mut().unwrap().local_review.document = Review::new(root.clone()); None => Vec::new(),
let store = crate::review::Store::open(&directory)?; };
let mut reviews = store.list(&root)?; self.detach_review_buffers();
let mut document = Review::new(root);
document.comparison = comparison.clone();
self.local_review = crate::review::ReviewState {
document,
initialized: true,
..Default::default()
};
let mut reviews: Vec<_> = reviews
.into_iter()
.filter(|review| review.comparison == comparison)
.collect();
if reviews.len() == 1 { if reviews.len() == 1 {
self.review_diff_mut().unwrap().local_review.document = reviews.pop().unwrap(); self.local_review.document = reviews.pop().unwrap();
} else if reviews.len() > 1 { } else if reviews.len() > 1 {
self.show_review_selector(reviews)?; self.show_review_selector(reviews)?;
} }
Ok(()) Ok(())
} }
fn review_comparison(&self) -> Option<[String; 2]> {
if self.active.review_buffer.is_some() {
return self.local_review.document.comparison.clone();
}
self.diff
.as_ref()
.and_then(|diff| diff.review_comparison.clone())
}
fn review_root(&self) -> Result<PathBuf, String> {
if self
.active
.review_buffer
.as_ref()
.is_some_and(|binding| binding.owner != self.tab_id)
{
return Err("Focus a source or comparison pane in this tab to select a review".into());
}
if self.active.review_buffer.is_some()
|| (self.active.path.is_none() && self.local_review.initialized && self.diff.is_none())
{
return Ok(self.local_review.document.root.clone());
}
if let Some(diff) = self.diff.as_ref() {
return diff
.comparison
.as_ref()
.map(|comparison| {
fs::canonicalize(&comparison.root).unwrap_or_else(|_| comparison.root.clone())
})
.ok_or_else(|| "Comparison is still loading".into());
}
let path = self
.active
.identity
.as_deref()
.or(self.active.path.as_deref())
.ok_or("Save the source file before commenting")?;
let root = crate::repository::discover_root(
path.parent().ok_or("Source has no parent directory")?,
)?;
Ok(fs::canonicalize(&root).unwrap_or(root))
}
fn open_review_selector(&mut self) -> Result<(), String> { fn open_review_selector(&mut self) -> Result<(), String> {
let diff = self.workspace_diff().ok_or("No comparison is open")?; let root = self.review_root()?;
let directory = self let directory = self
.review_directory .review_directory
.as_deref() .as_deref()
.ok_or("Review storage is not configured")?; .ok_or("Review storage is not configured")?;
let root = &diff let comparison = self.review_comparison();
.comparison let reviews = crate::review::Store::open(directory)?
.as_ref() .list(&root)?
.ok_or("Comparison is loading")? .into_iter()
.root; .filter(|review| review.comparison == comparison)
let reviews = crate::review::Store::open(directory)?.list(root)?; .collect();
self.show_review_selector(reviews) self.show_review_selector(reviews)
} }
fn show_review_selector(&mut self, reviews: Vec<Review>) -> Result<(), String> { fn show_review_selector(&mut self, reviews: Vec<Review>) -> Result<(), String> {
let mut text = String::from( let mut text = String::from(
"# Local reviews\n\nEnter opens the review under the caret.\n:diff.review.new starts a separate review.\n", "# Local reviews\n\nEnter opens the review under the caret.\n:review.new starts a separate review.\n",
); );
for review in reviews { for review in reviews {
let id = review.storage_id.unwrap(); let id = review.storage_id.unwrap();
@@ -95,14 +151,14 @@ impl Editor {
self.open_review_buffer( self.open_review_buffer(
ReviewText::Reviews, ReviewText::Reviews,
&text, &text,
"Local reviews · Enter opens · :diff.review.new".into(), "Local reviews · Enter opens · :review.new".into(),
)?; )?;
self.place_navigation(TextPosition { row, column: 0 }); self.place_navigation(TextPosition { row, column: 0 });
Ok(()) Ok(())
} }
fn mark_review_saved(&mut self) { fn mark_review_saved(&mut self) {
self.review_diff_mut().unwrap().local_review.dirty = false; self.local_review.dirty = false;
for buffer in std::iter::once(&mut self.active).chain(self.parked.values_mut()) { for buffer in std::iter::once(&mut self.active).chain(self.parked.values_mut()) {
if buffer if buffer
.review_buffer .review_buffer
@@ -120,21 +176,12 @@ impl Editor {
let Some(directory) = self.review_directory.as_deref() else { let Some(directory) = self.review_directory.as_deref() else {
return Ok(()); return Ok(());
}; };
if !self if !self.local_review.dirty {
.workspace_diff()
.is_some_and(|diff| diff.local_review.dirty)
{
return Ok(()); return Ok(());
} }
let mut store = crate::review::Store::open(directory)?; let mut store = crate::review::Store::open(directory)?;
store.save( store.save(&mut self.local_review.document)?;
&mut self self.local_review.dirty = false;
.review_diff_mut()
.ok_or("No comparison is open")?
.local_review
.document,
)?;
self.review_diff_mut().unwrap().local_review.dirty = false;
Ok(()) Ok(())
} }
pub fn review_panel_title(&self) -> Option<&str> { pub fn review_panel_title(&self) -> Option<&str> {
@@ -145,8 +192,7 @@ impl Editor {
} }
pub fn review_panel(&self) -> Option<usize> { pub fn review_panel(&self) -> Option<usize> {
self.review_pane self.review_pane.filter(|pane| *pane == self.pane_id)
.filter(|pane| *pane == self.pane_id && self.workspace_diff().is_some())
} }
pub(super) fn dismiss_review_panel(&mut self) -> bool { pub(super) fn dismiss_review_panel(&mut self) -> bool {
@@ -165,7 +211,7 @@ impl Editor {
buffer.view.word_wrap = wrap; buffer.view.word_wrap = wrap;
buffer.resolver_readonly = self.active.resolver_readonly; buffer.resolver_readonly = self.active.resolver_readonly;
if binding.pending_comment.take().is_some() { if binding.pending_comment.take().is_some() {
self.review_diff_mut().unwrap().local_review.selected = None; self.local_review.selected = None;
} }
buffer.review_buffer = Some(binding); buffer.review_buffer = Some(binding);
self.active = buffer; self.active = buffer;
@@ -175,25 +221,16 @@ impl Editor {
true true
} }
fn review_diff_mut(&mut self) -> Option<&mut DiffState> {
self.diff.as_mut().or(self.parked_diff.as_mut())
}
pub(super) fn local_reviews_dirty(&self) -> bool { pub(super) fn local_reviews_dirty(&self) -> bool {
self.workspace_diff() self.local_review.dirty
.is_some_and(|diff| diff.local_review.dirty) || self.tabs.values().any(|tab| tab.local_review.dirty)
|| self
.tabs
.values()
.any(|tab| tab.diff().is_some_and(|diff| diff.local_review.dirty))
|| std::iter::once(&self.active) || std::iter::once(&self.active)
.chain(self.parked.values()) .chain(self.parked.values())
.any(|buffer| buffer.review_buffer.is_some() && buffer.dirty()) .any(|buffer| buffer.review_buffer.is_some() && buffer.dirty())
} }
pub(super) fn current_review_dirty(&self) -> bool { pub(super) fn current_review_dirty(&self) -> bool {
self.workspace_diff() self.local_review.dirty
.is_some_and(|diff| diff.local_review.dirty)
|| std::iter::once(&self.active) || std::iter::once(&self.active)
.chain(self.parked.values()) .chain(self.parked.values())
.any(|buffer| { .any(|buffer| {
@@ -213,7 +250,7 @@ impl Editor {
return true; return true;
} }
if self.current_review_dirty() { if self.current_review_dirty() {
self.set_message("Unsaved local review; use :diff.review.save <path> before closing"); self.set_message("Unsaved local review; use :review.save <path> before closing");
true true
} else { } else {
false false
@@ -237,6 +274,10 @@ impl Editor {
root: PathBuf, root: PathBuf,
source: ReviewSource<'_>, source: ReviewSource<'_>,
) -> Result<(), String> { ) -> Result<(), String> {
if self.current_review_dirty() {
return Err("Save the current local review before opening another".into());
}
let comparison = self.review_comparison();
let (document, path, dirty) = match source { let (document, path, dirty) = match source {
ReviewSource::Stored(id) => { ReviewSource::Stored(id) => {
let directory = self let directory = self
@@ -254,17 +295,26 @@ impl Editor {
Some(path.to_path_buf()), Some(path.to_path_buf()),
self.review_directory.is_some(), self.review_directory.is_some(),
), ),
ReviewSource::New => (Review::new(root), None, true), ReviewSource::New => {
let mut document = Review::new(root);
document.comparison = comparison.clone();
(document, None, true)
}
}; };
if document.comparison != comparison {
return Err("Review belongs to a different comparison or source scope".into());
}
// Retire old drafts before comment IDs can be reused. // Retire old drafts before comment IDs can be reused.
self.detach_review_buffers(); self.detach_review_buffers();
let state = &mut self.review_diff_mut().unwrap().local_review; let state = &mut self.local_review;
state.document = document; state.document = document;
state.path = path; state.path = path;
state.selected = None; state.selected = None;
state.pending_navigation = None; state.pending_navigation = None;
state.dirty = dirty; state.dirty = dirty;
self.review_diff_mut().unwrap().restore_reviewed_files(); if let Some(diff) = self.diff.as_mut().or(self.parked_diff.as_mut()) {
diff.restore_reviewed_files(&self.local_review);
}
// Persistence failure leaves the identity change applied and unsaved. // Persistence failure leaves the identity change applied and unsaved.
self.autosave_local_review()?; self.autosave_local_review()?;
self.open_review_overview() self.open_review_overview()
@@ -272,7 +322,7 @@ impl Editor {
fn delete_local_review_comment(&mut self, args: &str) -> Result<(), String> { fn delete_local_review_comment(&mut self, args: &str) -> Result<(), String> {
let id = self.review_comment_id(args)?; let id = self.review_comment_id(args)?;
let state = &mut self.review_diff_mut().unwrap().local_review; let state = &mut self.local_review;
state.document.comments.retain(|comment| comment.id != id); state.document.comments.retain(|comment| comment.id != id);
state.selected = None; state.selected = None;
state.pending_navigation = None; state.pending_navigation = None;
@@ -308,14 +358,11 @@ impl Editor {
}) })
}) })
.collect(); .collect();
let Some(diff) = self.review_diff_mut() else { let state = &mut self.local_review;
return Vec::new();
};
let mut previous = Vec::new(); let mut previous = Vec::new();
for (kind, text, pending) in updates { for (kind, text, pending) in updates {
if let Some(mut comment) = pending if let Some(mut comment) = pending
&& !diff && !state
.local_review
.document .document
.comments .comments
.iter() .iter()
@@ -323,19 +370,18 @@ impl Editor {
{ {
previous.push((kind, None)); previous.push((kind, None));
comment.body = text; comment.body = text;
diff.local_review.document.comments.push(comment); state.document.comments.push(comment);
diff.local_review.dirty = true; state.dirty = true;
continue; continue;
} }
let destination = match kind { let destination = match kind {
ReviewText::Comment(id) => diff ReviewText::Comment(id) => state
.local_review
.document .document
.comments .comments
.iter_mut() .iter_mut()
.find(|comment| comment.id == id) .find(|comment| comment.id == id)
.map(|comment| &mut comment.body), .map(|comment| &mut comment.body),
ReviewText::Summary => Some(&mut diff.local_review.document.summary), ReviewText::Summary => Some(&mut state.document.summary),
ReviewText::Overview => None, ReviewText::Overview => None,
ReviewText::Reviews => None, ReviewText::Reviews => None,
}; };
@@ -344,22 +390,18 @@ impl Editor {
{ {
let old = std::mem::replace(destination, text); let old = std::mem::replace(destination, text);
previous.push((kind, Some(old))); previous.push((kind, Some(old)));
diff.local_review.dirty = true; state.dirty = true;
} }
} }
previous previous
} }
pub(super) fn save_local_review(&mut self, path: Option<&Path>) -> Result<(), String> { pub(super) fn save_local_review(&mut self, path: Option<&Path>) -> Result<(), String> {
let dirty = self let dirty = self.local_review.dirty;
.review_diff_mut()
.ok_or("No comparison is open")?
.local_review
.dirty;
let previous = self.sync_review_text(); let previous = self.sync_review_text();
let result = self.write_local_review(path); let result = self.write_local_review(path);
if result.is_err() { if result.is_err() {
let state = &mut self.review_diff_mut().unwrap().local_review; let state = &mut self.local_review;
for (kind, text) in previous { for (kind, text) in previous {
match (kind, text) { match (kind, text) {
(ReviewText::Comment(id), None) => { (ReviewText::Comment(id), None) => {
@@ -386,12 +428,8 @@ impl Editor {
fn write_local_review(&mut self, path: Option<&Path>) -> Result<(), String> { fn write_local_review(&mut self, path: Option<&Path>) -> Result<(), String> {
if self.review_directory.is_some() { if self.review_directory.is_some() {
if let Some(path) = path { if let Some(path) = path {
self.review_diff_mut() self.local_review.document.save(path)?;
.ok_or("No comparison is open")? self.local_review.path = Some(path.to_path_buf());
.local_review
.document
.save(path)?;
self.review_diff_mut().unwrap().local_review.path = Some(path.to_path_buf());
} }
self.autosave_local_review()?; self.autosave_local_review()?;
self.mark_review_saved(); self.mark_review_saved();
@@ -402,14 +440,11 @@ impl Editor {
}); });
return Ok(()); return Ok(());
} }
let state = &mut self let state = &mut self.local_review;
.review_diff_mut()
.ok_or("No comparison is open")?
.local_review;
let path = path let path = path
.map(Path::to_path_buf) .map(Path::to_path_buf)
.or_else(|| state.path.clone()) .or_else(|| state.path.clone())
.ok_or("Use :diff.review.save <path> to choose a local JSON review file")?; .ok_or("Use :review.save <path> to choose a local JSON review file")?;
state.document.save(&path)?; state.document.save(&path)?;
state.path = Some(path); state.path = Some(path);
self.mark_review_saved(); self.mark_review_saved();
@@ -423,19 +458,10 @@ impl Editor {
args: &str, args: &str,
) -> Result<(), String> { ) -> Result<(), String> {
if self.resolver().is_some() { if self.resolver().is_some() {
return Err("Local reviews require an ordinary diff comparison".into()); return Err("Local reviews are unavailable in conflict resolution workspaces".into());
} }
self.initialize_local_review()?; self.initialize_local_review()?;
let diff = self let root = self.review_root()?;
.workspace_diff()
.filter(|diff| diff.phase == Phase::View)
.ok_or("No comparison is open")?;
let root = diff
.comparison
.as_ref()
.ok_or("Comparison is still loading")?
.root
.clone();
if !matches!( if !matches!(
action, action,
Action::ReviewEdit Action::ReviewEdit
@@ -449,17 +475,6 @@ impl Editor {
{ {
return Err("This review command takes no arguments".into()); return Err("This review command takes no arguments".into());
} }
if self
.workspace_diff()
.unwrap()
.local_review
.document
.root
.as_os_str()
.is_empty()
{
self.review_diff_mut().unwrap().local_review.document = Review::new(root.clone());
}
if !matches!(action, Action::ReviewSave | Action::ReviewCopy) { if !matches!(action, Action::ReviewSave | Action::ReviewCopy) {
self.autosave_local_review()?; self.autosave_local_review()?;
} }
@@ -480,7 +495,7 @@ impl Editor {
return self.replace_local_review(root, source); return self.replace_local_review(root, source);
} }
match action { match action {
Action::DiffComment => self.add_review_comment()?, Action::Comment => self.add_review_comment()?,
Action::ReviewNew => self.replace_local_review(root, ReviewSource::New)?, Action::ReviewNew => self.replace_local_review(root, ReviewSource::New)?,
Action::ReviewEdit => { Action::ReviewEdit => {
let id = self.review_comment_id(args)?; let id = self.review_comment_id(args)?;
@@ -489,7 +504,7 @@ impl Editor {
Action::ReviewResolve | Action::ReviewUnresolve => { Action::ReviewResolve | Action::ReviewUnresolve => {
let id = self.review_comment_id(args)?; let id = self.review_comment_id(args)?;
let resolved = action == Action::ReviewResolve; let resolved = action == Action::ReviewResolve;
let state = &mut self.review_diff_mut().unwrap().local_review; let state = &mut self.local_review;
let comment = state let comment = state
.document .document
.comments .comments
@@ -522,7 +537,7 @@ impl Editor {
} }
Action::ReviewDelete => self.delete_local_review_comment(args)?, Action::ReviewDelete => self.delete_local_review_comment(args)?,
Action::ReviewNext | Action::ReviewPrevious => { Action::ReviewNext | Action::ReviewPrevious => {
let state = &self.workspace_diff().unwrap().local_review; let state = &self.local_review;
let comments = &state.document.comments; let comments = &state.document.comments;
if comments.is_empty() { if comments.is_empty() {
return Err("No local review comments".into()); return Err("No local review comments".into());
@@ -540,7 +555,7 @@ impl Editor {
} }
Action::ReviewOverview => self.open_review_overview()?, Action::ReviewOverview => self.open_review_overview()?,
Action::ReviewCopy => { Action::ReviewCopy => {
let review = &self.workspace_diff().unwrap().local_review.document; let review = &self.local_review.document;
let count = review.comments.len(); let count = review.comments.len();
if count == 0 { if count == 0 {
return Err("No local review comments".into()); return Err("No local review comments".into());
@@ -554,13 +569,7 @@ impl Editor {
self.set_message(format!("Copied {count} review comments")); self.set_message(format!("Copied {count} review comments"));
} }
Action::ReviewSummary => { Action::ReviewSummary => {
let text = self let text = self.local_review.document.summary.clone();
.workspace_diff()
.unwrap()
.local_review
.document
.summary
.clone();
self.open_review_buffer( self.open_review_buffer(
ReviewText::Summary, ReviewText::Summary,
&text, &text,
@@ -574,11 +583,11 @@ impl Editor {
"none" => None, "none" => None,
_ => { _ => {
return Err( return Err(
"Usage: diff.review.verdict <looks_good|changes_requested|none>".into(), "Usage: review.verdict <looks_good|changes_requested|none>".into()
); );
} }
}; };
let state = &mut self.review_diff_mut().unwrap().local_review; let state = &mut self.local_review;
if state.document.verdict != verdict { if state.document.verdict != verdict {
state.document.verdict = verdict; state.document.verdict = verdict;
state.dirty = true; state.dirty = true;
@@ -595,10 +604,7 @@ impl Editor {
} }
fn review_comment_id(&self, args: &str) -> Result<u64, String> { fn review_comment_id(&self, args: &str) -> Result<u64, String> {
let state = &self let state = &self.local_review;
.workspace_diff()
.ok_or("No comparison is open")?
.local_review;
let under_cursor = self let under_cursor = self
.active .active
.review_buffer .review_buffer
@@ -633,16 +639,72 @@ impl Editor {
.ok_or_else(|| format!("No local comment #{id}")) .ok_or_else(|| format!("No local comment #{id}"))
} }
pub(crate) fn source_review_anchor_range(
&self,
anchor: &Anchor,
) -> Option<std::ops::Range<TextPosition>> {
if self.local_review.document.comparison.is_some()
|| self.active.review_buffer.is_some()
|| !anchor.revision.starts_with("working:")
{
return None;
}
let path = self
.active
.identity
.as_ref()
.or(self.active.path.as_ref())?;
let relative = path.strip_prefix(&self.local_review.document.root).ok()?;
anchor.mapped_range(
&anchor.revision,
relative,
Side::After,
&self.active.lines,
false,
)
}
fn review_anchor_range(&self, anchor: &Anchor) -> Option<std::ops::Range<TextPosition>> {
if self.local_review.document.comparison.is_some()
&& let Some(diff) = self.workspace_diff()
{
return diff.review_anchor_range(anchor, &self.local_review);
}
let path = self.local_review.document.root.join(&anchor.path);
let buffer = std::iter::once(&self.active)
.chain(self.parked.values())
.find(|buffer| {
buffer.identity.as_ref() == Some(&path) && buffer.review_buffer.is_none()
})?;
if !anchor.revision.starts_with("working:") {
return None;
}
anchor.mapped_range(
&anchor.revision,
&anchor.path,
Side::After,
&buffer.lines,
false,
)
}
fn add_review_comment(&mut self) -> Result<(), String> { fn add_review_comment(&mut self) -> Result<(), String> {
let owner = self.diff_owner.ok_or("No comparison is open")?; if self.local_review.document.comparison.is_some()
&& let Some(owner) = self.diff_owner
{
if self.pane_id != owner { if self.pane_id != owner {
self.select_pane(owner); self.select_pane(owner);
} }
self.bind_diff_buffer(); self.bind_diff_buffer();
let focus = self if self
.diff_buffer_focus() .diff_buffer_focus()
.filter(|_| self.diff_interacting()) .filter(|_| self.diff_interacting())
.ok_or("Focus a diff text pane to add a comment")?; .is_none()
{
return Err("Focus a diff text pane to add a comment".into());
}
} else if self.active.review_buffer.is_some() || self.active.resolver_readonly {
return Err("Focus a source text pane to add a comment".into());
}
if self.selection_count() != 1 { if self.selection_count() != 1 {
return Err("Use one caret or one contiguous selection for a review comment".into()); return Err("Use one caret or one contiguous selection for a review comment".into());
} }
@@ -663,23 +725,46 @@ impl Editor {
}, },
} }
}); });
let diff = self.diff.as_ref().unwrap(); let content = self.active.lines.join("\n");
let comparison = diff.comparison.as_ref().unwrap(); let (revision, path, side) = if let Some(diff) = self.diff.as_ref() {
let comparison = diff.comparison.as_ref().ok_or("Comparison is loading")?;
let file = &comparison.files[diff.file]; let file = &comparison.files[diff.file];
let side = if focus == Focus::Before { let side = if self.diff_buffer_focus() == Some(Focus::Before) {
Side::Before Side::Before
} else { } else {
Side::After Side::After
}; };
let anchor = Anchor { (
revision: comparison.revisions[side.index()].clone(), comparison.revisions[side.index()].clone(),
path: if side == Side::Before { if side == Side::Before {
file.old_path.as_ref().unwrap_or(&file.path) file.old_path.as_ref().unwrap_or(&file.path)
} else { } else {
&file.path &file.path
} }
.clone(), .clone(),
side, side,
)
} else {
let root = &self.local_review.document.root;
let path = self
.active
.identity
.as_ref()
.or(self.active.path.as_ref())
.ok_or("Save the source file before commenting")?
.strip_prefix(root)
.map_err(|_| "Source is outside the review repository")?
.to_path_buf();
(
crate::repository::source_snapshot_revision(root, &content)?,
path,
Side::After,
)
};
let anchor = Anchor {
revision,
path,
side,
start: TextPosition { start: TextPosition {
row: range.start.row, row: range.start.row,
column: range.start.column, column: range.start.column,
@@ -688,9 +773,9 @@ impl Editor {
row: range.end.row, row: range.end.row,
column: range.end.column, column: range.end.column,
}, },
content: self.active.lines.join("\n"), content,
}; };
let id = diff let id = self
.local_review .local_review
.document .document
.comments .comments
@@ -727,10 +812,10 @@ impl Editor {
} }
fn open_review_comment(&mut self, id: u64, draft: Option<&Comment>) -> Result<(), String> { fn open_review_comment(&mut self, id: u64, draft: Option<&Comment>) -> Result<(), String> {
let diff = self.workspace_diff().unwrap(); let state = &self.local_review;
let comment = draft let comment = draft
.or_else(|| { .or_else(|| {
diff.local_review state
.document .document
.comments .comments
.iter() .iter()
@@ -744,7 +829,7 @@ impl Editor {
} else { } else {
"unresolved" "unresolved"
}; };
let mapped = diff.review_anchor_range(anchor); let mapped = self.review_anchor_range(anchor);
let current = mapped.is_some(); let current = mapped.is_some();
let location = if current { let location = if current {
"current" "current"
@@ -761,31 +846,82 @@ impl Editor {
range.end.column + 1, range.end.column + 1,
anchor.side anchor.side
); );
let target = diff.comparison.as_ref().and_then(|comparison| { let anchor = anchor.clone();
let mut stale = !current;
self.local_review.selected = Some(id);
if self.local_review.document.comparison.is_some()
&& let Some(owner) = self.diff_owner
{
let target = self
.workspace_diff()
.and_then(|diff| diff.comparison.as_ref())
.and_then(|comparison| {
comparison.files.iter().position(|file| { comparison.files.iter().position(|file| {
let path = if anchor.side == Side::Before { if anchor.side == Side::Before {
file.old_path.as_ref().unwrap_or(&file.path) file.old_path.as_ref().unwrap_or(&file.path) == &anchor.path
} else { } else {
&file.path file.path == anchor.path
}; }
path == &anchor.path
}) })
}); });
let stale = !current stale = !current
&& target.is_none_or(|index| diff.comparison.as_ref().unwrap().files[index].loaded); && target.is_none_or(|index| {
let start = anchor.start; self.workspace_diff()
let owner = self.diff_owner.unwrap(); .unwrap()
.comparison
.as_ref()
.unwrap()
.files[index]
.loaded
});
self.select_pane(owner); self.select_pane(owner);
let diff = self.diff.as_mut().unwrap();
diff.local_review.selected = Some(id);
if let Some(index) = target { if let Some(index) = target {
diff.select_file_index(index); self.diff.as_mut().unwrap().select_file_index(index);
diff.local_review.pending_navigation = Some(id); self.local_review.pending_navigation = Some(id);
} }
self.finish_review_navigation(); self.finish_review_navigation();
if draft.is_some() { if draft.is_some() {
self.place_navigation(start); self.place_navigation(anchor.start);
} }
} else {
if let Some(panel) = self.review_panel() {
self.select_pane(self.panes[&panel].origin.unwrap());
}
let path = self.local_review.document.root.join(&anchor.path);
if draft.is_none() {
let opened = self.edit_buffer(path.clone(), false).is_ok();
let mapped = opened.then(|| self.review_anchor_range(&anchor)).flatten();
stale = mapped.is_none();
if let Some(range) = mapped {
self.place_navigation(range.start);
} else {
let mut snapshot = Buffer::from_text(
self.next_buffer_id,
Some(path),
None,
&anchor.content,
None,
)
.map_err(|error| error.to_string())?;
snapshot.resolver_readonly = true;
self.add_buffer(snapshot);
self.place_navigation(anchor.start);
}
}
}
let title = title.replacen(
if stale {
" · current · "
} else {
" · original snapshot · "
},
if stale {
" · original snapshot · "
} else {
" · current · "
},
1,
);
self.open_review_buffer(ReviewText::Comment(id), &text, title)?; self.open_review_buffer(ReviewText::Comment(id), &text, title)?;
if stale { if stale {
self.set_message("Comment is stale; original snapshot anchor preserved"); self.set_message("Comment is stale; original snapshot anchor preserved");
@@ -794,18 +930,18 @@ impl Editor {
} }
pub(super) fn finish_review_navigation(&mut self) { pub(super) fn finish_review_navigation(&mut self) {
let state = &mut self.local_review;
let Some(diff) = self.diff.as_mut() else { let Some(diff) = self.diff.as_mut() else {
return; return;
}; };
let Some(id) = diff.local_review.pending_navigation else { let Some(id) = state.pending_navigation else {
return; return;
}; };
if !diff.selected_file_loaded() { if !diff.selected_file_loaded() {
return; return;
} }
diff.local_review.pending_navigation = None; state.pending_navigation = None;
let Some(comment) = diff let Some(comment) = state
.local_review
.document .document
.comments .comments
.iter() .iter()
@@ -827,7 +963,7 @@ impl Editor {
if selected_path != Some(&comment.anchor.path) { if selected_path != Some(&comment.anchor.path) {
return; return;
} }
let Some(range) = diff.review_anchor_range(&comment.anchor) else { let Some(range) = diff.review_anchor_range(&comment.anchor, state) else {
self.set_message("Comment is stale; original snapshot anchor preserved"); self.set_message("Comment is stale; original snapshot anchor preserved");
return; return;
}; };
@@ -844,8 +980,7 @@ impl Editor {
} }
fn open_review_overview(&mut self) -> Result<(), String> { fn open_review_overview(&mut self) -> Result<(), String> {
let diff = self.workspace_diff().unwrap(); let state = &self.local_review;
let state = &diff.local_review;
let verdict = match state.document.verdict { let verdict = match state.document.verdict {
Some(Verdict::LooksGood) => "Looks good", Some(Verdict::LooksGood) => "Looks good",
Some(Verdict::ChangesRequested) => "Changes requested", Some(Verdict::ChangesRequested) => "Changes requested",
@@ -868,16 +1003,19 @@ impl Editor {
.map_or_else(|| "not saved".into(), |path| path.display().to_string()) .map_or_else(|| "not saved".into(), |path| path.display().to_string())
}; };
let mut text = format!( let mut text = format!(
"# Local review\n\nVerdict: {verdict}\nStorage: {storage}\n\n## Summary\n{}\n\nEnter edits the comment under the caret.\n:diff.review.summary · :diff.review.verdict · :diff.review.save\n", "# Local review\n\nVerdict: {verdict}\nStorage: {storage}\n\n## Summary\n{}\n\nEnter edits the comment under the caret.\n:review.summary · :review.verdict · :review.save\n",
state.document.summary state.document.summary
); );
for comment in &state.document.comments { for comment in &state.document.comments {
let anchor = &comment.anchor; let anchor = &comment.anchor;
let mapped = diff.review_anchor_range(anchor); let mapped = self.review_anchor_range(anchor);
let range = mapped.clone().unwrap_or(anchor.start..anchor.end); let range = mapped.clone().unwrap_or(anchor.start..anchor.end);
let status = if mapped.is_some() { let status = if mapped.is_some() {
"current" "current"
} else if diff.comparison.as_ref().is_some_and(|comparison| { } else if self
.workspace_diff()
.and_then(|diff| diff.comparison.as_ref())
.is_some_and(|comparison| {
comparison.files.iter().any(|file| { comparison.files.iter().any(|file| {
!file.loaded !file.loaded
&& if anchor.side == Side::Before { && if anchor.side == Side::Before {
@@ -886,7 +1024,8 @@ impl Editor {
file.path == anchor.path file.path == anchor.path
} }
}) })
}) { })
{
"not checked (file not loaded)" "not checked (file not loaded)"
} else { } else {
"stale" "stale"
@@ -915,7 +1054,7 @@ impl Editor {
self.open_review_buffer( self.open_review_buffer(
ReviewText::Overview, ReviewText::Overview,
&text, &text,
"Local review overview · Enter edits · :diff.review.next".into(), "Local review overview · Enter edits · :review.next".into(),
) )
} }
@@ -927,6 +1066,11 @@ impl Editor {
) -> Result<(), String> { ) -> Result<(), String> {
self.prepare_command(); self.prepare_command();
self.finish_command_mode(); self.finish_command_mode();
let source = if self.review_panel().is_some() {
self.panes[&self.pane_id].origin.unwrap()
} else {
self.pane_id
};
let existing = std::iter::once(&self.active) let existing = std::iter::once(&self.active)
.chain(self.parked.values()) .chain(self.parked.values())
.find(|buffer| { .find(|buffer| {
@@ -945,14 +1089,14 @@ impl Editor {
id, id,
Pane { Pane {
buffer_id: self.active.id, buffer_id: self.active.id,
origin: self.diff_owner, origin: Some(source),
views: BTreeMap::from([(self.active.id, self.active.view.inherit())]), views: BTreeMap::from([(self.active.id, self.active.view.inherit())]),
}, },
); );
self.review_pane = Some(id); self.review_pane = Some(id);
id id
}; };
self.panes.get_mut(&panel).unwrap().origin = self.diff_owner; self.panes.get_mut(&panel).unwrap().origin = Some(source);
self.select_pane(panel); self.select_pane(panel);
if let Some(id) = existing { if let Some(id) = existing {
self.switch_buffer(id); self.switch_buffer(id);
@@ -978,9 +1122,9 @@ impl Editor {
self.add_buffer(buffer); self.add_buffer(buffer);
} }
self.set_message(if self.review_directory.is_some() { self.set_message(if self.review_directory.is_some() {
"Local review · :w saves · Escape discards unsaved text · :diff.review.save path exports JSON" "Local review · :w saves · Escape discards unsaved text · :review.save path exports JSON"
} else { } else {
"Local review · :w saves JSON; first choose :diff.review.save <path>" "Local review · :w saves JSON; first choose :review.save <path>"
}); });
Ok(()) Ok(())
} }
+469 -17
View File
@@ -13,7 +13,17 @@ pub(crate) struct PullRequestSummary {
pub title: String, pub title: String,
pub description: String, pub description: String,
pub closed: bool, pub closed: bool,
pub draft: bool,
pub approved: bool,
pub review_requested: bool,
pub created_at: String, pub created_at: String,
pub updated_at: String,
}
struct PullRequestMetadata {
size: Option<(u64, u64)>,
approved: bool,
review_requested: bool,
} }
pub(crate) struct PullRequestPage { pub(crate) struct PullRequestPage {
@@ -42,6 +52,7 @@ struct Forge {
provider: Provider, provider: Provider,
host: String, host: String,
endpoint: String, endpoint: String,
repository: String,
} }
fn encode(text: &str) -> String { fn encode(text: &str) -> String {
@@ -237,6 +248,7 @@ impl Forge {
provider, provider,
host: authority, host: authority,
endpoint, endpoint,
repository: path.to_owned(),
}) })
} }
@@ -308,14 +320,18 @@ impl Forge {
.transpose() .transpose()
} }
fn get( fn request(
&self, &self,
url: &str, url: &str,
body: Option<&str>,
token: Option<&str>, token: Option<&str>,
root: &Path, root: &Path,
cancelled: &AtomicBool, cancelled: &AtomicBool,
) -> Result<Value, String> { ) -> Result<Value, String> {
let mut headers = String::from("Accept: application/json\n"); let mut headers = String::from("Accept: application/json\n");
if body.is_some() {
headers.push_str("Content-Type: application/json\n");
}
if let Some(token) = token { if let Some(token) = token {
let prefix = match self.provider { let prefix = match self.provider {
Provider::Github => "Authorization: Bearer", Provider::Github => "Authorization: Bearer",
@@ -347,6 +363,9 @@ impl Forge {
"--url", "--url",
url, url,
]); ]);
if let Some(body) = body {
command.args(["--data-binary", body]);
}
let bytes = checked(run(command, headers.into_bytes(), cancelled)?).map_err( let bytes = checked(run(command, headers.into_bytes(), cancelled)?).map_err(
|_| "Forge API request failed; check curl, network access, and authentication", |_| "Forge API request failed; check curl, network access, and authentication",
)?; )?;
@@ -374,7 +393,7 @@ impl Forge {
&self, &self,
closed: bool, closed: bool,
page: u32, page: u32,
mut get: impl FnMut(&str) -> Result<Value, String>, mut request: impl FnMut(&str, Option<&str>) -> Result<Value, String>,
) -> Result<PullRequestPage, String> { ) -> Result<PullRequestPage, String> {
if page == 0 { if page == 0 {
return Err("Forge page numbers start at 1".into()); return Err("Forge page numbers start at 1".into());
@@ -394,17 +413,29 @@ impl Forge {
// Gitea's default sort is descending creation time; "oldest" reverses it. // Gitea's default sort is descending creation time; "oldest" reverses it.
Provider::Gitea => "limit=50", Provider::Gitea => "limit=50",
}; };
let values = get(&format!( let values = request(
"{}?state={state}&{query}&page={page}", &format!("{}?state={state}&{query}&page={page}", self.endpoint),
self.endpoint None,
))?; )?;
let values = values let values = values
.as_array() .as_array()
.ok_or("Forge API returned a non-array pull request list")?; .ok_or("Forge API returned a non-array pull request list")?;
// Servers may cap page sizes. Only an empty page proves exhaustion. // Servers may cap page sizes. Only an empty page proves exhaustion.
has_more |= !values.is_empty(); has_more |= !values.is_empty();
let metadata = self.metadata_with(values, &mut request);
for value in values { for value in values {
let entry = summary(self.provider, value)?; let id = number(
value,
if self.provider == Provider::Gitlab {
"iid"
} else {
"number"
},
)?;
let details = metadata.get(&id);
let mut entry = summary(self.provider, value, details.and_then(|d| d.size))?;
entry.approved = details.is_some_and(|d| d.approved);
entry.review_requested = details.is_some_and(|d| d.review_requested);
if entry.closed != closed { if entry.closed != closed {
return Err("Forge API returned a pull request in the wrong category".into()); return Err("Forge API returned a pull request in the wrong category".into());
} }
@@ -422,6 +453,407 @@ impl Forge {
Ok(PullRequestPage { entries, has_more }) Ok(PullRequestPage { entries, has_more })
} }
/// Batch GitHub/GitLab metadata; Gitea exposes reviews only per pull request.
fn metadata_with(
&self,
values: &[Value],
request: &mut impl FnMut(&str, Option<&str>) -> Result<Value, String>,
) -> BTreeMap<u64, PullRequestMetadata> {
if values.is_empty() {
return BTreeMap::new();
}
let api = self
.endpoint
.split_once(if self.provider == Provider::Gitlab {
"/projects/"
} else {
"/repos/"
})
.unwrap()
.0;
let viewer = request(&format!("{api}/user"), None).ok();
let username = viewer.as_ref().and_then(|viewer| {
viewer
.get(if self.provider == Provider::Gitlab {
"username"
} else {
"login"
})
.and_then(Value::as_str)
.filter(|name| !name.is_empty())
});
let mut metadata: BTreeMap<_, _> = values
.iter()
.filter_map(|value| {
let id = number(
value,
if self.provider == Provider::Gitlab {
"iid"
} else {
"number"
},
)
.ok()?;
Some((
id,
PullRequestMetadata {
size: value
.get("additions")
.and_then(Value::as_u64)
.zip(value.get("deletions").and_then(Value::as_u64)),
approved: false,
// GitHub's list contains only outstanding direct requests, not teams.
review_requested: self.provider == Provider::Github
&& username.is_some_and(|username| {
value
.get("requested_reviewers")
.and_then(Value::as_array)
.is_some_and(|reviewers| {
reviewers.iter().any(|reviewer| {
reviewer
.get("login")
.and_then(Value::as_str)
.is_some_and(|login| {
login.eq_ignore_ascii_case(username)
})
})
})
}),
},
))
})
.collect();
if self.provider == Provider::Gitea {
if let Some(viewer) = viewer.as_ref().and_then(|viewer| number(viewer, "id").ok()) {
for (&id, details) in &mut metadata {
// ponytail: Gitea has no batch reviews API; per-PR reads until it does.
// List requested_reviewers also includes completed reviews.
(details.approved, details.review_requested) = self
.gitea_reviews_with(id, viewer, request)
.unwrap_or_default();
}
}
return metadata;
}
if self.provider == Provider::Gitlab {
if let Some(username) = username {
self.gitlab_requests_with(values, username, &mut metadata, request);
}
}
let reviews = if self.provider == Provider::Github {
username.map_or_else(String::new, |username| {
format!(
"reviews(author:{},states:[APPROVED,CHANGES_REQUESTED,DISMISSED],last:1){{nodes{{state author{{login}}}}}}",
serde_json::to_string(username).unwrap()
)
})
} else {
String::new()
};
let mut fields = String::new();
for value in values {
let Some(id) = value
.get(if self.provider == Provider::Gitlab {
"iid"
} else {
"number"
})
.and_then(Value::as_u64)
else {
continue;
};
use std::fmt::Write;
match self.provider {
Provider::Github => write!(
fields,
"p{id}:pullRequest(number:{id}){{additions deletions {reviews}}}"
)
.unwrap(),
Provider::Gitlab => write!(
fields,
"p{id}:mergeRequest(iid:\"{id}\"){{diffStatsSummary{{additions deletions}}}}"
)
.unwrap(),
Provider::Gitea => unreachable!(),
}
}
let approval_args = if self.provider == Provider::Gitlab {
username.map(|username| {
let ids: Vec<_> = values
.iter()
.filter_map(|value| value.get("iid")?.as_u64().map(|id| id.to_string()))
.collect();
format!(
"iids:{},approvedBy:[{}],first:{}",
serde_json::to_string(&ids).unwrap(),
serde_json::to_string(username).unwrap(),
ids.len()
)
})
} else {
None
};
if let Some(args) = &approval_args {
use std::fmt::Write;
write!(
fields,
"approved:mergeRequests({args}){{nodes{{iid}} pageInfo{{hasNextPage endCursor}}}}"
)
.unwrap();
}
let (url, query) = if self.provider == Provider::Github {
let (owner, name) = self.repository.split_once('/').unwrap();
let api = self.endpoint.split_once("/repos/").unwrap().0;
(
format!("{}/graphql", api.strip_suffix("/v3").unwrap_or(api)),
format!(
"query{{repository(owner:{},name:{}){{{fields}}}}}",
serde_json::to_string(owner).unwrap(),
serde_json::to_string(name).unwrap()
),
)
} else {
(
format!("https://{}/api/graphql", self.host),
format!(
"query{{project(fullPath:{}){{{fields}}}}}",
serde_json::to_string(&self.repository).unwrap()
),
)
};
let body = serde_json::json!({ "query": query }).to_string();
// Missing/denied metadata must not discard independently known list data.
let Ok(response) = request(&url, Some(&body)) else {
return metadata;
};
let container = if self.provider == Provider::Github {
"/data/repository"
} else {
"/data/project"
};
let Some(entries) = response.pointer(container).and_then(Value::as_object) else {
return metadata;
};
for (alias, value) in entries {
let Some(details) = alias
.strip_prefix('p')
.and_then(|id| id.parse::<u64>().ok())
.and_then(|id| metadata.get_mut(&id))
else {
continue;
};
let stats = if self.provider == Provider::Gitlab {
value.get("diffStatsSummary")
} else {
Some(value)
};
details.size = stats
.and_then(|stats| {
stats
.get("additions")?
.as_u64()
.zip(stats.get("deletions")?.as_u64())
})
.or(details.size);
details.approved = self.provider == Provider::Github
&& username.is_some_and(|username| {
value
.pointer("/reviews/nodes")
.and_then(Value::as_array)
.is_some_and(|reviews| {
reviews.len() == 1
&& reviews[0]["state"] == "APPROVED"
&& reviews[0]
.pointer("/author/login")
.and_then(Value::as_str)
.is_some_and(|author| author.eq_ignore_ascii_case(username))
})
});
}
if let Some(args) = approval_args {
let mut response = response;
let mut cursor = None::<String>;
loop {
let Some(approvals) = response.pointer("/data/project/approved") else {
break;
};
if let Some(nodes) = approvals.get("nodes").and_then(Value::as_array) {
for node in nodes {
if let Some(details) = node
.get("iid")
.and_then(Value::as_str)
.and_then(|id| id.parse::<u64>().ok())
.and_then(|id| metadata.get_mut(&id))
{
details.approved = true;
}
}
}
if approvals.pointer("/pageInfo/hasNextPage") != Some(&Value::Bool(true)) {
break;
}
let Some(after) = approvals
.pointer("/pageInfo/endCursor")
.and_then(Value::as_str)
.filter(|after| !after.is_empty() && Some(*after) != cursor.as_deref())
else {
break;
};
cursor = Some(after.to_owned());
let body = serde_json::json!({
"query": format!(
"query{{project(fullPath:{}){{approved:mergeRequests({args},after:{}){{nodes{{iid}} pageInfo{{hasNextPage endCursor}}}}}}}}",
serde_json::to_string(&self.repository).unwrap(),
serde_json::to_string(after).unwrap()
)
}).to_string();
match request(&url, Some(&body)) {
Ok(next) => response = next,
Err(_) => break,
}
}
}
metadata
}
fn gitlab_requests_with(
&self,
values: &[Value],
username: &str,
metadata: &mut BTreeMap<u64, PullRequestMetadata>,
request: &mut impl FnMut(&str, Option<&str>) -> Result<Value, String>,
) {
let mut pending: BTreeMap<_, _> = values
.iter()
.filter_map(|value| {
let reviewers = value.get("reviewers")?.as_array()?;
if !reviewers.iter().any(|reviewer| {
reviewer.get("username").and_then(Value::as_str) == Some(username)
}) {
return None;
}
Some((number(value, "iid").ok()?, None::<String>))
})
.collect();
// Keep optional reviewer-state reads separate: unsupported/denied fields
// must not invalidate the independent statistics and approval query.
while !pending.is_empty() {
use std::fmt::Write;
let mut fields = String::new();
// Ten aliases stay below GitLab's default query-complexity limit.
let batch: BTreeMap<_, _> = (0..10).filter_map(|_| pending.pop_first()).collect();
for (id, cursor) in &batch {
let after = cursor.as_ref().map_or_else(String::new, |cursor| {
format!(",after:{}", serde_json::to_string(cursor).unwrap())
});
write!(fields, "p{id}:mergeRequest(iid:\"{id}\"){{reviewers(first:20{after}){{nodes{{username mergeRequestInteraction{{reviewState}}}} pageInfo{{hasNextPage endCursor}}}}}}").unwrap();
}
let body = serde_json::json!({
"query": format!("query{{project(fullPath:{}){{{fields}}}}}",
serde_json::to_string(&self.repository).unwrap())
})
.to_string();
let Ok(response) = request(&format!("https://{}/api/graphql", self.host), Some(&body))
else {
continue;
};
for (id, cursor) in batch {
let Some(reviewers) = response.pointer(&format!("/data/project/p{id}/reviewers"))
else {
continue;
};
let own = reviewers
.get("nodes")
.and_then(Value::as_array)
.and_then(|nodes| {
nodes.iter().find(|node| {
node.get("username").and_then(Value::as_str) == Some(username)
})
});
if let Some(own) = own {
if let Some(details) = metadata.get_mut(&id) {
details.review_requested = matches!(
own.pointer("/mergeRequestInteraction/reviewState")
.and_then(Value::as_str),
Some("UNREVIEWED" | "REVIEW_STARTED")
);
}
} else if reviewers.pointer("/pageInfo/hasNextPage") == Some(&Value::Bool(true)) {
if let Some(after) = reviewers
.pointer("/pageInfo/endCursor")
.and_then(Value::as_str)
.filter(|after| !after.is_empty() && Some(*after) != cursor.as_deref())
{
pending.insert(id, Some(after.to_owned()));
}
}
}
}
}
fn gitea_reviews_with(
&self,
id: u64,
viewer: u64,
request: &mut impl FnMut(&str, Option<&str>) -> Result<Value, String>,
) -> Result<(bool, bool), String> {
let mut latest = None::<(u64, bool)>;
let mut requested = None::<u64>;
let mut submitted = 0;
for page in 1.. {
let response = request(
&format!("{}/{id}/reviews?limit=50&page={page}", self.endpoint),
None,
)?;
let reviews = response
.as_array()
.ok_or("Forge API returned a non-array review list")?;
if reviews.is_empty() {
return Ok((
latest.is_some_and(|(_, approved)| approved),
requested.is_some_and(|id| id > submitted),
));
}
for review in reviews {
if review.pointer("/user/id").and_then(Value::as_u64) != Some(viewer)
|| review.get("team").is_some_and(|team| !team.is_null())
{
continue;
}
let state = field(review, "state")?;
match state {
"PENDING" => continue,
"REQUEST_REVIEW" => {
if review.get("dismissed").and_then(Value::as_bool) == Some(false) {
if let Some(id) = review.get("id").and_then(Value::as_u64) {
requested = Some(requested.map_or(id, |previous| previous.max(id)));
}
}
continue;
}
"COMMENT" => {
if let Some(id) = review.get("id").and_then(Value::as_u64) {
submitted = submitted.max(id);
}
continue;
}
"APPROVED" | "REQUEST_CHANGES" => {}
_ => return Err("Forge API returned invalid review state".into()),
}
let id = number(review, "id")?;
submitted = submitted.max(id);
let dismissed = review
.get("dismissed")
.and_then(Value::as_bool)
.ok_or("Forge API returned invalid dismissed flag")?;
if latest.is_none_or(|(previous, _)| id > previous) {
latest = Some((id, state == "APPROVED" && !dismissed));
}
}
}
unreachable!()
}
fn resolve_with( fn resolve_with(
&self, &self,
id: u64, id: u64,
@@ -477,9 +909,9 @@ fn gitea_head(value: &Value, id: u64) -> Result<String, String> {
sha(object, "sha") sha(object, "sha")
} }
fn created_at(value: &Value) -> Result<String, String> { fn timestamp(value: &Value, key: &str) -> Result<String, String> {
let invalid = || "Forge API returned invalid created_at".to_owned(); let invalid = || format!("Forge API returned invalid {key}");
let text = field(value, "created_at")?; let text = field(value, key)?;
let digits = |text: &str| -> Option<i32> { let digits = |text: &str| -> Option<i32> {
(!text.is_empty() && text.bytes().all(|b| b.is_ascii_digit())) (!text.is_empty() && text.bytes().all(|b| b.is_ascii_digit()))
.then(|| text.parse().ok()) .then(|| text.parse().ok())
@@ -567,17 +999,33 @@ fn created_at(value: &Value) -> Result<String, String> {
)) ))
} }
fn summary(provider: Provider, value: &Value) -> Result<PullRequestSummary, String> { fn summary(
provider: Provider,
value: &Value,
size: Option<(u64, u64)>,
) -> Result<PullRequestSummary, String> {
let gitlab = provider == Provider::Gitlab; let gitlab = provider == Provider::Gitlab;
let (closed, merged) = status(provider, value)?; let (closed, merged) = status(provider, value)?;
let draft = match value.get("draft") {
None => false,
Some(value) => value
.as_bool()
.ok_or("Forge API returned invalid draft flag")?,
};
let author = author(provider, value)?; let author = author(provider, value)?;
let state = if merged { let state = if merged {
"merged" "merged"
} else if closed { } else if closed {
"closed" "closed"
} else if draft {
"draft"
} else { } else {
"open" "open"
}; };
let size = size.map_or_else(
|| "size unavailable".into(),
|(added, deleted)| format!("+{added} -{deleted}"),
);
let (base, head) = if gitlab { let (base, head) = if gitlab {
( (
value.get("target_branch").and_then(Value::as_str), value.get("target_branch").and_then(Value::as_str),
@@ -601,11 +1049,15 @@ fn summary(provider: Provider, value: &Value) -> Result<PullRequestSummary, Stri
number: number(value, if gitlab { "iid" } else { "number" })?, number: number(value, if gitlab { "iid" } else { "number" })?,
title: field(value, "title")?.to_owned(), title: field(value, "title")?.to_owned(),
description: match (base, head) { description: match (base, head) {
(Some(base), Some(head)) => format!("{author} · {state} · {head} → {base}"), (Some(base), Some(head)) => format!("{author} · {state} · {size} · {head} → {base}"),
_ => format!("{author} · {state}"), _ => format!("{author} · {state} · {size}"),
}, },
closed, closed,
created_at: created_at(value)?, draft,
approved: false,
review_requested: false,
created_at: timestamp(value, "created_at")?,
updated_at: timestamp(value, "updated_at")?,
}) })
} }
@@ -788,8 +1240,8 @@ pub(crate) fn page(
ssh_hostname(command, destination, port, cancelled) ssh_hostname(command, destination, port, cancelled)
})?; })?;
let token = forge.token(root, cancelled)?; let token = forge.token(root, cancelled)?;
forge.page_with(closed, page, |url| { forge.page_with(closed, page, |url, body| {
forge.get(url, token.as_deref(), root, cancelled) forge.request(url, body, token.as_deref(), root, cancelled)
}) })
} }
@@ -807,7 +1259,7 @@ pub(crate) fn resolve(
})?; })?;
let token = forge.token(root, cancelled)?; let token = forge.token(root, cancelled)?;
forge.resolve_with(number, |url| { forge.resolve_with(number, |url| {
forge.get(url, token.as_deref(), root, cancelled) forge.request(url, None, token.as_deref(), root, cancelled)
}) })
} }
+3
View File
@@ -2,6 +2,7 @@ mod battery;
mod blame; mod blame;
pub mod chrome; pub mod chrome;
pub mod clipboard; pub mod clipboard;
pub(crate) mod cursor;
pub mod diff; pub mod diff;
pub mod editor; pub mod editor;
pub mod files; pub mod files;
@@ -12,6 +13,8 @@ mod lsp_config;
mod markdown; mod markdown;
pub mod panes; pub mod panes;
pub mod plugin; pub mod plugin;
mod pull_request_preferences;
mod pull_requests;
pub mod repository; pub mod repository;
pub mod resolve; pub mod resolve;
pub mod review; pub mod review;
+1
View File
@@ -14,6 +14,7 @@ pub fn resolve(value: Value) -> Result<Vec<ServerConfig>, String> {
crate::syntax::RUST_ID => Some((&[&["rust-analyzer"]], "rs")), crate::syntax::RUST_ID => Some((&[&["rust-analyzer"]], "rs")),
crate::syntax::PYTHON_ID => Some((&[&["ty", "server"], &["ruff", "server"]], "py")), crate::syntax::PYTHON_ID => Some((&[&["ty", "server"], &["ruff", "server"]], "py")),
crate::syntax::RUBY_ID => Some((&[&["solargraph", "stdio"]], "rb")), crate::syntax::RUBY_ID => Some((&[&["solargraph", "stdio"]], "rb")),
crate::syntax::TYPST_ID => Some((&[&["tinymist", "lsp"]], "typ")),
_ => None, _ => None,
}; };
let mut options = match value { let mut options = match value {
+19 -9
View File
@@ -13,8 +13,9 @@ Usage: vamp [--config PATH | --no-config] [FILE]
vamp [--config PATH | --no-config] --review list [--repo PATH] [--json] vamp [--config PATH | --no-config] --review list [--repo PATH] [--json]
vamp [--config PATH | --no-config] --review show ID [--repo PATH] [--json] [--all] vamp [--config PATH | --no-config] --review show ID [--repo PATH] [--json] [--all]
vamp [--config PATH | --no-config] --review delete REVIEW_ID COMMENT_ID [--repo PATH] [--json] vamp [--config PATH | --no-config] --review delete REVIEW_ID COMMENT_ID [--repo PATH] [--json]
vamp [--config PATH | --no-config] --review resolve REVIEW_ID COMMENT_ID [--repo PATH] [--json]
Review CLI: list/show are read-only; delete commits one comment deletion immediately. Review CLI: list/show are read-only; delete/resolve commit one comment change immediately.
Show defaults to unresolved comments; --all includes resolved. Show defaults to unresolved comments; --all includes resolved.
Use vamp -- --review to edit a file named --review. Use vamp -- --review to edit a file named --review.
@@ -84,7 +85,7 @@ Restart: :restart closes clean buffers; unsaved buffers remain open and block re
Tabs: :tab.new, :tab.previous, :tab.next, :tab.close, :tab.force_close Tabs: :tab.new, :tab.previous, :tab.next, :tab.close, :tab.force_close
Tabs retain pane layouts and independent views; close protects exclusively displayed unsaved edits Tabs retain pane layouts and independent views; close protects exclusively displayed unsaved edits
Markdown links: :follow_link (primary caret; local files only) Markdown links: :follow_link (primary caret; local files only)
Diff: :diff (Normal); choose Before then After; Working checkout After edits live unsaved buffers Diff: :diff (Normal); floating revision/bookmark lists; choose Before then After; Before marked inline
Before and historical/remote After stay read-only; Tab/Shift+Tab categories/Normal focus Before and historical/remote After stay read-only; Tab/Shift+Tab categories/Normal focus
All text panes use native motions, selections and copy; read-only panes reject edits/saves All text panes use native motions, selections and copy; read-only panes reject edits/saves
Switching Before/After preserves the aligned cursor row and display column Switching Before/After preserves the aligned cursor row and display column
@@ -92,21 +93,29 @@ Diff: :diff (Normal); choose Before then After; Working checkout After edits liv
Normal [/] explicitly expands context; Insert brackets remain literal text Normal [/] explicitly expands context; Insert brackets remain literal text
Normal Space v cycles split/unified; Space s flips left/right vs above/below split Normal Space v cycles split/unified; Space s flips left/right vs above/below split
Defaults: config.diff_view_mode = \"split\"; config.diff_split_orientation = \"vertical\" Defaults: config.diff_view_mode = \"split\"; config.diff_split_orientation = \"vertical\"
Working After follows descendant checkouts; config.diff_follow_working_copy = false disables it Follow checkout After edits live buffers and follows descendants; config.diff_follow_working_copy = false disables following
Esc closes Before/After selectors; :diff.close exits an opened comparison explicitly Esc closes Before/After selectors; :diff.close exits an opened comparison explicitly
Remote refs/history load into temporary comparison repos without changing active refs/checkout Remote refs/history load into temporary comparison repos without changing active refs/checkout
Changed files: normal picker/explorer bindings, Ctrl+w close; A/M/D/R status and rename paths Changed files: normal picker/explorer bindings, Ctrl+w close; A/M/D/R status and rename paths
Local reviews: :diff.comment anchors exact Visual text, Visual Line rows, or the current line Local reviews: :comment anchors exact Visual text, Visual Line rows, or the current line
Works in ordinary repository source buffers and diff text panes
Different resolved Before/After pairs select separate reviews; reopening a pair resumes its review
Working refreshes retain the active review; ordinary source reviews stay separate
Selected comments highlight their precise text Selected comments highlight their precise text
:diff.review.edit/delete [ID], :diff.review.next/previous, :diff.review.overview :review.edit/delete [ID], :review.next/previous, :review.overview
:diff.review.summary; :diff.review.verdict looks_good|changes_requested|none :review.summary; :review.verdict looks_good|changes_requested|none
:diff.review.copy copies all saved comments in CLI format using the configured clipboard :review.copy copies all saved comments in CLI format using the configured clipboard
:w saves comment/summary text, including hidden drafts; verdicts/deletions commit immediately :w saves comment/summary text, including hidden drafts; verdicts/deletions commit immediately
:diff.review.save PATH exports JSON; :diff.review.open [ID|PATH] selects/imports; :diff.review.new :review.save PATH exports JSON; :review.open [ID|PATH] selects/imports; :review.new
Normal Esc or :pane.close discards unsaved text and dismisses the floating editor Normal Esc or :pane.close discards unsaved text and dismisses the floating editor
Snapshot anchors stay immutable; stale comments lose gutter markers; no publishing Snapshot anchors stay immutable; stale comments lose gutter markers; no publishing
Pull requests: :pull_requests [REMOTE]; GitHub/GitLab/Gitea Open/Closed/All tabs, type to search Pull requests: :pull_requests [REMOTE]; GitHub/GitLab/Gitea Open/Closed/Drafts/All tabs, type to search
Enter opens the immutable PR head against its merge base; API auth uses provider tokens or gh/glab Enter opens the immutable PR head against its merge base; API auth uses provider tokens or gh/glab
🙏 marks a personal review request; 👍 marks your active approval (API account)
Ctrl+s sort menu: 1-4 precedence, Backspace clear, Left/Right date direction
Ctrl+f filter menu: Space includes/excludes personal review states; Enter applies, Esc cancels
Sorting persists; filters last for this session; config.pull_request_sort / config.pull_request_filters set startup choices
Symbols: config.pull_request_review_requested_symbol / config.pull_request_approved_symbol
Resolve jj conflicts: :resolve opens the current working-copy conflicts in a dedicated workspace Resolve jj conflicts: :resolve opens the current working-copy conflicts in a dedicated workspace
Editable marker-free Draft vs readonly Alternative; :resolve.history shows inputs/base Editable marker-free Draft vs readonly Alternative; :resolve.history shows inputs/base
config.resolve_history_layout = \"columns\" (left/base/right) or \"base_below\" (left/right above base) config.resolve_history_layout = \"columns\" (left/base/right) or \"base_below\" (left/right above base)
@@ -120,6 +129,7 @@ Set VAMP_RUBY to choose the Ruby executable.
Native LSP is disabled by default: config.lsp[\"rust\"] = true enables a preset Native LSP is disabled by default: config.lsp[\"rust\"] = true enables a preset
Presets: rust -> rust-analyzer, python -> ty server + ruff server, ruby -> solargraph stdio Presets: rust -> rust-analyzer, python -> ty server + ruff server, ruby -> solargraph stdio
typst -> tinymist lsp
Custom languages: config.lsp[\"my-language\"] = { command: [...], extensions: [...] } Custom languages: config.lsp[\"my-language\"] = { command: [...], extensions: [...] }
Server stacks: config.lsp[\"python\"] = { servers: [{ command: [...] }, { command: [...] }] } Server stacks: config.lsp[\"python\"] = { servers: [{ command: [...] }, { command: [...] }] }
LSP commands: :lsp.definition, :lsp.diagnostics, :lsp.hover LSP commands: :lsp.definition, :lsp.diagnostics, :lsp.hover
+168
View File
@@ -0,0 +1,168 @@
use crate::pull_requests::{Preferences, SortSettings};
use serde::{Deserialize, Serialize};
use std::{
ffi::OsStr,
fs::{self, OpenOptions},
io::{self, Write},
path::{Path, PathBuf},
sync::atomic::{AtomicU64, Ordering},
};
static NEXT_TEMP: AtomicU64 = AtomicU64::new(1);
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct StoredPreferences<T> {
version: u8,
preferences: T,
}
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct StoredSort<T> {
#[serde(default)]
sort: T,
// Previously saved filters are deliberately ignored, including invalid values.
#[serde(default, rename = "filters", skip_serializing)]
_filters: serde::de::IgnoredAny,
}
pub(crate) fn default_path() -> Result<PathBuf, String> {
path_from(
std::env::var_os("XDG_STATE_HOME").as_deref(),
std::env::var_os("HOME").as_deref(),
)
}
fn path_from(xdg: Option<&OsStr>, home: Option<&OsStr>) -> Result<PathBuf, String> {
if let Some(path) = xdg.map(Path::new).filter(|path| path.is_absolute()) {
return Ok(path.join("vamp/pull_requests.json"));
}
home.map(Path::new)
.filter(|path| path.is_absolute())
.map(|path| path.join(".local/state/vamp/pull_requests.json"))
.ok_or_else(|| {
"Cannot locate pull request preferences: HOME must be an absolute directory".into()
})
}
fn read_preferences(path: &Path) -> Result<Option<Preferences>, String> {
match fs::symlink_metadata(path) {
Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(None),
Err(error) => return Err(error.to_string()),
Ok(metadata) if !metadata.is_file() => {
return Err("preferences must be a regular file (not a symlink)".into());
}
Ok(_) => {}
}
let bytes = fs::read(path).map_err(|error| error.to_string())?;
let stored: StoredPreferences<StoredSort<SortSettings>> =
serde_json::from_slice(&bytes).map_err(|error| error.to_string())?;
if stored.version != 1 {
return Err(format!(
"unsupported preferences version {}",
stored.version
));
}
let preferences = Preferences {
sort: stored.preferences.sort,
..Preferences::default()
};
preferences.validate()?;
Ok(Some(preferences))
}
pub(crate) struct Store {
path: Option<PathBuf>,
blocked: Option<String>,
}
impl Store {
pub(crate) fn load(path: Result<PathBuf, String>) -> (Self, Preferences, Option<String>) {
let result = match &path {
Ok(path) => read_preferences(path),
Err(error) => Err(error.clone()),
};
let (preferences, blocked) = match result {
Ok(preferences) => (preferences.unwrap_or_default(), None),
Err(error) => (Preferences::default(), Some(error)),
};
let store = Self {
path: path.ok(),
blocked,
};
let notice = store.blocked.as_ref().map(|error| store.notice(error));
(store, preferences, notice)
}
pub(crate) fn disabled() -> Self {
Self {
path: None,
blocked: None,
}
}
fn notice(&self, error: &str) -> String {
let location = self.path.as_ref().map_or_else(
|| "Pull request preferences".to_owned(),
|path| format!("Pull request preferences ({})", path.display()),
);
format!("{location}: {error}. Changes are session-only; existing data was preserved.")
}
pub(crate) fn save(&self, preferences: &Preferences) -> Result<(), String> {
self.save_inner(preferences)
.map_err(|error| self.notice(&error))
}
fn save_inner(&self, preferences: &Preferences) -> Result<(), String> {
if let Some(error) = &self.blocked {
return Err(error.clone());
}
preferences.validate()?;
let Some(path) = &self.path else {
return Ok(());
};
// Refuse to overwrite data that became corrupt or incompatible after startup.
read_preferences(path)?;
let bytes = serde_json::to_vec_pretty(&StoredPreferences {
version: 1,
preferences: StoredSort {
sort: &preferences.sort,
_filters: serde::de::IgnoredAny,
},
})
.map_err(|error| error.to_string())?;
let parent = path.parent().ok_or("preferences path has no parent")?;
fs::create_dir_all(parent).map_err(|error| error.to_string())?;
let (temporary, mut file) = loop {
let id = NEXT_TEMP.fetch_add(1, Ordering::Relaxed);
let temporary = parent.join(format!(".pull-requests-{}-{id}.tmp", std::process::id()));
let mut options = OpenOptions::new();
options.write(true).create_new(true);
#[cfg(unix)]
{
use std::os::unix::fs::OpenOptionsExt;
options.mode(0o600);
}
match options.open(&temporary) {
Ok(file) => break (temporary, file),
Err(error) if error.kind() == io::ErrorKind::AlreadyExists => continue,
Err(error) => return Err(error.to_string()),
}
};
let result = (|| {
file.write_all(&bytes).and_then(|_| file.sync_all())?;
drop(file);
read_preferences(path).map_err(io::Error::other)?;
// ponytail: optimistic validation; OS compare-and-swap if concurrent writers matter.
fs::rename(&temporary, path)
})();
let _ = fs::remove_file(temporary);
result.map_err(|error| error.to_string())
}
}
#[cfg(test)]
#[path = "../tests/unit/pull_request_preferences.rs"]
mod tests;
+144
View File
@@ -0,0 +1,144 @@
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub(crate) struct Preferences {
pub sort: SortSettings,
pub filters: Vec<ReviewFilter>,
}
impl Default for Preferences {
fn default() -> Self {
Self {
sort: BTreeMap::new(),
filters: ReviewFilter::ALL.to_vec(),
}
}
}
pub(crate) type SortSettings = BTreeMap<SortField, SortRule>;
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum SortField {
Requested,
UpdatedAt,
Approved,
CreatedAt,
}
impl SortField {
pub const ALL: [Self; 4] = [
Self::Requested,
Self::UpdatedAt,
Self::Approved,
Self::CreatedAt,
];
pub fn label(self) -> &'static str {
match self {
Self::Requested => "Requested from me",
Self::UpdatedAt => "Updated at",
Self::Approved => "Approved by me",
Self::CreatedAt => "Created at",
}
}
pub fn is_date(self) -> bool {
matches!(self, Self::UpdatedAt | Self::CreatedAt)
}
}
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub(crate) struct SortRule {
pub precedence: Option<u8>,
pub direction: Direction,
}
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum Direction {
Asc,
#[default]
Desc,
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum ReviewFilter {
Requested,
Approved,
Other,
}
impl ReviewFilter {
pub const ALL: [Self; 3] = [Self::Requested, Self::Approved, Self::Other];
pub fn label(self) -> &'static str {
match self {
Self::Requested => "Requested from me",
Self::Approved => "Approved by me",
Self::Other => "Other / unavailable",
}
}
}
impl Preferences {
pub fn validate(&self) -> Result<(), String> {
let mut ranks = [false; 4];
for rule in self.sort.values() {
if let Some(rank) = rule.precedence {
if !(1..=4).contains(&rank) {
return Err("Sort precedence must be between 1 and 4".into());
}
if std::mem::replace(&mut ranks[usize::from(rank - 1)], true) {
return Err("Sort precedence must be unique".into());
}
}
}
for (index, filter) in self.filters.iter().enumerate() {
if self.filters[..index].contains(filter) {
return Err("Review filters must be unique".into());
}
}
Ok(())
}
pub fn ordered_fields(&self) -> [SortField; 4] {
let mut slots = [None; 4];
for (&field, rule) in &self.sort {
if let Some(rank) = rule.precedence {
slots[usize::from(rank - 1)] = Some(field);
}
}
let mut unranked = SortField::ALL.into_iter().filter(|field| {
self.sort
.get(field)
.is_none_or(|rule| rule.precedence.is_none())
});
slots.map(|field| field.unwrap_or_else(|| unranked.next().expect("four sort fields")))
}
pub fn set_rank(&mut self, field: SortField, rank: Option<u8>) {
self.sort.entry(field).or_default().precedence = None;
let Some(mut rank) = rank else {
return;
};
let mut field = field;
loop {
let displaced = self
.sort
.iter()
.find_map(|(&other, rule)| (rule.precedence == Some(rank)).then_some(other));
self.sort.entry(field).or_default().precedence = Some(rank);
let Some(other) = displaced else {
break;
};
self.sort.get_mut(&other).expect("ranked field").precedence = None;
field = other;
rank = rank % 4 + 1;
}
}
}
+134 -13
View File
@@ -1,7 +1,8 @@
//! Read-only active-repository discovery and isolated revision comparison. //! Read-only active-repository discovery and isolated revision comparison.
use crate::diff::{ use crate::diff::{
BlameRevision, Catalog, Category, ChangedFile, Comparison, ComparisonMode, FileStatus, BlameRevision, Catalog, Category, ChangedFile, Comparison, ComparisonMode, FileStatus,
PullRequestPage, RepoKind, Revision, RevisionTarget, line_hunks, PullRequestMetadata, PullRequestPage, RepoKind, Revision, RevisionGraph, RevisionTarget,
line_hunks,
}; };
use std::{ use std::{
collections::{BTreeMap, BTreeSet}, collections::{BTreeMap, BTreeSet},
@@ -1093,6 +1094,24 @@ pub fn discover_root(path: &Path) -> Result<PathBuf, String> {
discover_root_with_cancellation(path, &AtomicBool::new(false)) discover_root_with_cancellation(path, &AtomicBool::new(false))
} }
/// Identify the exact source bytes without writing objects or snapshotting the checkout.
pub(crate) fn source_snapshot_revision(root: &Path, content: &str) -> Result<String, String> {
let mut command = if root.join(".jj").exists() {
git_command(&store_for_jj(root)?)
} else {
let mut command = Command::new("git");
command.arg("-C").arg(root);
command
};
command.args(["hash-object", "--no-filters", "--stdin"]);
let id = text(checked(run(
command,
content.as_bytes().to_vec(),
&AtomicBool::new(false),
)?)?)?;
Ok(format!("working:{}", id.trim()))
}
fn discover_root_with_cancellation(path: &Path, cancelled: &AtomicBool) -> Result<PathBuf, String> { fn discover_root_with_cancellation(path: &Path, cancelled: &AtomicBool) -> Result<PathBuf, String> {
let path = fs::canonicalize(path).map_err(|error| error.to_string())?; let path = fs::canonicalize(path).map_err(|error| error.to_string())?;
let root = path let root = path
@@ -1162,10 +1181,25 @@ impl Repository {
root: &Path, root: &Path,
store: &Path, store: &Path,
entries: &mut Vec<Revision>, entries: &mut Vec<Revision>,
graph: &mut BTreeMap<String, RevisionGraph>,
notices: &mut Vec<String>, notices: &mut Vec<String>,
) -> Result<(), String> { ) -> Result<(), String> {
if self.kind == RepoKind::Jujutsu { if self.kind == RepoKind::Jujutsu {
let template = r#""[" ++ json(commit_id) ++ "," ++ json(change_id) ++ "," ++ json(description) ++ "," ++ json(local_bookmarks.map(|b| b.name())) ++ "," ++ json(remote_bookmarks.map(|b| b.name())) ++ "," ++ json(remote_bookmarks.map(|b| b.remote())) ++ "]\n""#; #[derive(serde::Deserialize)]
struct JjRevision(
String,
String,
String,
Vec<String>,
Vec<String>,
Vec<String>,
Vec<String>,
String,
String,
bool,
bool,
);
let template = r#""[" ++ json(commit_id) ++ "," ++ json(change_id) ++ "," ++ json(description) ++ "," ++ json(local_bookmarks.map(|b| b.name())) ++ "," ++ json(remote_bookmarks.map(|b| b.name())) ++ "," ++ json(remote_bookmarks.map(|b| b.remote())) ++ "," ++ json(parents.map(|p| p.commit_id())) ++ "," ++ json(author.name()) ++ "," ++ json(author.timestamp().format("%Y-%m-%d %H:%M")) ++ "," ++ json(current_working_copy) ++ "," ++ json(immutable) ++ "]\n""#;
let revset = if root == self.root { let revset = if root == self.root {
"all()" "all()"
} else { } else {
@@ -1174,15 +1208,40 @@ impl Repository {
let output = let output =
text(self.jj(root, &["log", "--no-graph", "-r", revset, "-T", template])?)?; text(self.jj(root, &["log", "--no-graph", "-r", revset, "-T", template])?)?;
for line in output.lines() { for line in output.lines() {
let (id, change, description, bookmarks, remote_names, remotes): ( let JjRevision(
String, id,
String, change,
String, description,
Vec<String>, bookmarks,
Vec<String>, remote_names,
Vec<String>, remotes,
parents,
author,
timestamp,
current,
immutable,
) = serde_json::from_str(line) ) = serde_json::from_str(line)
.map_err(|e| format!("Cannot decode Jujutsu revision: {e}"))?; .map_err(|e| format!("Cannot decode Jujutsu revision: {e}"))?;
graph.entry(id.clone()).or_insert_with(|| RevisionGraph {
change_id: change.clone(),
description: description.trim_end_matches('\n').into(),
parents,
author,
timestamp,
bookmarks: bookmarks
.iter()
.cloned()
.chain(
remote_names
.iter()
.zip(&remotes)
.map(|(name, remote)| format!("{name}@{remote}")),
)
.collect::<Vec<_>>()
.join(" "),
current: current && root == self.root,
immutable,
});
let target = RevisionTarget::Commit(id.clone()); let target = RevisionTarget::Commit(id.clone());
entries.push(Revision { entries.push(Revision {
target: target.clone(), target: target.clone(),
@@ -1352,15 +1411,69 @@ impl Repository {
}; };
let mut entries = vec![Revision { let mut entries = vec![Revision {
target: RevisionTarget::Working, target: RevisionTarget::Working,
label: "Working checkout".into(), label: "Checkout snapshot".into(),
description: description:
"On-disk tracked and eligible untracked files; unsaved buffers are excluded".into(), "On-disk tracked and eligible untracked files; unsaved buffers are excluded".into(),
category, category,
}]; }];
let mut notices = vec![]; let mut notices = vec![];
self.revisions(&self.root, &self.store, &mut entries, &mut notices)?; let mut graph = BTreeMap::new();
self.revisions(
&self.root,
&self.store,
&mut entries,
&mut graph,
&mut notices,
)?;
if let Some((root, store)) = &self.private { if let Some((root, store)) = &self.private {
self.revisions(root, store, &mut entries, &mut notices)?; self.revisions(root, store, &mut entries, &mut graph, &mut notices)?;
}
if self.kind == RepoKind::Jujutsu && self.private.is_some() {
let order: BTreeMap<_, _> = entries
.iter()
.enumerate()
.filter_map(|(index, entry)| match &entry.target {
RevisionTarget::Commit(id) => Some((id.as_str(), index)),
_ => None,
})
.collect();
let mut children: BTreeMap<_, usize> =
graph.keys().map(|id| (id.as_str(), 0)).collect();
for node in graph.values() {
for parent in &node.parents {
if let Some(count) = children.get_mut(parent.as_str()) {
*count += 1;
}
}
}
let mut ready: BTreeSet<_> = children
.iter()
.filter(|(_, count)| **count == 0)
.map(|(&id, _)| (order[id], id))
.collect();
let mut ranks = BTreeMap::new();
while let Some((_, id)) = ready.pop_first() {
ranks.insert(id, ranks.len() + 1);
for parent in &graph[id].parents {
if let Some(count) = children.get_mut(parent.as_str()) {
*count -= 1;
if *count == 0 {
ready.insert((order[parent.as_str()], parent.as_str()));
}
}
}
}
entries.sort_by_key(|entry| match &entry.target {
RevisionTarget::Working => 0,
RevisionTarget::Commit(id) => ranks.get(id.as_str()).copied().unwrap_or(usize::MAX),
RevisionTarget::Bookmark { .. } => entry
.description
.split_whitespace()
.nth(1)
.and_then(|id| ranks.get(id).copied())
.unwrap_or(usize::MAX),
_ => usize::MAX,
});
} }
for remote in &self.remotes { for remote in &self.remotes {
for &view in self.kind.categories() { for &view in self.kind.categories() {
@@ -1421,6 +1534,7 @@ impl Repository {
Ok(Catalog { Ok(Catalog {
kind: self.kind, kind: self.kind,
entries, entries,
graph,
notice: if notices.is_empty() { notice: if notices.is_empty() {
None None
} else { } else {
@@ -1635,11 +1749,18 @@ impl Repository {
description: pull.description, description: pull.description,
category: if pull.closed { category: if pull.closed {
Category::Closed Category::Closed
} else if pull.draft {
Category::Drafts
} else { } else {
Category::Open Category::Open
}, },
}, },
pull.created_at, PullRequestMetadata {
created_at: pull.created_at,
updated_at: pull.updated_at,
requested: pull.review_requested,
approved: pull.approved,
},
) )
}) })
.collect(), .collect(),
+88 -20
View File
@@ -43,7 +43,7 @@ pub enum Verdict {
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct Anchor { pub struct Anchor {
/// Frozen comparison context; `content` additionally captures any live buffer edits. /// Frozen repository context; source comments use the exact buffer's Git blob identity.
pub revision: String, pub revision: String,
pub path: PathBuf, pub path: PathBuf,
pub side: Side, pub side: Side,
@@ -195,6 +195,8 @@ pub struct ReviewedFile {
pub struct Review { pub struct Review {
pub version: u32, pub version: u32,
pub root: PathBuf, pub root: PathBuf,
/// Ordered frozen comparison endpoints; `None` is a source review.
pub comparison: Option<[String; 2]>,
pub summary: String, pub summary: String,
pub verdict: Option<Verdict>, pub verdict: Option<Verdict>,
pub comments: Vec<Comment>, pub comments: Vec<Comment>,
@@ -231,8 +233,9 @@ impl Review {
fs::canonicalize(&root).unwrap_or(root) fs::canonicalize(&root).unwrap_or(root)
}; };
Self { Self {
version: 4, version: 5,
root, root,
comparison: None,
summary: String::new(), summary: String::new(),
verdict: None, verdict: None,
comments: Vec::new(), comments: Vec::new(),
@@ -249,12 +252,20 @@ impl Review {
.iter() .iter()
.filter(|comment| comment.resolved) .filter(|comment| comment.resolved)
.count(); .count();
let (scope, before, arrow, after) = match &self.comparison {
Some([before, after]) => ("comparison ", before.as_str(), " → ", after.as_str()),
None => ("source", "", "", ""),
};
format!( format!(
"Review ID: {}{}{}\n Verdict: {}; {} unresolved, {} resolved ({} total)\n", "Review ID: {}{}{}\n Scope: {}{}{}{}\n Verdict: {}; {} unresolved, {} resolved ({} total)\n",
self.storage_id self.storage_id
.map_or_else(|| "null".into(), |id| id.to_string()), .map_or_else(|| "null".into(), |id| id.to_string()),
if self.summary.is_empty() { "" } else { ": " }, if self.summary.is_empty() { "" } else { ": " },
self.summary, self.summary,
scope,
before,
arrow,
after,
match self.verdict { match self.verdict {
Some(Verdict::LooksGood) => "looks_good", Some(Verdict::LooksGood) => "looks_good",
Some(Verdict::ChangesRequested) => "changes_requested", Some(Verdict::ChangesRequested) => "changes_requested",
@@ -279,9 +290,24 @@ impl Review {
.filter(|comment| all || !comment.resolved) .filter(|comment| all || !comment.resolved)
{ {
let anchor = &comment.anchor; let anchor = &comment.anchor;
let excerpt = anchor.excerpt();
let language =
match crate::syntax::language_id(Some(&anchor.path), anchor.content.lines().next())
{
Some("honey") => "hon",
language => language.unwrap_or(""),
};
let fence_width = 3.max(
excerpt
.split(|ch| ch != '`')
.map(str::len)
.max()
.unwrap_or(0)
+ 1,
);
writeln!( writeln!(
text, text,
"\nComment {} [{}] {} ({}) {}:{}–{}:{} @ {}\n{}\n{}", "\nComment {} [{}] {} ({}) {}:{}–{}:{} @ {}",
comment.id, comment.id,
if comment.resolved { if comment.resolved {
"resolved" "resolved"
@@ -298,21 +324,31 @@ impl Review {
anchor.end.row, anchor.end.row,
anchor.end.column, anchor.end.column,
anchor.revision, anchor.revision,
anchor.excerpt(),
comment.body,
) )
.unwrap(); .unwrap();
write!(text, "{:`<fence_width$}{language}\n{excerpt}", "").unwrap();
if !excerpt.ends_with('\n') {
text.push('\n');
}
writeln!(text, "{:`<fence_width$}\n{}", "", comment.body).unwrap();
} }
text text
} }
fn validate(&self) -> Result<(), String> { fn validate(&self) -> Result<(), String> {
if self.version != 4 { if self.version != 5 {
return Err(format!("Unsupported review version {}", self.version)); return Err(format!("Unsupported review version {}", self.version));
} }
if !self.root.is_absolute() || !self.root.is_dir() { if !self.root.is_absolute() || !self.root.is_dir() {
return Err("Review repository root must be an existing absolute directory".into()); return Err("Review repository root must be an existing absolute directory".into());
} }
if let Some(revisions) = &self.comparison
&& revisions
.iter()
.any(|revision| revision.is_empty() || revision.chars().any(char::is_control))
{
return Err("Review comparison endpoints require immutable revision identities".into());
}
let mut ids = BTreeSet::new(); let mut ids = BTreeSet::new();
for comment in &self.comments { for comment in &self.comments {
if comment.id == 0 || !ids.insert(comment.id) { if comment.id == 0 || !ids.insert(comment.id) {
@@ -374,7 +410,7 @@ impl Review {
} }
let header: Header = serde_json::from_slice(bytes) let header: Header = serde_json::from_slice(bytes)
.map_err(|error| format!("Invalid review JSON: {error}"))?; .map_err(|error| format!("Invalid review JSON: {error}"))?;
if header.version != 4 { if header.version != 5 {
return Err(format!("Unsupported review version {}", header.version)); return Err(format!("Unsupported review version {}", header.version));
} }
serde_json::from_slice(bytes).map_err(|error| format!("Invalid review JSON: {error}")) serde_json::from_slice(bytes).map_err(|error| format!("Invalid review JSON: {error}"))
@@ -477,7 +513,14 @@ const REVIEWS_SCHEMA: &str = "CREATE TABLE reviews (
root TEXT NOT NULL, root TEXT NOT NULL,
revision INTEGER NOT NULL CHECK (revision > 0), revision INTEGER NOT NULL CHECK (revision > 0),
summary TEXT NOT NULL, summary TEXT NOT NULL,
verdict TEXT CHECK (verdict IN ('looks_good', 'changes_requested')) verdict TEXT CHECK (verdict IN ('looks_good', 'changes_requested')),
before_revision TEXT,
after_revision TEXT,
CHECK (
(before_revision IS NULL AND after_revision IS NULL)
OR (before_revision IS NOT NULL AND after_revision IS NOT NULL
AND length(before_revision) > 0 AND length(after_revision) > 0)
)
) STRICT"; ) STRICT";
// SQLite integers are signed; decimal text preserves the model's full u64 comment IDs. // SQLite integers are signed; decimal text preserves the model's full u64 comment IDs.
@@ -560,7 +603,7 @@ impl Store {
.map_err(database_error)? .map_err(database_error)?
.collect::<Result<_, _>>() .collect::<Result<_, _>>()
.map_err(database_error)?; .map_err(database_error)?;
if version != 3 || schema != [COMMENTS_SCHEMA, REVIEWED_FILES_SCHEMA, REVIEWS_SCHEMA] { if version != 4 || schema != [COMMENTS_SCHEMA, REVIEWED_FILES_SCHEMA, REVIEWS_SCHEMA] {
return Err(format!( return Err(format!(
"Unsupported review database schema (version {version}); existing data was not changed" "Unsupported review database schema (version {version}); existing data was not changed"
)); ));
@@ -628,7 +671,7 @@ impl Store {
.execute_batch(REVIEWED_FILES_SCHEMA) .execute_batch(REVIEWED_FILES_SCHEMA)
.map_err(database_error)?; .map_err(database_error)?;
transaction transaction
.pragma_update(None, "user_version", 3) .pragma_update(None, "user_version", 4)
.map_err(database_error)?; .map_err(database_error)?;
transaction.commit().map_err(database_error)?; transaction.commit().map_err(database_error)?;
} else { } else {
@@ -655,7 +698,7 @@ impl Store {
let reviews = { let reviews = {
let mut statement = transaction let mut statement = transaction
.prepare( .prepare(
"SELECT id, root, revision, summary, verdict FROM reviews WHERE root = ?1 ORDER BY id DESC", "SELECT id, root, revision, summary, verdict, before_revision, after_revision FROM reviews WHERE root = ?1 ORDER BY id DESC",
) )
.map_err(database_error)?; .map_err(database_error)?;
let mut rows = statement.query([root_text]).map_err(database_error)?; let mut rows = statement.query([root_text]).map_err(database_error)?;
@@ -680,7 +723,7 @@ impl Store {
.map_err(database_error)?; .map_err(database_error)?;
let review = { let review = {
let mut statement = transaction let mut statement = transaction
.prepare("SELECT id, root, revision, summary, verdict FROM reviews WHERE id = ?1 AND root = ?2") .prepare("SELECT id, root, revision, summary, verdict, before_revision, after_revision FROM reviews WHERE id = ?1 AND root = ?2")
.map_err(database_error)?; .map_err(database_error)?;
let mut rows = statement let mut rows = statement
.query(params![id, root_text]) .query(params![id, root_text])
@@ -716,6 +759,9 @@ impl Store {
_ => return Err("Invalid review storage identity".into()), _ => return Err("Invalid review storage identity".into()),
}; };
let mut size = review.root.as_os_str().len() + review.summary.len(); let mut size = review.root.as_os_str().len() + review.summary.len();
if let Some(revisions) = &review.comparison {
size += revisions[0].len() + revisions[1].len();
}
for comment in &review.comments { for comment in &review.comments {
size = size size = size
.checked_add( .checked_add(
@@ -750,26 +796,34 @@ impl Store {
Some(Verdict::ChangesRequested) => Some("changes_requested"), Some(Verdict::ChangesRequested) => Some("changes_requested"),
None => None, None => None,
}; };
let before = review
.comparison
.as_ref()
.map(|revisions| revisions[0].as_str());
let after = review
.comparison
.as_ref()
.map(|revisions| revisions[1].as_str());
let transaction = self let transaction = self
.connection .connection
.transaction_with_behavior(TransactionBehavior::Immediate) .transaction_with_behavior(TransactionBehavior::Immediate)
.map_err(database_error)?; .map_err(database_error)?;
let id = if let Some(id) = review.storage_id { let id = if let Some(id) = review.storage_id {
let changed = transaction.execute( let changed = transaction.execute(
"UPDATE reviews SET revision = ?1, summary = ?2, verdict = ?3 WHERE id = ?4 AND root = ?5 AND revision = ?6", "UPDATE reviews SET revision = ?1, summary = ?2, verdict = ?3 WHERE id = ?4 AND root = ?5 AND revision = ?6 AND before_revision IS ?7 AND after_revision IS ?8",
params![revision, review.summary, verdict, id, root, review.storage_revision], params![revision, review.summary, verdict, id, root, review.storage_revision, before, after],
).map_err(database_error)?; ).map_err(database_error)?;
if changed != 1 { if changed != 1 {
return Err( return Err(
"Review changed in another session; draft kept, reload before saving".into(), "Review changed in another session or comparison scope changed; draft kept, reload before saving".into(),
); );
} }
id id
} else { } else {
transaction transaction
.execute( .execute(
"INSERT INTO reviews (root, revision, summary, verdict) VALUES (?1, ?2, ?3, ?4)", "INSERT INTO reviews (root, revision, summary, verdict, before_revision, after_revision) VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
params![root, revision, review.summary, verdict], params![root, revision, review.summary, verdict, before, after],
) )
.map_err(database_error)?; .map_err(database_error)?;
transaction.last_insert_rowid() transaction.last_insert_rowid()
@@ -888,9 +942,15 @@ fn stored_review(
|row| row.get(0), |row| row.get(0),
) )
.map_err(database_error)?; .map_err(database_error)?;
if stored_bytes < 0 let mut header_bytes = stored_root.len() + summary.len();
|| stored_bytes as u64 + stored_root.len() as u64 + summary.len() as u64 > LIMIT as u64 for index in [5, 6] {
if let rusqlite::types::ValueRef::Text(bytes) =
row.get_ref(index).map_err(database_error)?
{ {
header_bytes += bytes.len();
}
}
if stored_bytes < 0 || stored_bytes as u64 + header_bytes as u64 > LIMIT as u64 {
return Err("Review exceeds the 64 MiB limit".into()); return Err("Review exceeds the 64 MiB limit".into());
} }
let mut review = Review { let mut review = Review {
@@ -898,6 +958,14 @@ fn stored_review(
..Review::default() ..Review::default()
}; };
review.summary = summary.to_owned(); review.summary = summary.to_owned();
review.comparison = match (
row.get::<_, Option<String>>(5).map_err(database_error)?,
row.get::<_, Option<String>>(6).map_err(database_error)?,
) {
(None, None) => None,
(Some(before), Some(after)) => Some([before, after]),
_ => return Err("Invalid stored review comparison endpoints".into()),
};
review.verdict = match row review.verdict = match row
.get::<_, Option<String>>(4) .get::<_, Option<String>>(4)
.map_err(database_error)? .map_err(database_error)?
+51 -16
View File
@@ -9,9 +9,14 @@ use vamp::{
ruby, ruby,
}; };
enum CommentAction {
Delete,
Resolve,
}
pub struct Request { pub struct Request {
id: Option<i64>, id: Option<i64>,
delete_comment: Option<u64>, comment: Option<(CommentAction, u64)>,
repo: Option<PathBuf>, repo: Option<PathBuf>,
json: bool, json: bool,
all: bool, all: bool,
@@ -19,15 +24,17 @@ pub struct Request {
impl Request { impl Request {
pub fn parse(args: &mut impl Iterator<Item = OsString>) -> Result<Self, String> { pub fn parse(args: &mut impl Iterator<Item = OsString>) -> Result<Self, String> {
let usage = "--review requires list, show ID, or delete REVIEW_ID COMMENT_ID"; let usage = "--review requires list, show ID, delete REVIEW_ID COMMENT_ID, or resolve REVIEW_ID COMMENT_ID";
let command = args.next().ok_or(usage)?; let command = args.next().ok_or(usage)?;
let id = if command == "list" { let id = if command == "list" {
None None
} else if command == "show" || command == "delete" { } else if command == "show" || command == "delete" || command == "resolve" {
let error = if command == "show" { let error = if command == "show" {
"`show` requires a positive review ID.\nUsage: vamp --review show ID [--all]\n`--all` includes resolved comments; it does not select all reviews." "`show` requires a positive review ID.\nUsage: vamp --review show ID [--all]\n`--all` includes resolved comments; it does not select all reviews."
} else { } else if command == "delete" {
"`delete` requires a positive review ID.\nUsage: vamp --review delete REVIEW_ID COMMENT_ID" "`delete` requires a positive review ID.\nUsage: vamp --review delete REVIEW_ID COMMENT_ID"
} else {
"`resolve` requires a positive review ID.\nUsage: vamp --review resolve REVIEW_ID COMMENT_ID"
}; };
let id = args.next().ok_or(error)?; let id = args.next().ok_or(error)?;
Some( Some(
@@ -39,21 +46,32 @@ impl Request {
} else { } else {
return Err(usage.into()); return Err(usage.into());
}; };
let delete_comment = if command == "delete" { let comment = if command == "delete" || command == "resolve" {
let error = "delete requires a positive comment ID"; let error = if command == "delete" {
"delete requires a positive comment ID"
} else {
"resolve requires a positive comment ID"
};
let id = args.next().ok_or(error)?; let id = args.next().ok_or(error)?;
Some( let id = id
id.to_str() .to_str()
.and_then(|id| id.parse::<u64>().ok()) .and_then(|id| id.parse::<u64>().ok())
.filter(|id| *id > 0) .filter(|id| *id > 0)
.ok_or(error)?, .ok_or(error)?;
) Some((
if command == "delete" {
CommentAction::Delete
} else {
CommentAction::Resolve
},
id,
))
} else { } else {
None None
}; };
Ok(Self { Ok(Self {
id, id,
delete_comment, comment,
repo: None, repo: None,
json: false, json: false,
all: false, all: false,
@@ -69,8 +87,7 @@ impl Request {
self.repo = Some(PathBuf::from(args.next().ok_or("--repo requires a path")?)); self.repo = Some(PathBuf::from(args.next().ok_or("--repo requires a path")?));
} else if arg == "--json" && !self.json { } else if arg == "--json" && !self.json {
self.json = true; self.json = true;
} else if arg == "--all" && self.id.is_some() && self.delete_comment.is_none() && !self.all } else if arg == "--all" && self.id.is_some() && self.comment.is_none() && !self.all {
{
self.all = true; self.all = true;
} else { } else {
return Err(format!( return Err(format!(
@@ -92,6 +109,7 @@ fn envelope(review: &Review, all: bool, comments: bool) -> Value {
"repository": review.root, "repository": review.root,
"id": review.storage_id, "id": review.storage_id,
"revision": review.storage_revision, "revision": review.storage_revision,
"comparison": review.comparison,
"summary": review.summary, "summary": review.summary,
"verdict": review.verdict, "verdict": review.verdict,
"counts": { "total": review.comments.len(), "resolved": resolved, "unresolved": review.comments.len() - resolved }, "counts": { "total": review.comments.len(), "resolved": resolved, "unresolved": review.comments.len() - resolved },
@@ -124,19 +142,36 @@ pub fn run(request: &Request, config: Option<&Path>) -> Result<(), String> {
root.display() root.display()
))? ))?
.load(&root, id)?; .load(&root, id)?;
if let Some(comment_id) = request.delete_comment { if let Some((action, comment_id)) = &request.comment {
let index = review let index = review
.comments .comments
.iter() .iter()
.position(|comment| comment.id == comment_id) .position(|comment| comment.id == *comment_id)
.ok_or_else(|| format!("Comment {comment_id} does not exist in review {id}"))?; .ok_or_else(|| format!("Comment {comment_id} does not exist in review {id}"))?;
let changed = match action {
CommentAction::Delete => {
review.comments.remove(index); review.comments.remove(index);
true
}
CommentAction::Resolve => {
let comment = &mut review.comments[index];
let changed = !comment.resolved;
comment.resolved = true;
changed
}
};
if changed {
Store::open(&directory)?.save(&mut review)?; Store::open(&directory)?.save(&mut review)?;
} }
}
vec![review] vec![review]
} else { } else {
match store { match store {
Some(store) => store.list(&root)?, Some(store) => store
.list(&root)?
.into_iter()
.filter(|review| !review.comments.is_empty())
.collect(),
None => Vec::new(), None => Vec::new(),
} }
}; };
+52
View File
@@ -1,6 +1,7 @@
use crate::chrome::{ChromeLine, PopupConfig}; use crate::chrome::{ChromeLine, PopupConfig};
use crate::editor::{Context, Effect, Feature}; use crate::editor::{Context, Effect, Feature};
use crate::plugin::{DocumentEvent, PluginEvent, PluginUpdate, UpdateEffect}; use crate::plugin::{DocumentEvent, PluginEvent, PluginUpdate, UpdateEffect};
use crate::pull_requests::{Preferences, ReviewFilter, SortSettings};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::io::{self, BufRead, BufReader, Write}; use std::io::{self, BufRead, BufReader, Write};
use std::num::{NonZeroU8, NonZeroUsize}; use std::num::{NonZeroU8, NonZeroUsize};
@@ -42,6 +43,7 @@ pub struct Config {
pub clipboard_mode: String, pub clipboard_mode: String,
pub git_blame: bool, pub git_blame: bool,
pub git_gutter: crate::gutter::GutterStyle, pub git_gutter: crate::gutter::GutterStyle,
pub(crate) cursor: crate::cursor::CursorConfig,
pub top_bar: ChromeLine, pub top_bar: ChromeLine,
pub bottom_bar: ChromeLine, pub bottom_bar: ChromeLine,
pub popup: PopupConfig, pub popup: PopupConfig,
@@ -58,6 +60,10 @@ pub struct Config {
pub diff_view_mode: crate::diff::ViewMode, pub diff_view_mode: crate::diff::ViewMode,
pub diff_split_orientation: crate::panes::SplitAxis, pub diff_split_orientation: crate::panes::SplitAxis,
pub diff_follow_working_copy: bool, pub diff_follow_working_copy: bool,
pub pull_request_review_requested_symbol: String,
pub pull_request_approved_symbol: String,
pub(crate) pull_request_sort: Option<SortSettings>,
pub(crate) pull_request_filters: Option<Vec<ReviewFilter>>,
pub resolve_history_layout: crate::editor::ResolverLayout, pub resolve_history_layout: crate::editor::ResolverLayout,
} }
@@ -96,6 +102,7 @@ impl Default for Config {
clipboard_mode: "system".into(), clipboard_mode: "system".into(),
git_blame: true, git_blame: true,
git_gutter: crate::gutter::GutterStyle::default(), git_gutter: crate::gutter::GutterStyle::default(),
cursor: crate::cursor::CursorConfig::default(),
top_bar: ChromeLine::top(), top_bar: ChromeLine::top(),
bottom_bar: ChromeLine::bottom(), bottom_bar: ChromeLine::bottom(),
popup: PopupConfig::default(), popup: PopupConfig::default(),
@@ -112,6 +119,10 @@ impl Default for Config {
diff_view_mode: crate::diff::ViewMode::Split, diff_view_mode: crate::diff::ViewMode::Split,
diff_split_orientation: crate::panes::SplitAxis::Vertical, diff_split_orientation: crate::panes::SplitAxis::Vertical,
diff_follow_working_copy: true, diff_follow_working_copy: true,
pull_request_review_requested_symbol: "🙏".into(),
pull_request_approved_symbol: "👍".into(),
pull_request_sort: None,
pull_request_filters: None,
resolve_history_layout: crate::editor::ResolverLayout::Columns, resolve_history_layout: crate::editor::ResolverLayout::Columns,
} }
} }
@@ -137,6 +148,7 @@ pub fn load_config(path: &Path) -> Result<Config, String> {
clipboard_mode, clipboard_mode,
git_blame, git_blame,
git_gutter, git_gutter,
cursor,
top_bar, top_bar,
bottom_bar, bottom_bar,
popup, popup,
@@ -153,6 +165,10 @@ pub fn load_config(path: &Path) -> Result<Config, String> {
diff_view_mode, diff_view_mode,
diff_split_orientation, diff_split_orientation,
diff_follow_working_copy, diff_follow_working_copy,
pull_request_review_requested_symbol,
pull_request_approved_symbol,
pull_request_sort,
pull_request_filters,
resolve_history_layout, resolve_history_layout,
.. ..
} = *response; } = *response;
@@ -179,6 +195,7 @@ pub fn load_config(path: &Path) -> Result<Config, String> {
config.clipboard_mode = clipboard_mode; config.clipboard_mode = clipboard_mode;
config.git_blame = git_blame; config.git_blame = git_blame;
config.git_gutter = git_gutter; config.git_gutter = git_gutter;
config.cursor = cursor;
config.top_bar = top_bar; config.top_bar = top_bar;
config.bottom_bar = bottom_bar; config.bottom_bar = bottom_bar;
config.popup = popup; config.popup = popup;
@@ -195,6 +212,19 @@ pub fn load_config(path: &Path) -> Result<Config, String> {
config.diff_view_mode = diff_view_mode; config.diff_view_mode = diff_view_mode;
config.diff_split_orientation = diff_split_orientation; config.diff_split_orientation = diff_split_orientation;
config.diff_follow_working_copy = diff_follow_working_copy; config.diff_follow_working_copy = diff_follow_working_copy;
config.pull_request_review_requested_symbol = pull_request_review_requested_symbol;
config.pull_request_approved_symbol = pull_request_approved_symbol;
let sort_configured = pull_request_sort.is_some();
let filters_configured = pull_request_filters.is_some();
let preferences = Preferences {
sort: pull_request_sort.unwrap_or_default(),
filters: pull_request_filters.unwrap_or_default(),
};
preferences
.validate()
.map_err(|error| format!("Ruby config: {error}"))?;
config.pull_request_sort = sort_configured.then_some(preferences.sort);
config.pull_request_filters = filters_configured.then_some(preferences.filters);
config.resolve_history_layout = resolve_history_layout; config.resolve_history_layout = resolve_history_layout;
Ok(config) Ok(config)
} }
@@ -532,6 +562,8 @@ struct ConfigFrame {
clipboard_mode: String, clipboard_mode: String,
git_blame: bool, git_blame: bool,
git_gutter: crate::gutter::GutterStyle, git_gutter: crate::gutter::GutterStyle,
#[serde(default)]
cursor: crate::cursor::CursorConfig,
#[serde(deserialize_with = "crate::chrome::top")] #[serde(deserialize_with = "crate::chrome::top")]
top_bar: ChromeLine, top_bar: ChromeLine,
#[serde(deserialize_with = "crate::chrome::bottom")] #[serde(deserialize_with = "crate::chrome::bottom")]
@@ -556,9 +588,29 @@ struct ConfigFrame {
diff_view_mode: crate::diff::ViewMode, diff_view_mode: crate::diff::ViewMode,
diff_split_orientation: crate::panes::SplitAxis, diff_split_orientation: crate::panes::SplitAxis,
diff_follow_working_copy: bool, diff_follow_working_copy: bool,
#[serde(deserialize_with = "pull_request_symbol")]
pull_request_review_requested_symbol: String,
#[serde(deserialize_with = "pull_request_symbol")]
pull_request_approved_symbol: String,
#[serde(default)]
pull_request_sort: Option<SortSettings>,
#[serde(default)]
pull_request_filters: Option<Vec<ReviewFilter>>,
resolve_history_layout: crate::editor::ResolverLayout, resolve_history_layout: crate::editor::ResolverLayout,
} }
fn pull_request_symbol<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<String, D::Error> {
let symbol = String::deserialize(deserializer)?;
if symbol.chars().any(char::is_control) {
return Err(serde::de::Error::custom(
"pull request symbols must not contain control characters",
));
}
Ok(symbol)
}
fn whitespace_characters<'de, D: serde::Deserializer<'de>>( fn whitespace_characters<'de, D: serde::Deserializer<'de>>(
deserializer: D, deserializer: D,
) -> Result<BTreeMap<char, char>, D::Error> { ) -> Result<BTreeMap<char, char>, D::Error> {
+108
View File
@@ -142,6 +142,7 @@ module Vamp
@clipboard_mode = "system" @clipboard_mode = "system"
@git_blame = true @git_blame = true
@git_gutter = "bar" @git_gutter = "bar"
@cursor = {}
@bar = BarConfig.new @bar = BarConfig.new
@popup = PopupConfig.new @popup = PopupConfig.new
@labels = {} @labels = {}
@@ -157,6 +158,10 @@ module Vamp
@diff_view_mode = "split" @diff_view_mode = "split"
@diff_split_orientation = "vertical" @diff_split_orientation = "vertical"
@diff_follow_working_copy = true @diff_follow_working_copy = true
@pull_request_review_requested_symbol = "🙏"
@pull_request_approved_symbol = "👍"
@pull_request_sort = nil
@pull_request_filters = nil
@resolve_history_layout = "columns" @resolve_history_layout = "columns"
end end
@@ -227,6 +232,32 @@ module Vamp
@git_gutter = style @git_gutter = style
end end
# @param options [Hash{String, Symbol => Boolean, String, Symbol}] mode_colors defaults to true; mode shapes default to block
# @return [Hash{String => Boolean, String}]
def cursor=(options)
raise TypeError, "cursor options must be a Hash" unless options.is_a?(Hash)
@cursor = options.each_with_object({}) do |(option, value), result|
option = option.to_s if option.is_a?(Symbol)
option = Vamp.string!(option, "cursor option")
raise ArgumentError, "duplicate cursor option: #{option}" if result.key?(option)
case option
when "mode_colors"
raise TypeError, "cursor mode_colors must be true or false" unless [true, false].include?(value)
when "normal", "insert", "command", "search", "visual"
value = value.to_s if value.is_a?(Symbol)
value = Vamp.string!(value, "cursor shape")
unless %w[block bar underline].include?(value)
raise ArgumentError, "cursor shape must be block, bar, or underline"
end
else
raise ArgumentError, "unknown cursor option: #{option}"
end
result[option] = value
end
end
# @param values [Hash{String, Symbol => String}] # @param values [Hash{String, Symbol => String}]
# @return [Hash] # @return [Hash]
def labels=(values) def labels=(values)
@@ -327,6 +358,72 @@ module Vamp
@diff_follow_working_copy = enabled @diff_follow_working_copy = enabled
end end
# @param symbol [String] empty to hide the review-request indicator
# @return [String]
def pull_request_review_requested_symbol=(symbol)
@pull_request_review_requested_symbol = pull_request_symbol!(symbol, "pull_request_review_requested_symbol")
end
# @param symbol [String] empty to hide the approval indicator
# @return [String]
def pull_request_approved_symbol=(symbol)
@pull_request_approved_symbol = pull_request_symbol!(symbol, "pull_request_approved_symbol")
end
# @param fields [Hash{String, Symbol => Hash}, nil] explicit ranks and sort directions
# @return [Hash, nil]
def pull_request_sort=(fields)
return @pull_request_sort = nil if fields.nil?
raise TypeError, "pull_request_sort must be a Hash or nil" unless fields.is_a?(Hash)
ranks = []
normalized = Vamp.chrome_hash!(fields).to_h do |field, options|
unless %w[requested updated_at approved created_at].include?(field)
raise ArgumentError, "unknown pull_request_sort field: #{field}"
end
raise TypeError, "pull_request_sort #{field} must be a Hash" unless options.is_a?(Hash)
options = Vamp.chrome_hash!(options)
unknown = options.keys - %w[precedence direction]
raise ArgumentError, "unknown pull_request_sort option: #{unknown.first}" unless unknown.empty?
rank = options["precedence"]
unless rank.nil? || (rank.is_a?(Integer) && rank.between?(1, 4))
raise ArgumentError, "pull_request_sort precedence must be between 1 and 4"
end
raise ArgumentError, "duplicate pull_request_sort precedence: #{rank}" if rank && ranks.include?(rank)
ranks << rank if rank
if options.key?("direction")
direction = options["direction"]
direction = direction.to_s if direction.is_a?(Symbol)
unless %w[asc desc].include?(direction)
raise ArgumentError, "pull_request_sort direction must be asc or desc"
end
options["direction"] = direction
end
[field, options]
end
@pull_request_sort = normalized
end
# @param filters [Array<String, Symbol>, nil] selected personal review buckets
# @return [Array<String>, nil]
def pull_request_filters=(filters)
return @pull_request_filters = nil if filters.nil?
raise TypeError, "pull_request_filters must be an Array or nil" unless filters.is_a?(Array)
normalized = filters.map do |filter|
filter = filter.to_s if filter.is_a?(Symbol)
unless %w[requested approved other].include?(filter)
raise ArgumentError, "unknown pull_request_filters value: #{filter.inspect}"
end
filter
end
unless normalized.uniq.length == normalized.length
raise ArgumentError, "duplicate pull_request_filters value"
end
@pull_request_filters = normalized
end
# @param layout [String] "columns" or "base_below" # @param layout [String] "columns" or "base_below"
# @return [String] # @return [String]
def resolve_history_layout=(layout) def resolve_history_layout=(layout)
@@ -371,6 +468,7 @@ module Vamp
"file_explorer_view" => @file_explorer_view, "clipboard_mode" => @clipboard_mode, "file_explorer_view" => @file_explorer_view, "clipboard_mode" => @clipboard_mode,
"git_blame" => @git_blame, "git_blame" => @git_blame,
"git_gutter" => @git_gutter, "git_gutter" => @git_gutter,
"cursor" => @cursor,
"scroll_distance" => @scroll_distance, "scroll_distance" => @scroll_distance,
"scroll_step_lines" => @scroll_step_lines, "scroll_step_lines" => @scroll_step_lines,
"highlight_trailing_whitespace" => @highlight_trailing_whitespace, "highlight_trailing_whitespace" => @highlight_trailing_whitespace,
@@ -382,10 +480,20 @@ module Vamp
"diff_context_lines" => @diff_context_lines, "diff_expand_lines" => @diff_expand_lines, "diff_context_lines" => @diff_context_lines, "diff_expand_lines" => @diff_expand_lines,
"diff_view_mode" => @diff_view_mode, "diff_split_orientation" => @diff_split_orientation, "diff_view_mode" => @diff_view_mode, "diff_split_orientation" => @diff_split_orientation,
"diff_follow_working_copy" => @diff_follow_working_copy, "diff_follow_working_copy" => @diff_follow_working_copy,
"pull_request_review_requested_symbol" => @pull_request_review_requested_symbol,
"pull_request_approved_symbol" => @pull_request_approved_symbol,
"pull_request_sort" => @pull_request_sort, "pull_request_filters" => @pull_request_filters,
"resolve_history_layout" => @resolve_history_layout } "resolve_history_layout" => @resolve_history_layout }
end end
private private
def pull_request_symbol!(symbol, label)
symbol = Vamp.string!(symbol, label)
raise ArgumentError, "#{label} must not contain control characters" if symbol.match?(/[[:cntrl:]]/)
symbol
end
# @param spaces [Integer, nil] # @param spaces [Integer, nil]
# @return [Integer, nil] # @return [Integer, nil]
def tab_spaces!(spaces) def tab_spaces!(spaces)
+58
View File
@@ -450,6 +450,7 @@ struct ShellCommand {
/// the editor, but cannot independently mutate its plugin registry. /// the editor, but cannot independently mutate its plugin registry.
pub struct EditorSession { pub struct EditorSession {
editor: Editor, editor: Editor,
pull_request_preferences_store: crate::pull_request_preferences::Store,
plugins: BTreeMap<String, RubyPlugin>, plugins: BTreeMap<String, RubyPlugin>,
documents: BTreeMap<usize, TrackedDocument>, documents: BTreeMap<usize, TrackedDocument>,
requests: BTreeMap<String, AsyncRequests>, requests: BTreeMap<String, AsyncRequests>,
@@ -488,6 +489,20 @@ impl EditorSession {
file: Option<PathBuf>, file: Option<PathBuf>,
capabilities: Vec<String>, capabilities: Vec<String>,
config: Option<&Path>, config: Option<&Path>,
) -> io::Result<Self> {
let path = if cfg!(test) {
None
} else {
Some(crate::pull_request_preferences::default_path())
};
Self::open_with_preferences_path(file, capabilities, config, path)
}
pub(crate) fn open_with_preferences_path(
file: Option<PathBuf>,
capabilities: Vec<String>,
config: Option<&Path>,
preferences_path: Option<Result<PathBuf, String>>,
) -> io::Result<Self> { ) -> io::Result<Self> {
let mut editor = Editor::open(file, capabilities)?; let mut editor = Editor::open(file, capabilities)?;
let mut notices = Vec::new(); let mut notices = Vec::new();
@@ -501,6 +516,29 @@ impl EditorSession {
}), }),
None => Config::default(), None => Config::default(),
}; };
editor.cursor_config = config.cursor;
let (pull_request_preferences_store, mut preferences, notice) = match preferences_path {
Some(path) => crate::pull_request_preferences::Store::load(path),
None => (
crate::pull_request_preferences::Store::disabled(),
crate::pull_requests::Preferences::default(),
None,
),
};
if let Some(notice) = notice {
notices.push(notice);
}
editor.pull_request_configured = [
config.pull_request_sort.is_some(),
config.pull_request_filters.is_some(),
];
if let Some(sort) = config.pull_request_sort {
preferences.sort = sort;
}
if let Some(filters) = config.pull_request_filters {
preferences.filters = filters;
}
editor.pull_request_preferences = preferences;
editor.set_review_directory(match config.review_directory { editor.set_review_directory(match config.review_directory {
Some(directory) => directory, Some(directory) => directory,
None => crate::review::default_directory().map_err(io::Error::other)?, None => crate::review::default_directory().map_err(io::Error::other)?,
@@ -542,6 +580,9 @@ impl EditorSession {
editor.set_tab_spaces(config.tab_spaces, config.language_tab_spaces); editor.set_tab_spaces(config.tab_spaces, config.language_tab_spaces);
editor.set_diff_context_options(config.diff_context_lines, config.diff_expand_lines); editor.set_diff_context_options(config.diff_context_lines, config.diff_expand_lines);
editor.set_diff_display_options(config.diff_view_mode, config.diff_split_orientation); editor.set_diff_display_options(config.diff_view_mode, config.diff_split_orientation);
editor.diff_follow_working_copy = config.diff_follow_working_copy;
editor.pull_request_review_requested_symbol = config.pull_request_review_requested_symbol;
editor.pull_request_approved_symbol = config.pull_request_approved_symbol;
editor.resolve_history_layout = config.resolve_history_layout; editor.resolve_history_layout = config.resolve_history_layout;
if let Err(error) = if let Err(error) =
editor.set_chrome_config(config.top_bar, config.bottom_bar, config.labels) editor.set_chrome_config(config.top_bar, config.bottom_bar, config.labels)
@@ -578,6 +619,7 @@ impl EditorSession {
} }
let mut session = Self { let mut session = Self {
editor, editor,
pull_request_preferences_store,
plugins, plugins,
documents: BTreeMap::new(), documents: BTreeMap::new(),
requests: BTreeMap::new(), requests: BTreeMap::new(),
@@ -663,6 +705,7 @@ impl EditorSession {
} }
self.start_diff_request(); self.start_diff_request();
self.start_resolver_requests(); self.start_resolver_requests();
self.save_pull_request_preferences();
} }
pub fn execute(&mut self, command: &str) { pub fn execute(&mut self, command: &str) {
@@ -675,6 +718,20 @@ impl EditorSession {
} }
self.start_diff_request(); self.start_diff_request();
self.start_resolver_requests(); self.start_resolver_requests();
self.save_pull_request_preferences();
}
fn save_pull_request_preferences(&mut self) -> bool {
if !std::mem::take(&mut self.editor.pull_request_preferences_changed) {
return false;
}
if let Err(error) = self
.pull_request_preferences_store
.save(&self.editor.pull_request_preferences)
{
self.editor.set_message(error);
}
true
} }
fn start_resolver_requests(&mut self) { fn start_resolver_requests(&mut self) {
@@ -1848,6 +1905,7 @@ impl EditorSession {
fn poll_at(&mut self, now: Instant) -> bool { fn poll_at(&mut self, now: Instant) -> bool {
let mut changed = self.refresh_files_at(now); let mut changed = self.refresh_files_at(now);
changed |= self.save_pull_request_preferences();
changed |= self.poll_gutter_at(now); changed |= self.poll_gutter_at(now);
changed |= self.synchronize_documents(); changed |= self.synchronize_documents();
changed |= self.poll_battery(); changed |= self.poll_battery();
+1
View File
@@ -13,6 +13,7 @@ use languages::LanguageSpec;
pub(crate) const RUST_ID: &str = "rust"; pub(crate) const RUST_ID: &str = "rust";
pub(crate) const RUBY_ID: &str = "ruby"; pub(crate) const RUBY_ID: &str = "ruby";
pub(crate) const PYTHON_ID: &str = "python"; pub(crate) const PYTHON_ID: &str = "python";
pub(crate) const TYPST_ID: &str = "typst";
// Full trees and their indexes are optional; editing remains available beyond these budgets. // Full trees and their indexes are optional; editing remains available beyond these budgets.
const MAX_SYNTAX_BYTES: usize = 1024 * 1024; const MAX_SYNTAX_BYTES: usize = 1024 * 1024;
+37 -1
View File
@@ -90,6 +90,32 @@ const CPP_INJECTIONS: &str = "
(raw_string_content) @injection.content) (raw_string_content) @injection.content)
"; ";
// The Typst crate exports its grammar but not queries. Use its AST nodes with
// Vamp's supported capture roles, and standard captures for raw-code injections.
const TYPST_HIGHLIGHTS: &str = r#"
(comment) @comment
(string) @string
(number) @number
[(bool) (none) (auto)] @keyword
[
"let" "if" "else" "while" "for" "in" "import" "as" "include"
"show" "set" "return" "break" "continue" "context" "and" "or" "not"
] @keyword
(call item: (ident) @function)
(call item: (field field: (ident) @function))
[
(heading) (emph) (strong) (url) (label) (ref) (symbol)
(raw_blck) (raw_span)
] @markup
(item "-" @markup.list)
(term ["/" ":"] @markup.list)
"#;
const TYPST_INJECTIONS: &str = "
(raw_blck
lang: (ident) @injection.language
(blob) @injection.content)
";
fn javascript_injections() -> &'static str { fn javascript_injections() -> &'static str {
// The trailing upstream hbs/@glimmer rule uses a nonstandard #offset! directive, // The trailing upstream hbs/@glimmer rule uses a nonstandard #offset! directive,
// not injection.* captures. Glimmer is outside the selected language set; // not injection.* captures. Glimmer is outside the selected language set;
@@ -118,7 +144,7 @@ fn spec(
} }
} }
static LANGUAGES: LazyLock<[LanguageSpec; 20]> = LazyLock::new(|| { static LANGUAGES: LazyLock<[LanguageSpec; 21]> = LazyLock::new(|| {
[ [
spec( spec(
super::RUST_ID, super::RUST_ID,
@@ -280,6 +306,14 @@ static LANGUAGES: LazyLock<[LanguageSpec; 20]> = LazyLock::new(|| {
"", "",
"", "",
), ),
spec(
super::TYPST_ID,
"Typst",
tree_sitter_typst::LANGUAGE.into(),
TYPST_HIGHLIGHTS,
TYPST_INJECTIONS,
"",
),
] ]
}); });
@@ -320,6 +354,7 @@ pub(super) fn by_name(name: &str) -> Option<&'static LanguageSpec> {
("golang", "Go"), ("golang", "Go"),
("hon", "Honey"), ("hon", "Honey"),
("honeylang", "Honey"), ("honeylang", "Honey"),
("typ", "Typst"),
]; ];
let name = ALIASES let name = ALIASES
.iter() .iter()
@@ -376,6 +411,7 @@ fn detect_path(path: &Path) -> Option<&'static LanguageSpec> {
"go" => "Go", "go" => "Go",
"zig" => "Zig", "zig" => "Zig",
"hon" => "Honey", "hon" => "Honey",
"typ" => "Typst",
_ => return None, _ => return None,
} }
} }
+531 -94
View File
File diff suppressed because it is too large Load Diff
-4
View File
@@ -629,10 +629,6 @@ fn branch_changes_default_and_mode_switches_compare_the_selected_divergent_tips(
session.editor().diff().unwrap().comparison_mode, session.editor().diff().unwrap().comparison_mode,
ComparisonMode::Snapshots ComparisonMode::Snapshots
); );
assert_eq!(
session.editor().message(),
"Working checkout requires Snapshots"
);
} }
#[test] #[test]
+25
View File
@@ -1367,6 +1367,31 @@ fn jj_private_fetch_discovers_never_fetched_bookmark_and_searchable_remote_chang
); );
assert_eq!(changed(&comparison, Path::new("file")).after, ["local"]); assert_eq!(changed(&comparison, Path::new("file")).after, ["local"]);
let loaded = repository.fetch_remote("origin").unwrap(); let loaded = repository.fetch_remote("origin").unwrap();
assert_eq!(loaded.graph[&tip].parents, [ancestor.clone()]);
assert_eq!(
loaded.graph[&ancestor].description,
"remote historic needle"
);
assert!(!loaded.graph[&tip].current);
let positions: std::collections::BTreeMap<_, _> = loaded
.entries
.iter()
.filter(|entry| entry.category == Category::Revisions)
.enumerate()
.filter_map(|(index, entry)| match &entry.target {
RevisionTarget::Commit(id) => Some((id.as_str(), index)),
_ => None,
})
.collect();
for (id, metadata) in &loaded.graph {
for parent in &metadata.parents {
if let (Some(child), Some(parent)) =
(positions.get(id.as_str()), positions.get(parent.as_str()))
{
assert!(child < parent);
}
}
}
let historic = loaded let historic = loaded
.entries .entries
.iter() .iter()
+211
View File
@@ -115,6 +115,17 @@ fn cli_deletes_only_the_requested_comment_and_preserves_failed_targets() {
assert!(empty.comments.is_empty()); assert!(empty.comments.is_empty());
assert_eq!(empty.storage_revision, loaded.storage_revision + 1); assert_eq!(empty.storage_revision, loaded.storage_revision + 1);
assert_eq!(empty.summary, review.summary); assert_eq!(empty.summary, review.summary);
let output = cli("repo", &["list", "--json"]);
assert!(output.status.success(), "{:?}", output);
let list: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
assert_eq!(list["reviews"], serde_json::json!([]));
let output = cli("repo", &["list"]);
assert!(output.status.success(), "{:?}", output);
assert!(
String::from_utf8(output.stdout)
.unwrap()
.contains("No stored reviews.")
);
assert_eq!( assert_eq!(
store store
.load(&other.root, other.storage_id.unwrap()) .load(&other.root, other.storage_id.unwrap())
@@ -128,3 +139,203 @@ fn cli_deletes_only_the_requested_comment_and_preserves_failed_targets() {
assert!(!output.status.success()); assert!(!output.status.success());
assert!(!storage.exists()); assert!(!storage.exists());
} }
#[test]
fn cli_resolves_only_the_requested_comment_and_preserves_original_feedback() {
let directory = Directory(
std::env::temp_dir().join(format!("vamp-review-cli-resolve-{}", std::process::id())),
);
fs::create_dir(&directory.0).unwrap();
let root = directory.0.canonicalize().unwrap();
for name in ["repo", "other"] {
let output = Command::new("jj")
.args(["git", "init"])
.arg(root.join(name))
.env("JJ_CONFIG", "/dev/null")
.output()
.unwrap();
assert!(output.status.success(), "{:?}", output);
}
let config = root.join("config.rb");
fs::write(
&config,
"Vamp.configure { |config| config.review_directory = 'reviews' }",
)
.unwrap();
let storage = root.join("reviews");
let mut store = Store::open(&storage).unwrap();
let mut review = Review::new(root.join("repo"));
review.comparison = Some(["frozen-base".into(), "working:frozen-tip".into()]);
review.summary = "Keep summary".into();
review.verdict = Some(Verdict::ChangesRequested);
review.comments = [u64::MAX, 2, 3]
.into_iter()
.map(|id| Comment {
id,
body: format!("Original feedback {id}\nKeep this history."),
resolved: id == 3,
anchor: Anchor {
revision: "original-snapshot".into(),
path: "old/file.rs".into(),
side: Side::Before,
start: TextPosition { row: 0, column: 1 },
end: TextPosition { row: 1, column: 1 },
content: "xe\u{301}👩‍💻\n界z\n".into(),
},
})
.collect();
store.save(&mut review).unwrap();
let mut other = Review::new(root.join("other"));
other.comments = review.comments.clone();
store.save(&mut other).unwrap();
let mut source = Review::new(review.root.clone());
source.summary = "Progress without comments".into();
source.verdict = Some(Verdict::LooksGood);
store.save(&mut source).unwrap();
let mut reversed = Review::new(review.root.clone());
reversed.comparison = Some(["working:frozen-tip".into(), "frozen-base".into()]);
store.save(&mut reversed).unwrap();
let id = review.storage_id.unwrap();
let id_text = id.to_string();
let cli = |repo: &str, args: &[&str]| {
Command::new(env!("CARGO_BIN_EXE_vamp"))
.arg("--config")
.arg(&config)
.arg("--review")
.args(args)
.arg("--repo")
.arg(root.join(repo))
.current_dir(&root)
.output()
.unwrap()
};
let path = storage.join("reviews.sqlite3");
let before = fs::read(&path).unwrap();
for (repo, args) in [
("repo", vec!["resolve"]),
("repo", vec!["resolve", &id_text]),
("repo", vec!["resolve", "0", "1"]),
("repo", vec!["resolve", &id_text, "0"]),
("repo", vec!["resolve", "999", "1"]),
("repo", vec!["resolve", &id_text, "1"]),
("other", vec!["resolve", &id_text, "2"]),
("repo", vec!["resolve", &id_text, "2", "--all"]),
] {
let output = cli(repo, &args);
assert!(!output.status.success(), "{:?}", output);
assert_eq!(fs::read(&path).unwrap(), before);
}
let output = cli(
"repo",
&["resolve", &id_text, "18446744073709551615", "--json"],
);
assert!(output.status.success(), "{:?}", output);
let json: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
assert_eq!(json["id"], id);
assert_eq!(json["revision"], review.storage_revision + 1);
assert_eq!(json["comparison"], serde_json::json!(review.comparison));
assert_eq!(
json["counts"],
serde_json::json!({"total": 3, "resolved": 2, "unresolved": 1})
);
assert_eq!(json["comments"].as_array().unwrap().len(), 1);
assert_eq!(json["comments"][0]["id"], 2);
let loaded = store.load(&review.root, id).unwrap();
let mut expected = review.comments.clone();
expected[0].resolved = true;
assert_eq!(loaded.comments, expected);
assert_eq!(loaded.summary, review.summary);
assert_eq!(loaded.verdict, review.verdict);
assert_eq!(loaded.reviewed_files, review.reviewed_files);
assert_eq!(loaded.comparison, review.comparison);
assert!(store.save(&mut review).is_err()); // Stale editors cannot undo resolution.
assert_eq!(store.load(&review.root, id).unwrap().comments, expected);
let output = cli("repo", &["show", &id_text, "--all", "--json"]);
assert!(output.status.success(), "{:?}", output);
let all: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
assert_eq!(all["comments"].as_array().unwrap().len(), 3);
let original = &all["comments"][0];
assert_eq!(original["id"], u64::MAX);
assert_eq!(original["body"], review.comments[0].body);
assert_eq!(original["resolved"], true);
assert_eq!(original["anchor"]["revision"], "original-snapshot");
assert_eq!(original["anchor"]["path"], "old/file.rs");
assert_eq!(
original["anchor"]["start"],
serde_json::json!({"row": 0, "column": 1})
);
assert_eq!(original["excerpt"], "e\u{301}👩‍💻\n界");
let output = cli("repo", &["show", &id_text, "--json"]);
assert!(output.status.success(), "{:?}", output);
assert_eq!(
serde_json::from_slice::<serde_json::Value>(&output.stdout).unwrap(),
json
);
let before = fs::read(&path).unwrap();
for comment in ["18446744073709551615", "3"] {
let output = cli("repo", &["resolve", &id_text, comment, "--json"]);
assert!(output.status.success(), "{:?}", output);
assert_eq!(
serde_json::from_slice::<serde_json::Value>(&output.stdout).unwrap(),
json
);
assert_eq!(fs::read(&path).unwrap(), before);
}
let output = cli("repo", &["list", "--json"]);
assert!(output.status.success(), "{:?}", output);
let list: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
assert_eq!(
list["reviews"]
.as_array()
.unwrap()
.iter()
.map(|review| review["id"].as_i64().unwrap())
.collect::<Vec<_>>(),
vec![id]
);
assert_eq!(list["reviews"][0]["comparison"], json["comparison"]);
assert_eq!(list["reviews"][0]["counts"], json["counts"]);
let output = cli("repo", &["list"]);
assert!(output.status.success(), "{:?}", output);
let text = String::from_utf8(output.stdout).unwrap();
assert!(!text.contains("Progress without comments"));
assert!(text.contains("Scope: comparison frozen-base → working:frozen-tip"));
assert!(!text.contains("Scope: comparison working:frozen-tip → frozen-base"));
assert_eq!(fs::read(&path).unwrap(), before);
let output = cli(
"repo",
&["show", &source.storage_id.unwrap().to_string(), "--json"],
);
assert!(output.status.success(), "{:?}", output);
let shown: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
assert_eq!(shown["summary"], source.summary);
assert_eq!(shown["verdict"], "looks_good");
let output = cli("repo", &["resolve", &id_text, "2"]);
assert!(output.status.success(), "{:?}", output);
let text = String::from_utf8(output.stdout).unwrap();
assert!(!text.contains("Original feedback"));
let loaded = store.load(&review.root, id).unwrap();
assert_eq!(loaded.storage_revision, review.storage_revision + 2);
assert!(loaded.comments.iter().all(|comment| comment.resolved));
let output = cli("repo", &["list", "--json"]);
assert!(output.status.success(), "{:?}", output);
let list: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
assert_eq!(list["reviews"][0]["id"], id);
assert_eq!(
list["reviews"][0]["counts"],
serde_json::json!({"total": 3, "resolved": 3, "unresolved": 0})
);
assert_eq!(
store
.load(&other.root, other.storage_id.unwrap())
.unwrap()
.comments,
other.comments
);
drop(store);
fs::remove_dir_all(&storage).unwrap();
let output = cli("repo", &["resolve", &id_text, "2"]);
assert!(!output.status.success(), "{:?}", output);
assert!(!storage.exists());
}
-1
View File
@@ -79,7 +79,6 @@ fn omitted_options_inherit_and_explicit_groups_replace_defaults() {
fn both_positions_accept_all_builtins_and_custom_styles() { fn both_positions_accept_all_builtins_and_custom_styles() {
let defaults = ChromeLine::top(); let defaults = ChromeLine::top();
assert_eq!(defaults.right, ["diff", "shell", "battery"]); assert_eq!(defaults.right, ["diff", "shell", "battery"]);
assert_eq!(defaults.segment("diff"), defaults.segment("shell"));
let names = [ let names = [
"tabs", "tabs",
"mode", "mode",
+782 -98
View File
File diff suppressed because it is too large Load Diff
+600 -245
View File
File diff suppressed because it is too large Load Diff
+657 -16
View File
@@ -7,6 +7,627 @@ fn parse(url: &str, provider: Option<&str>) -> Result<Forge, String> {
}) })
} }
#[test]
fn github_personal_approvals_use_the_viewer_and_last_decisive_review() {
let forge = parse("https://github.com/owner/repo", None).unwrap();
let values: Vec<_> = (1..=8).map(|id| json!({"number": id})).collect();
let metadata = forge.metadata_with(&values, &mut |url, body| {
if url.ends_with("/user") {
assert_eq!(url, "https://api.github.com/user");
return Ok(json!({"login": "viewer"}));
}
let body: Value = serde_json::from_str(body.unwrap()).unwrap();
let query = body["query"].as_str().unwrap();
assert!(query.contains("author:\"viewer\""));
assert!(query.contains("states:[APPROVED,CHANGES_REQUESTED,DISMISSED],last:1"));
assert!(!query.contains("mutation"));
Ok(json!({"data":{"repository":{
"p1":{"additions":3,"deletions":4,"reviews":{"nodes":[{"state":"APPROVED","author":{"login":"VIEWER"}}]}},
"p2":{"reviews":{"nodes":[{"state":"CHANGES_REQUESTED","author":{"login":"viewer"}}]}},
"p3":{"reviews":{"nodes":[{"state":"DISMISSED","author":{"login":"viewer"}}]}},
"p4":{"reviews":null},
"p5":{"reviews":{"nodes":[{"state":"COMMENTED","author":{"login":"viewer"}}]}},
"p6":{"reviews":{"nodes":[{"state":"APPROVED","author":{"login":"someone-else"}}]}},
"p7":{"reviews":{"nodes":[{"state":"PENDING","author":{"login":"viewer"}}]}},
"p8":{"reviews":{"nodes":[{"state":"APPROVED","author":{"login":"viewer"}}]}}
}}}))
});
assert_eq!(
metadata
.iter()
.filter_map(|(id, details)| details.approved.then_some(*id))
.collect::<Vec<_>>(),
[1, 8]
);
assert_eq!(metadata[&1].size, Some((3, 4)));
assert_eq!(metadata[&8].size, None);
}
#[test]
fn gitlab_personal_approvals_filter_by_viewer_and_follow_connection_pages() {
let forge = parse("https://gitlab.com/group/repo", None).unwrap();
let values = [json!({"iid":7}), json!({"iid":8}), json!({"iid":9})];
let metadata = forge.metadata_with(&values, &mut |url, body| {
if url.ends_with("/user") {
assert_eq!(url, "https://gitlab.com/api/v4/user");
return Ok(json!({"username":"viewer"}));
}
let body: Value = serde_json::from_str(body.unwrap()).unwrap();
let query = body["query"].as_str().unwrap();
assert!(query.contains("approvedBy:[\"viewer\"]"));
assert!(query.contains("iids:[\"7\",\"8\",\"9\"]"));
assert!(!query.contains("mutation"));
if query.contains("after:\"next-page\"") {
return Ok(json!({"data":{"project":{"approved":{
"nodes":[{"iid":"8"}],
"pageInfo":{"hasNextPage":false,"endCursor":null}
}}}}));
}
Ok(json!({"data":{"project":{
"p7":{"diffStatsSummary":{"additions":5,"deletions":6}},
"p8":{"diffStatsSummary":null},
"p9":{"diffStatsSummary":{"additions":0,"deletions":0}},
"approved":{
"nodes":[{"iid":"7"},{"iid":"999"}],
"pageInfo":{"hasNextPage":true,"endCursor":"next-page"}
}
}}}))
});
assert!(metadata[&7].approved && metadata[&8].approved);
assert!(!metadata[&9].approved);
assert!(!metadata.contains_key(&999));
assert_eq!(metadata[&7].size, Some((5, 6)));
assert_eq!(metadata[&8].size, None);
}
#[test]
fn gitea_personal_approvals_ignore_other_users_and_honor_later_decisions_and_failures() {
let forge = parse("https://codeberg.org/owner/repo", None).unwrap();
let own = |id, state: &str, dismissed| json!({"id":id,"user":{"id":42},"state":state,"dismissed":dismissed});
let approved = own(10, "APPROVED", false);
for (pages, expected) in [
(
vec![
Ok(json!([approved.clone()])),
Ok(json!([
own(30, "COMMENT", false),
own(31, "PENDING", false),
own(32, "REQUEST_REVIEW", false)
])),
Ok(json!([])),
],
true,
),
(
vec![
Ok(json!([approved.clone()])),
Ok(json!([own(20, "REQUEST_CHANGES", false)])),
Ok(json!([])),
],
false,
),
(
vec![
Ok(json!([approved.clone()])),
Ok(json!([own(20, "APPROVED", true)])),
Ok(json!([])),
],
false,
),
(
vec![
Ok(json!([{"id":10,"user":{"id":7},"state":"APPROVED","dismissed":false}])),
Ok(json!([])),
],
false,
),
(
vec![
Ok(json!([approved.clone()])),
Err("later review page failed".into()),
],
false,
),
(
vec![Ok(json!([{"id":10,"user":{"id":42},"state":"APPROVED"}]))],
false,
),
// Select by review identity, not response order; a later approval replaces a rejection.
(
vec![
Ok(json!([
own(20, "APPROVED", false),
own(10, "REQUEST_CHANGES", false)
])),
Ok(json!([])),
],
true,
),
] {
let mut pages = pages.into_iter();
let metadata = forge.metadata_with(
&[json!({"number":7,"additions":1,"deletions":2})],
&mut |url, body| {
assert!(body.is_none());
if url.ends_with("/user") {
assert_eq!(url, "https://codeberg.org/api/v1/user");
return Ok(json!({"id":42}));
}
assert!(url.starts_with(
"https://codeberg.org/api/v1/repos/owner/repo/pulls/7/reviews?limit=50&page="
));
pages.next().expect("unexpected review page")
},
);
assert_eq!(metadata[&7].approved, expected);
assert_eq!(metadata[&7].size, Some((1, 2)));
}
}
#[test]
fn unavailable_viewer_or_metadata_never_fabricates_personal_approval() {
for (url, provider) in [
("https://github.com/owner/repo", Provider::Github),
("https://gitlab.com/group/repo", Provider::Gitlab),
("https://codeberg.org/owner/repo", Provider::Gitea),
] {
let forge = parse(url, None).unwrap();
for unavailable_viewer in [true, false] {
let metadata = forge.metadata_with(
&[json!({"number":7,"iid":7,"additions":0,"deletions":0,
"requested_reviewers":[{"login":"viewer","id":42}],
"reviewers":[{"username":"viewer"}]})],
&mut |url, body| {
if url.ends_with("/user") {
return if unavailable_viewer {
Err("no API credentials".into())
} else {
Ok(json!({"login":"viewer","username":"viewer","id":42}))
};
}
if provider == Provider::Gitea {
assert!(
!unavailable_viewer,
"anonymous listings must not fetch reviews"
);
assert!(body.is_none());
}
Err("metadata denied".into())
},
);
assert!(metadata.values().all(|details| !details.approved));
assert!(metadata.values().all(|details| details.review_requested
== (provider == Provider::Github && !unavailable_viewer)));
if provider == Provider::Gitea {
assert_eq!(metadata[&7].size, Some((0, 0)));
}
}
}
}
#[test]
fn github_outstanding_requests_use_list_users_independently_of_review_metadata() {
let forge = parse("https://github.com/owner/repo", None).unwrap();
for (reviewers, expected) in [
(json!([{"login":"VIEWER"}]), true), // Direct or re-requested after approval.
(json!([]), false), // Completed or removed requests are absent.
(json!([{"login":"another-user"}]), false),
(Value::Null, false),
] {
for denied in [false, true] {
let metadata = forge.metadata_with(
&[json!({"number":7,"requested_reviewers":reviewers,
"requested_teams":[{"slug":"viewer"}],"additions":3,"deletions":4})],
&mut |url, body| {
if url.ends_with("/user") {
return Ok(json!({"login":"viewer"}));
}
assert!(body.is_some());
if denied {
return Err("GraphQL denied".into());
}
Ok(
json!({"data":{"repository":{"p7":{"additions":3,"deletions":4,
"reviews":{"nodes":[{"state":"APPROVED","author":{"login":"viewer"}}]}}}}}),
)
},
);
assert_eq!(metadata[&7].review_requested, expected);
assert_eq!(metadata[&7].approved, !denied);
assert_eq!(metadata[&7].size, Some((3, 4)));
}
}
}
#[test]
fn gitlab_outstanding_requests_require_personal_unfinished_review_and_follow_pages() {
let forge = parse("https://gitlab.com/group/repo", None).unwrap();
let mut values: Vec<_> = (1..=10)
.map(|id| json!({"iid":id,"reviewers":[{"username":"viewer"}]}))
.collect();
values[8]["reviewers"] = json!([]); // Removed reviewer.
values[9]["reviewers"] = json!([{"username":"another-user"}]);
let mut request_reads = 0;
let metadata = forge.metadata_with(&values, &mut |url, body| {
if url.ends_with("/user") {
return Ok(json!({"username":"viewer"}));
}
let body: Value = serde_json::from_str(body.unwrap()).unwrap();
let query = body["query"].as_str().unwrap();
assert!(!query.contains("mutation"));
if !query.contains("reviewState") {
return Ok(json!({"data":{"project":{
"p1":{"diffStatsSummary":{"additions":5,"deletions":6}},
"approved":{"nodes":[{"iid":"1"},{"iid":"4"}],"pageInfo":{"hasNextPage":false}}
}}}));
}
request_reads += 1;
assert!(query.contains("reviewers(first:20"));
assert!(!query.contains("p9:") && !query.contains("p10:"));
if query.contains("after:\"next\"") {
return Ok(json!({"data":{"project":{"p2":{"reviewers":{
"nodes":[{"username":"viewer","mergeRequestInteraction":{"reviewState":"REVIEW_STARTED"}}],
"pageInfo":{"hasNextPage":false}
}}}}}));
}
let mut entries = serde_json::Map::new();
for (id, state) in [(1, "UNREVIEWED"), (3, "REVIEWED"), (4, "APPROVED"),
(5, "REQUESTED_CHANGES"), (6, "UNAPPROVED"), (7, ""), (8, "UNKNOWN")] {
entries.insert(format!("p{id}"), json!({"reviewers":{
"nodes":[{"username":"viewer","mergeRequestInteraction":{"reviewState":state}}],
"pageInfo":{"hasNextPage":false}
}}));
}
entries.insert("p2".into(), json!({"reviewers":{
"nodes":[{"username":"another-user","mergeRequestInteraction":{"reviewState":"UNREVIEWED"}}],
"pageInfo":{"hasNextPage":true,"endCursor":"next"}
}}));
Ok(json!({"data":{"project":entries}}))
});
assert_eq!(request_reads, 2);
assert_eq!(
metadata
.iter()
.filter_map(|(id, details)| details.review_requested.then_some(*id))
.collect::<Vec<_>>(),
[1, 2]
);
assert!(metadata[&1].approved && metadata[&4].approved);
assert_eq!(metadata[&1].size, Some((5, 6)));
}
#[test]
fn gitlab_request_failures_preserve_approval_and_statistics() {
let forge = parse("https://gitlab.com/group/repo", None).unwrap();
for denied in [
Err("review states denied".into()),
Ok(json!({"data":{"project":{
"p7":{"reviewers":null}
}}})),
Ok(json!({"data":{"project":{"p7":{"reviewers":{"nodes":[
{"username":"viewer","mergeRequestInteraction":{"reviewState":null}}
]}}}}})),
] {
let metadata = forge.metadata_with(
&[json!({"iid":7,"reviewers":[{"username":"viewer"}]})],
&mut |url, body| {
if url.ends_with("/user") {
return Ok(json!({"username":"viewer"}));
}
let body: Value = serde_json::from_str(body.unwrap()).unwrap();
if body["query"].as_str().unwrap().contains("reviewState") {
return denied.clone();
}
Ok(json!({"data":{"project":{
"p7":{"diffStatsSummary":{"additions":0,"deletions":1}},
"approved":{"nodes":[{"iid":"7"}],"pageInfo":{"hasNextPage":false}}
}}}))
},
);
assert!(!metadata[&7].review_requested);
assert!(metadata[&7].approved);
assert_eq!(metadata[&7].size, Some((0, 1)));
}
}
#[test]
fn gitlab_request_batches_cover_fifty_rows_without_exceeding_complexity_limit() {
let forge = parse("https://gitlab.com/group/repo", None).unwrap();
let values: Vec<_> = (1..=50)
.map(|id| {
json!({
"iid":id,"reviewers":[{"username":"viewer"}]
})
})
.collect();
let mut batches = 0;
let metadata = forge.metadata_with(&values, &mut |url, body| {
if url.ends_with("/user") {
return Ok(json!({"username":"viewer"}));
}
let body: Value = serde_json::from_str(body.unwrap()).unwrap();
let query = body["query"].as_str().unwrap();
if !query.contains("reviewState") {
return Err("independent metadata unavailable".into());
}
batches += 1;
assert_eq!(query.matches("reviewers(first:20)").count(), 10);
let entries: serde_json::Map<_, _> = (1..=50)
.filter(|id| query.contains(&format!("p{id}:mergeRequest")))
.map(|id| (format!("p{id}"), json!({"reviewers":{
"nodes":[{"username":"viewer","mergeRequestInteraction":{"reviewState":"UNREVIEWED"}}],
"pageInfo":{"hasNextPage":false}
}}))).collect();
Ok(json!({"data":{"project":entries}}))
});
assert_eq!(batches, 5);
assert_eq!(metadata.len(), 50);
assert!(metadata.values().all(|details| details.review_requested));
}
#[test]
fn gitea_requests_ignore_list_assignments_and_use_current_direct_review_rows() {
let forge = parse("https://codeberg.org/owner/repo", None).unwrap();
let own = |id, state: &str| {
json!({
"id":id,"user":{"id":42},"team":null,"state":state,"dismissed":false
})
};
for (reviews, requested, approved) in [
(json!([own(10, "REQUEST_REVIEW")]), true, false),
(json!([own(10, "APPROVED")]), false, true), // Completed or removed request row.
(json!([own(10, "COMMENT")]), false, false),
(json!([own(10, "REQUEST_CHANGES")]), false, false),
(
json!([own(10, "APPROVED"), own(20, "REQUEST_REVIEW")]),
true,
true,
),
(
json!([
own(20, "REQUEST_REVIEW"),
own(10, "APPROVED"),
own(30, "PENDING")
]),
true,
true,
),
(
json!([own(10, "REQUEST_REVIEW"), own(20, "COMMENT")]),
false,
false,
),
(
json!([own(10, "REQUEST_REVIEW"), own(20, "APPROVED")]),
false,
true,
),
(
json!([{"id":10,"user":{"id":7},"state":"REQUEST_REVIEW","dismissed":false}]),
false,
false,
),
(
json!([{"id":10,"user":{"id":42},"team":{"id":1},"state":"REQUEST_REVIEW","dismissed":false}]),
false,
false,
),
(
json!([{"id":20,"user":{"id":42},"state":"REQUEST_REVIEW"},
own(10, "APPROVED")]),
false,
true,
),
(json!([]), false, false),
] {
let mut pages = vec![reviews, json!([])].into_iter();
let metadata = forge.metadata_with(
&[json!({"number":7,"additions":1,"deletions":2,"requested_reviewers":[{"id":42}]})],
&mut |url, body| {
assert!(body.is_none());
if url.ends_with("/user") {
return Ok(json!({"id":42}));
}
pages.next().ok_or_else(|| "unexpected page".into())
},
);
assert_eq!(metadata[&7].review_requested, requested);
assert_eq!(metadata[&7].approved, approved);
assert_eq!(metadata[&7].size, Some((1, 2)));
}
}
#[test]
fn gitea_incomplete_request_pages_do_not_fabricate_requests_or_lose_list_statistics() {
let forge = parse("https://codeberg.org/owner/repo", None).unwrap();
let metadata = forge.metadata_with(
&[json!({"number":7,"additions":0,"deletions":2})],
&mut |url, _| {
if url.ends_with("/user") {
return Ok(json!({"id":42}));
}
if url.ends_with("page=1") {
return Ok(json!([{"id":10,"user":{"id":42},"team":null,
"state":"REQUEST_REVIEW","dismissed":false}]));
}
Err("remaining reviews denied".into())
},
);
assert!(!metadata[&7].review_requested);
assert_eq!(metadata[&7].size, Some((0, 2)));
}
#[test]
fn summaries_keep_outstanding_requests_and_approvals_independent() {
for (url, provider) in [
("https://github.com/owner/repo", Provider::Github),
("https://gitlab.com/owner/repo", Provider::Gitlab),
("https://codeberg.org/owner/repo", Provider::Gitea),
] {
let forge = parse(url, None).unwrap();
let page = forge.page_with(false, 1, |url, body| {
if url.ends_with("/user") {
return Ok(json!({"id":42,"login":"viewer","username":"viewer"}));
}
if let Some(body) = body {
let body: Value = serde_json::from_str(body).unwrap();
if body["query"].as_str().unwrap().contains("reviewState") {
return Ok(json!({"data":{"project":{"p7":{"reviewers":{
"nodes":[{"username":"viewer","mergeRequestInteraction":{"reviewState":"UNREVIEWED"}}],
"pageInfo":{"hasNextPage":false}
}}}}}));
}
return if provider == Provider::Github {
Ok(json!({"data":{"repository":{"p7":{"additions":1,"deletions":2,
"reviews":{"nodes":[{"state":"APPROVED","author":{"login":"viewer"}}]}}}}}))
} else {
Ok(json!({"data":{"project":{
"p7":{"diffStatsSummary":{"additions":1,"deletions":2}},
"approved":{"nodes":[{"iid":"7"}],"pageInfo":{"hasNextPage":false}}
}}}))
};
}
if url.contains("/7/reviews?") {
return Ok(if url.ends_with("page=1") {
json!([
{"id":10,"user":{"id":42},"state":"APPROVED","dismissed":false},
{"id":20,"user":{"id":42},"state":"REQUEST_REVIEW","dismissed":false}
])
} else {
json!([])
});
}
Ok(json!([{"number":7,"iid":7,"title":"Request again","created_at":"2024-01-01T00:00:00Z",
"updated_at":"2024-01-02T01:00:00+01:00",
"state":if provider == Provider::Gitlab { "opened" } else { "open" },
"merged":false,"merged_at":null,"user":{"login":"author"},"author":{"username":"author"},
"requested_reviewers":[{"login":"viewer","id":42}],"reviewers":[{"username":"viewer"}],
"additions":1,"deletions":2}]))
}).unwrap();
assert_eq!(page.entries.len(), 1);
assert!(page.entries[0].approved && page.entries[0].review_requested);
assert!(page.entries[0].description.contains("+1 -2"));
assert_eq!(page.entries[0].updated_at, "2024-01-02T00:00:00.000000000Z");
}
}
#[test]
fn draft_summaries_keep_open_closed_and_merged_states_distinct() {
for provider in [Provider::Github, Provider::Gitlab, Provider::Gitea] {
for (closed, merged, expected) in [
(false, false, "draft"),
(true, false, "closed"),
(true, true, "merged"),
] {
let mut value = json!({
"number": 7, "iid": 7, "title": "Unfinished work", "draft": true,
"state": if merged && provider == Provider::Gitlab { "merged" }
else if closed { "closed" }
else if provider == Provider::Gitlab { "opened" } else { "open" },
"merged": merged,
"merged_at": if merged { Some("2024-01-02T00:00:00Z") } else { None },
"user": null, "author": null, "created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-02T00:00:00Z"
});
let entry = summary(provider, &value, Some((1, 2))).unwrap();
assert!(entry.draft);
assert_eq!(entry.closed, closed);
assert_eq!(
entry.description,
format!("deleted user · {expected} · +1 -2")
);
if !closed {
value["draft"] = json!(false);
assert!(!summary(provider, &value, None).unwrap().draft);
value.as_object_mut().unwrap().remove("draft");
assert!(!summary(provider, &value, None).unwrap().draft);
value["draft"] = json!("true");
assert!(summary(provider, &value, None).is_err());
}
}
}
}
#[test]
fn pull_request_sizes_include_zero_and_preserve_unknown_statistics() {
for (url, provider) in [
("https://github.com/owner/repo", Provider::Github),
("https://github.enterprise/owner/repo", Provider::Github),
("https://gitlab.com/group/repo", Provider::Gitlab),
("https://codeberg.org/owner/repo", Provider::Gitea),
] {
let forge = parse(
url,
Some(match provider {
Provider::Github => "github",
Provider::Gitlab => "gitlab",
Provider::Gitea => "gitea",
}),
)
.unwrap();
let page = forge
.page_with(false, 1, |url, body| {
if url.ends_with("/user") {
return Err("unauthenticated fixture".into());
}
if let Some(body) = body {
let query: Value = serde_json::from_str(body).unwrap();
let query = query["query"].as_str().unwrap();
assert!(query.starts_with("query{"));
assert!(!query.contains("mutation"));
if provider == Provider::Github {
assert_eq!(
url,
if forge.host == "github.com" {
"https://api.github.com/graphql"
} else {
"https://github.enterprise/api/graphql"
}
);
assert!(query.contains("p7:pullRequest(number:7)"));
return Ok(json!({"data":{"repository":{
"p7":{"additions":123,"deletions":45},
"p8":{"additions":0,"deletions":0},
"p9":null
}}}));
}
assert_eq!(url, "https://gitlab.com/api/graphql");
assert!(query.contains("p7:mergeRequest(iid:\"7\")"));
return Ok(json!({"data":{"project":{
"p7":{"diffStatsSummary":{"additions":123,"deletions":45}},
"p8":{"diffStatsSummary":{"additions":0,"deletions":0}},
"p9":{"diffStatsSummary":null}
}}}));
}
Ok(Value::Array((7..=9).map(|id| json!({
"merged_at":null, "merged":false,
"number":id, "iid":id, "title":"Sized PR",
"state":if provider == Provider::Gitlab { "opened" } else { "open" },
"user":{"login":"author"}, "author":{"username":"author"},
"created_at":"2024-01-01T00:00:00Z",
"updated_at":"2024-01-02T00:00:00Z",
"base":{"ref":"main"}, "head":{"ref":"topic"},
"target_branch":"main", "source_branch":"topic",
"additions":match id { 7 => Some(123), 8 => Some(0), _ => None },
"deletions":match id { 7 => Some(45), 8 => Some(0), _ => None }
})).collect()))
})
.unwrap();
let description = |id| {
&page
.entries
.iter()
.find(|entry| entry.number == id)
.unwrap()
.description
};
assert!(description(7).contains("open · +123 -45 · topic → main"));
assert!(description(8).contains("open · +0 -0 · topic → main"));
assert!(description(9).contains("size unavailable"));
assert!(!description(9).contains("+0 -0"));
}
}
#[test] #[test]
fn pages_are_bounded_newest_first_summaries_without_historical_metadata() { fn pages_are_bounded_newest_first_summaries_without_historical_metadata() {
for (provider, url, query) in [ for (provider, url, query) in [
@@ -27,34 +648,38 @@ fn pages_are_bounded_newest_first_summaries_without_historical_metadata() {
), ),
] { ] {
let forge = parse(url, None).unwrap(); let forge = parse(url, None).unwrap();
let mut calls = 0; let page = forge.page_with(false, 3, |url, body| {
let page = forge.page_with(false, 3, |url| { if url.ends_with("/user") {
calls += 1; return Err("unauthenticated fixture".into());
}
if body.is_some() {
return Err("statistics unavailable".into());
}
assert_eq!(url, format!("{}?{query}", forge.endpoint)); assert_eq!(url, format!("{}?{query}", forge.endpoint));
Ok(json!([ Ok(json!([
{"number": 1, "iid": 1, "title": "Older", "state": if provider == Provider::Gitlab { "opened" } else { "open" }, {"number": 1, "iid": 1, "title": "Older", "state": if provider == Provider::Gitlab { "opened" } else { "open" },
"user": null, "author": null, "merged_at": null, "merged": false, "created_at": "2024-01-01T01:00:00+01:00"}, "user": null, "author": null, "merged_at": null, "merged": false, "created_at": "2024-01-01T01:00:00+01:00", "updated_at":"2024-02-01T01:00:00+01:00"},
{"number": 2, "iid": 2, "title": "Newer", "state": if provider == Provider::Gitlab { "opened" } else { "open" }, {"number": 2, "iid": 2, "title": "Newer", "state": if provider == Provider::Gitlab { "opened" } else { "open" },
"user": {"login": "author"}, "author": {"username": "author"}, "merged_at": null, "merged": false, "user": {"login": "author"}, "author": {"username": "author"}, "merged_at": null, "merged": false,
"created_at": "2024-01-01T00:00:00.001Z", "diff_refs": null, "head": {"sha": "not-a-commit"}} "created_at": "2024-01-01T00:00:00.001Z", "updated_at":"2024-02-01T00:00:00.001Z", "diff_refs": null, "head": {"sha": "not-a-commit"}}
])) ]))
}).unwrap(); }).unwrap();
assert_eq!(calls, 1);
assert_eq!( assert_eq!(
page.entries.iter().map(|p| p.number).collect::<Vec<_>>(), page.entries.iter().map(|p| p.number).collect::<Vec<_>>(),
[2, 1] [2, 1]
); );
assert_eq!(page.entries[0].description, "author · open");
assert!(page.entries[1].description.contains("deleted user")); assert!(page.entries[1].description.contains("deleted user"));
assert_eq!(page.entries[1].updated_at, "2024-02-01T00:00:00.000000000Z");
assert_eq!(page.entries[0].updated_at, "2024-02-01T00:00:00.001000000Z");
assert!( assert!(
page.has_more, page.has_more,
"A short, server-capped page is not exhaustion" "A short, server-capped page is not exhaustion"
); );
let empty = forge.page_with(false, 4, |_| Ok(json!([]))).unwrap(); let empty = forge.page_with(false, 4, |_, _| Ok(json!([]))).unwrap();
assert!(empty.entries.is_empty() && !empty.has_more); assert!(empty.entries.is_empty() && !empty.has_more);
assert!( assert!(
forge forge
.page_with(false, 0, |_| panic!("Page zero must not request")) .page_with(false, 0, |_, _| panic!("Page zero must not request"))
.is_err() .is_err()
); );
} }
@@ -67,7 +692,13 @@ fn gitlab_closed_combines_closed_and_merged_pages_without_open_requests() {
for page in 1..=3 { for page in 1..=3 {
let mut states = Vec::new(); let mut states = Vec::new();
let result = forge let result = forge
.page_with(true, page, |url| { .page_with(true, page, |url, body| {
if url.ends_with("/user") {
return Err("unauthenticated fixture".into());
}
if body.is_some() {
return Err("statistics unavailable".into());
}
assert!(url.ends_with(&format!("&page={page}"))); assert!(url.ends_with(&format!("&page={page}")));
let state = if url.contains("?state=closed&") { let state = if url.contains("?state=closed&") {
"closed" "closed"
@@ -83,7 +714,7 @@ fn gitlab_closed_combines_closed_and_merged_pages_without_open_requests() {
_ => return Ok(json!([])), _ => return Ok(json!([])),
}; };
Ok(json!([{"iid": id, "title": state, "state": state, Ok(json!([{"iid": id, "title": state, "state": state,
"author": null, "created_at": date, "diff_refs": null}])) "author": null, "created_at": date, "updated_at": date, "diff_refs": null}]))
}) })
.unwrap(); .unwrap();
assert_eq!(states, ["closed", "merged"]); assert_eq!(states, ["closed", "merged"]);
@@ -100,9 +731,15 @@ fn gitlab_closed_combines_closed_and_merged_pages_without_open_requests() {
} }
all.sort_unstable_by(|a, b| b.created_at.cmp(&a.created_at)); all.sort_unstable_by(|a, b| b.created_at.cmp(&a.created_at));
assert_eq!(all.iter().map(|p| p.number).collect::<Vec<_>>(), [3, 2, 1]); assert_eq!(all.iter().map(|p| p.number).collect::<Vec<_>>(), [3, 2, 1]);
let raced = forge.page_with(true, 1, |url| { let raced = forge.page_with(true, 1, |url, body| {
if url.ends_with("/user") {
return Err("unauthenticated fixture".into());
}
if body.is_some() {
return Err("statistics unavailable".into());
}
Ok(json!([{"iid": 7, "title": "Raced merge", "state": if url.contains("?state=merged&") { "merged" } else { "closed" }, Ok(json!([{"iid": 7, "title": "Raced merge", "state": if url.contains("?state=merged&") { "merged" } else { "closed" },
"author": null, "created_at": "2024-01-01T00:00:00Z"}])) "author": null, "created_at": "2024-01-01T00:00:00Z", "updated_at": "2024-01-02T00:00:00Z"}]))
}).unwrap(); }).unwrap();
assert_eq!(raced.entries.len(), 1); assert_eq!(raced.entries.len(), 1);
assert!(raced.entries[0].description.contains("merged")); assert!(raced.entries[0].description.contains("merged"));
@@ -124,7 +761,9 @@ fn timestamps_normalize_offsets_precision_and_calendar_boundaries() {
"2024-01-01T00:00:00.000000001Z", "2024-01-01T00:00:00.000000001Z",
), ),
] { ] {
assert_eq!(created_at(&json!({"created_at": input})).unwrap(), expected); for key in ["created_at", "updated_at"] {
assert_eq!(timestamp(&json!({(key): input}), key).unwrap(), expected);
}
} }
for input in [ for input in [
"", "",
@@ -139,11 +778,13 @@ fn timestamps_normalize_offsets_precision_and_calendar_boundaries() {
"0001-01-01T00:00:00+01:00", "0001-01-01T00:00:00+01:00",
"9999-12-31T23:00:00-02:00", "9999-12-31T23:00:00-02:00",
] { ] {
for key in ["created_at", "updated_at"] {
assert!( assert!(
created_at(&json!({"created_at": input})).is_err(), timestamp(&json!({(key): input}), key).is_err(),
"{input}" "{key}: {input}"
); );
} }
}
} }
#[test] #[test]
+148
View File
@@ -0,0 +1,148 @@
use super::*;
use crate::pull_requests::{Direction, ReviewFilter, SortField, SortRule};
struct Fixture(PathBuf);
impl Fixture {
fn new() -> Self {
let path = std::env::temp_dir().join(format!(
"vamp-pr-preferences-{}-{}",
std::process::id(),
NEXT_TEMP.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir(&path).unwrap();
Self(path)
}
fn path(&self) -> PathBuf {
self.0.join("state/vamp/pull_requests.json")
}
}
impl Drop for Fixture {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.0);
}
}
#[test]
fn paths_use_absolute_xdg_state_or_home_without_reading_environment() {
assert_eq!(
path_from(Some(OsStr::new("/state")), Some(OsStr::new("/home"))).unwrap(),
PathBuf::from("/state/vamp/pull_requests.json")
);
for xdg in [None, Some(OsStr::new("")), Some(OsStr::new("relative"))] {
assert_eq!(
path_from(xdg, Some(OsStr::new("/home"))).unwrap(),
PathBuf::from("/home/.local/state/vamp/pull_requests.json")
);
}
assert!(path_from(None, None).is_err());
assert!(path_from(None, Some(OsStr::new("relative"))).is_err());
}
#[test]
fn loading_is_lazy_and_applied_preferences_round_trip_atomically() {
let fixture = Fixture::new();
let path = fixture.path();
let (store, mut preferences, notice) = Store::load(Ok(path.clone()));
assert_eq!(preferences, Preferences::default());
assert!(notice.is_none());
assert!(!path.parent().unwrap().exists());
preferences.filters = vec![ReviewFilter::Approved];
preferences.sort.insert(
SortField::UpdatedAt,
SortRule {
precedence: Some(1),
direction: Direction::Asc,
},
);
store.save(&preferences).unwrap();
let (_, loaded, notice) = Store::load(Ok(path.clone()));
assert_eq!(loaded.sort, preferences.sort);
assert_eq!(loaded.filters, Preferences::default().filters);
assert!(!fs::read_to_string(&path).unwrap().contains("filters"));
assert!(notice.is_none());
preferences.filters.clear();
preferences.sort.clear();
store.save(&preferences).unwrap();
assert_eq!(Store::load(Ok(path)).1, Preferences::default());
assert_eq!(
fs::read_dir(fixture.0.join("state/vamp")).unwrap().count(),
1
);
}
#[test]
fn previously_saved_filters_are_ignored_without_changing_sort_or_file() {
let fixture = Fixture::new();
let path = fixture.path();
fs::create_dir_all(path.parent().unwrap()).unwrap();
for filters in [
r#"[]"#,
r#"["approved"]"#,
r#"["unknown"]"#,
r#"{"invalid":true}"#,
] {
let bytes = format!(
r#"{{"version":1,"preferences":{{"sort":{{"created_at":{{"precedence":1,"direction":"asc"}}}},"filters":{filters}}}}}"#
);
fs::write(&path, &bytes).unwrap();
let (_, loaded, notice) = Store::load(Ok(path.clone()));
assert!(notice.is_none());
assert_eq!(loaded.filters, Preferences::default().filters);
assert_eq!(loaded.sort[&SortField::CreatedAt].direction, Direction::Asc);
assert_eq!(fs::read_to_string(&path).unwrap(), bytes);
}
}
#[test]
fn corrupt_incompatible_and_invalid_data_is_preserved_even_after_apply() {
let fixture = Fixture::new();
let path = fixture.path();
fs::create_dir_all(path.parent().unwrap()).unwrap();
for bytes in [
"not json",
r#"{"version":2,"preferences":{}}"#,
r#"{"version":1,"preferences":{"sort":{"unknown":{}}}}"#,
r#"{"version":1,"preferences":{"sort":{"updated_at":{"direction":"up"}}}}"#,
r#"{"version":1,"preferences":{"sort":{"updated_at":{"precedence":0}}}}"#,
r#"{"version":1,"preferences":{"sort":{"updated_at":{"precedence":1},"created_at":{"precedence":1}}}}"#,
] {
fs::write(&path, bytes).unwrap();
let (store, loaded, notice) = Store::load(Ok(path.clone()));
assert_eq!(loaded, Preferences::default());
assert!(notice.unwrap().contains("session-only"));
assert!(store.save(&loaded).unwrap_err().contains("preserved"));
assert_eq!(fs::read_to_string(&path).unwrap(), bytes);
}
}
#[test]
fn failed_writes_and_newly_incompatible_data_are_reported_without_replacement() {
let fixture = Fixture::new();
let path = fixture.path();
let (store, preferences, _) = Store::load(Ok(path.clone()));
fs::write(fixture.0.join("state"), "keep this file").unwrap();
assert!(
store
.save(&preferences)
.unwrap_err()
.contains("session-only")
);
assert_eq!(
fs::read_to_string(fixture.0.join("state")).unwrap(),
"keep this file"
);
fs::remove_file(fixture.0.join("state")).unwrap();
fs::create_dir_all(path.parent().unwrap()).unwrap();
let incompatible = r#"{"version":9,"preferences":{}}"#;
fs::write(&path, incompatible).unwrap();
assert!(
store
.save(&preferences)
.unwrap_err()
.contains("unsupported")
);
assert_eq!(fs::read_to_string(path).unwrap(), incompatible);
}
+74
View File
@@ -463,6 +463,80 @@ fn working_jj_conflicted_parent_uses_cli_projection_without_snapshotting() {
} }
} }
#[test]
fn jj_catalog_exposes_fixed_metadata_and_merge_parents_without_snapshotting() {
let temp = Temporary::new().unwrap();
let root = &temp.0;
fixture_command(root, "jj", &["git", "init", "--no-colocate", "."]);
fixture_command(root, "jj", &["describe", "-m", "Base"]);
let id = |root: &Path| {
fixture_command(
root,
"jj",
&[
"--ignore-working-copy",
"log",
"--no-graph",
"-r",
"@",
"-T",
"commit_id",
],
)
};
let base = id(root);
fixture_command(root, "jj", &["bookmark", "create", "base"]);
fixture_command(root, "jj", &["new", &base, "-m", "Left"]);
let left = id(root);
fixture_command(root, "jj", &["new", &base, "-m", "Right"]);
let right = id(root);
fixture_command(root, "jj", &["new", &left, &right, "-m", "Merge"]);
let current = id(root);
let operation = fixture_command(
root,
"jj",
&[
"--ignore-working-copy",
"op",
"log",
"--no-graph",
"-n",
"1",
"-T",
"id",
],
);
let mut repository = Repository::open(root, Arc::new(AtomicBool::new(false))).unwrap();
let catalog = repository.catalog().unwrap();
let merge = &catalog.graph[&current];
assert_eq!(merge.parents, [left, right]);
assert_eq!(merge.author, "Picker Author");
assert_eq!(merge.timestamp, "2001-01-01 00:00");
assert_eq!(merge.description, "Merge");
assert!(!merge.change_id.is_empty());
assert!(merge.current);
assert_eq!(catalog.graph[&base].bookmarks, "base");
assert!(!catalog.graph[&base].current);
assert!(catalog.graph[&"0".repeat(40)].immutable);
assert_eq!(
fixture_command(
root,
"jj",
&[
"--ignore-working-copy",
"op",
"log",
"--no-graph",
"-n",
"1",
"-T",
"id"
]
),
operation
);
}
#[test] #[test]
fn cancellation_kills_pipe_holding_children_and_drains_both_streams() { fn cancellation_kills_pipe_holding_children_and_drains_both_streams() {
let temp = Temporary::new().unwrap(); let temp = Temporary::new().unwrap();
+212 -5
View File
@@ -1,5 +1,72 @@
use super::*; use super::*;
#[test]
fn text_excerpts_use_detected_languages_and_cannot_close_their_own_fences() {
use crate::plugin::TextPosition;
for (path, content, start_row, expected) in [
(
"source.hon",
"[8]Builtin",
0,
"```hon\n[8]Builtin\n```\nFeedback **outside**\n",
),
(
"source.rs",
"let value = \"界\";\n",
0,
"```rust\nlet value = \"界\";\n```\nFeedback **outside**\n",
),
(
"Makefile",
"all:\n\techo ok",
0,
"```makefile\nall:\n\techo ok\n```\nFeedback **outside**\n",
),
(
"script",
"#!/usr/bin/env python3\nprint('界')\n",
1,
"```python\nprint('界')\n```\nFeedback **outside**\n",
),
(
"unknown.data",
"e\u{301}👩‍💻\n界",
0,
"```\ne\u{301}👩‍💻\n界\n```\nFeedback **outside**\n",
),
(
"example.md",
"```rust\n````\n```",
0,
"`````markdown\n```rust\n````\n```\n`````\nFeedback **outside**\n",
),
] {
let mut review = Review::default();
review.comments.push(Comment {
id: 1,
resolved: false,
body: "Feedback **outside**".into(),
anchor: Anchor {
revision: "snapshot".into(),
path: path.into(),
side: Side::After,
start: TextPosition {
row: start_row,
column: 0,
},
end: TextPosition {
row: content.split('\n').count() - 1,
column: content.rsplit('\n').next().unwrap().graphemes(true).count(),
},
content: content.into(),
},
});
let text = review.format_text(false);
assert!(text.ends_with(expected), "{path}: {text}");
}
}
struct Directory(PathBuf); struct Directory(PathBuf);
impl Drop for Directory { impl Drop for Directory {
fn drop(&mut self) { fn drop(&mut self) {
@@ -84,7 +151,7 @@ fn database_restarts_preserve_identity_and_exact_stale_anchors() {
let exported = fs::read(&path).unwrap(); let exported = fs::read(&path).unwrap();
let json: serde_json::Value = serde_json::from_slice(&exported).unwrap(); let json: serde_json::Value = serde_json::from_slice(&exported).unwrap();
assert_eq!(json["comments"][0]["resolved"], true); assert_eq!(json["comments"][0]["resolved"], true);
assert_eq!(json["version"], 4); assert_eq!(json["version"], 5);
assert_eq!(json["reviewed_files"][0]["after"], "live 👩‍🔬\r\n"); assert_eq!(json["reviewed_files"][0]["after"], "live 👩‍🔬\r\n");
assert!(json["reviewed_files"][1]["after"].is_null()); assert!(json["reviewed_files"][1]["after"].is_null());
assert_eq!(json["reviewed_files"][2]["after"], ""); assert_eq!(json["reviewed_files"][2]["after"], "");
@@ -122,6 +189,139 @@ fn database_restarts_preserve_identity_and_exact_stale_anchors() {
assert_eq!(loaded.verdict, verdict); assert_eq!(loaded.verdict, verdict);
} }
#[test]
fn comparison_scopes_roundtrip_in_order_and_cannot_move_saved_reviews() {
let directory = directory();
let root = directory.0.canonicalize().unwrap();
let storage = root.join("storage");
let mut store = Store::open(&storage).unwrap();
let mut source = Review::new(root.clone());
store.save(&mut source).unwrap();
let endpoints = ["frozen-base".to_owned(), "working:frozen-tip".to_owned()];
let mut comparison = Review::new(root.clone());
comparison.comparison = Some(endpoints.clone());
store.save(&mut comparison).unwrap();
let id = comparison.storage_id.unwrap();
assert!(source.summary_text().contains("Scope: source"));
assert!(
comparison
.summary_text()
.contains("Scope: comparison frozen-base → working:frozen-tip")
);
let mut reversed = Review::new(root.clone());
reversed.comparison = Some([endpoints[1].clone(), endpoints[0].clone()]);
store.save(&mut reversed).unwrap();
drop(store);
let mut store = Store::open(&storage).unwrap();
let reviews = store.list(&root).unwrap();
assert_eq!(reviews.len(), 3);
assert_eq!(reviews[0].comparison, reversed.comparison);
assert_eq!(reviews[1].comparison, Some(endpoints.clone()));
assert_eq!(reviews[2].comparison, None);
let mut loaded = store.load(&root, id).unwrap();
let path = root.join("comparison.json");
loaded.save(&path).unwrap();
let json: serde_json::Value = serde_json::from_slice(&fs::read(&path).unwrap()).unwrap();
assert_eq!(json["comparison"], serde_json::json!(endpoints));
let imported = Review::load(&path, &root).unwrap();
assert_eq!(imported.comparison, loaded.comparison);
loaded.comparison = None;
assert!(store.save(&mut loaded).unwrap_err().contains("scope"));
assert_eq!(store.load(&root, id).unwrap().comparison, Some(endpoints));
assert_eq!(loaded.storage_revision, 1);
source.comparison = reversed.comparison;
assert!(store.save(&mut source).is_err());
assert_eq!(
store
.load(&root, source.storage_id.unwrap())
.unwrap()
.comparison,
None
);
}
#[test]
fn invalid_comparison_scopes_and_old_json_are_rejected_without_replacing_data() {
let directory = directory();
let root = directory.0.canonicalize().unwrap();
let mut review = Review::new(root.clone());
let path = root.join("review.json");
review.save(&path).unwrap();
let original = fs::read(&path).unwrap();
let mut store = Store::open(&root.join("storage")).unwrap();
for endpoint in ["", "bad\nrevision", "bad\0revision"] {
for side in [0, 1] {
let mut endpoints = ["base".to_owned(), "tip".to_owned()];
endpoints[side] = endpoint.into();
review.comparison = Some(endpoints);
assert!(review.save(&path).unwrap_err().contains("immutable"));
assert!(store.save(&mut review).unwrap_err().contains("immutable"));
assert_eq!(fs::read(&path).unwrap(), original);
assert_eq!((review.storage_id, review.storage_revision), (None, 0));
}
}
assert!(store.list(&root).unwrap().is_empty());
let mut old: serde_json::Value = serde_json::from_slice(&original).unwrap();
old["version"] = 4.into();
old.as_object_mut().unwrap().remove("comparison");
let bytes = serde_json::to_vec(&old).unwrap();
fs::write(&path, &bytes).unwrap();
assert!(
Review::load(&path, &root)
.unwrap_err()
.contains("Unsupported review version 4")
);
assert_eq!(fs::read(&path).unwrap(), bytes);
let fresh = Review::new(root.clone());
assert!(fresh.save(&path).is_err());
assert_eq!(fs::read(&path).unwrap(), bytes);
}
#[test]
fn comparison_rows_enforce_complete_pairs_and_the_review_size_limit() {
let directory = directory();
let root = directory.0.canonicalize().unwrap();
let mut store = Store::open(&root.join("storage")).unwrap();
let mut review = Review::new(root.clone());
store.save(&mut review).unwrap();
let id = review.storage_id.unwrap();
for update in [
"before_revision = 'base'",
"after_revision = 'tip'",
"before_revision = '', after_revision = 'tip'",
"before_revision = 'base', after_revision = ''",
] {
assert!(
store
.connection
.execute(&format!("UPDATE reviews SET {update} WHERE id = ?1"), [id],)
.is_err()
);
}
store
.connection
.execute(
"UPDATE reviews SET before_revision = 'base', after_revision = char(10) WHERE id = ?1",
[id],
)
.unwrap();
assert!(store.load(&root, id).unwrap_err().contains("immutable"));
store
.connection
.execute(
"UPDATE reviews SET after_revision = hex(zeroblob(?1)) WHERE id = ?2",
params![(LIMIT / 2) as i64, id],
)
.unwrap();
assert!(store.load(&root, id).unwrap_err().contains("64 MiB"));
assert!(store.list(&root).unwrap_err().contains("64 MiB"));
review.comparison = Some(["base".into(), "x".repeat(LIMIT)]);
assert!(store.save(&mut review).unwrap_err().contains("64 MiB"));
let path = root.join("too-large.json");
assert!(review.save(&path).unwrap_err().contains("64 MiB"));
assert!(!path.exists());
}
#[test] #[test]
fn database_repository_identity_is_canonical_and_independent() { fn database_repository_identity_is_canonical_and_independent() {
let first = directory(); let first = directory();
@@ -201,9 +401,16 @@ fn database_conflicts_and_locked_writes_keep_drafts_and_identity() {
#[test] #[test]
fn incompatible_database_schemas_are_preserved() { fn incompatible_database_schemas_are_preserved() {
let previous = format!( let previous = format!(
"{REVIEWS_SCHEMA}; {COMMENTS_SCHEMA}; "CREATE TABLE reviews (
id INTEGER PRIMARY KEY CHECK (id > 0),
root TEXT NOT NULL,
revision INTEGER NOT NULL CHECK (revision > 0),
summary TEXT NOT NULL,
verdict TEXT CHECK (verdict IN ('looks_good', 'changes_requested'))
) STRICT;
{COMMENTS_SCHEMA}; {REVIEWED_FILES_SCHEMA};
INSERT INTO reviews VALUES (1, '/old/repo', 1, 'Preserve me', 'looks_good'); INSERT INTO reviews VALUES (1, '/old/repo', 1, 'Preserve me', 'looks_good');
PRAGMA user_version = 2" PRAGMA user_version = 3"
); );
for schema in [ for schema in [
previous.as_str(), previous.as_str(),
@@ -732,12 +939,12 @@ fn exact_grapheme_ranges_roundtrip_and_reject_invalid_coordinates() {
.as_object_mut() .as_object_mut()
.unwrap() .unwrap()
.remove("resolved"); .remove("resolved");
for version in [2, 3, 4] { for version in [2, 3, 4, 5] {
missing_resolution["version"] = version.into(); missing_resolution["version"] = version.into();
let bytes = serde_json::to_vec(&missing_resolution).unwrap(); let bytes = serde_json::to_vec(&missing_resolution).unwrap();
fs::write(&path, &bytes).unwrap(); fs::write(&path, &bytes).unwrap();
let error = Review::load(&path, &root).unwrap_err(); let error = Review::load(&path, &root).unwrap_err();
if version < 4 { if version < 5 {
assert!(error.contains("Unsupported review version")); assert!(error.contains("Unsupported review version"));
} else { } else {
assert!(error.contains("missing field")); assert!(error.contains("missing field"));
+38
View File
@@ -105,3 +105,41 @@ fn existing_storage_is_read_only_and_unchanged() {
} }
std::fs::remove_dir_all(directory).unwrap(); std::fs::remove_dir_all(directory).unwrap();
} }
#[test]
fn comment_mutations_require_positive_explicit_ids_and_reject_all() {
for command in ["delete", "resolve"] {
for ids in [
vec![],
vec!["1"],
vec!["0", "1"],
vec!["-1", "1"],
vec!["9223372036854775808", "1"],
vec!["all", "1"],
vec!["1", "0"],
vec!["1", "-1"],
vec!["1", "18446744073709551616"],
vec!["1", "--json"],
] {
let mut args = std::iter::once(command).chain(ids).map(OsString::from);
assert!(Request::parse(&mut args).is_err());
}
let mut args = [command, "9223372036854775807", "18446744073709551615"]
.into_iter()
.map(OsString::from);
let mut request = Request::parse(&mut args).unwrap();
assert_eq!(request.id, Some(i64::MAX));
let (action, id) = request.comment.as_ref().unwrap();
assert_eq!(*id, u64::MAX);
assert!(matches!(
(command, action),
("delete", CommentAction::Delete) | ("resolve", CommentAction::Resolve)
));
assert!(request.option(OsStr::new("--all"), &mut args).is_err());
request.option(OsStr::new("--json"), &mut args).unwrap();
let mut repo = [OsString::from("checkout")].into_iter();
request.option(OsStr::new("--repo"), &mut repo).unwrap();
assert!(request.json);
assert_eq!(request.repo, Some(PathBuf::from("checkout")));
}
}
+227 -5
View File
@@ -106,7 +106,7 @@ fn review_directory_resolves_config_paths_and_keeps_session_startup_lazy() {
} }
#[test] #[test]
fn review_directory_wire_field_is_required_nullable_and_validated() { fn review_directory_and_review_symbol_wire_fields_are_required_and_validated() {
let mut frame = serde_json::json!({ let mut frame = serde_json::json!({
"version": 1, "type": "config", "plugins": [], "lsp": {}, "bindings": [], "version": 1, "type": "config", "plugins": [], "lsp": {}, "bindings": [],
"review_directory": null, "leader": "space", "review_directory": null, "leader": "space",
@@ -119,6 +119,7 @@ fn review_directory_wire_field_is_required_nullable_and_validated() {
"diff_context_lines": 10, "diff_expand_lines": 15, "diff_context_lines": 10, "diff_expand_lines": 15,
"diff_view_mode": "split", "diff_split_orientation": "vertical", "diff_view_mode": "split", "diff_split_orientation": "vertical",
"resolve_history_layout": "columns", "resolve_history_layout": "columns",
"pull_request_review_requested_symbol": "🙏", "pull_request_approved_symbol": "👍",
"diff_follow_working_copy": true "diff_follow_working_copy": true
}); });
for value in [serde_json::Value::Null, serde_json::json!("reviews")] { for value in [serde_json::Value::Null, serde_json::json!("reviews")] {
@@ -136,10 +137,83 @@ fn review_directory_wire_field_is_required_nullable_and_validated() {
frame["review_directory"] = value; frame["review_directory"] = value;
assert!(serde_json::from_value::<Response>(frame.clone()).is_err()); assert!(serde_json::from_value::<Response>(frame.clone()).is_err());
} }
frame["review_directory"] = serde_json::Value::Null;
for field in [
"pull_request_review_requested_symbol",
"pull_request_approved_symbol",
] {
for value in ["", "👩‍🚀 R", "ok"] {
frame[field] = serde_json::json!(value);
assert!(serde_json::from_value::<Response>(frame.clone()).is_ok());
}
for value in [
serde_json::json!(null),
serde_json::json!(false),
serde_json::json!(7),
serde_json::json!([]),
serde_json::json!({}),
serde_json::json!("\0"),
serde_json::json!("\n"),
serde_json::json!("\t"),
serde_json::json!("\u{7f}"),
serde_json::json!("\u{85}"),
] {
frame[field] = value;
assert!(serde_json::from_value::<Response>(frame.clone()).is_err());
}
frame.as_object_mut().unwrap().remove(field);
assert!(serde_json::from_value::<Response>(frame.clone()).is_err());
frame[field] = serde_json::json!("");
}
frame.as_object_mut().unwrap().remove("review_directory"); frame.as_object_mut().unwrap().remove("review_directory");
assert!(serde_json::from_value::<Response>(frame).is_err()); assert!(serde_json::from_value::<Response>(frame).is_err());
} }
#[test]
fn pull_request_symbols_load_defaults_custom_and_empty_and_reject_invalid_ruby_values() {
let fixture = Fixture::new();
let path = fixture.file("config.rb", "Vamp.configure { |_| }");
let config = load_config(&path).unwrap();
assert_eq!(config.pull_request_review_requested_symbol, "🙏");
assert_eq!(config.pull_request_approved_symbol, "👍");
for symbol in ["", "👩‍🚀 R", "ok"] {
let value = serde_json::to_string(symbol).unwrap();
let path = fixture.file("config.rb", &format!(
"Vamp.configure {{ |c| c.pull_request_review_requested_symbol = {value}; c.pull_request_approved_symbol = {value} }}"
));
let config = load_config(&path).unwrap();
assert_eq!(config.pull_request_review_requested_symbol, symbol);
assert_eq!(config.pull_request_approved_symbol, symbol);
}
for field in [
"pull_request_review_requested_symbol",
"pull_request_approved_symbol",
] {
for value in [
"nil",
"false",
"7",
"[]",
"{}",
":ok",
r#""\n""#,
r#""\t""#,
r#""\0""#,
r#""\u007f""#,
r#""\u0085""#,
] {
let path = fixture.file(
"config.rb",
&format!("Vamp.configure {{ |c| c.{field} = {value} }}"),
);
assert!(
load_config(&path).unwrap_err().contains(field),
"{field}: {value}"
);
}
}
}
#[test] #[test]
fn tab_spaces_follow_active_language_and_preserve_native_edit_semantics() { fn tab_spaces_follow_active_language_and_preserve_native_edit_semantics() {
let fixture = Fixture::new(); let fixture = Fixture::new();
@@ -544,9 +618,9 @@ fn config_leader_defaults_custom_keys_validation_and_required_wire_field() {
assert!(load_config(&path).unwrap_err().contains(error), "{value}"); assert!(load_config(&path).unwrap_err().contains(error), "{value}");
} }
for frame in [ for frame in [
r#"{"type":"config","version":1,"plugins":[],"lsp":{},"review_directory":null,"bindings":[],"file_explorer_side":"right","file_picker_view":"list","file_explorer_view":"tree","clipboard_mode":"system","git_blame":true,"git_gutter":"bar","scroll_distance":0,"highlight_trailing_whitespace":false,"whitespace_characters":{},"whitespace_scope":"all","tab_spaces":null,"language_tab_spaces":{},"top_bar":{},"bottom_bar":{},"popup":{"command":{},"search":{}},"labels":{},"diff_context_lines":10,"diff_expand_lines":15,"diff_view_mode":"split","diff_split_orientation":"vertical","diff_follow_working_copy":true,"resolve_history_layout":"columns"}"#, r#"{"type":"config","version":1,"plugins":[],"lsp":{},"review_directory":null,"bindings":[],"file_explorer_side":"right","file_picker_view":"list","file_explorer_view":"tree","clipboard_mode":"system","git_blame":true,"git_gutter":"bar","scroll_distance":0,"highlight_trailing_whitespace":false,"whitespace_characters":{},"whitespace_scope":"all","tab_spaces":null,"language_tab_spaces":{},"top_bar":{},"bottom_bar":{},"popup":{"command":{},"search":{}},"labels":{},"diff_context_lines":10,"diff_expand_lines":15,"diff_view_mode":"split","diff_split_orientation":"vertical","diff_follow_working_copy":true,"pull_request_review_requested_symbol":"🙏","pull_request_approved_symbol":"👍","resolve_history_layout":"columns"}"#,
r#"{"type":"config","version":1,"plugins":[],"lsp":{},"review_directory":null,"bindings":[],"leader":null,"file_explorer_side":"right","file_picker_view":"list","file_explorer_view":"tree","clipboard_mode":"system","git_blame":true,"git_gutter":"bar","scroll_distance":0,"highlight_trailing_whitespace":false,"whitespace_characters":{},"whitespace_scope":"all","tab_spaces":null,"language_tab_spaces":{},"top_bar":{},"bottom_bar":{},"popup":{"command":{},"search":{}},"labels":{},"diff_context_lines":10,"diff_expand_lines":15,"diff_view_mode":"split","diff_split_orientation":"vertical","diff_follow_working_copy":true,"resolve_history_layout":"columns"}"#, r#"{"type":"config","version":1,"plugins":[],"lsp":{},"review_directory":null,"bindings":[],"leader":null,"file_explorer_side":"right","file_picker_view":"list","file_explorer_view":"tree","clipboard_mode":"system","git_blame":true,"git_gutter":"bar","scroll_distance":0,"highlight_trailing_whitespace":false,"whitespace_characters":{},"whitespace_scope":"all","tab_spaces":null,"language_tab_spaces":{},"top_bar":{},"bottom_bar":{},"popup":{"command":{},"search":{}},"labels":{},"diff_context_lines":10,"diff_expand_lines":15,"diff_view_mode":"split","diff_split_orientation":"vertical","diff_follow_working_copy":true,"pull_request_review_requested_symbol":"🙏","pull_request_approved_symbol":"👍","resolve_history_layout":"columns"}"#,
r#"{"type":"config","version":1,"plugins":[],"lsp":{},"review_directory":null,"bindings":[],"leader":7,"file_explorer_side":"right","file_picker_view":"list","file_explorer_view":"tree","clipboard_mode":"system","git_blame":true,"git_gutter":"bar","scroll_distance":0,"highlight_trailing_whitespace":false,"whitespace_characters":{},"whitespace_scope":"all","tab_spaces":null,"language_tab_spaces":{},"top_bar":{},"bottom_bar":{},"popup":{"command":{},"search":{}},"labels":{},"diff_context_lines":10,"diff_expand_lines":15,"diff_view_mode":"split","diff_split_orientation":"vertical","diff_follow_working_copy":true,"resolve_history_layout":"columns"}"#, r#"{"type":"config","version":1,"plugins":[],"lsp":{},"review_directory":null,"bindings":[],"leader":7,"file_explorer_side":"right","file_picker_view":"list","file_explorer_view":"tree","clipboard_mode":"system","git_blame":true,"git_gutter":"bar","scroll_distance":0,"highlight_trailing_whitespace":false,"whitespace_characters":{},"whitespace_scope":"all","tab_spaces":null,"language_tab_spaces":{},"top_bar":{},"bottom_bar":{},"popup":{"command":{},"search":{}},"labels":{},"diff_context_lines":10,"diff_expand_lines":15,"diff_view_mode":"split","diff_split_orientation":"vertical","diff_follow_working_copy":true,"pull_request_review_requested_symbol":"🙏","pull_request_approved_symbol":"👍","resolve_history_layout":"columns"}"#,
] { ] {
assert!(serde_json::from_str::<Response>(frame).is_err(), "{frame}"); assert!(serde_json::from_str::<Response>(frame).is_err(), "{frame}");
} }
@@ -579,6 +653,69 @@ fn git_gutter_config_modes_default_and_rejection() {
} }
} }
#[test]
fn cursor_config_partial_shapes_and_invalid_options() {
use crate::cursor::CursorShape::{Bar, Block, Underline};
let fixture = Fixture::new();
for (options, mode_colors, shapes) in [
(
r#"{ insert: :bar, "visual" => "underline" }"#,
true,
[Block, Bar, Block, Block, Underline],
),
(
r#"{ mode_colors: false, normal: "bar", insert: :underline, command: :bar, search: "underline", visual: :block }"#,
false,
[Bar, Underline, Bar, Underline, Block],
),
(
r#"{ "mode_colors" => true, normal: :underline, insert: "block", command: "underline", search: :bar, visual: "bar" }"#,
true,
[Underline, Block, Underline, Bar, Bar],
),
] {
let path = fixture.file(
"config.rb",
&format!("Vamp.configure {{ |config| config.cursor = {options} }}"),
);
let cursor = load_config(&path).unwrap().cursor;
assert_eq!(cursor.mode_colors, mode_colors);
assert_eq!(
[
cursor.normal,
cursor.insert,
cursor.command,
cursor.search,
cursor.visual
],
shapes
);
}
for options in [
"nil",
"false",
"[]",
"{ mode_colors: nil }",
"{ mode_colors: 1 }",
r#"{ mode_colors: "true" }"#,
"{ insert: nil }",
"{ insert: false }",
"{ insert: 1 }",
"{ insert: :beam }",
r#"{ normal: "" }"#,
"{ unknown: :block }",
"{ 1 => :block }",
r#"{ insert: :bar, "insert" => :block }"#,
] {
let path = fixture.file(
"config.rb",
&format!("Vamp.configure {{ |config| config.cursor = {options} }}"),
);
assert!(load_config(&path).is_err(), "{options}");
}
}
#[test] #[test]
fn git_blame_boolean_config_typed_toggle_palette_and_wire_validation() { fn git_blame_boolean_config_typed_toggle_palette_and_wire_validation() {
let fixture = Fixture::new(); let fixture = Fixture::new();
@@ -632,6 +769,7 @@ end
"labels": {}, "diff_context_lines": 10, "diff_expand_lines": 15, "labels": {}, "diff_context_lines": 10, "diff_expand_lines": 15,
"diff_view_mode": "split", "diff_split_orientation": "vertical", "diff_view_mode": "split", "diff_split_orientation": "vertical",
"resolve_history_layout": "columns", "resolve_history_layout": "columns",
"pull_request_review_requested_symbol": "🙏", "pull_request_approved_symbol": "👍",
"diff_follow_working_copy": true "diff_follow_working_copy": true
}); });
assert!(serde_json::from_value::<Response>(frame.clone()).is_ok()); assert!(serde_json::from_value::<Response>(frame.clone()).is_ok());
@@ -773,6 +911,7 @@ end"#,
"labels": {}, "diff_context_lines": 10, "diff_expand_lines": 15, "labels": {}, "diff_context_lines": 10, "diff_expand_lines": 15,
"diff_view_mode": "split", "diff_split_orientation": "vertical", "diff_view_mode": "split", "diff_split_orientation": "vertical",
"resolve_history_layout": "columns", "resolve_history_layout": "columns",
"pull_request_review_requested_symbol": "🙏", "pull_request_approved_symbol": "👍",
"diff_follow_working_copy": true "diff_follow_working_copy": true
}); });
for value in ["all", "leading"] { for value in ["all", "leading"] {
@@ -1036,6 +1175,7 @@ fn config_diff_excerpt_counts_accept_custom_values_and_reject_invalid_values() {
"clipboard_mode": "system", "diff_context_lines": 0, "diff_expand_lines": 7, "clipboard_mode": "system", "diff_context_lines": 0, "diff_expand_lines": 7,
"diff_view_mode": "split", "diff_split_orientation": "vertical", "diff_view_mode": "split", "diff_split_orientation": "vertical",
"resolve_history_layout": "columns", "resolve_history_layout": "columns",
"pull_request_review_requested_symbol": "🙏", "pull_request_approved_symbol": "👍",
"diff_follow_working_copy": true "diff_follow_working_copy": true
}); });
for setting in ["diff_context_lines", "diff_expand_lines"] { for setting in ["diff_context_lines", "diff_expand_lines"] {
@@ -1148,6 +1288,7 @@ fn config_scroll_distance_accepts_nil_and_counts_and_rejects_invalid_values() {
"diff_context_lines": 10, "diff_expand_lines": 15, "diff_context_lines": 10, "diff_expand_lines": 15,
"diff_view_mode": "split", "diff_split_orientation": "vertical", "diff_view_mode": "split", "diff_split_orientation": "vertical",
"resolve_history_layout": "columns", "resolve_history_layout": "columns",
"pull_request_review_requested_symbol": "🙏", "pull_request_approved_symbol": "👍",
"diff_follow_working_copy": true, "scroll_distance": 0 "diff_follow_working_copy": true, "scroll_distance": 0
}); });
for distance in [None, Some(0), Some(7), Some(usize::MAX)] { for distance in [None, Some(0), Some(7), Some(usize::MAX)] {
@@ -1202,6 +1343,7 @@ fn lsp_configuration_is_disabled_unless_explicitly_enabled() {
r#"Vamp.configure do |config| r#"Vamp.configure do |config|
config.lsp["rust"] = false config.lsp["rust"] = false
config.lsp["python"] = false config.lsp["python"] = false
config.lsp["typst"] = false
config.lsp["not-a-preset"] = false config.lsp["not-a-preset"] = false
end"#, end"#,
] { ] {
@@ -1221,13 +1363,15 @@ fn lsp_presets_custom_languages_and_overrides_reach_native_configuration() {
config.lsp["rust"] = true config.lsp["rust"] = true
config.lsp["python"] = true config.lsp["python"] = true
config.lsp["ruby"] = true config.lsp["ruby"] = true
config.lsp["typst"] = true
end"#, end"#,
); );
let config = load_config(&path).unwrap(); let config = load_config(&path).unwrap();
assert_eq!(config.lsp.len(), 4); assert_eq!(config.lsp.len(), 5);
for (language, command, extension) in [ for (language, command, extension) in [
("rust", &["rust-analyzer"][..], "rs"), ("rust", &["rust-analyzer"][..], "rs"),
("ruby", &["solargraph", "stdio"][..], "rb"), ("ruby", &["solargraph", "stdio"][..], "rb"),
("typst", &["tinymist", "lsp"][..], "typ"),
] { ] {
let server = config let server = config
.lsp .lsp
@@ -1582,6 +1726,7 @@ fn lsp_wire_configuration_is_resolved_after_decoding() {
"clipboard_mode": "system", "diff_context_lines": 10, "diff_expand_lines": 15, "clipboard_mode": "system", "diff_context_lines": 10, "diff_expand_lines": 15,
"diff_view_mode": "split", "diff_split_orientation": "vertical", "diff_view_mode": "split", "diff_split_orientation": "vertical",
"resolve_history_layout": "columns", "resolve_history_layout": "columns",
"pull_request_review_requested_symbol": "🙏", "pull_request_approved_symbol": "👍",
"diff_follow_working_copy": true "diff_follow_working_copy": true
}); });
let Response::Config(config) = serde_json::from_value::<Response>(frame.clone()).unwrap() let Response::Config(config) = serde_json::from_value::<Response>(frame.clone()).unwrap()
@@ -2277,3 +2422,80 @@ fn ruby_rejects_invalid_document_context_and_sync_async_dsl_usage() {
plugin.host.child.is_none() && plugin.host.reader.is_none() && plugin.host.writer.is_none() plugin.host.child.is_none() && plugin.host.reader.is_none() && plugin.host.writer.is_none()
); );
} }
#[test]
fn pull_request_preferences_distinguish_unset_nil_and_explicit_sections() {
use crate::pull_requests::{Direction, ReviewFilter, SortField};
let fixture = Fixture::new();
for assignment in [
"",
"config.pull_request_sort = nil; config.pull_request_filters = nil",
] {
let path = fixture.file(
"config.rb",
&format!("Vamp.configure {{ |config| {assignment} }}"),
);
let config = load_config(&path).unwrap();
assert!(config.pull_request_sort.is_none());
assert!(config.pull_request_filters.is_none());
}
let path = fixture.file(
"config.rb",
r#"
Vamp.configure do |config|
config.pull_request_sort = {
updated_at: {precedence: 1, direction: :desc},
created_at: {direction: :asc}
}
config.pull_request_filters = [:requested, :approved]
end
"#,
);
let config = load_config(&path).unwrap();
let sort = config.pull_request_sort.unwrap();
assert_eq!(sort[&SortField::UpdatedAt].precedence, Some(1));
assert_eq!(sort[&SortField::UpdatedAt].direction, Direction::Desc);
assert_eq!(sort[&SortField::CreatedAt].precedence, None);
assert_eq!(sort[&SortField::CreatedAt].direction, Direction::Asc);
assert_eq!(
config.pull_request_filters.unwrap(),
[ReviewFilter::Requested, ReviewFilter::Approved]
);
let path = fixture.file("config.rb", "Vamp.configure { |config| config.pull_request_sort = {}; config.pull_request_filters = [] }");
let config = load_config(&path).unwrap();
assert!(config.pull_request_sort.unwrap().is_empty());
assert!(config.pull_request_filters.unwrap().is_empty());
}
#[test]
fn pull_request_preferences_reject_unknown_values_and_invalid_ranks() {
let fixture = Fixture::new();
for (field, value) in [
("sort", "[]"),
("sort", "{unknown: {}}"),
("sort", "{updated_at: []}"),
("sort", "{updated_at: {unknown: 1}}"),
("sort", "{updated_at: {direction: :up}}"),
("sort", "{updated_at: {direction: nil}}"),
("sort", "{updated_at: {precedence: 0}}"),
("sort", "{updated_at: {precedence: 5}}"),
("sort", "{updated_at: {precedence: 1.0}}"),
(
"sort",
"{updated_at: {precedence: 1}, created_at: {precedence: 1}}",
),
("filters", "{}"),
("filters", "[:unknown]"),
("filters", "[:requested, :requested]"),
] {
let path = fixture.file(
"config.rb",
&format!("Vamp.configure {{ |config| config.pull_request_{field} = {value} }}"),
);
let error = load_config(&path).unwrap_err();
assert!(
error.contains(&format!("pull_request_{field}")),
"{value}: {error}"
);
}
}
+177
View File
@@ -556,6 +556,7 @@ fn checkout_diff_polling_uses_injected_interval_independently_of_endpoint_follow
id, id,
Ok(DiffOutcome::Catalog(Catalog { Ok(DiffOutcome::Catalog(Catalog {
kind: RepoKind::Git, kind: RepoKind::Git,
graph: Default::default(),
notice: None, notice: None,
entries: [ entries: [
RevisionTarget::Working, RevisionTarget::Working,
@@ -1481,6 +1482,23 @@ end
assert_eq!(session.editor().lines(), &["a!bc"]); assert_eq!(session.editor().lines(), &["a!bc"]);
} }
#[test]
fn configured_pull_request_symbols_reach_editor() {
let fixture = Fixture::new();
fixture.file("buffer.txt", "abc");
let session = fixture.open(
r#"Vamp.configure do |config|
config.pull_request_review_requested_symbol = "👩‍🚀 review"
config.pull_request_approved_symbol = ""
end"#,
);
assert_eq!(
session.editor().pull_request_review_requested_symbol,
"👩‍🚀 review"
);
assert_eq!(session.editor().pull_request_approved_symbol, "");
}
#[test] #[test]
fn diff_display_preferences_survive_reopening() { fn diff_display_preferences_survive_reopening() {
use crate::{diff::ViewMode, panes::SplitAxis}; use crate::{diff::ViewMode, panes::SplitAxis};
@@ -3708,6 +3726,7 @@ fn async_responses_edit_only_current_bound_working_after_and_refresh_projection(
id, id,
Ok(DiffOutcome::Catalog(Catalog { Ok(DiffOutcome::Catalog(Catalog {
kind: RepoKind::Git, kind: RepoKind::Git,
graph: Default::default(),
notice: None, notice: None,
entries: vec![ entries: vec![
revision(RevisionTarget::Commit("base".into()), "base"), revision(RevisionTarget::Commit("base".into()), "base"),
@@ -3819,3 +3838,161 @@ fn async_responses_edit_only_current_bound_working_after_and_refresh_projection(
session.editor.execute("diff.close"); session.editor.execute("diff.close");
assert!(session.editor.dirty()); assert!(session.editor.dirty());
} }
#[test]
fn applied_pull_request_filters_survive_picker_reopen_but_not_restart() {
use crate::pull_requests::ReviewFilter;
let fixture = Fixture::new();
let path = fixture.0.join("state/pull_requests.json");
let mut session =
EditorSession::open_with_preferences_path(None, vec![], None, Some(Ok(path.clone())))
.unwrap();
assert!(!path.exists());
session.editor.execute("pull_requests");
// Consume the queued listing so menu input cannot start a forge worker.
assert!(session.editor.take_diff_request().is_some());
session.handle(Input::Ctrl('f'));
session.handle(Input::Char(' '));
assert!(!path.exists());
session.handle(Input::Escape);
assert_eq!(
session.editor.pull_request_preferences,
crate::pull_requests::Preferences::default()
);
assert!(!path.exists());
session.handle(Input::Ctrl('f'));
session.handle(Input::Char(' '));
session.handle(Input::Down);
session.handle(Input::Char(' '));
assert!(!path.exists());
session.handle(Input::Enter);
assert!(!path.exists());
assert!(!session.editor.pull_request_preferences_changed);
assert_eq!(
session.editor.pull_request_preferences.filters,
[ReviewFilter::Other]
);
session.handle(Input::Escape);
session.editor.execute("pull_requests");
assert!(session.editor.take_diff_request().is_some());
session.handle(Input::Ctrl('f'));
session.handle(Input::Enter);
assert_eq!(
session.editor.pull_request_preferences.filters,
[ReviewFilter::Other]
);
// A sort edit still persists, without carrying the active filter to disk.
session.handle(Input::Ctrl('s'));
session.handle(Input::Char('1'));
session.handle(Input::Enter);
assert!(path.exists());
let reopened =
EditorSession::open_with_preferences_path(None, vec![], None, Some(Ok(path))).unwrap();
assert_eq!(
reopened.editor.pull_request_preferences.filters,
crate::pull_requests::Preferences::default().filters
);
assert_eq!(reopened.editor.pull_request_configured, [false, false]);
}
#[test]
fn configured_pull_request_sections_replace_only_their_persisted_section() {
use crate::pull_requests::{Direction, Preferences, ReviewFilter, SortField, SortRule};
let fixture = Fixture::new();
let path = fixture.0.join("state/pull_requests.json");
let (store, mut preferences, _) =
crate::pull_request_preferences::Store::load(Ok(path.clone()));
preferences.filters = vec![ReviewFilter::Other];
preferences.sort.insert(
SortField::UpdatedAt,
SortRule {
precedence: Some(1),
direction: Direction::Asc,
},
);
store.save(&preferences).unwrap();
let bytes = fs::read(&path).unwrap();
for (configuration, expected, configured) in [
(
"config.pull_request_sort = {}",
Preferences {
sort: Default::default(),
filters: Preferences::default().filters,
},
[true, false],
),
(
"config.pull_request_filters = []",
Preferences {
sort: preferences.sort.clone(),
filters: vec![],
},
[false, true],
),
(
"config.pull_request_sort = {created_at: {direction: :asc}}; config.pull_request_filters = nil",
Preferences {
sort: [(
SortField::CreatedAt,
SortRule {
precedence: None,
direction: Direction::Asc,
},
)]
.into(),
filters: Preferences::default().filters,
},
[true, false],
),
] {
let config = fixture.file(
"config.rb",
&format!("Vamp.configure {{ |config| {configuration} }}"),
);
let session = EditorSession::open_with_preferences_path(
None,
vec![],
Some(&config),
Some(Ok(path.clone())),
)
.unwrap();
assert_eq!(session.editor.pull_request_preferences, expected);
assert_eq!(session.editor.pull_request_configured, configured);
assert_eq!(fs::read(&path).unwrap(), bytes);
}
}
#[test]
fn corrupt_pull_request_storage_warns_and_apply_remains_session_only() {
let fixture = Fixture::new();
let path = fixture.file("pull_requests.json", "preserve invalid bytes");
let mut session =
EditorSession::open_with_preferences_path(None, vec![], None, Some(Ok(path.clone())))
.unwrap();
assert!(session.editor.message().contains("session-only"));
session.editor.execute("pull_requests");
assert!(session.editor.take_diff_request().is_some());
session.handle(Input::Ctrl('s'));
session.handle(Input::Char('1'));
session.handle(Input::Enter);
assert!(session.editor.message().contains("preserved"));
assert_eq!(fs::read_to_string(path).unwrap(), "preserve invalid bytes");
}
#[test]
fn failed_pull_request_save_keeps_applied_session_preferences_and_reports_failure() {
let fixture = Fixture::new();
let parent = fixture.0.join("state");
let path = parent.join("pull_requests.json");
let mut session =
EditorSession::open_with_preferences_path(None, vec![], None, Some(Ok(path))).unwrap();
fs::write(&parent, "do not replace").unwrap();
session.editor.execute("pull_requests");
assert!(session.editor.take_diff_request().is_some());
session.handle(Input::Ctrl('s'));
session.handle(Input::Char('1'));
session.handle(Input::Enter);
assert!(session.editor.message().contains("session-only"));
assert!(!session.editor.pull_request_preferences_changed);
assert_eq!(fs::read_to_string(parent).unwrap(), "do not replace");
}
+34
View File
@@ -648,6 +648,40 @@ fn honey_highlights_declarations_literals_edits_and_markdown_fences() {
} }
} }
#[test]
fn typst_highlights_markup_code_edits_and_fenced_languages() {
let source = "= Heading\n#let message = \"hello é\"\n#let count = 42\n\
#text(message) // note\n*strong* and _emphasis_\n\
```rust\nfn main() { let n = 7; }\n```";
let mut cache = self::cache(source, "main.typ");
assert_eq!(cache.language(), Some("Typst"));
assert!(!cache.tree.as_ref().unwrap().root_node().has_error());
for (row, token, kind) in [
(0, "Heading", SyntaxKind::Markup),
(1, "let", SyntaxKind::Keyword),
(1, "hello é", SyntaxKind::String),
(2, "42", SyntaxKind::Number),
(3, "text", SyntaxKind::Function),
(3, "// note", SyntaxKind::Comment),
(4, "strong", SyntaxKind::Markup),
(4, "emphasis", SyntaxKind::Markup),
(6, "fn", SyntaxKind::Keyword),
(6, "7", SyntaxKind::Number),
] {
assert_token(&cache, source, row, token, kind);
}
let edited = source.replace("\"hello é\"", "false");
cache.update(&lines(&edited), Some(Path::new("main.typ")), 1);
assert_token(&cache, &edited, 1, "false", SyntaxKind::Keyword);
assert_fresh(&cache, &edited, "main.typ");
for tag in ["typst", "typ"] {
let markdown = format!("```{tag}\n#let count = 42\n```");
let injected = self::cache(&markdown, "README.md");
assert_token(&injected, &markdown, 1, "let", SyntaxKind::Keyword);
assert_token(&injected, &markdown, 1, "42", SyntaxKind::Number);
}
}
#[test] #[test]
fn filenames_shebang_save_as_and_tsx_use_actual_grammar_identity() { fn filenames_shebang_save_as_and_tsx_use_actual_grammar_identity() {
let source = lines("\u{feff}#!/usr/bin/env python3\nreturn 42"); let source = lines("\u{feff}#!/usr/bin/env python3\nreturn 42");
+2
View File
@@ -22,6 +22,8 @@ fn selected_files_and_auxiliary_grammars_are_registered() {
("main.C", "C++"), ("main.C", "C++"),
("main.go", "Go"), ("main.go", "Go"),
("main.zig", "Zig"), ("main.zig", "Zig"),
("main.typ", "Typst"),
("main.TYP", "Typst"),
] { ] {
assert_eq!( assert_eq!(
detect(Some(Path::new(filename)), None).map(|spec| spec.name), detect(Some(Path::new(filename)), None).map(|spec| spec.name),
+909 -254
View File
File diff suppressed because it is too large Load Diff