Rearchitect the plugin, with mini.test specs #1

Merged
eleith merged 22 commits from rearchitecture into main 2026-09-22 17:52:49 +00:00
Owner

Description:

Same plugin, reorganized so it's easier to follow and change.

Code

  • model/ holds the comments and where they are, ui/ what's drawn, export/ the output formats.
  • comments.lua is the only place comments change, and it keeps the signs in sync.
  • plugin/ defines the commands. setup() is no longer needed but still works.
  • Files stay under about 200 lines.

Tests

  • mini.test replaces the homemade runner. make clones it, pinned, into deps/.
  • tests/unit covers single modules. tests/features runs the commands.
  • 129 specs, one per behavior, each starting from a clean editor.

Behavior changes

  • Comments on the same lines sort in the order they were added (comment-10 used to sort before comment-2).
  • The picker and Markdown export describe locations the way the window title does ("lines 3–5", "line 3, col 5–12"). Quickfix jumps to the selected text.
  • Neovim 0.12 is the minimum.

Also includes three earlier commits from main: the padding color, the test runner fix, and the single comment window.

Description: Same plugin, reorganized so it's easier to follow and change. Code - model/ holds the comments and where they are, ui/ what's drawn, export/ the output formats. - comments.lua is the only place comments change, and it keeps the signs in sync. - plugin/ defines the commands. setup() is no longer needed but still works. - Files stay under about 200 lines. Tests - mini.test replaces the homemade runner. make clones it, pinned, into deps/. - tests/unit covers single modules. tests/features runs the commands. - 129 specs, one per behavior, each starting from a clean editor. Behavior changes - Comments on the same lines sort in the order they were added (comment-10 used to sort before comment-2). - The picker and Markdown export describe locations the way the window title does ("lines 3–5", "line 3, col 5–12"). Quickfix jumps to the selected text. - Neovim 0.12 is the minimum. Also includes three earlier commits from main: the padding color, the test runner fix, and the single comment window.
eleith added 6 commits 2026-09-22 15:52:45 +00:00
The padding column is a statuscolumn, which draws in LineNr, so it
showed as a strip in colorschemes that give LineNr its own background.
The test runner matched FAIL only at the start of a line, but Neovim can
print mode messages before it, so failures showed as ok. It now finds
FAIL anywhere and treats a suite that never reports ok as failed.

That exposed two failures: the padding test still expected the old
winhighlight, and the long title test expected the wrong columns and
measured with strdisplaywidth, which counts linebreak padding in the
current window. Title fitting now uses nvim_strwidth too.
A comment opens in one window, as in Google Docs: :CommentShow shows it
in normal mode, and you edit it there and :w to save. :CommentEdit and
scratch.edit() are gone, and :Comment on a commented range opens the
same window.

:CommentNext and :CommentPrev move any open comment window to the next
or previous comment, a new one included. With unsaved changes they
refuse, like :bnext, so nothing is lost. The title shows the count and
the mode: "comment (3 of 4) [NORMAL]".
make test clones mini.test at a pinned version into deps/, once per
version, and runs tests/**/*_spec.lua in-process before the old suites.
Specs use describe/it/before_each with mini.test's expect, and each one
starts from a reset editor through tests/helpers.lua.

The export suite is the first one ported, as list_export_spec.lua.
reflow.lua and orphans.lua become anchoring_spec.lua, and spans.lua
becomes spans_spec.lua. Each case builds its own buffer instead of
continuing from the edits before it.

In-process specs are enough: helpers fire TextChanged and break undo
blocks where headless Neovim doesn't, and answer vim.ui.select.
Split the smoke suite into feature specs
ci/woodpecker/pr/ci Pipeline was successful
353f7dc4d9
smoke.lua becomes commenting, window, show_delete, navigation and signs
specs, plus cases in list_export and anchoring. :e! gets a fixture file
instead of the repo's LICENSE. The old runner and minimal_init.lua go,
so make test runs mini.test only.
eleith added 1 commit 2026-09-22 15:55:12 +00:00
Cover the behavior that had no specs
ci/woodpecker/pr/ci Pipeline was successful
360002021f
Specs for the unnamed-buffer warning, the window border, cancelled
pickers, deleting with nothing to delete, :CommentToggle usage,
navigation with other files or a changed comment, clipboard failure,
sorting across files, nested code fences and :checkhealth.

