diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml new file mode 100644 index 0000000..840f693 --- /dev/null +++ b/.github/workflows/demo.yml @@ -0,0 +1,25 @@ +name: demo + +# Renders demo/demo.tape and uploads demo.gif as a workflow artifact. +on: + workflow_dispatch: + pull_request: + paths: + - demo/** + +jobs: + vhs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: stable + - uses: charmbracelet/vhs-action@v2 + with: + path: demo/demo.tape + - uses: actions/upload-artifact@v4 + with: + name: demo + path: demo/demo.gif diff --git a/README.md b/README.md index 3b8f52a..19d5292 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Leave annotations on exact pieces of code, then hand them to an AI agent as one - Works in [gh-review.nvim](https://github.com/gh-tui-tools/gh-review.nvim) diff buffers: the source becomes a GitHub link at the PR commit - No dependencies. Neovim 0.9+. +![demo](demo/demo.gif) + ## Export format ````markdown @@ -173,3 +175,14 @@ If an annotation's text can't be found when the buffer opens, it stays where it ```sh nvim --headless -u NONE -c "luafile tests/run.lua" ``` + +## Demo + +The GIF above is recorded with [VHS](https://github.com/charmbracelet/vhs) from `demo/demo.tape`. +It runs Neovim with `demo/init.lua` on a copy of `demo/reconcile.go` in a throwaway git repo, so your own annotations are not touched: + +```sh +vhs demo/demo.tape +``` + +The `demo` workflow renders it too (on demand, and on pull requests that change `demo/`) and uploads `demo.gif` as an artifact. diff --git a/demo/demo.tape b/demo/demo.tape new file mode 100644 index 0000000..6e19a5e --- /dev/null +++ b/demo/demo.tape @@ -0,0 +1,79 @@ +# Render with `vhs demo/demo.tape` from the repository root. +# Needs vhs (https://github.com/charmbracelet/vhs), nvim 0.10+ and git. + +Output demo/demo.gif + +Require nvim +Require git + +Set Shell "bash" +Set FontSize 18 +Set Width 1200 +Set Height 720 +Set Padding 20 +Set Theme "Catppuccin Mocha" +Set TypingSpeed 60ms + +# Throwaway git project, so the source paths are relative to its root. +Hide +Type `R=$PWD D=$(mktemp -d) && mkdir -p $D/pkg/controller && cp demo/reconcile.go $D/pkg/controller/ && cd $D && git init -q && stty -ixon && clear` +Enter +Type "nvim -u $R/demo/init.lua pkg/controller/reconcile.go" +Enter +Sleep 1.5s +Show + +Sleep 1s + +# 1. Annotate a character selection. +Type "/r.Client" +Enter +Sleep 500ms +Type "vf)" +Sleep 800ms +Space +Type "aa" +Sleep 600ms +Type "Should be a Patch: Update conflicts with the status writer." +Sleep 500ms +Ctrl+S +Sleep 1.5s + +# 2. Annotate a whole line. +Type "/30" +Enter +Sleep 500ms +Type "V" +Sleep 600ms +Space +Type "aa" +Sleep 600ms +Type "Make the requeue interval configurable?" +Sleep 500ms +Ctrl+S +Sleep 1.5s + +# 3. Jump between annotations. +Type "[a" +Sleep 1s +Type "]a" +Sleep 1s + +# 4. Annotations follow edits: add an import above them. +Type "gg3j" +Sleep 300ms +Type `o"fmt"` +Escape +Sleep 1.5s + +# 5. Preview what the agent gets. +Space +Type "ap" +Sleep 4s +Type "q" +Sleep 300ms + +# Clean up. +Hide +Type ":qa!" +Enter diff --git a/demo/init.lua b/demo/init.lua new file mode 100644 index 0000000..38cbffc --- /dev/null +++ b/demo/init.lua @@ -0,0 +1,22 @@ +-- Minimal config for the VHS demo: `vhs demo/demo.tape` from the repo root. +local repo = vim.fs.dirname(vim.fs.dirname(debug.getinfo(1, "S").source:sub(2))) +vim.opt.runtimepath:prepend(repo) + +vim.g.mapleader = " " +vim.opt.number = true +vim.opt.signcolumn = "yes" +vim.opt.termguicolors = true +vim.opt.swapfile = false +vim.opt.shortmess:append("I") +vim.opt.laststatus = 3 + +require("annotate").setup({ + -- Throwaway store, so the demo never touches real annotations. + data_dir = vim.fn.tempname(), +}) + +local a = require("annotate") +vim.keymap.set({ "n", "x" }, "aa", a.add, { desc = "Annotate" }) +vim.keymap.set("n", "ap", a.preview, { desc = "Annotate: preview" }) +vim.keymap.set("n", "]a", function() a.jump(1) end, { desc = "Next annotation" }) +vim.keymap.set("n", "[a", function() a.jump(-1) end, { desc = "Previous annotation" }) diff --git a/demo/reconcile.go b/demo/reconcile.go new file mode 100644 index 0000000..8eaf6f9 --- /dev/null +++ b/demo/reconcile.go @@ -0,0 +1,17 @@ +package controller + +import ( + "context" + "time" +) + +// Reconcile brings the cluster state in line with obj. +func (r *Reconciler) Reconcile(ctx context.Context, obj *Object) error { + obj.Status.LastSync = time.Now() + + if err := r.Client.Update(ctx, obj); err != nil { + return err + } + + return r.requeue(ctx, obj, 30*time.Second) +} diff --git a/lua/annotate/init.lua b/lua/annotate/init.lua index 0780887..edcd4de 100644 --- a/lua/annotate/init.lua +++ b/lua/annotate/init.lua @@ -81,6 +81,8 @@ function M.jump(dir) if not src then return end + -- Positions in the store are stale until synced from the buffer's extmarks. + render.sync(vim.api.nvim_get_current_buf()) local cur = vim.api.nvim_win_get_cursor(0) local list = store.for_key(src.root, src.key) table.sort(list, function(x, y) diff --git a/tests/run.lua b/tests/run.lua index 7c80fc3..6f91e86 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -538,5 +538,21 @@ test("list.picker = quickfix skips installed pickers", function() eq(vim.fn.getqflist({ size = 0 }).size, 1) end) +test("jump follows unsaved edits", function() + vim.fn.delete(tmp .. "/data", "rf") + open_go() + vim.fn.cursor(4, 12) + table.insert(answers, { text = "x" }) + vim.cmd("normal! vf)\27") + vim.cmd("'<,'>Annotate add") + vim.api.nvim_buf_set_lines(0, 1, 1, false, { "// added", "// lines" }) + vim.fn.cursor(1, 1) + annotate.jump(1) + eq(vim.api.nvim_win_get_cursor(0), { 6, 11 }) + vim.fn.cursor(10, 1) + annotate.jump(-1) + eq(vim.api.nvim_win_get_cursor(0), { 6, 11 }) +end) + print(string.format("\n%d passed, %d failed", passed, failures)) vim.cmd(failures == 0 and "qa!" or "cq!")