Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 448c3bf477 | |||
| 815fcccbe8 | |||
| c1bff63111 |
@@ -26,9 +26,13 @@ vamp --review resolve 1 3 --repo . # Mark comment 3 resolved, preserving its fee
|
||||
|
||||
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.
|
||||
|
||||
`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. `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.
|
||||
|
||||
|
||||
@@ -1,3 +1,26 @@
|
||||
- [x] improve: conflict resolution view.
|
||||
- two-pane mode:
|
||||
- currently, we display the two panes as if it were a diff, where the left side will be displayed as if the code in question will be removed, and the left pane will display the code in question as if it will be added.
|
||||
- this doesn't really make sense, since code on either side (either version) will be added/removed.
|
||||
- i'm wondering if it would make sense to display in both panels both changes that would and changes that would add code, meaning:
|
||||
- if some code would be removed, it would display in red with a minus
|
||||
- if some code would be added, it would display in green with a plus
|
||||
- this would be the case for both panes
|
||||
- probably something similar for three-pane mode would make sense.
|
||||
- [x] improve: code commenting format. example of comment in current format:
|
||||
<attachment>
|
||||
Comment 14 [unresolved] source/sema/resolve.hon (after) 22:9–22:19 @ working:a3b4159a340b3546e2108bc2dc0e7c302fc6d84b
|
||||
[8]Builtin
|
||||
can't we do `[_]Builtin` here instead for array size inference? if not, this is probably an oversight in the brolang compiler 🤔
|
||||
</attachment>
|
||||
- would probably be nice to instead do this though, if possible, i.e. wrapping the code snippet in question in a codeblock annotated with the right language, e.g.:
|
||||
<attachment>
|
||||
Comment 14 [unresolved] source/sema/resolve.hon (after) 22:9–22:19 @ working:a3b4159a340b3546e2108bc2dc0e7c302fc6d84b
|
||||
```hon
|
||||
[8]Builtin
|
||||
```
|
||||
can't we do `[_]Builtin` here instead for array size inference? if not, this is probably an oversight in the brolang compiler 🤔
|
||||
</attachment>
|
||||
- [ ] 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.
|
||||
- preserve explicit PR identity and reviewed commit IDs; validate anchors against GitHub's PR diff and recheck the PR head before submission.
|
||||
|
||||
@@ -17,10 +17,10 @@ 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.
|
||||
- `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.
|
||||
- `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.
|
||||
`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.
|
||||
- `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. 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 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` owns tab-local review state independently of comparisons. Ordinary repository source buffers and diff panes share the comment editor, immutable anchors, storage, and review commands. 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. 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`. The session supplies the configured or XDG default directory; direct `Editor` callers inject a directory with `set_review_directory` to enable persistence.
|
||||
`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.
|
||||
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.
|
||||
|
||||
+7
-3
@@ -98,11 +98,13 @@ Diff-stat checks cover unopened frozen files, additions/deletions/renames, binar
|
||||
|
||||
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. Live PTY smoke selects a source line, creates a comment with `:comment`, saves with `:w`, verifies its exact excerpt through the review CLI, restarts with `:review.next`, and reopens after changing the selected source to observe the preserved original snapshot. Review state is tab-owned rather than comparison-owned; diff regression coverage remains required.
|
||||
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.
|
||||
|
||||
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.
|
||||
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.
|
||||
@@ -117,9 +119,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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
+13
-5
@@ -504,8 +504,8 @@ Local review buffers (comments, summaries, overview, and stored-review selector)
|
||||
| `:review.verdict looks_good` | Record **Looks good** |
|
||||
| `:review.verdict changes_requested` | Record **Changes requested**; `none` clears the verdict |
|
||||
| `:review.save [path]` | Commit to SQLite; with a path, also export JSON for sharing |
|
||||
| `:review.open [id or path]` | Show stored reviews, open a stored review ID, or import a JSON review as a new review |
|
||||
| `:review.new` | Create a separate stored review for the current repository |
|
||||
| `: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 |
|
||||
| `:review.new` | Create another stored review for the current comparison or ordinary-source scope |
|
||||
|
||||
File checkmarks remain diff-specific (`:diff.review.toggle`).
|
||||
|
||||
@@ -513,17 +513,21 @@ Comment and summary text is committed only by **`:w`** or **`:review.save`**, wh
|
||||
|
||||
`: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.
|
||||
|
||||
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. 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 `:review.open id`. Use `:review.new` for another independent review.
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
@@ -573,6 +577,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.
|
||||
|
||||
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.
|
||||
|
||||
| Command | Behavior |
|
||||
@@ -588,6 +594,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.
|
||||
|
||||
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”.
|
||||
|
||||
**`: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.
|
||||
|
||||
+321
-89
@@ -356,6 +356,9 @@ pub(crate) struct ColumnLine<'a> {
|
||||
pub side: Focus,
|
||||
pub source_row: usize,
|
||||
pub numbers: [Option<usize>; 2],
|
||||
/// Change polarity is independent of the native source/pane.
|
||||
pub polarity: Focus,
|
||||
pub native: bool,
|
||||
pub changed: bool,
|
||||
pub emphasize: bool,
|
||||
pub newline: bool,
|
||||
@@ -409,6 +412,46 @@ impl<'a> ColumnView<'a> {
|
||||
DisplayRow::Line(index) => index,
|
||||
};
|
||||
let row = self.diff.rows.get(index)?;
|
||||
let side = self.diff.display_focus(display).unwrap_or(self.info.focus);
|
||||
if let Some(conflict) = &self.diff.conflict {
|
||||
let Some(line) = &conflict.rows[index][usize::from(side == Focus::After)] else {
|
||||
return Some(ColumnRow::Gap);
|
||||
};
|
||||
let source = if line.removed {
|
||||
&conflict.base
|
||||
} else if side == Focus::Before {
|
||||
&self.file.before
|
||||
} else {
|
||||
&self.file.after
|
||||
};
|
||||
return Some(ColumnRow::Text(ColumnLine {
|
||||
text: source.get(line.source).map(String::as_str).or(Some("")),
|
||||
side,
|
||||
source_row: line.source,
|
||||
numbers: if line.removed {
|
||||
[None; 2]
|
||||
} else {
|
||||
[row.before, row.after]
|
||||
},
|
||||
polarity: if line.removed {
|
||||
Focus::Before
|
||||
} else {
|
||||
Focus::After
|
||||
},
|
||||
native: !line.removed,
|
||||
changed: line.changed,
|
||||
emphasize: true,
|
||||
newline: line.source + 1 < source.len()
|
||||
|| if line.removed {
|
||||
conflict.base.last().is_some_and(String::is_empty)
|
||||
} else if side == Focus::Before {
|
||||
self.file.before_eof
|
||||
} else {
|
||||
self.file.after_eof
|
||||
},
|
||||
changes: Cow::Borrowed(&line.changes),
|
||||
}));
|
||||
}
|
||||
let side = if self.info.unified {
|
||||
self.diff.display_focus(display).unwrap_or(self.info.focus)
|
||||
} else {
|
||||
@@ -436,6 +479,8 @@ impl<'a> ColumnView<'a> {
|
||||
self.diff.display_source_row(Focus::Before, display),
|
||||
self.diff.display_source_row(Focus::After, display),
|
||||
],
|
||||
polarity: side,
|
||||
native: true,
|
||||
changed: row.kind == RowKind::Changed
|
||||
|| (before && row.kind == RowKind::Removed)
|
||||
|| (!before && row.kind == RowKind::Added),
|
||||
@@ -459,6 +504,35 @@ impl<'a> ColumnView<'a> {
|
||||
}))
|
||||
}
|
||||
|
||||
/// Wrapping includes display-only removals without computing character diffs.
|
||||
/// Removed base rows occupy a disjoint cache-key space from native rows.
|
||||
pub fn text_row(&self, display: usize) -> Option<(usize, &'a str)> {
|
||||
let DisplayRow::Line(index) = *self.diff.display_rows.get(display)? else {
|
||||
return None;
|
||||
};
|
||||
let side = self.info.focus;
|
||||
if self
|
||||
.diff
|
||||
.display_focus(display)
|
||||
.is_some_and(|focus| focus != side)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
if let Some(conflict) = &self.diff.conflict {
|
||||
let line = conflict.rows[index][usize::from(side == Focus::After)].as_ref()?;
|
||||
if line.removed {
|
||||
return Some((usize::MAX - line.source, &conflict.base[line.source]));
|
||||
}
|
||||
}
|
||||
let source = self.diff.display_source_row(side, display)?;
|
||||
let lines = if side == Focus::Before {
|
||||
&self.file.before
|
||||
} else {
|
||||
&self.file.after
|
||||
};
|
||||
Some((source, lines.get(source).map_or("", String::as_str)))
|
||||
}
|
||||
|
||||
/// Caret mapping stays on this view's native side, even in unified display.
|
||||
pub fn native_row(&self, display: usize) -> Option<usize> {
|
||||
self.diff.display_source_row(self.info.focus, display)
|
||||
@@ -489,9 +563,105 @@ impl<'a> ColumnView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Base-relative candidate patches with display-only removed base lines.
|
||||
#[derive(Debug)]
|
||||
struct ConflictChanges {
|
||||
base: Vec<String>,
|
||||
rows: Vec<[Option<ConflictLine>; 2]>,
|
||||
base_rows: Vec<Option<usize>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ConflictLine {
|
||||
source: usize,
|
||||
removed: bool,
|
||||
changed: bool,
|
||||
changes: Vec<[std::ops::Range<usize>; 2]>,
|
||||
}
|
||||
|
||||
impl ConflictChanges {
|
||||
fn new(base: &[String], candidates: [&[String]; 2]) -> Self {
|
||||
let mut pairs = candidates.map(|candidate| {
|
||||
let mut diff = DiffState::new();
|
||||
diff.set_resolver_text(base, candidate, None);
|
||||
diff
|
||||
});
|
||||
for pair in &mut pairs {
|
||||
if pair.lazy_changes {
|
||||
for row in &mut pair.rows {
|
||||
if row.kind == RowKind::Changed {
|
||||
// Large inputs keep the existing whole-line fallback instead of
|
||||
// eagerly running a character diff for every changed row.
|
||||
row.changes = vec![[0..usize::MAX, 0..usize::MAX]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let [left, right] = pairs.map(|pair| pair.rows.into_iter().peekable());
|
||||
let (mut left, mut right) = (left, right);
|
||||
let mut result = Self {
|
||||
base: base.to_vec(),
|
||||
rows: Vec::new(),
|
||||
base_rows: Vec::new(),
|
||||
};
|
||||
while left.peek().is_some() || right.peek().is_some() {
|
||||
let insertion = left.peek().is_some_and(|row| row.before.is_none())
|
||||
|| right.peek().is_some_and(|row| row.before.is_none());
|
||||
let rows = [&mut left, &mut right].map(|rows| {
|
||||
if rows
|
||||
.peek()
|
||||
.is_some_and(|row| !insertion || row.before.is_none())
|
||||
{
|
||||
rows.next()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
let base_row = rows.iter().flatten().find_map(|row| row.before);
|
||||
let removal =
|
||||
base_row.is_some() && rows.iter().flatten().any(|row| row.kind != RowKind::Equal);
|
||||
let line = |row: &AlignedRow, removed: bool| {
|
||||
let source = if removed { row.before } else { row.after }?;
|
||||
let side = usize::from(!removed);
|
||||
Some(ConflictLine {
|
||||
source,
|
||||
removed,
|
||||
changed: row.kind != RowKind::Equal,
|
||||
changes: row
|
||||
.changes
|
||||
.iter()
|
||||
.map(|change| [change[side].clone(), change[side].clone()])
|
||||
.collect(),
|
||||
})
|
||||
};
|
||||
if removal {
|
||||
result.rows.push(std::array::from_fn(|side| {
|
||||
let row = rows[side].as_ref()?;
|
||||
line(row, row.kind != RowKind::Equal)
|
||||
}));
|
||||
result.base_rows.push(base_row);
|
||||
}
|
||||
let additions = std::array::from_fn(|side| {
|
||||
let row = rows[side].as_ref()?;
|
||||
if removal && row.kind == RowKind::Equal {
|
||||
None
|
||||
} else {
|
||||
line(row, false)
|
||||
}
|
||||
});
|
||||
if additions.iter().any(Option::is_some) {
|
||||
result.rows.push(additions);
|
||||
result.base_rows.push(if removal { None } else { base_row });
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
/// Immutable left/base/right conflict History, aligned at shared base rows.
|
||||
pub(crate) struct HistoryComparison {
|
||||
columns: [DiffState; 3],
|
||||
candidates: DiffState,
|
||||
base: DiffState,
|
||||
}
|
||||
|
||||
/// A read-only projection for the existing diff painter.
|
||||
@@ -499,7 +669,6 @@ pub(crate) struct HistoryColumn<'a> {
|
||||
pub diff: &'a DiffState,
|
||||
pub file: &'a ChangedFile,
|
||||
pub focus: Focus,
|
||||
pub lines: &'a [String],
|
||||
}
|
||||
|
||||
impl<'a> HistoryColumn<'a> {
|
||||
@@ -514,92 +683,54 @@ impl<'a> HistoryColumn<'a> {
|
||||
|
||||
impl HistoryComparison {
|
||||
pub fn new(sources: [&str; 3]) -> Self {
|
||||
let [left, base, right] =
|
||||
let [left, base_lines, right] =
|
||||
sources.map(|text| text.split('\n').map(str::to_owned).collect::<Vec<_>>());
|
||||
let mut columns: [DiffState; 3] = std::array::from_fn(|_| DiffState::new());
|
||||
columns[0].set_resolver_text(&base, &left);
|
||||
columns[1].set_resolver_text(&base, &base);
|
||||
columns[2].set_resolver_text(&base, &right);
|
||||
let mut left = std::mem::take(&mut columns[0].rows).into_iter().peekable();
|
||||
let mut right = std::mem::take(&mut columns[2].rows).into_iter().peekable();
|
||||
columns[1].rows.clear();
|
||||
// Stitch the existing pairwise alignments at their shared base rows.
|
||||
while left.peek().is_some() || right.peek().is_some() {
|
||||
let insertion = left.peek().is_some_and(|row| row.before.is_none())
|
||||
|| right.peek().is_some_and(|row| row.before.is_none());
|
||||
let take_left = left
|
||||
.peek()
|
||||
.is_some_and(|row| !insertion || row.before.is_none());
|
||||
let take_right = right
|
||||
.peek()
|
||||
.is_some_and(|row| !insertion || row.before.is_none());
|
||||
let empty = || AlignedRow {
|
||||
before: None,
|
||||
after: None,
|
||||
kind: RowKind::Equal,
|
||||
changes: Vec::new(),
|
||||
};
|
||||
let left_row = if take_left {
|
||||
left.next().unwrap()
|
||||
} else {
|
||||
empty()
|
||||
};
|
||||
let right_row = if take_right {
|
||||
right.next().unwrap()
|
||||
} else {
|
||||
empty()
|
||||
};
|
||||
let base = left_row.before.or(right_row.before);
|
||||
let changed = left_row.kind != RowKind::Equal || right_row.kind != RowKind::Equal;
|
||||
let changes = left_row
|
||||
.changes
|
||||
.iter()
|
||||
.chain(&right_row.changes)
|
||||
.map(|change| [change[0].clone(), change[0].clone()])
|
||||
.collect();
|
||||
columns[1].rows.push(AlignedRow {
|
||||
before: base,
|
||||
after: base,
|
||||
kind: if changed {
|
||||
RowKind::Changed
|
||||
} else {
|
||||
RowKind::Equal
|
||||
},
|
||||
changes,
|
||||
});
|
||||
columns[0].rows.push(left_row);
|
||||
columns[2].rows.push(right_row);
|
||||
}
|
||||
for column in &mut columns {
|
||||
let mut candidates = DiffState::new();
|
||||
candidates.set_resolver_text(&left, &right, Some(&base_lines));
|
||||
let mut base = DiffState::new();
|
||||
base.set_resolver_text(&base_lines, &base_lines, None);
|
||||
let conflict = candidates.conflict.as_ref().unwrap();
|
||||
base.rows = conflict
|
||||
.base_rows
|
||||
.iter()
|
||||
.zip(&candidates.rows)
|
||||
.zip(&conflict.rows)
|
||||
.map(|((&source, row), lines)| AlignedRow {
|
||||
before: source,
|
||||
after: source,
|
||||
kind: row.kind,
|
||||
changes: lines
|
||||
.iter()
|
||||
.flatten()
|
||||
.filter(|line| line.removed)
|
||||
.flat_map(|line| line.changes.iter().cloned())
|
||||
.collect(),
|
||||
})
|
||||
.collect();
|
||||
for column in [&mut candidates, &mut base] {
|
||||
column.display_rows = (0..column.rows.len()).map(DisplayRow::Line).collect();
|
||||
column.rebuild_source_ranges();
|
||||
}
|
||||
Self { columns }
|
||||
Self { candidates, base }
|
||||
}
|
||||
|
||||
pub fn row_count(&self) -> usize {
|
||||
self.columns[0].rows.len()
|
||||
self.candidates.rows.len()
|
||||
}
|
||||
|
||||
pub fn column(&self, index: usize) -> HistoryColumn<'_> {
|
||||
let diff = &self.columns[index];
|
||||
let diff = if index == 1 {
|
||||
&self.base
|
||||
} else {
|
||||
&self.candidates
|
||||
};
|
||||
let file = &diff.comparison.as_ref().unwrap().files[0];
|
||||
let focus = if index == 1 {
|
||||
Focus::Before
|
||||
} else {
|
||||
let focus = if index == 2 {
|
||||
Focus::After
|
||||
};
|
||||
let lines = if focus == Focus::Before {
|
||||
&file.before
|
||||
} else {
|
||||
&file.after
|
||||
Focus::Before
|
||||
};
|
||||
HistoryColumn {
|
||||
diff,
|
||||
file,
|
||||
focus,
|
||||
lines,
|
||||
}
|
||||
HistoryColumn { diff, file, focus }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -642,6 +773,9 @@ pub struct DiffState {
|
||||
pub error: Option<String>,
|
||||
pub comparison: Option<Comparison>,
|
||||
pub comparison_id: Option<u64>,
|
||||
/// Frozen initial endpoint identities; checkout refreshes do not select a new review.
|
||||
pub(crate) review_comparison: Option<[String; 2]>,
|
||||
review_root: Option<PathBuf>,
|
||||
pub reviewed_files: BTreeSet<usize>,
|
||||
pub(crate) snapshot_roots: [Option<PathBuf>; 2],
|
||||
pub files: Option<FilePicker>,
|
||||
@@ -660,6 +794,7 @@ pub struct DiffState {
|
||||
lazy_changes: bool,
|
||||
/// Native empty terminal rows explicitly supplied by resolver text.
|
||||
terminal_rows: [Option<usize>; 2],
|
||||
conflict: Option<ConflictChanges>,
|
||||
excerpt_ranges: Vec<(usize, usize)>,
|
||||
pub live_buffer: Option<usize>,
|
||||
pub live_revision: Option<u64>,
|
||||
@@ -708,6 +843,8 @@ impl DiffState {
|
||||
error: None,
|
||||
comparison: None,
|
||||
comparison_id: None,
|
||||
review_comparison: None,
|
||||
review_root: None,
|
||||
reviewed_files: BTreeSet::new(),
|
||||
files: None,
|
||||
snapshot_roots: [None, None],
|
||||
@@ -723,6 +860,7 @@ impl DiffState {
|
||||
display_rows: Vec::new(),
|
||||
display_sides: Vec::new(),
|
||||
source_ranges: Default::default(),
|
||||
conflict: None,
|
||||
lazy_changes: false,
|
||||
terminal_rows: [None; 2],
|
||||
excerpt_ranges: Vec::new(),
|
||||
@@ -786,7 +924,12 @@ impl DiffState {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn set_resolver_text(&mut self, draft: &[String], alternative: &[String]) {
|
||||
pub(crate) fn set_resolver_text(
|
||||
&mut self,
|
||||
draft: &[String],
|
||||
alternative: &[String],
|
||||
base: Option<&[String]>,
|
||||
) {
|
||||
fn content(lines: &[String]) -> (&[String], bool) {
|
||||
let eof = lines.len() > 1 && lines.last().is_some_and(String::is_empty);
|
||||
let content = if eof {
|
||||
@@ -809,6 +952,11 @@ impl DiffState {
|
||||
let after_terminal = (alternative.len() > after.len()).then_some(after.len());
|
||||
if self.phase == Phase::View
|
||||
&& self.terminal_rows == [before_terminal, after_terminal]
|
||||
&& self
|
||||
.conflict
|
||||
.as_ref()
|
||||
.map(|conflict| conflict.base.as_slice())
|
||||
== base
|
||||
&& self.comparison.as_ref().is_some_and(|comparison| {
|
||||
let file = &comparison.files[self.file];
|
||||
file.before == before
|
||||
@@ -836,15 +984,59 @@ impl DiffState {
|
||||
file.before_eof = before_eof;
|
||||
file.after_eof = after_eof;
|
||||
file.hunks = line_hunks(before, before_eof, after, after_eof);
|
||||
self.align_file();
|
||||
if base.is_none() {
|
||||
self.align_file();
|
||||
if before_terminal.is_some() || after_terminal.is_some() {
|
||||
self.rows.push(AlignedRow {
|
||||
before: before_terminal,
|
||||
after: after_terminal,
|
||||
kind: RowKind::Equal,
|
||||
changes: Vec::new(),
|
||||
});
|
||||
self.reset_excerpts();
|
||||
}
|
||||
}
|
||||
self.terminal_rows = [before_terminal, after_terminal];
|
||||
if before_terminal.is_some() || after_terminal.is_some() {
|
||||
self.rows.push(AlignedRow {
|
||||
before: before_terminal,
|
||||
after: after_terminal,
|
||||
kind: RowKind::Equal,
|
||||
changes: Vec::new(),
|
||||
});
|
||||
if let Some(base) = base {
|
||||
let conflict = ConflictChanges::new(base, [draft, alternative]);
|
||||
self.rows = conflict
|
||||
.rows
|
||||
.iter()
|
||||
.map(|lines| {
|
||||
let native = |side: usize| {
|
||||
lines[side]
|
||||
.as_ref()
|
||||
.filter(|line| !line.removed)
|
||||
.map(|line| line.source)
|
||||
};
|
||||
AlignedRow {
|
||||
before: native(0),
|
||||
after: native(1),
|
||||
kind: if lines.iter().flatten().any(|line| line.changed) {
|
||||
RowKind::Changed
|
||||
} else {
|
||||
RowKind::Equal
|
||||
},
|
||||
changes: Vec::new(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let base_width = base.iter().map(|line| line_width(line)).max().unwrap_or(0);
|
||||
self.max_before = draft
|
||||
.iter()
|
||||
.map(|line| line_width(line))
|
||||
.max()
|
||||
.unwrap_or(0)
|
||||
.max(base_width);
|
||||
self.max_after = alternative
|
||||
.iter()
|
||||
.map(|line| line_width(line))
|
||||
.max()
|
||||
.unwrap_or(0)
|
||||
.max(base_width);
|
||||
self.lazy_changes = false;
|
||||
self.after_widths.clear();
|
||||
self.conflict = Some(conflict);
|
||||
self.reset_excerpts();
|
||||
}
|
||||
if self.comparison.as_ref().unwrap().files[self.file]
|
||||
@@ -1034,6 +1226,13 @@ impl DiffState {
|
||||
}
|
||||
Ok(Outcome::CheckoutRefresh(Some(mut comparison)))
|
||||
| Ok(Outcome::BookmarkRefresh(mut comparison)) => {
|
||||
if bookmark_refresh {
|
||||
self.review_root = Some(
|
||||
std::fs::canonicalize(&comparison.root)
|
||||
.unwrap_or_else(|_| comparison.root.clone()),
|
||||
);
|
||||
self.review_comparison = Some(comparison.revisions.clone());
|
||||
}
|
||||
let pinned = !bookmark_refresh
|
||||
&& self
|
||||
.after
|
||||
@@ -1157,6 +1356,10 @@ impl DiffState {
|
||||
self.error = None;
|
||||
}
|
||||
Ok(Outcome::Comparison(comparison)) if expected == Some(RequestKind::Comparison) => {
|
||||
self.review_root = Some(
|
||||
std::fs::canonicalize(&comparison.root)
|
||||
.unwrap_or_else(|_| comparison.root.clone()),
|
||||
);
|
||||
self.live_files.clear();
|
||||
self.modified_after.clear();
|
||||
self.frozen_after.clear();
|
||||
@@ -1177,6 +1380,7 @@ impl DiffState {
|
||||
files.reveal_path(&file.path);
|
||||
}
|
||||
self.files = Some(files);
|
||||
self.review_comparison = Some(comparison.revisions.clone());
|
||||
self.comparison = Some(comparison);
|
||||
self.comparison_id = Some(id);
|
||||
self.snapshot_roots = [None, None];
|
||||
@@ -1708,6 +1912,7 @@ impl DiffState {
|
||||
self.phase = Phase::After;
|
||||
self.comparison = None;
|
||||
self.comparison_id = None;
|
||||
self.review_comparison = None;
|
||||
self.reviewed_files.clear();
|
||||
self.queue(operation);
|
||||
}
|
||||
@@ -2021,6 +2226,27 @@ impl DiffState {
|
||||
.files
|
||||
.get(index)
|
||||
.ok_or("No changed file is selected")?;
|
||||
if comparison
|
||||
.revisions
|
||||
.iter()
|
||||
.all(|revision| !revision.is_empty())
|
||||
{
|
||||
if !review.initialized && review.document.root.as_os_str().is_empty() {
|
||||
review.document = crate::review::Review::new(
|
||||
self.review_root
|
||||
.as_ref()
|
||||
.unwrap_or(&comparison.root)
|
||||
.clone(),
|
||||
);
|
||||
review.document.comparison = self.review_comparison.clone();
|
||||
review.initialized = true;
|
||||
}
|
||||
if &review.document.root != self.review_root.as_ref().unwrap_or(&comparison.root)
|
||||
|| review.document.comparison != self.review_comparison
|
||||
{
|
||||
return Err("Select the review for this comparison first");
|
||||
}
|
||||
}
|
||||
let reviewed = !self.reviewed_files.remove(&index);
|
||||
if reviewed {
|
||||
self.reviewed_files.insert(index);
|
||||
@@ -2031,9 +2257,6 @@ impl DiffState {
|
||||
.iter()
|
||||
.all(|revision| !revision.is_empty())
|
||||
{
|
||||
if review.document.root.as_os_str().is_empty() {
|
||||
review.document = crate::review::Review::new(comparison.root.clone());
|
||||
}
|
||||
let records = &mut review.document.reviewed_files;
|
||||
records.retain(|record| {
|
||||
record.revisions
|
||||
@@ -2068,7 +2291,9 @@ impl DiffState {
|
||||
let Some(comparison) = self.comparison.as_ref() else {
|
||||
return;
|
||||
};
|
||||
if review.document.root != comparison.root {
|
||||
if &review.document.root != self.review_root.as_ref().unwrap_or(&comparison.root)
|
||||
|| review.document.comparison != self.review_comparison
|
||||
{
|
||||
return;
|
||||
}
|
||||
let records: BTreeMap<_, _> = review
|
||||
@@ -2516,7 +2741,9 @@ impl DiffState {
|
||||
self.modified_after.insert(self.file);
|
||||
}
|
||||
let comparison = self.comparison.as_ref().unwrap();
|
||||
let record = (review.document.root == comparison.root)
|
||||
let record = (&review.document.root
|
||||
== self.review_root.as_ref().unwrap_or(&comparison.root)
|
||||
&& review.document.comparison == self.review_comparison)
|
||||
.then(|| {
|
||||
review.document.reviewed_files.iter().position(|record| {
|
||||
record.revisions
|
||||
@@ -2677,6 +2904,7 @@ impl DiffState {
|
||||
fn rebuild_file(&mut self, reset: bool) {
|
||||
self.normalize_focus();
|
||||
self.rows.clear();
|
||||
self.conflict = None;
|
||||
self.terminal_rows = [None; 2];
|
||||
self.display_rows.clear();
|
||||
self.display_sides.clear();
|
||||
@@ -2857,7 +3085,11 @@ impl DiffState {
|
||||
// Unified hunks show all removals before all additions, without alignment holes.
|
||||
for side in [Focus::Before, Focus::After] {
|
||||
for aligned in run_start..index {
|
||||
if self.source_row(side, aligned).is_some() {
|
||||
if self.source_row(side, aligned).is_some()
|
||||
|| self.conflict.as_ref().is_some_and(|conflict| {
|
||||
conflict.rows[aligned][usize::from(side == Focus::After)].is_some()
|
||||
})
|
||||
{
|
||||
self.display_rows.push(DisplayRow::Line(aligned));
|
||||
self.display_sides.push(Some(side));
|
||||
}
|
||||
|
||||
+57
-6
@@ -1694,7 +1694,7 @@ pub struct ResolverFile {
|
||||
pub seed_source: usize,
|
||||
projection: Option<crate::resolve::Projection>,
|
||||
diff: DiffState,
|
||||
comparison_key: Option<(u64, usize)>,
|
||||
comparison_key: Option<(u64, usize, Option<usize>)>,
|
||||
}
|
||||
|
||||
impl ResolverFile {
|
||||
@@ -3088,11 +3088,34 @@ impl Editor {
|
||||
let Some(buffer) = self.buffer(draft_buffer) else {
|
||||
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 first_comparison = file.diff.comparison_id.is_none();
|
||||
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 {
|
||||
Some(projection) => projection.alternative(source),
|
||||
None => Ok(file
|
||||
@@ -3141,7 +3164,7 @@ impl Editor {
|
||||
.set_context_options(self.diff_context_options.0, self.diff_context_options.1);
|
||||
let previous_id = file.diff.comparison_id;
|
||||
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 {
|
||||
self.next_diff_request = self
|
||||
.next_diff_request
|
||||
@@ -4570,6 +4593,16 @@ impl Editor {
|
||||
.as_mut()
|
||||
.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;
|
||||
if self.diff.as_ref().is_some_and(DiffState::refresh_pending)
|
||||
&& !matches!(&result, Ok(Outcome::CheckoutRefresh(None)))
|
||||
@@ -4630,8 +4663,7 @@ impl Editor {
|
||||
view.clamp(&self.active.lines);
|
||||
self.active.view = view;
|
||||
}
|
||||
if self.review_directory.is_some()
|
||||
&& self.resolver().is_none()
|
||||
if self.resolver().is_none()
|
||||
&& self
|
||||
.workspace_diff()
|
||||
.is_some_and(|diff| diff.phase == Phase::View)
|
||||
@@ -10109,6 +10141,9 @@ impl Editor {
|
||||
self.active.view.mode = Mode::Normal;
|
||||
}
|
||||
if entry.action == Action::DiffModeToggle {
|
||||
if self.local_review_close_blocked() {
|
||||
return None;
|
||||
}
|
||||
let Some(diff) = self.diff.as_mut() else {
|
||||
self.set_message("No comparison is open");
|
||||
return None;
|
||||
@@ -10122,6 +10157,19 @@ impl Editor {
|
||||
return None;
|
||||
}
|
||||
if entry.action == Action::DiffReviewToggle {
|
||||
if self
|
||||
.picker_diff()
|
||||
.is_none_or(|diff| diff.phase != Phase::View)
|
||||
{
|
||||
self.set_message("No comparison is open");
|
||||
return None;
|
||||
}
|
||||
if self.resolver().is_none()
|
||||
&& 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()
|
||||
@@ -10231,6 +10279,9 @@ impl Editor {
|
||||
self.active.view.command_line.clear();
|
||||
self.active.view.mode = Mode::Normal;
|
||||
}
|
||||
if let Err(error) = self.initialize_local_review() {
|
||||
self.set_message(format!("Local review: {error}"));
|
||||
}
|
||||
} else {
|
||||
self.set_message("The diff.close command takes no arguments");
|
||||
}
|
||||
|
||||
+70
-20
@@ -34,12 +34,15 @@ impl Editor {
|
||||
|
||||
pub(super) fn initialize_local_review(&mut self) -> Result<(), String> {
|
||||
let root = self.review_root()?;
|
||||
if self.local_review.document.root == root {
|
||||
let comparison = self.review_comparison();
|
||||
if self.local_review.document.root == root
|
||||
&& self.local_review.document.comparison == comparison
|
||||
{
|
||||
self.local_review.initialized = true;
|
||||
return Ok(());
|
||||
}
|
||||
if self.current_review_dirty() {
|
||||
return Err("Save the current review before changing repositories".into());
|
||||
return Err("Save the current review before changing review scopes".into());
|
||||
}
|
||||
let reviews = match self.review_directory.as_deref() {
|
||||
Some(directory) => crate::review::Store::open_read_only(directory)?
|
||||
@@ -49,12 +52,17 @@ impl Editor {
|
||||
None => Vec::new(),
|
||||
};
|
||||
self.detach_review_buffers();
|
||||
let mut document = Review::new(root);
|
||||
document.comparison = comparison.clone();
|
||||
self.local_review = crate::review::ReviewState {
|
||||
document: Review::new(root),
|
||||
document,
|
||||
initialized: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut reviews = reviews;
|
||||
let mut reviews: Vec<_> = reviews
|
||||
.into_iter()
|
||||
.filter(|review| review.comparison == comparison)
|
||||
.collect();
|
||||
if reviews.len() == 1 {
|
||||
self.local_review.document = reviews.pop().unwrap();
|
||||
} else if reviews.len() > 1 {
|
||||
@@ -63,8 +71,30 @@ impl Editor {
|
||||
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 let Some(diff) = self.workspace_diff() {
|
||||
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()
|
||||
@@ -73,18 +103,16 @@ impl Editor {
|
||||
})
|
||||
.ok_or_else(|| "Comparison is still loading".into());
|
||||
}
|
||||
if self.active.review_buffer.is_some()
|
||||
|| (self.active.path.is_none() && self.local_review.initialized)
|
||||
{
|
||||
return Ok(self.local_review.document.root.clone());
|
||||
}
|
||||
let path = self
|
||||
.active
|
||||
.identity
|
||||
.as_deref()
|
||||
.or(self.active.path.as_deref())
|
||||
.ok_or("Save the source file before commenting")?;
|
||||
crate::repository::discover_root(path.parent().ok_or("Source has no parent directory")?)
|
||||
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> {
|
||||
@@ -93,7 +121,12 @@ impl Editor {
|
||||
.review_directory
|
||||
.as_deref()
|
||||
.ok_or("Review storage is not configured")?;
|
||||
let reviews = crate::review::Store::open(directory)?.list(&root)?;
|
||||
let comparison = self.review_comparison();
|
||||
let reviews = crate::review::Store::open(directory)?
|
||||
.list(&root)?
|
||||
.into_iter()
|
||||
.filter(|review| review.comparison == comparison)
|
||||
.collect();
|
||||
self.show_review_selector(reviews)
|
||||
}
|
||||
|
||||
@@ -241,6 +274,10 @@ impl Editor {
|
||||
root: PathBuf,
|
||||
source: ReviewSource<'_>,
|
||||
) -> 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 {
|
||||
ReviewSource::Stored(id) => {
|
||||
let directory = self
|
||||
@@ -258,8 +295,15 @@ impl Editor {
|
||||
Some(path.to_path_buf()),
|
||||
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.
|
||||
self.detach_review_buffers();
|
||||
let state = &mut self.local_review;
|
||||
@@ -431,9 +475,6 @@ impl Editor {
|
||||
{
|
||||
return Err("This review command takes no arguments".into());
|
||||
}
|
||||
if self.local_review.document.root.as_os_str().is_empty() {
|
||||
self.local_review.document = Review::new(root.clone());
|
||||
}
|
||||
if !matches!(action, Action::ReviewSave | Action::ReviewCopy) {
|
||||
self.autosave_local_review()?;
|
||||
}
|
||||
@@ -602,7 +643,10 @@ impl Editor {
|
||||
&self,
|
||||
anchor: &Anchor,
|
||||
) -> Option<std::ops::Range<TextPosition>> {
|
||||
if self.active.review_buffer.is_some() || !anchor.revision.starts_with("working:") {
|
||||
if self.local_review.document.comparison.is_some()
|
||||
|| self.active.review_buffer.is_some()
|
||||
|| !anchor.revision.starts_with("working:")
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let path = self
|
||||
@@ -621,7 +665,9 @@ impl Editor {
|
||||
}
|
||||
|
||||
fn review_anchor_range(&self, anchor: &Anchor) -> Option<std::ops::Range<TextPosition>> {
|
||||
if let Some(diff) = self.workspace_diff() {
|
||||
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);
|
||||
@@ -642,7 +688,9 @@ impl Editor {
|
||||
)
|
||||
}
|
||||
fn add_review_comment(&mut self) -> Result<(), String> {
|
||||
if let Some(owner) = self.diff_owner {
|
||||
if self.local_review.document.comparison.is_some()
|
||||
&& let Some(owner) = self.diff_owner
|
||||
{
|
||||
if self.pane_id != owner {
|
||||
self.select_pane(owner);
|
||||
}
|
||||
@@ -801,7 +849,9 @@ impl Editor {
|
||||
let anchor = anchor.clone();
|
||||
let mut stale = !current;
|
||||
self.local_review.selected = Some(id);
|
||||
if let Some(owner) = self.diff_owner {
|
||||
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())
|
||||
|
||||
@@ -99,6 +99,8 @@ Diff: :diff (Normal); choose Before then After; Working checkout After edits liv
|
||||
Changed files: normal picker/explorer bindings, Ctrl+w close; A/M/D/R status and rename paths
|
||||
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
|
||||
:review.edit/delete [ID], :review.next/previous, :review.overview
|
||||
:review.summary; :review.verdict looks_good|changes_requested|none
|
||||
|
||||
+88
-20
@@ -195,6 +195,8 @@ pub struct ReviewedFile {
|
||||
pub struct Review {
|
||||
pub version: u32,
|
||||
pub root: PathBuf,
|
||||
/// Ordered frozen comparison endpoints; `None` is a source review.
|
||||
pub comparison: Option<[String; 2]>,
|
||||
pub summary: String,
|
||||
pub verdict: Option<Verdict>,
|
||||
pub comments: Vec<Comment>,
|
||||
@@ -231,8 +233,9 @@ impl Review {
|
||||
fs::canonicalize(&root).unwrap_or(root)
|
||||
};
|
||||
Self {
|
||||
version: 4,
|
||||
version: 5,
|
||||
root,
|
||||
comparison: None,
|
||||
summary: String::new(),
|
||||
verdict: None,
|
||||
comments: Vec::new(),
|
||||
@@ -249,12 +252,20 @@ impl Review {
|
||||
.iter()
|
||||
.filter(|comment| comment.resolved)
|
||||
.count();
|
||||
let (scope, before, arrow, after) = match &self.comparison {
|
||||
Some([before, after]) => ("comparison ", before.as_str(), " → ", after.as_str()),
|
||||
None => ("source", "", "", ""),
|
||||
};
|
||||
format!(
|
||||
"Review ID: {}{}{}\n Verdict: {}; {} unresolved, {} resolved ({} total)\n",
|
||||
"Review ID: {}{}{}\n Scope: {}{}{}{}\n Verdict: {}; {} unresolved, {} resolved ({} total)\n",
|
||||
self.storage_id
|
||||
.map_or_else(|| "null".into(), |id| id.to_string()),
|
||||
if self.summary.is_empty() { "" } else { ": " },
|
||||
self.summary,
|
||||
scope,
|
||||
before,
|
||||
arrow,
|
||||
after,
|
||||
match self.verdict {
|
||||
Some(Verdict::LooksGood) => "looks_good",
|
||||
Some(Verdict::ChangesRequested) => "changes_requested",
|
||||
@@ -279,9 +290,24 @@ impl Review {
|
||||
.filter(|comment| all || !comment.resolved)
|
||||
{
|
||||
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!(
|
||||
text,
|
||||
"\nComment {} [{}] {} ({}) {}:{}–{}:{} @ {}\n{}\n{}",
|
||||
"\nComment {} [{}] {} ({}) {}:{}–{}:{} @ {}",
|
||||
comment.id,
|
||||
if comment.resolved {
|
||||
"resolved"
|
||||
@@ -298,21 +324,31 @@ impl Review {
|
||||
anchor.end.row,
|
||||
anchor.end.column,
|
||||
anchor.revision,
|
||||
anchor.excerpt(),
|
||||
comment.body,
|
||||
)
|
||||
.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
|
||||
}
|
||||
|
||||
fn validate(&self) -> Result<(), String> {
|
||||
if self.version != 4 {
|
||||
if self.version != 5 {
|
||||
return Err(format!("Unsupported review version {}", self.version));
|
||||
}
|
||||
if !self.root.is_absolute() || !self.root.is_dir() {
|
||||
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();
|
||||
for comment in &self.comments {
|
||||
if comment.id == 0 || !ids.insert(comment.id) {
|
||||
@@ -374,7 +410,7 @@ impl Review {
|
||||
}
|
||||
let header: Header = serde_json::from_slice(bytes)
|
||||
.map_err(|error| format!("Invalid review JSON: {error}"))?;
|
||||
if header.version != 4 {
|
||||
if header.version != 5 {
|
||||
return Err(format!("Unsupported review version {}", header.version));
|
||||
}
|
||||
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,
|
||||
revision INTEGER NOT NULL CHECK (revision > 0),
|
||||
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";
|
||||
|
||||
// SQLite integers are signed; decimal text preserves the model's full u64 comment IDs.
|
||||
@@ -560,7 +603,7 @@ impl Store {
|
||||
.map_err(database_error)?
|
||||
.collect::<Result<_, _>>()
|
||||
.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!(
|
||||
"Unsupported review database schema (version {version}); existing data was not changed"
|
||||
));
|
||||
@@ -628,7 +671,7 @@ impl Store {
|
||||
.execute_batch(REVIEWED_FILES_SCHEMA)
|
||||
.map_err(database_error)?;
|
||||
transaction
|
||||
.pragma_update(None, "user_version", 3)
|
||||
.pragma_update(None, "user_version", 4)
|
||||
.map_err(database_error)?;
|
||||
transaction.commit().map_err(database_error)?;
|
||||
} else {
|
||||
@@ -655,7 +698,7 @@ impl Store {
|
||||
let reviews = {
|
||||
let mut statement = transaction
|
||||
.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)?;
|
||||
let mut rows = statement.query([root_text]).map_err(database_error)?;
|
||||
@@ -680,7 +723,7 @@ impl Store {
|
||||
.map_err(database_error)?;
|
||||
let review = {
|
||||
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)?;
|
||||
let mut rows = statement
|
||||
.query(params![id, root_text])
|
||||
@@ -716,6 +759,9 @@ impl Store {
|
||||
_ => return Err("Invalid review storage identity".into()),
|
||||
};
|
||||
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 {
|
||||
size = size
|
||||
.checked_add(
|
||||
@@ -750,26 +796,34 @@ impl Store {
|
||||
Some(Verdict::ChangesRequested) => Some("changes_requested"),
|
||||
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
|
||||
.connection
|
||||
.transaction_with_behavior(TransactionBehavior::Immediate)
|
||||
.map_err(database_error)?;
|
||||
let id = if let Some(id) = review.storage_id {
|
||||
let changed = transaction.execute(
|
||||
"UPDATE reviews SET revision = ?1, summary = ?2, verdict = ?3 WHERE id = ?4 AND root = ?5 AND revision = ?6",
|
||||
params![revision, review.summary, verdict, id, root, review.storage_revision],
|
||||
"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, before, after],
|
||||
).map_err(database_error)?;
|
||||
if changed != 1 {
|
||||
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
|
||||
} else {
|
||||
transaction
|
||||
.execute(
|
||||
"INSERT INTO reviews (root, revision, summary, verdict) VALUES (?1, ?2, ?3, ?4)",
|
||||
params![root, revision, review.summary, verdict],
|
||||
"INSERT INTO reviews (root, revision, summary, verdict, before_revision, after_revision) VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
|
||||
params![root, revision, review.summary, verdict, before, after],
|
||||
)
|
||||
.map_err(database_error)?;
|
||||
transaction.last_insert_rowid()
|
||||
@@ -888,9 +942,15 @@ fn stored_review(
|
||||
|row| row.get(0),
|
||||
)
|
||||
.map_err(database_error)?;
|
||||
if stored_bytes < 0
|
||||
|| stored_bytes as u64 + stored_root.len() as u64 + summary.len() as u64 > LIMIT as u64
|
||||
{
|
||||
let mut header_bytes = stored_root.len() + summary.len();
|
||||
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());
|
||||
}
|
||||
let mut review = Review {
|
||||
@@ -898,6 +958,14 @@ fn stored_review(
|
||||
..Review::default()
|
||||
};
|
||||
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
|
||||
.get::<_, Option<String>>(4)
|
||||
.map_err(database_error)?
|
||||
|
||||
@@ -109,6 +109,7 @@ fn envelope(review: &Review, all: bool, comments: bool) -> Value {
|
||||
"repository": review.root,
|
||||
"id": review.storage_id,
|
||||
"revision": review.storage_revision,
|
||||
"comparison": review.comparison,
|
||||
"summary": review.summary,
|
||||
"verdict": review.verdict,
|
||||
"counts": { "total": review.comments.len(), "resolved": resolved, "unresolved": review.comments.len() - resolved },
|
||||
|
||||
+55
-51
@@ -392,14 +392,9 @@ impl HistoryDiff {
|
||||
for column in 0..3 {
|
||||
if self.wrapping[column]
|
||||
&& self.widths[column] > 0
|
||||
&& let Some(source) = self.comparison.column(column).source_row(row)
|
||||
&& let Some((key, text)) = self.comparison.column(column).view().text_row(row)
|
||||
{
|
||||
let lines = self.comparison.column(column).lines;
|
||||
height = height.max(
|
||||
self.wrap[column]
|
||||
.segments(source, lines.get(source).map_or("", String::as_str))
|
||||
.len(),
|
||||
);
|
||||
height = height.max(self.wrap[column].segments(key, text).len());
|
||||
}
|
||||
}
|
||||
height
|
||||
@@ -432,10 +427,9 @@ impl HistoryDiff {
|
||||
let mut final_segments = [false; 2];
|
||||
let projection = self.comparison.column(column);
|
||||
let side = usize::from(projection.focus == Focus::After);
|
||||
if let Some(source) = projection.source_row(self.top.display) {
|
||||
let text = projection.lines.get(source).map_or("", String::as_str);
|
||||
if let Some((key, text)) = projection.view().text_row(self.top.display) {
|
||||
if self.wrapping[column] {
|
||||
let parts = self.wrap[column].segments(source, text);
|
||||
let parts = self.wrap[column].segments(key, text);
|
||||
segments[side] = parts.get(self.top.continuation).copied();
|
||||
final_segments[side] = self.top.continuation + 1 == parts.len();
|
||||
} else if self.top.continuation == 0 {
|
||||
@@ -4682,6 +4676,7 @@ fn paint_diff_content<'a>(
|
||||
continue;
|
||||
};
|
||||
let before = line.side == Focus::Before;
|
||||
let removed = line.polarity == Focus::Before;
|
||||
let index = line.source_row;
|
||||
let segment = segments.and_then(|segments| segments[usize::from(!before)]);
|
||||
let left = segment.map_or(left, |segment| segment.start);
|
||||
@@ -4694,7 +4689,7 @@ fn paint_diff_content<'a>(
|
||||
let text_area = Rect::new(content.x + gutter as u16, row_area.y, paint_width as u16, 1);
|
||||
let changed = line.changed;
|
||||
let background = if changed && line.emphasize {
|
||||
colors.row[usize::from(!before)]
|
||||
colors.row[usize::from(!removed)]
|
||||
} else {
|
||||
Color::Reset
|
||||
};
|
||||
@@ -4711,12 +4706,12 @@ fn paint_diff_content<'a>(
|
||||
);
|
||||
if gutter > 0 && wrapped.is_none_or(|rows| rows[screen].position.continuation == 0) {
|
||||
let marker = if changed {
|
||||
if before { '-' } else { '+' }
|
||||
if removed { '-' } else { '+' }
|
||||
} else {
|
||||
' '
|
||||
};
|
||||
let color = if changed {
|
||||
if before { Color::Red } else { Color::Green }
|
||||
if removed { Color::Red } else { Color::Green }
|
||||
} else {
|
||||
Color::DarkGray
|
||||
};
|
||||
@@ -4732,35 +4727,41 @@ fn paint_diff_content<'a>(
|
||||
}
|
||||
(Some(old), None) => format!("{old:>old_digits$} {:>new_digits$}{marker} ", ""),
|
||||
(None, Some(new)) => format!("{:>old_digits$} {new:>new_digits$}{marker} ", ""),
|
||||
(None, None) => unreachable!("displayed diff line has a source"),
|
||||
(None, None) => format!("{:>old_digits$} {:>new_digits$}{marker} ", "", ""),
|
||||
}
|
||||
} else {
|
||||
let digits = view.info.source_extents[usize::from(!before)]
|
||||
.max(1)
|
||||
.ilog10() as usize
|
||||
+ 1;
|
||||
format!("{:>digits$}{marker} ", index + 1)
|
||||
if line.native {
|
||||
format!("{:>digits$}{marker} ", index + 1)
|
||||
} else {
|
||||
format!("{:>digits$}{marker} ", "")
|
||||
}
|
||||
};
|
||||
frame.render_widget(
|
||||
Paragraph::new(label).style(Style::default().fg(color).bg(background)),
|
||||
Rect::new(content.x, row_area.y, gutter as u16, 1),
|
||||
);
|
||||
}
|
||||
paint_syntax_line(
|
||||
frame,
|
||||
source_text,
|
||||
syntax[usize::from(!before)].line(index),
|
||||
text_area,
|
||||
left,
|
||||
);
|
||||
paint_semantic_line(
|
||||
frame,
|
||||
source_text,
|
||||
semantic[usize::from(!before)],
|
||||
index,
|
||||
text_area,
|
||||
left,
|
||||
);
|
||||
if line.native {
|
||||
paint_syntax_line(
|
||||
frame,
|
||||
source_text,
|
||||
syntax[usize::from(!before)].line(index),
|
||||
text_area,
|
||||
left,
|
||||
);
|
||||
paint_semantic_line(
|
||||
frame,
|
||||
source_text,
|
||||
semantic[usize::from(!before)],
|
||||
index,
|
||||
text_area,
|
||||
left,
|
||||
);
|
||||
}
|
||||
if let Some(characters) = whitespace_characters {
|
||||
paint_whitespace(
|
||||
frame,
|
||||
@@ -4769,13 +4770,17 @@ fn paint_diff_content<'a>(
|
||||
left,
|
||||
characters,
|
||||
whitespace_scope,
|
||||
syntax[usize::from(!before)].string_spans(index),
|
||||
if line.native {
|
||||
syntax[usize::from(!before)].string_spans(index)
|
||||
} else {
|
||||
&[]
|
||||
},
|
||||
line.newline,
|
||||
true,
|
||||
);
|
||||
}
|
||||
if line.emphasize {
|
||||
let style = Style::default().bg(colors.character[usize::from(!before)]);
|
||||
let style = Style::default().bg(colors.character[usize::from(!removed)]);
|
||||
for range in line.changes() {
|
||||
if !range.is_empty() {
|
||||
paint_grapheme_range(frame, text_area, left, source_text, range.clone(), style);
|
||||
@@ -5080,7 +5085,7 @@ impl DiffWrapViewport {
|
||||
fn row(
|
||||
&mut self,
|
||||
diff: &DiffState,
|
||||
file: &ChangedFile,
|
||||
_file: &ChangedFile,
|
||||
position: DiffWrapPosition,
|
||||
) -> WrappedDiffRow {
|
||||
let mut segments = [None; 2];
|
||||
@@ -5099,15 +5104,16 @@ impl DiffWrapViewport {
|
||||
Some(DisplayRow::Line(_))
|
||||
) {
|
||||
for (side, focus) in [Focus::Before, Focus::After].into_iter().enumerate() {
|
||||
let source = diff.display_source_row(focus, position.display);
|
||||
if let Some(source) = source.filter(|_| self.widths[side] > 0) {
|
||||
let (cache, lines) = if side == 0 {
|
||||
(&mut self.before, &file.before)
|
||||
let view = diff.column_view(focus).unwrap();
|
||||
if let Some((key, text)) = view.text_row(position.display)
|
||||
&& self.widths[side] > 0
|
||||
{
|
||||
let cache = if side == 0 {
|
||||
&mut self.before
|
||||
} else {
|
||||
(&mut self.after, &file.after)
|
||||
&mut self.after
|
||||
};
|
||||
let text = lines.get(source).map_or("", String::as_str);
|
||||
let parts = cache.segments(source, text);
|
||||
let parts = cache.segments(key, text);
|
||||
segments[side] = parts.get(position.continuation).copied();
|
||||
final_segments[side] = position.continuation + 1 == parts.len();
|
||||
}
|
||||
@@ -5122,7 +5128,7 @@ impl DiffWrapViewport {
|
||||
}
|
||||
}
|
||||
|
||||
fn height(&mut self, diff: &DiffState, file: &ChangedFile, display: usize) -> usize {
|
||||
fn height(&mut self, diff: &DiffState, _file: &ChangedFile, display: usize) -> usize {
|
||||
if !diff.word_wrap {
|
||||
return 1;
|
||||
}
|
||||
@@ -5131,18 +5137,16 @@ impl DiffWrapViewport {
|
||||
}
|
||||
let mut height = 1;
|
||||
for (side, focus) in [Focus::Before, Focus::After].into_iter().enumerate() {
|
||||
let source = diff.display_source_row(focus, display);
|
||||
if let Some(source) = source.filter(|_| self.widths[side] > 0) {
|
||||
let (cache, lines) = if side == 0 {
|
||||
(&mut self.before, &file.before)
|
||||
let view = diff.column_view(focus).unwrap();
|
||||
if let Some((key, text)) = view.text_row(display)
|
||||
&& self.widths[side] > 0
|
||||
{
|
||||
let cache = if side == 0 {
|
||||
&mut self.before
|
||||
} else {
|
||||
(&mut self.after, &file.after)
|
||||
&mut self.after
|
||||
};
|
||||
height = height.max(
|
||||
cache
|
||||
.segments(source, lines.get(source).map_or("", String::as_str))
|
||||
.len(),
|
||||
);
|
||||
height = height.max(cache.segments(key, text).len());
|
||||
}
|
||||
}
|
||||
height
|
||||
|
||||
+22
-2
@@ -154,6 +154,7 @@ fn cli_resolves_only_the_requested_comment_and_preserves_original_feedback() {
|
||||
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]
|
||||
@@ -176,6 +177,11 @@ fn cli_resolves_only_the_requested_comment_and_preserves_original_feedback() {
|
||||
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());
|
||||
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]| {
|
||||
@@ -214,6 +220,7 @@ fn cli_resolves_only_the_requested_comment_and_preserves_original_feedback() {
|
||||
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})
|
||||
@@ -227,6 +234,7 @@ fn cli_resolves_only_the_requested_comment_and_preserves_original_feedback() {
|
||||
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);
|
||||
|
||||
@@ -264,8 +272,20 @@ fn cli_resolves_only_the_requested_comment_and_preserves_original_feedback() {
|
||||
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().len(), 1);
|
||||
assert_eq!(list["reviews"][0]["counts"], json["counts"]);
|
||||
assert_eq!(list["reviews"].as_array().unwrap().len(), 3);
|
||||
assert_eq!(
|
||||
list["reviews"][0]["comparison"],
|
||||
serde_json::json!(reversed.comparison)
|
||||
);
|
||||
assert!(list["reviews"][1]["comparison"].is_null());
|
||||
assert_eq!(list["reviews"][2]["comparison"], json["comparison"]);
|
||||
assert_eq!(list["reviews"][2]["counts"], json["counts"]);
|
||||
let output = cli("repo", &["list"]);
|
||||
assert!(output.status.success(), "{:?}", output);
|
||||
let text = String::from_utf8(output.stdout).unwrap();
|
||||
assert!(text.contains("Scope: source"));
|
||||
assert!(text.contains("Scope: comparison frozen-base → working:frozen-tip"));
|
||||
assert!(text.contains("Scope: comparison working:frozen-tip → frozen-base"));
|
||||
let output = cli("repo", &["resolve", &id_text, "2"]);
|
||||
assert!(output.status.success(), "{:?}", output);
|
||||
let text = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
+85
-14
@@ -19,7 +19,8 @@ fn conflict_history_preserves_source_gaps_base_changes_and_native_eof_rows() {
|
||||
assert_eq!(
|
||||
rows,
|
||||
[
|
||||
[Some(0), Some(0), Some(0)],
|
||||
[None, Some(0), None],
|
||||
[Some(0), None, Some(0)],
|
||||
[None, None, Some(1)],
|
||||
[Some(1), Some(1), Some(2)],
|
||||
[Some(2), Some(2), Some(3)],
|
||||
@@ -44,13 +45,13 @@ fn conflict_history_preserves_source_gaps_base_changes_and_native_eof_rows() {
|
||||
assert!(line.changes().any(|range| range.contains(&column)));
|
||||
}
|
||||
assert!(!line.changes().any(|range| range.contains(&4)));
|
||||
let ColumnRow::Text(line) = base.row(2).unwrap() else {
|
||||
let ColumnRow::Text(line) = base.row(3).unwrap() else {
|
||||
panic!("unchanged base row must contain text");
|
||||
};
|
||||
assert!(!line.changed);
|
||||
assert_eq!(line.changes().count(), 0);
|
||||
let right = history.column(2);
|
||||
let ColumnRow::Text(line) = right.view().row(1).unwrap() else {
|
||||
let ColumnRow::Text(line) = right.view().row(2).unwrap() else {
|
||||
panic!("inserted right row must contain text");
|
||||
};
|
||||
assert_eq!(line.text, Some("added"));
|
||||
@@ -62,9 +63,45 @@ fn conflict_history_preserves_source_gaps_base_changes_and_native_eof_rows() {
|
||||
"abc deg\nadded\nkeep\n",
|
||||
"xbc def\nkeep\n",
|
||||
]);
|
||||
assert_eq!(history.column(1).view().native_row(1), Some(1));
|
||||
assert_eq!(history.column(0).view().native_row(1), None);
|
||||
assert_eq!(history.column(2).view().native_row(1), None);
|
||||
assert_eq!(history.column(1).view().native_row(2), Some(1));
|
||||
assert_eq!(history.column(0).view().native_row(2), None);
|
||||
assert_eq!(history.column(2).view().native_row(2), None);
|
||||
// Deletions are visible on either side, but never become editable source rows.
|
||||
let history = HistoryComparison::new(["keep\n", "old\nkeep\n", "new\nkeep\n"]);
|
||||
for column in [0, 2] {
|
||||
let projection = history.column(column).view();
|
||||
let ColumnRow::Text(line) = projection.row(0).unwrap() else {
|
||||
panic!("removed base text must remain visible");
|
||||
};
|
||||
assert_eq!(line.text, Some("old"));
|
||||
assert!(line.changed);
|
||||
assert_eq!(line.polarity, Focus::Before);
|
||||
assert!(!line.native);
|
||||
assert_eq!(projection.native_row(0), None);
|
||||
assert_eq!(projection.text_row(0), Some((usize::MAX, "old")));
|
||||
}
|
||||
assert!(matches!(
|
||||
history.column(0).view().row(1),
|
||||
Some(ColumnRow::Gap)
|
||||
));
|
||||
let right = history.column(2).view();
|
||||
let ColumnRow::Text(line) = right.row(1).unwrap() else {
|
||||
panic!("replacement must be an addition");
|
||||
};
|
||||
assert_eq!(line.text, Some("new"));
|
||||
assert_eq!(line.polarity, Focus::After);
|
||||
assert_eq!(right.native_row(1), Some(0));
|
||||
assert_eq!(right.display_row(0), Some(1));
|
||||
let history = HistoryComparison::new(["left", "", "right"]);
|
||||
for column in [0, 2] {
|
||||
let projection = history.column(column).view();
|
||||
let ColumnRow::Text(line) = projection.row(0).unwrap() else {
|
||||
panic!("add/add without a base must show additions on both sides");
|
||||
};
|
||||
assert!(line.changed && line.native);
|
||||
assert_eq!(line.polarity, Focus::After);
|
||||
assert_eq!(projection.native_row(0), Some(0));
|
||||
}
|
||||
for text in ["", "\n", "same", "same\n"] {
|
||||
let history = HistoryComparison::new([text; 3]);
|
||||
let native_rows = text.split('\n').count();
|
||||
@@ -83,7 +120,7 @@ fn resolver_equal_text_retains_native_rows_and_cached_viewport() {
|
||||
for text in ["", "\n", "same\n", "same"] {
|
||||
let lines: Vec<_> = text.split('\n').map(str::to_owned).collect();
|
||||
let mut state = DiffState::new();
|
||||
state.set_resolver_text(&lines, &lines);
|
||||
state.set_resolver_text(&lines, &lines, None);
|
||||
assert_eq!(state.pane_layout(), PaneLayout::Split);
|
||||
assert!(state.comparison.as_ref().unwrap().files[0].hunks.is_empty());
|
||||
assert_eq!(
|
||||
@@ -99,7 +136,7 @@ fn resolver_equal_text_retains_native_rows_and_cached_viewport() {
|
||||
state.top = 1;
|
||||
state.left_before = 3;
|
||||
state.left_after = 4;
|
||||
state.set_resolver_text(&lines, &lines);
|
||||
state.set_resolver_text(&lines, &lines, None);
|
||||
assert_eq!(state.comparison_id, id);
|
||||
assert_eq!((state.top, state.left_before, state.left_after), (1, 3, 4));
|
||||
}
|
||||
@@ -2333,6 +2370,7 @@ fn live_state(before: Vec<String>, after: Vec<String>, eof: bool) -> DiffState {
|
||||
loaded: true,
|
||||
}],
|
||||
});
|
||||
state.review_comparison = Some(["base".into(), "working:snapshot".into()]);
|
||||
state.files = Some(FilePicker::from_paths(
|
||||
PathBuf::new(),
|
||||
[(0, PathBuf::from("file"))],
|
||||
@@ -2407,7 +2445,7 @@ fn column_view_distinguishes_native_terminal_rows_from_missing_ordinary_text() {
|
||||
for text in ["", "same\n"] {
|
||||
let lines: Vec<_> = text.split('\n').map(str::to_owned).collect();
|
||||
let mut state = DiffState::new();
|
||||
state.set_resolver_text(&lines, &lines);
|
||||
state.set_resolver_text(&lines, &lines, None);
|
||||
for focus in [Focus::Before, Focus::After] {
|
||||
let view = state.column_view(focus).unwrap();
|
||||
let native = lines.len() - 1;
|
||||
@@ -2727,7 +2765,33 @@ fn restored_review_marks_use_file_identities_and_rename_paths_not_catalog_order(
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unchanged_file_review_survives_other_files_changing() {
|
||||
fn review_marks_cannot_cross_comparison_scopes_even_with_matching_file_identities() {
|
||||
let mut review = crate::review::ReviewState::default();
|
||||
let mut state = DiffState::new();
|
||||
let mut first = comparison();
|
||||
first.files[0].review_revisions = Some(["file-before".into(), "file-after".into()]);
|
||||
state.request_kind = Some(RequestKind::Comparison);
|
||||
state.apply_result(1, Ok(Outcome::Comparison(first)));
|
||||
state.toggle_reviewed(&mut review).unwrap();
|
||||
let initial_scope = review.document.comparison.clone();
|
||||
let mut second = comparison();
|
||||
second.files[0].review_revisions = Some(["file-before".into(), "file-after".into()]);
|
||||
second.revisions[1] = "another-head".into();
|
||||
state.request_kind = Some(RequestKind::Comparison);
|
||||
state.apply_result(2, Ok(Outcome::Comparison(second)));
|
||||
state.restore_reviewed_files(&review);
|
||||
assert!(state.reviewed_files.is_empty());
|
||||
assert_eq!(
|
||||
state.toggle_reviewed(&mut review),
|
||||
Err("Select the review for this comparison first")
|
||||
);
|
||||
assert!(state.reviewed_files.is_empty());
|
||||
assert_eq!(review.document.comparison, initial_scope);
|
||||
assert_eq!(review.document.reviewed_files.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn working_refresh_retains_scope_and_unchanged_file_progress() {
|
||||
let mut review = crate::review::ReviewState::default();
|
||||
use crate::repository::Repository;
|
||||
use std::sync::{Arc, atomic::AtomicBool};
|
||||
@@ -2788,20 +2852,27 @@ fn unchanged_file_review_survives_other_files_changing() {
|
||||
.compare(2, &before, &after, ComparisonMode::Snapshots, &[])
|
||||
.unwrap();
|
||||
assert_ne!(changes.revisions, original_revisions);
|
||||
state.request_kind = Some(RequestKind::Comparison);
|
||||
state.apply_result(2, Ok(Outcome::Comparison(changes)));
|
||||
state.after = Some(after);
|
||||
state.request_kind = None;
|
||||
state.pending = None;
|
||||
state.loading = false;
|
||||
state.queue_checkout_refresh(true);
|
||||
state.take_request();
|
||||
assert!(state.apply_result(2, Ok(Outcome::CheckoutRefresh(Some(changes)))));
|
||||
assert_eq!(state.review_comparison, Some(original_revisions));
|
||||
review.document = store.load(&root, id).unwrap();
|
||||
state.restore_reviewed_files(&review);
|
||||
assert_eq!(state.reviewed_files, BTreeSet::from([0]));
|
||||
state.load_file(0);
|
||||
let detail = repository.load_file(2, 0).unwrap();
|
||||
state.apply_result(
|
||||
assert!(state.apply_result(
|
||||
3,
|
||||
Ok(Outcome::File {
|
||||
comparison_id: 2,
|
||||
file_index: 0,
|
||||
file: detail,
|
||||
}),
|
||||
);
|
||||
));
|
||||
state.restore_reviewed_files(&review);
|
||||
assert_eq!(state.reviewed_files, BTreeSet::from([0]));
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
|
||||
+327
-9
@@ -122,7 +122,10 @@ fn resolver_shares_native_excerpt_search_motions_and_explicit_writable_side() {
|
||||
}
|
||||
let draft = before.join("\n");
|
||||
let alternative = after.join("\n");
|
||||
let mut resolver = resolver_editor(&draft, &[(&draft, false), (&alternative, false)]);
|
||||
let mut resolver = resolver_editor(
|
||||
&draft,
|
||||
&[(&draft, false), (&alternative, false), (&draft, true)],
|
||||
);
|
||||
let mut ordinary = editor();
|
||||
historical_diff(&mut ordinary, &directory.0, before, after);
|
||||
for editor in [&mut resolver, &mut ordinary] {
|
||||
@@ -161,10 +164,6 @@ fn resolver_shares_native_excerpt_search_motions_and_explicit_writable_side() {
|
||||
.is_some()
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
resolver.diff().unwrap().display_rows,
|
||||
ordinary.diff().unwrap().display_rows
|
||||
);
|
||||
assert!(resolver.diff_editing());
|
||||
assert!(resolver.diff().unwrap().side_editable(Focus::Before));
|
||||
assert!(!resolver.diff().unwrap().side_editable(Focus::After));
|
||||
@@ -397,7 +396,6 @@ fn resolver_history_selects_every_side_and_base_without_moving_draft_or_viewport
|
||||
editor.set_diff_viewport(diff.comparison_id.unwrap(), diff.file, 8, 2, 4);
|
||||
let cursor = editor.cursor();
|
||||
let buffer = editor.buffer_id();
|
||||
let id = editor.resolver_diff().unwrap().comparison_id;
|
||||
assert!(editor.file_picker().is_none());
|
||||
editor.execute("word_wrap.toggle");
|
||||
assert!(editor.word_wrap());
|
||||
@@ -419,7 +417,6 @@ fn resolver_history_selects_every_side_and_base_without_moving_draft_or_viewport
|
||||
assert_eq!(editor.cursor(), cursor);
|
||||
assert_eq!(editor.buffer_id(), buffer);
|
||||
let diff = editor.resolver_diff().unwrap();
|
||||
assert_eq!(diff.comparison_id, id);
|
||||
assert_eq!((diff.top, diff.left_before, diff.left_after), (8, 2, 4));
|
||||
assert!(editor.word_wrap());
|
||||
editor.handle(Input::Char('\t'));
|
||||
@@ -3020,6 +3017,15 @@ fn diff_preserves_parked_buffers_visual_carets_and_insert_history() {
|
||||
}
|
||||
|
||||
fn working_diff(editor: &mut Editor, root: &Path, paths: &[&str]) -> Box<[(PathBuf, String)]> {
|
||||
working_diff_with_revisions(editor, root, paths, ["base", "working-snapshot"])
|
||||
}
|
||||
|
||||
fn working_diff_with_revisions(
|
||||
editor: &mut Editor,
|
||||
root: &Path,
|
||||
paths: &[&str],
|
||||
revisions: [&str; 2],
|
||||
) -> Box<[(PathBuf, String)]> {
|
||||
use crate::diff::{Catalog, Category, ChangedFile, Comparison, FileStatus, RepoKind, Revision};
|
||||
editor.execute("diff");
|
||||
let (id, _) = editor.take_diff_request().unwrap();
|
||||
@@ -3073,7 +3079,7 @@ fn working_diff(editor: &mut Editor, root: &Path, paths: &[&str]) -> Box<[(PathB
|
||||
Ok(Outcome::Comparison(Comparison {
|
||||
blame: Default::default(),
|
||||
root: root.canonicalize().unwrap(),
|
||||
revisions: ["base".into(), "working-snapshot".into()],
|
||||
revisions: revisions.map(str::to_owned),
|
||||
before: "base".into(),
|
||||
after: "Working".into(),
|
||||
editable_paths: paths.iter().map(|path| PathBuf::from(*path)).collect(),
|
||||
@@ -3084,6 +3090,16 @@ fn working_diff(editor: &mut Editor, root: &Path, paths: &[&str]) -> Box<[(PathB
|
||||
}
|
||||
|
||||
fn historical_diff(editor: &mut Editor, root: &Path, before: Vec<String>, after: Vec<String>) {
|
||||
historical_diff_with_revisions(editor, root, before, after, ["base", "head"]);
|
||||
}
|
||||
|
||||
fn historical_diff_with_revisions(
|
||||
editor: &mut Editor,
|
||||
root: &Path,
|
||||
before: Vec<String>,
|
||||
after: Vec<String>,
|
||||
revisions: [&str; 2],
|
||||
) {
|
||||
use crate::diff::{Catalog, Category, ChangedFile, Comparison, FileStatus, RepoKind, Revision};
|
||||
editor.execute("diff");
|
||||
let (id, _) = editor.take_diff_request().unwrap();
|
||||
@@ -3111,7 +3127,7 @@ fn historical_diff(editor: &mut Editor, root: &Path, before: Vec<String>, after:
|
||||
Ok(Outcome::Comparison(Comparison {
|
||||
blame: Default::default(),
|
||||
root: root.to_owned(),
|
||||
revisions: ["base".into(), "head".into()],
|
||||
revisions: revisions.map(str::to_owned),
|
||||
before: "base".into(),
|
||||
after: "head".into(),
|
||||
editable_paths: Default::default(),
|
||||
@@ -3157,6 +3173,305 @@ fn source_review_editor(directory: &Directory, text: &str) -> (Editor, PathBuf,
|
||||
(editor, root, path)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comparison_reviews_use_ordered_resolved_identities_and_resume_only_the_same_pair() {
|
||||
use crate::review::{Store, Verdict};
|
||||
let directory = Directory::new();
|
||||
let (mut editor, root, _) = source_review_editor(&directory, "source\n");
|
||||
historical_diff(&mut editor, &root, vec!["old".into()], vec!["new".into()]);
|
||||
editor.execute("comment");
|
||||
type_text(&mut editor, "iPair feedback");
|
||||
editor.handle(Input::Escape);
|
||||
editor.execute("w");
|
||||
editor.handle(Input::Escape);
|
||||
editor.execute("diff.review.toggle");
|
||||
editor.execute("review.verdict looks_good");
|
||||
let original = editor.local_review.document.clone();
|
||||
editor.handle(Input::Escape);
|
||||
for pair in [["other", "head"], ["base", "other"], ["head", "base"]] {
|
||||
historical_diff_with_revisions(
|
||||
&mut editor,
|
||||
&root,
|
||||
vec!["old".into()],
|
||||
vec!["new".into()],
|
||||
pair,
|
||||
);
|
||||
assert_eq!(
|
||||
editor.local_review.document.comparison,
|
||||
Some(pair.map(str::to_owned))
|
||||
);
|
||||
assert!(editor.local_review.document.comments.is_empty());
|
||||
assert!(editor.local_review.document.verdict.is_none());
|
||||
assert!(editor.local_review.document.reviewed_files.is_empty());
|
||||
assert!(editor.workspace_diff().unwrap().reviewed_files.is_empty());
|
||||
editor.execute("review.verdict changes_requested");
|
||||
assert_ne!(editor.local_review.document.storage_id, original.storage_id);
|
||||
editor.handle(Input::Escape);
|
||||
}
|
||||
historical_diff(&mut editor, &root, vec!["old".into()], vec!["new".into()]);
|
||||
assert_eq!(editor.local_review.document.storage_id, original.storage_id);
|
||||
assert_eq!(
|
||||
editor.local_review.document.comments[0].body,
|
||||
"Pair feedback"
|
||||
);
|
||||
assert_eq!(
|
||||
editor.local_review.document.verdict,
|
||||
Some(Verdict::LooksGood)
|
||||
);
|
||||
assert_eq!(
|
||||
editor.workspace_diff().unwrap().reviewed_files,
|
||||
BTreeSet::from([0])
|
||||
);
|
||||
assert_eq!(
|
||||
Store::open(&root.join("reviews"))
|
||||
.unwrap()
|
||||
.list(&root)
|
||||
.unwrap()
|
||||
.len(),
|
||||
4
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_and_comparison_reviews_remain_separate_in_shared_panes_and_tabs() {
|
||||
let directory = Directory::new();
|
||||
let (mut editor, root, _) = source_review_editor(&directory, "source\n");
|
||||
let source = editor.pane_id;
|
||||
editor.execute("comment");
|
||||
type_text(&mut editor, "iSource feedback");
|
||||
editor.handle(Input::Escape);
|
||||
editor.execute("w");
|
||||
let source_id = editor.local_review.document.storage_id;
|
||||
editor.handle(Input::Escape);
|
||||
editor.split_pane(SplitAxis::Vertical);
|
||||
let comparison_pane = editor.pane_id;
|
||||
historical_diff(&mut editor, &root, vec!["old".into()], vec!["new".into()]);
|
||||
editor.execute("comment");
|
||||
type_text(&mut editor, "iComparison feedback");
|
||||
editor.handle(Input::Escape);
|
||||
editor.execute("w");
|
||||
let comparison_id = editor.local_review.document.storage_id;
|
||||
assert_ne!(comparison_id, source_id);
|
||||
editor.handle(Input::Escape);
|
||||
editor.select_pane(source);
|
||||
editor.execute("review.edit 1");
|
||||
assert_eq!(editor.local_review.document.storage_id, source_id);
|
||||
assert!(editor.local_review.document.comparison.is_none());
|
||||
assert_eq!(editor.context().text, "Source feedback");
|
||||
editor.handle(Input::Escape);
|
||||
editor.select_pane(comparison_pane);
|
||||
editor.execute("review.edit 1");
|
||||
assert_eq!(editor.local_review.document.storage_id, comparison_id);
|
||||
assert_eq!(editor.context().text, "Comparison feedback");
|
||||
editor.handle(Input::Escape);
|
||||
editor.select_pane(source);
|
||||
editor.execute("tab.new");
|
||||
editor.execute("review.edit 1");
|
||||
assert_eq!(editor.local_review.document.storage_id, source_id);
|
||||
assert_eq!(editor.context().text, "Source feedback");
|
||||
editor.handle(Input::Escape);
|
||||
historical_diff(&mut editor, &root, vec!["old".into()], vec!["new".into()]);
|
||||
assert_eq!(editor.local_review.document.storage_id, comparison_id);
|
||||
editor.execute("tab.previous");
|
||||
editor.select_pane(comparison_pane);
|
||||
editor.execute("review.edit 1");
|
||||
assert_eq!(editor.context().text, "Comparison feedback");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn review_selectors_and_explicit_opens_reject_other_comparison_and_source_scopes() {
|
||||
use crate::review::{Review, Store};
|
||||
let directory = Directory::new();
|
||||
let (mut editor, root, _) = source_review_editor(&directory, "source\n");
|
||||
let mut store = Store::open(&root.join("reviews")).unwrap();
|
||||
let mut source = Review::new(root.clone());
|
||||
source.summary = "source-only".into();
|
||||
store.save(&mut source).unwrap();
|
||||
let mut other = Review::new(root.clone());
|
||||
other.comparison = Some(["different".into(), "head".into()]);
|
||||
other.summary = "other-pair-only".into();
|
||||
store.save(&mut other).unwrap();
|
||||
let other_json = root.join("other.json");
|
||||
other.save(&other_json).unwrap();
|
||||
let source_json = root.join("source.json");
|
||||
source.save(&source_json).unwrap();
|
||||
historical_diff(&mut editor, &root, vec!["old".into()], vec!["new".into()]);
|
||||
editor.execute("review.verdict looks_good");
|
||||
let current = editor.local_review.document.clone();
|
||||
for command in [
|
||||
format!("review.open {}", source.storage_id.unwrap()),
|
||||
format!("review.open {}", other.storage_id.unwrap()),
|
||||
format!("review.open {}", source_json.display()),
|
||||
format!("review.open {}", other_json.display()),
|
||||
] {
|
||||
editor.execute(&command);
|
||||
assert!(
|
||||
editor
|
||||
.message()
|
||||
.contains("different comparison or source scope")
|
||||
);
|
||||
assert_eq!(editor.local_review.document.storage_id, current.storage_id);
|
||||
assert_eq!(editor.local_review.document.comparison, current.comparison);
|
||||
assert_eq!(editor.local_review.document.verdict, current.verdict);
|
||||
}
|
||||
editor.execute("review.new");
|
||||
let second_id = editor.local_review.document.storage_id;
|
||||
editor.execute("review.open");
|
||||
assert!(!editor.context().text.contains("source-only"));
|
||||
assert!(!editor.context().text.contains("other-pair-only"));
|
||||
editor.handle(Input::Enter);
|
||||
assert_eq!(editor.local_review.document.storage_id, second_id);
|
||||
editor.execute(&format!("review.open {}", current.storage_id.unwrap()));
|
||||
assert_eq!(editor.local_review.document.storage_id, current.storage_id);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dirty_review_drafts_guard_scope_replacement_new_reviews_and_mode_changes() {
|
||||
let directory = Directory::new();
|
||||
let (mut editor, root, _) = source_review_editor(&directory, "source\n");
|
||||
let source = editor.pane_id;
|
||||
editor.split_pane(SplitAxis::Vertical);
|
||||
let comparison_pane = editor.pane_id;
|
||||
historical_diff(&mut editor, &root, vec!["old".into()], vec!["new".into()]);
|
||||
editor.execute("comment");
|
||||
type_text(&mut editor, "iUnsaved feedback");
|
||||
editor.handle(Input::Escape);
|
||||
let draft = editor.buffer_id();
|
||||
let panel = editor.review_pane.unwrap();
|
||||
let scope = editor.local_review.document.comparison.clone();
|
||||
editor.execute("review.new");
|
||||
assert!(editor.message().contains("Save the current local review"));
|
||||
assert_eq!(editor.context().text, "Unsaved feedback");
|
||||
editor.select_pane(source);
|
||||
editor.execute("review.overview");
|
||||
assert!(editor.message().contains("changing review scopes"));
|
||||
assert_eq!(editor.local_review.document.comparison, scope);
|
||||
editor.select_pane(comparison_pane);
|
||||
let comparison = editor.workspace_diff().unwrap().comparison_id;
|
||||
editor.act(Action::DiffModeToggle);
|
||||
assert_eq!(editor.workspace_diff().unwrap().comparison_id, comparison);
|
||||
assert!(editor.workspace_diff().unwrap().comparison.is_some());
|
||||
editor.execute("diff");
|
||||
assert_eq!(editor.workspace_diff().unwrap().comparison_id, comparison);
|
||||
editor.select_pane(panel);
|
||||
assert_eq!(editor.buffer_id(), draft);
|
||||
assert_eq!(editor.context().text, "Unsaved feedback");
|
||||
editor.execute("w");
|
||||
editor.handle(Input::Escape);
|
||||
editor.select_pane(source);
|
||||
editor.execute("review.overview");
|
||||
assert!(editor.local_review.document.comparison.is_none());
|
||||
assert!(editor.local_review.document.comments.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn working_refresh_keeps_review_scope_and_drafts_but_explicit_reopen_uses_new_identities() {
|
||||
let directory = Directory::new();
|
||||
let (mut editor, root, _) = source_review_editor(&directory, "source\n");
|
||||
fs::write(root.join("file.txt"), "original\n").unwrap();
|
||||
working_diff(&mut editor, &root, &["file.txt"]);
|
||||
editor.handle(Input::Enter);
|
||||
editor.execute("comment");
|
||||
type_text(&mut editor, "iWorking feedback");
|
||||
editor.handle(Input::Escape);
|
||||
editor.execute("w");
|
||||
editor.handle(Input::Escape);
|
||||
let original_id = editor.local_review.document.storage_id;
|
||||
let scope = editor.local_review.document.comparison.clone();
|
||||
editor.execute("review.summary");
|
||||
type_text(&mut editor, "iUnsaved working summary");
|
||||
editor.handle(Input::Escape);
|
||||
let panel = editor.review_pane.unwrap();
|
||||
let owner = editor.diff_owner.unwrap();
|
||||
editor.queue_checkout_refreshes(true);
|
||||
let (_, request, _) = editor.take_next_diff_request().unwrap();
|
||||
let mut replacement = editor.with_pane(owner, |editor| {
|
||||
editor.diff.as_mut().unwrap().comparison.take().unwrap()
|
||||
});
|
||||
replacement.revisions[1] = "working:changed".into();
|
||||
replacement.files[0].after = vec!["refreshed".into()];
|
||||
assert!(editor.apply_diff_result(request, Ok(Outcome::CheckoutRefresh(Some(replacement)))));
|
||||
assert_eq!(editor.local_review.document.comparison, scope);
|
||||
assert_eq!(editor.local_review.document.storage_id, original_id);
|
||||
assert_eq!(
|
||||
editor.local_review.document.comments[0].body,
|
||||
"Working feedback"
|
||||
);
|
||||
assert!(editor.current_review_dirty());
|
||||
editor.select_pane(panel);
|
||||
assert_eq!(editor.context().text, "Unsaved working summary");
|
||||
editor.execute("w");
|
||||
editor.handle(Input::Escape);
|
||||
working_diff_with_revisions(
|
||||
&mut editor,
|
||||
&root,
|
||||
&["file.txt"],
|
||||
["base", "working:changed"],
|
||||
);
|
||||
assert!(editor.local_review.document.comments.is_empty());
|
||||
assert!(editor.local_review.document.summary.is_empty());
|
||||
editor.execute("review.verdict looks_good");
|
||||
assert_ne!(editor.local_review.document.storage_id, original_id);
|
||||
editor.handle(Input::Escape);
|
||||
working_diff(&mut editor, &root, &["file.txt"]);
|
||||
assert_eq!(editor.local_review.document.storage_id, original_id);
|
||||
assert_eq!(
|
||||
editor.local_review.document.summary,
|
||||
"Unsaved working summary"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moved_bookmark_selects_new_review_and_dirty_draft_blocks_endpoint_replacement() {
|
||||
use crate::diff::Comparison;
|
||||
let directory = Directory::new();
|
||||
let (mut editor, root, _) = source_review_editor(&directory, "source\n");
|
||||
historical_diff(&mut editor, &root, vec!["old".into()], vec!["new".into()]);
|
||||
editor.execute("review.verdict looks_good");
|
||||
let original_id = editor.local_review.document.storage_id;
|
||||
editor.handle(Input::Escape);
|
||||
editor.execute("review.summary");
|
||||
type_text(&mut editor, "iBookmark draft");
|
||||
editor.handle(Input::Escape);
|
||||
let panel = editor.review_pane.unwrap();
|
||||
let moved = || Comparison {
|
||||
revisions: ["base".into(), "moved-head".into()],
|
||||
root: root.clone(),
|
||||
before: "base".into(),
|
||||
after: "head".into(),
|
||||
blame: Default::default(),
|
||||
editable_paths: Default::default(),
|
||||
files: Vec::new(),
|
||||
};
|
||||
editor.queue_checkout_refreshes(false);
|
||||
let (_, request, _) = editor.take_next_diff_request().unwrap();
|
||||
assert!(editor.apply_diff_result(request, Ok(Outcome::BookmarkRefresh(moved()))));
|
||||
assert_eq!(editor.local_review.document.storage_id, original_id);
|
||||
assert_eq!(
|
||||
editor
|
||||
.workspace_diff()
|
||||
.unwrap()
|
||||
.comparison
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.revisions[1],
|
||||
"head"
|
||||
);
|
||||
editor.select_pane(panel);
|
||||
assert_eq!(editor.context().text, "Bookmark draft");
|
||||
editor.execute("w");
|
||||
editor.handle(Input::Escape);
|
||||
editor.queue_checkout_refreshes(false);
|
||||
let (_, request, _) = editor.take_next_diff_request().unwrap();
|
||||
assert!(editor.apply_diff_result(request, Ok(Outcome::BookmarkRefresh(moved()))));
|
||||
assert_eq!(
|
||||
editor.local_review.document.comparison,
|
||||
Some(["base".into(), "moved-head".into()])
|
||||
);
|
||||
assert!(editor.local_review.document.verdict.is_none());
|
||||
assert!(editor.local_review.document.summary.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_review_drafts_guard_source_pane_close_and_saved_panels_retarget() {
|
||||
let directory = Directory::new();
|
||||
@@ -3446,6 +3761,8 @@ fn review_navigation_maps_working_ranges_and_preserves_stale_snapshots() {
|
||||
.unwrap()
|
||||
.revisions[1] = "working:old".into();
|
||||
editor.local_review.document = crate::review::Review::new(root);
|
||||
editor.local_review.document.comparison =
|
||||
editor.workspace_diff().unwrap().review_comparison.clone();
|
||||
let anchor = Anchor {
|
||||
revision: "working:old".into(),
|
||||
path: "file.txt".into(),
|
||||
@@ -7598,6 +7915,7 @@ mod system_clipboard {
|
||||
let root = fixture.0.0.canonicalize().unwrap();
|
||||
let storage = root.join("reviews");
|
||||
let mut review = Review::new(root.clone());
|
||||
review.comparison = Some(["base".into(), "head".into()]);
|
||||
review.summary = "Review summary".into();
|
||||
review.verdict = Some(Verdict::ChangesRequested);
|
||||
review.comments = vec![
|
||||
|
||||
+212
-5
@@ -1,5 +1,72 @@
|
||||
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);
|
||||
impl Drop for Directory {
|
||||
fn drop(&mut self) {
|
||||
@@ -84,7 +151,7 @@ fn database_restarts_preserve_identity_and_exact_stale_anchors() {
|
||||
let exported = fs::read(&path).unwrap();
|
||||
let json: serde_json::Value = serde_json::from_slice(&exported).unwrap();
|
||||
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!(json["reviewed_files"][1]["after"].is_null());
|
||||
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);
|
||||
}
|
||||
|
||||
#[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]
|
||||
fn database_repository_identity_is_canonical_and_independent() {
|
||||
let first = directory();
|
||||
@@ -201,9 +401,16 @@ fn database_conflicts_and_locked_writes_keep_drafts_and_identity() {
|
||||
#[test]
|
||||
fn incompatible_database_schemas_are_preserved() {
|
||||
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');
|
||||
PRAGMA user_version = 2"
|
||||
PRAGMA user_version = 3"
|
||||
);
|
||||
for schema in [
|
||||
previous.as_str(),
|
||||
@@ -732,12 +939,12 @@ fn exact_grapheme_ranges_roundtrip_and_reject_invalid_coordinates() {
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.remove("resolved");
|
||||
for version in [2, 3, 4] {
|
||||
for version in [2, 3, 4, 5] {
|
||||
missing_resolution["version"] = version.into();
|
||||
let bytes = serde_json::to_vec(&missing_resolution).unwrap();
|
||||
fs::write(&path, &bytes).unwrap();
|
||||
let error = Review::load(&path, &root).unwrap_err();
|
||||
if version < 4 {
|
||||
if version < 5 {
|
||||
assert!(error.contains("Unsupported review version"));
|
||||
} else {
|
||||
assert!(error.contains("missing field"));
|
||||
|
||||
+71
-170
@@ -1272,10 +1272,6 @@ fn resolver_renders_aligned_native_draft_alternative_and_separate_history() {
|
||||
assert!(!heading.contains(resolver.files[current_file].path.to_string_lossy().as_ref()));
|
||||
assert!(!heading.split_whitespace().any(|word| word == "M"));
|
||||
}
|
||||
assert!(
|
||||
line_at(&terminal, alternative, alternative.bottom() - 1)
|
||||
.contains(&resolver.files[current_file].sources[alternative_index].label)
|
||||
);
|
||||
assert!(
|
||||
line_at(&terminal, draft, draft.bottom() - 1)
|
||||
.chars()
|
||||
@@ -1286,165 +1282,47 @@ fn resolver_renders_aligned_native_draft_alternative_and_separate_history() {
|
||||
let content = diff_inner(area);
|
||||
let x = content.right() - geometry.text_widths[side];
|
||||
let buffer = terminal.backend().buffer();
|
||||
assert_eq!(buffer[(x, content.y)].symbol(), "v");
|
||||
assert_eq!(
|
||||
buffer[(x, content.y)].bg,
|
||||
views.panels.diff_colors.row[side]
|
||||
);
|
||||
assert_eq!(buffer[(x + 8, content.y)].symbol(), "b");
|
||||
assert_eq!(buffer[(x, content.y)].bg, views.panels.diff_colors.row[0]);
|
||||
assert_eq!(
|
||||
buffer[(x + 8, content.y)].bg,
|
||||
views.panels.diff_colors.character[side]
|
||||
views.panels.diff_colors.character[0]
|
||||
);
|
||||
assert_eq!(buffer[(x, content.y + 1)].symbol(), "v");
|
||||
assert_eq!(
|
||||
buffer[(x, content.y + 1)].bg,
|
||||
views.panels.diff_colors.row[1]
|
||||
);
|
||||
}
|
||||
assert_ne!(
|
||||
line_at(&terminal, diff_inner(draft), draft.y + 1),
|
||||
line_at(&terminal, diff_inner(alternative), alternative.y + 1)
|
||||
line_at(&terminal, diff_inner(draft), draft.y + 2),
|
||||
line_at(&terminal, diff_inner(alternative), alternative.y + 2)
|
||||
);
|
||||
for area in [draft, alternative] {
|
||||
assert!(
|
||||
line_at(&terminal, diff_inner(area), area.y + 2).contains("opening context 00"),
|
||||
line_at(&terminal, diff_inner(area), area.y + 3).contains("opening context 00"),
|
||||
"Preexisting unsaved working-buffer edits must appear in both projections"
|
||||
);
|
||||
}
|
||||
let diff = session.editor().diff().unwrap();
|
||||
let file = &diff.comparison.as_ref().unwrap().files[diff.file];
|
||||
let mut reference_file = syntax_diff_file(
|
||||
&file.path.to_string_lossy(),
|
||||
&file.before.join("\n"),
|
||||
&file.after.join("\n"),
|
||||
);
|
||||
reference_file.before_eof = file.before_eof;
|
||||
reference_file.after_eof = file.after_eof;
|
||||
reference_file.hunks = crate::diff::line_hunks(
|
||||
&reference_file.before,
|
||||
reference_file.before_eof,
|
||||
&reference_file.after,
|
||||
reference_file.after_eof,
|
||||
);
|
||||
let mut reference = Editor::open(None, vec![]).unwrap();
|
||||
for _ in 1..session.editor().tab_count() {
|
||||
reference.execute("tab.new");
|
||||
}
|
||||
reference
|
||||
.set_chrome_config(
|
||||
session.editor().top_bar_config().clone(),
|
||||
session.editor().bottom_bar_config().clone(),
|
||||
BTreeMap::new(),
|
||||
)
|
||||
.unwrap();
|
||||
install_readonly_diff(&mut reference, reference_file);
|
||||
reference.handle(Input::Ctrl('w'));
|
||||
let cursor = session.editor().cursor();
|
||||
for ch in format!("{}g", cursor.row + 1).chars() {
|
||||
reference.handle(Input::Char(ch));
|
||||
}
|
||||
reference.handle(Input::Home);
|
||||
for _ in 0..cursor.column {
|
||||
reference.handle(Input::Right);
|
||||
}
|
||||
assert_eq!(reference.cursor(), cursor);
|
||||
assert_eq!(
|
||||
reference.diff_buffer_focus(),
|
||||
session.editor().diff_buffer_focus()
|
||||
);
|
||||
let mut reference_terminal =
|
||||
Terminal::new(ratatui::backend::TestBackend::new(120, 30)).unwrap();
|
||||
let mut reference_views = BufferViewports::default();
|
||||
reference_views.set_theme(Some(DARK_DIFF_THEME));
|
||||
for command in [
|
||||
None,
|
||||
Some("diff.orientation.toggle"),
|
||||
Some("diff.view.toggle"),
|
||||
Some("diff.view.toggle"),
|
||||
Some("diff.orientation.toggle"),
|
||||
"diff.orientation.toggle",
|
||||
"diff.view.toggle",
|
||||
"diff.view.toggle",
|
||||
"diff.orientation.toggle",
|
||||
] {
|
||||
if let Some(command) = command {
|
||||
session.execute(command);
|
||||
reference.execute(command);
|
||||
}
|
||||
session.execute(command);
|
||||
render(&mut terminal, &mut views, &mut session);
|
||||
render_native_diff(
|
||||
&mut reference_terminal,
|
||||
&mut reference_views,
|
||||
&mut reference,
|
||||
);
|
||||
let actual = views.panels.diff.as_ref().unwrap();
|
||||
let expected = reference_views.panels.diff.as_ref().unwrap();
|
||||
assert_eq!(actual.view_mode, expected.view_mode);
|
||||
assert_eq!(actual.split_axis, expected.split_axis);
|
||||
assert_eq!(actual.text_widths, expected.text_widths);
|
||||
for (side, ((actual_pane, _), (expected_pane, _))) in actual.regions[1..]
|
||||
.iter()
|
||||
.zip(&expected.regions[1..])
|
||||
.enumerate()
|
||||
{
|
||||
assert_eq!(
|
||||
(
|
||||
actual_pane.x,
|
||||
actual_pane.y,
|
||||
actual_pane.width,
|
||||
actual_pane.height
|
||||
),
|
||||
(
|
||||
expected_pane.x,
|
||||
expected_pane.y,
|
||||
expected_pane.width,
|
||||
expected_pane.height
|
||||
)
|
||||
);
|
||||
let actual_text = Rect {
|
||||
x: diff_inner(*actual_pane).right() - actual.text_widths[side],
|
||||
width: actual.text_widths[side],
|
||||
..diff_inner(*actual_pane)
|
||||
};
|
||||
let expected_text = Rect {
|
||||
x: diff_inner(*expected_pane).right() - expected.text_widths[side],
|
||||
width: expected.text_widths[side],
|
||||
..diff_inner(*expected_pane)
|
||||
};
|
||||
for row in 0..actual_text.height {
|
||||
assert_eq!(
|
||||
line_at(&terminal, actual_text, actual_text.y + row),
|
||||
line_at(&reference_terminal, expected_text, expected_text.y + row,),
|
||||
"{command:?}, row {row}, full rows: {:?} / {:?}",
|
||||
line_at(&terminal, diff_inner(*actual_pane), actual_text.y + row),
|
||||
line_at(
|
||||
&reference_terminal,
|
||||
diff_inner(*expected_pane),
|
||||
expected_text.y + row,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
let screen = screen_text(&terminal);
|
||||
assert!(screen.contains("value = base;"));
|
||||
assert!(screen.contains("value = left;"));
|
||||
assert!(screen.contains("value = right;"));
|
||||
assert_eq!(session.editor().lines(), original_draft);
|
||||
}
|
||||
let folded_context_rows = screen_text(&terminal).matches("context").count();
|
||||
session.handle(Input::Char(']'));
|
||||
reference.handle(Input::Char(']'));
|
||||
render(&mut terminal, &mut views, &mut session);
|
||||
render_native_diff(
|
||||
&mut reference_terminal,
|
||||
&mut reference_views,
|
||||
&mut reference,
|
||||
);
|
||||
let folds = |editor: &Editor| {
|
||||
editor
|
||||
.diff()
|
||||
.unwrap()
|
||||
.display_rows
|
||||
.iter()
|
||||
.filter_map(|row| match row {
|
||||
DisplayRow::Fold { start, end } => Some((*start, *end)),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(folds(session.editor()), folds(&reference));
|
||||
let expanded_context_rows = screen_text(&terminal).matches("context").count();
|
||||
assert!(expanded_context_rows > folded_context_rows);
|
||||
assert_eq!(
|
||||
expanded_context_rows,
|
||||
screen_text(&reference_terminal).matches("context").count()
|
||||
);
|
||||
let third_source = session.editor().resolver().unwrap().files[current_file]
|
||||
.sources
|
||||
.iter()
|
||||
@@ -1453,7 +1331,7 @@ fn resolver_renders_aligned_native_draft_alternative_and_separate_history() {
|
||||
session.execute(&format!("resolve.source {}", third_source + 1));
|
||||
render(&mut terminal, &mut views, &mut session);
|
||||
assert!(
|
||||
line_at(&terminal, diff_inner(alternative), alternative.y + 1).contains("value = third;")
|
||||
line_at(&terminal, diff_inner(alternative), alternative.y + 2).contains("value = third;")
|
||||
);
|
||||
let right_content = diff_inner(alternative);
|
||||
assert!(
|
||||
@@ -1516,9 +1394,15 @@ fn resolver_renders_aligned_native_draft_alternative_and_separate_history() {
|
||||
assert!(left_heading.contains("unsaved"));
|
||||
assert!(!right_heading.contains("unsaved"));
|
||||
assert!(right_heading.contains("read-only"));
|
||||
assert!(line_at(&terminal, left, left.y + 1).contains("manual opening context 00"));
|
||||
assert!(line_at(&terminal, right, right.y + 1).contains("opening context 00"));
|
||||
assert!(!line_at(&terminal, right, right.y + 1).contains("manual"));
|
||||
assert!(
|
||||
(left.y..left.bottom())
|
||||
.any(|y| line_at(&terminal, left, y).contains("manual opening context 00"))
|
||||
);
|
||||
assert!(
|
||||
(right.y..right.bottom())
|
||||
.any(|y| line_at(&terminal, right, y).contains("opening context 00"))
|
||||
);
|
||||
assert!(!(right.y..right.bottom()).any(|y| line_at(&terminal, right, y).contains("manual")));
|
||||
session.handle(Input::Char('u'));
|
||||
assert_eq!(session.editor().lines(), original_draft);
|
||||
session.handle(Input::Up);
|
||||
@@ -1637,7 +1521,11 @@ fn resolver_renders_aligned_native_draft_alternative_and_separate_history() {
|
||||
let source_rows: Vec<_> = views
|
||||
.rects
|
||||
.iter()
|
||||
.map(|(_, area)| line_at(&terminal, *area, area.y))
|
||||
.map(|(_, area)| {
|
||||
(area.y..area.bottom())
|
||||
.map(|y| line_at(&terminal, *area, y))
|
||||
.collect::<String>()
|
||||
})
|
||||
.collect();
|
||||
assert!(source_rows.iter().any(|row| row.contains("base")));
|
||||
assert!(source_rows.iter().any(|row| row.contains("left")));
|
||||
@@ -1645,19 +1533,15 @@ fn resolver_renders_aligned_native_draft_alternative_and_separate_history() {
|
||||
let history = &views.history[&views.history_key.unwrap()];
|
||||
for (column, (_, content)) in views.rects.iter().enumerate() {
|
||||
let x = content.right() - history.widths[column] as u16;
|
||||
let side = usize::from(column != 1);
|
||||
let buffer = terminal.backend().buffer();
|
||||
assert_eq!(buffer[(x, content.y)].symbol(), "v");
|
||||
assert_eq!(
|
||||
buffer[(x, content.y)].bg,
|
||||
views.panels.diff_colors.row[side]
|
||||
);
|
||||
assert_eq!(buffer[(x, content.y)].bg, views.panels.diff_colors.row[0]);
|
||||
assert_eq!(
|
||||
buffer[(x + 8, content.y)].bg,
|
||||
views.panels.diff_colors.character[side]
|
||||
views.panels.diff_colors.character[0]
|
||||
);
|
||||
assert_eq!(
|
||||
buffer[(x, content.y + 1)].bg,
|
||||
buffer[(x, content.y + 2)].bg,
|
||||
Color::Reset,
|
||||
"Shared historical context must not be highlighted as changed"
|
||||
);
|
||||
@@ -1672,22 +1556,21 @@ fn resolver_renders_aligned_native_draft_alternative_and_separate_history() {
|
||||
session.editor_mut().focus_resolver_pane(right_history);
|
||||
session.execute(&format!("resolve.source {}", third_source + 1));
|
||||
render(&mut terminal, &mut views, &mut session);
|
||||
assert!(
|
||||
views
|
||||
.rects
|
||||
.iter()
|
||||
.any(|(_, area)| { line_at(&terminal, *area, area.y).contains("value = third;") })
|
||||
);
|
||||
assert!(views.rects.iter().any(|(_, area)| {
|
||||
(area.y..area.bottom()).any(|y| line_at(&terminal, *area, y).contains("value = third;"))
|
||||
}));
|
||||
let history_areas = [views.rects[0].1, views.rects[1].1, views.rects[2].1];
|
||||
let insertion_y = (history_areas[2].y..history_areas[2].bottom())
|
||||
.find(|&y| line_at(&terminal, history_areas[2], y).contains("third-only"))
|
||||
.unwrap();
|
||||
for content in history_areas.into_iter().take(2) {
|
||||
assert!(
|
||||
line_at(&terminal, content, content.y + 1)
|
||||
line_at(&terminal, content, insertion_y)
|
||||
.chars()
|
||||
.all(|ch| ch == '╱'),
|
||||
"The historical input insertion must leave aligned gaps in input/base"
|
||||
);
|
||||
}
|
||||
assert!(line_at(&terminal, history_areas[2], history_areas[2].y + 1).contains("third-only"));
|
||||
let context_rows: Vec<_> = history_areas
|
||||
.into_iter()
|
||||
.map(|content| {
|
||||
@@ -1734,9 +1617,18 @@ fn resolver_renders_aligned_native_draft_alternative_and_separate_history() {
|
||||
)
|
||||
));
|
||||
render(&mut terminal, &mut views, &mut session);
|
||||
for content in history_areas {
|
||||
assert!(line_at(&terminal, content, content.y).contains("context 01"));
|
||||
}
|
||||
let context: Vec<_> = history_areas
|
||||
.into_iter()
|
||||
.map(|content| {
|
||||
line_at(&terminal, content, content.y)
|
||||
.split_once("context ")
|
||||
.unwrap()
|
||||
.1
|
||||
.trim_end()
|
||||
.to_owned()
|
||||
})
|
||||
.collect();
|
||||
assert!(context.iter().all(|line| line == &context[0]));
|
||||
assert_eq!(session.editor().pane_id(), history_pane);
|
||||
assert_eq!(session.editor().cursor(), history_cursor);
|
||||
assert!(views.scroll(
|
||||
@@ -1801,7 +1693,7 @@ fn resolver_renders_aligned_native_draft_alternative_and_separate_history() {
|
||||
(right_area, "value = right;"),
|
||||
(base_area, "value = base;"),
|
||||
] {
|
||||
assert!(line_at(&terminal, area, area.y).contains(value));
|
||||
assert!((area.y..area.bottom()).any(|y| line_at(&terminal, area, y).contains(value)));
|
||||
}
|
||||
bottom.handle(Input::Char('\t'));
|
||||
assert_eq!(bottom.editor().pane_id(), right);
|
||||
@@ -1818,9 +1710,18 @@ fn resolver_renders_aligned_native_draft_alternative_and_separate_history() {
|
||||
document_wheel(MouseEventKind::ScrollDown, base_area.x, base_area.y)
|
||||
));
|
||||
render(&mut terminal, &mut views, &mut bottom);
|
||||
for area in [left_area, right_area, base_area] {
|
||||
assert!(line_at(&terminal, area, area.y).contains("context 02"));
|
||||
}
|
||||
let context: Vec<_> = [left_area, right_area, base_area]
|
||||
.into_iter()
|
||||
.map(|area| {
|
||||
line_at(&terminal, area, area.y)
|
||||
.split_once("context ")
|
||||
.unwrap()
|
||||
.1
|
||||
.trim_end()
|
||||
.to_owned()
|
||||
})
|
||||
.collect();
|
||||
assert!(context.iter().all(|line| line == &context[0]));
|
||||
let readonly = bottom.editor().context().text;
|
||||
bottom.handle(Input::Char('i'));
|
||||
bottom.handle(Input::Paste("must not edit base".into()));
|
||||
|
||||
Reference in New Issue
Block a user