helpers.notified() runs scheduled notifications before reading them,
and reset flushes them so none reach the next spec.
eleith added 1 commit 2026-09-22 15:59:27 +00:00
Move the comment list into model/store.lua
ci/woodpecker/pr/ci Pipeline was successful
6a7f5d3620
The store holds the comments and their ids and makes no Neovim calls.
One remove(predicate) replaces remove_ids and remove_buffer. state.lua
keeps only the views: where each comment is now, and its snippet.
eleith added 1 commit 2026-09-22 16:02:34 +00:00
Order comments on the same lines by their number
ci/woodpecker/pr/ci Pipeline was successful
be805ea1bf
Ids were compared as text, so comment-10 sorted before comment-2. They
now compare by the number in the id, the order they were added.
eleith added 1 commit 2026-09-22 16:05:18 +00:00
Describe locations in location.lua
ci/woodpecker/pr/ci Pipeline was successful
a5d15bd89a
The window title's location format becomes location.describe, with
title and fit beside it. A comment view is now a comment plus a
location.
eleith added 1 commit 2026-09-22 16:10:27 +00:00
Rename context.lua to paths.lua
ci/woodpecker/pr/ci Pipeline was successful
2605e731e2
It finds a file's git root and its path relative to that root, so the
name says so. Its own trim gives way to vim.trim.
eleith added 1 commit 2026-09-22 16:12:20 +00:00
Group the export modules in export/
ci/woodpecker/pr/ci Pipeline was successful
aaf7470d4c
markdown.lua, json.lua and the clipboard copy (export.lua) move into
export/, unchanged. Unit specs check the whole markdown output and the
json fields.
eleith added 1 commit 2026-09-22 16:16:38 +00:00
Split render.lua into anchors and signs
ci/woodpecker/pr/ci Pipeline was successful
8ef9e7e0fb
model/anchors.lua keeps the extmarks that track where comments are.
ui/signs.lua draws the signs from them and holds their visibility.
eleith force-pushed rearchitecture from b9785b3d71 to 8ef9e7e0fb 2026-09-22 16:16:38 +00:00 Compare
eleith added 1 commit 2026-09-22 16:22:32 +00:00
Change comments only through comments.lua
ci/woodpecker/pr/ci Pipeline was successful
b60ab66161
Adding, editing, deleting, clearing and forgetting a buffer's comments
go through comments.lua, which keeps anchors and signs in sync, so the
hand-written sign redraws go. state.lua becomes model/views.lua.
eleith added 1 commit 2026-09-22 16:25:37 +00:00
Move the comment window and notifications into ui/
ci/woodpecker/pr/ci Pipeline was successful
966409c759
ui/window.lua has the two-pane frame and tracks the open comment window,
so the frame no longer needs an on_close hook. ui/notify.lua replaces
notify(message, kind) with info, warn and error.
eleith added 1 commit 2026-09-22 16:36:54 +00:00
Move next and prev into navigate.lua
ci/woodpecker/pr/ci Pipeline was successful
eb4e08c186
navigate.jump either cycles the open comment window or moves the cursor
to the next comment's line. Cycling shows a comment, so navigate calls
annotate.show. The buffer's views and index_of move into model/views.
eleith added 1 commit 2026-09-22 16:42:14 +00:00
Split the commands into actions, export and quickfix
ci/woodpecker/pr/ci Pipeline was successful
991230b4fa
annotate.lua becomes actions.lua, with toggle and clear from init.lua.
Rendering and :CommentExport move into export/init.lua, and ui.lua
becomes ui/quickfix.lua for :CommentList. init.lua is the Lua API and
setup.
eleith added 1 commit 2026-09-22 16:44:35 +00:00
Name lists of comments views, and find them one way
ci/woodpecker/pr/ci Pipeline was successful
3cb710ee68
Lists that were called items are views, anchored or comments. actions
finds a buffer's comments through views.in_buffer, so views.find and
find_all go. Helpers used only inside their module become local.
eleith added 1 commit 2026-09-22 16:48:08 +00:00
Define the commands in plugin/, without setup()
ci/woodpecker/pr/ci Pipeline was successful
4e6987f08e
plugin/scratch-comments.lua defines the commands and loads the plugin
when one runs. The autocmds and the sign highlight are set when their
modules first load, so nothing runs on text changes before a comment
command has. setup() is kept as a no-op for configs that call it.
eleith added 1 commit 2026-09-22 16:51:11 +00:00
Describe locations one way, and put columns in quickfix
ci/woodpecker/pr/ci Pipeline was successful
f5da74b756
The picker and the markdown export use location.describe, the window
title's format: "line 3", "lines 3–5", "line 3, col 5–12". This fixes the
picker's "lines 3" for one line. Quickfix gets a span's columns, so ]q
lands on the text.
eleith added 1 commit 2026-09-22 17:01:03 +00:00
Require Neovim 0.12
ci/woodpecker/pr/ci Pipeline was successful
537221dd0c
The comment window reads 'winborder', which needs 0.11, and CI tests on
0.12. :checkhealth, the README and the help file now say 0.12.
eleith added 1 commit 2026-09-22 17:23:24 +00:00
Only a new comment opens in insert mode, and :CommentList lands on a
span's text. The wording is plainer throughout. The README now maps the
code layout and says how to run the checks.
eleith changed title from Rearchitecture to Rearchitect the plugin, with mini.test specs 2026-09-22 17:52:24 +00:00
eleith merged commit 962a2c7f17 into main 2026-09-22 17:52:49 +00:00
eleith deleted branch rearchitecture 2026-09-22 17:52:49 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: eleith/scratch-comments.nvim#1