Neovim companion (nvim/) #2
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Moved from thatrichan/revue#70.
A Neovim plugin doing what the JetBrains plugin (
jetbrains/) does, in Neovim's way: commands, a pull request list in a buffer or picker, signs in the gutter, and Revue opening a pull request in the running Neovim that has its branch.Neovim 0.10 or later, pure Lua, no other dependency (Telescope, fzf-lua and snacks pickers used when present).
Features
:Revue/:Revue open: the current branch's pull request in Revue, or its New pull request page (revue --pull-request <dir>).:Revue list: the repository's open pull requests (revue --pulls, with--show, drafts, search, pages) in Revue's sections (This branch, To review, Mine, Others), in a picker when one is installed, else a scratch buffer.<CR>opens the details buffer (revue --pull): review, checks, conflicts, files, conversation, stack; mappings to open in Revue or the browser, yank the link, switch to the branch, create the worktree (--worktree), fetch the branch (--fetch-branch).--branch-pull,--pending);:Revue fileopens the file in the pull request at the cursor's line;:Revue commenton a visual selection adds a pending comment (--comment, the body typed in a small floating window);:Revue fileslists the pull request's files to jump to.statuslinecomponent: the branch's pull request number and state, for lualine and others.require("revue_companion").setup({ path = …, signs = …, keys = … }): therevueexecutable (empty: PATH, then the install places the JetBrains plugin looks in), no default mappings beyond the buffer-local ones in its own windows.:checkhealth revue_companion: findsrevue, readsrevue --version'seditor <N>line, and says whether Revue is running.It talks to Revue only through the
revuecommand (Revue'sdocs/command-line.md, "What editors can ask"), run withvim.systemso nothing blocks the editor. No tokens enter Neovim.The way back: Revue reaching a running Neovim
Every Neovim already listens on an RPC socket (
v:servername), so it needs no server of its own:<Revue's data folder>/companions/nvim-<pid>.jsonwith{ "kind": "nvim", "pid", "socket": v:servername, "version" }, written at startup and removed onVimLeavePre. Revue ignores a stale file (pid gone, socket refusing).require("revue_companion").projects()(cwd and tabs' working directories, each repository's root, branch and remotes, whether the UI is focused) andrequire("revue_companion").open({ path, repo, branch, file, line })(:tcdto the folder in a new tab unless one has the branch, then:edit fileat the line).$WINDOWIDor the terminal's process on Linux), and says so when it can't.companionsmodule reads these files too, and annvimclient (a small msgpack-RPC call over the socket: Unix socket, or named pipe on Windows) does the two requests. The editor chooser (thatrichan/revue#68) then treats Neovim like any other companion.Where it lives
nvim/in this repository, laid out as plugin managers expect (nvim/lua/revue_companion/,nvim/plugin/,nvim/doc/revue-companion.txt); lazy.nvim and others install it from this repository with their subdirectory option (lazy.nvim:{ "thatrichan/revue-companion", url = …, config = …, dir/subdir = "nvim" }, to check per manager). Tests withbustedormini.testin headless Neovim against a fakerevueprinting fixture JSON,styluaandluacheck; releases asnvim-vX.Y.Ztags.If a subdirectory turns out awkward for the plugin managers, a mirror repository (
revue-companion.nvim) published fromnvim/by the release workflow is the fallback.Plan
companionsregistration in Revue (shared with VS Code) and itsnvimRPC client, with tests against a headless Neovim.revue: open, list, details, file, comment, files, health.docs/editors.mdgets a Neovim section, and:help revue-companion.revuecommand, so Open in editor can reach them #80Step 1 of
nvim/PLAN.mdis in (merged in757fcc8)::Revue open | file | browse | yank | sign-in, with completion and<Plug>mappings; nothing loads at startup.revueas the JetBrains plugin does, gating oneditor N,vim.systemso nothing blocks.require("revue_companion").status(),:checkhealth revue_companion,:help revue-companion.revue, mini.test specs (task nvim:test, coverage 97 %), stylua and selene (task nvim:lint)..forgejo/workflows/nvim.ymlon Neovim 0.11.7, stable and nightly.revue_companion, Neovim 0.11 the oldest (the plan says so now).Next: step 2, the pull request list and a pull request's page. The way back needs thatrichan/revue#80 first.
Step 2 is in (merged in
8cf6020): the pull request list and a pull request's page.:Revue list [all|involved|to-review|review|reviewed|mine] [drafts|no-drafts]: arevue://pulls/<root>buffer in Revue's sections as folds, starred first; keys<CR>ogxysf/Rg?; the next page loads at the end.:Revue pickthroughvim.ui.select.revue://pull/<owner>/<repo>/<n>, read-only Markdown (gOoutline): state, review, checks, conflicts, tickets, files, conversation, Slack threads, stack;<CR>opens a file at its line,bfetches and switches to the branch,wmakes a worktree in a new tab.<Plug>(RevueList)/<Plug>(RevuePick),:helpsections; 170 specs, coverage 97 %.Next: step 3, signs and pending comments in your buffers,
:Revue diff,files,comment.Step 3 is in (merged in
a466f44): the pull request in your own files.✎with their first line as virtual text; refreshed when Revue answers and on focus.]r/[r(with a count) between the pull request's changes.:Revue diff(editor 3): the file before the pull request in a split, in diff mode.:Revue files: the pull request's files, opened at their first change.:Revue comments: your pending comments and the open conversations in the quickfix list.:Revue comment(Normal, a range or visual): a Markdown float,:w/<C-s>sends it as a pending comment,qgives up.signs/comments, highlight groups,:help revue-companion→ IN YOUR FILES; 230 specs, coverage 97 %.Next: step 4, the review in Neovim (
:Revue review).Step 5, the way back, is in (merged in
b8202e4), against thatrichan/revue#80 (editor 9):editor 9andv:servernameset, the plugin registers withrevue --companion nvim --pid … --socket <v:servername>without blocking, and runs--companion-goneon quit. Theregistersetting turns it off.require("revue_companion").projects()(the working directory and each tab's, their repositories, focus) and.open({path, repo, branch, file, line})(the tab with that repository on the branch, else a new tab with:tcd, then the file at the line). Both are in:help revue-companion-from-revue.:checkhealthsays whether Revue knows this Neovim runs.Not yet tried against a real Revue. Still to do: step 4 (the review tab) and step 6 (README, release, mirror).
Steps 4 and 6 are in (merged in
e2c510b), so every step of the plan is built::Revue review [LINK](alsoron a pull request's page): a tab with the files as a tree (status, lines, 💬 conversations, ✎ pending, ✓ viewed) and the two sides in diff mode (text from Git when the clone has both commits, else--sides). Conversations as virtual lines under their lines, kept level on both sides;]c/[c,]f/[f,cto comment (normal or visual, either side),vviewed (editor 7), a float to reply, resolve (editor 5), react (editor 8), edit / delete your pending ones and apply a suggestion;@completion frommentionable.:Revue submit: the summary in a float with what goes with it, then the verdict (and resolve yours, Slack thread).:Revue threadsinto the quickfix list..forgejo/workflows/release-nvim.yml(by hand) testsnvim/on its own, tagsnvim-vX.Y.Z, and publishesnvim/tothatrichan/revue-companion.nvimwhen theNVIM_MIRROR_TOKENsecret is set;nvim/README.mdis that repository's README.#!, on the ruler left on the screen by 0.11, and on Revue's answers arriving before a screenshot. Fixed (0e94701); the specs pass on v0.11.7, stable and nightly.338 specs. Left: creating the mirror repository and its secret, the first release, and trying it against a real Revue.
Every step of the plan is built; the way back also skips registering over SSH or in a container, and
projects()lists the repositories of other open files. CI passes on 0.11.7, stable and nightly. nvim 0.1.0 is queued (release-nvim), which also fillsrevue-companion.nvim; Revue's docs/editors.md already has the Neovim section. Checking the release and trying it against Revue 0.44 are in #9.