refactor: rename compile/toggle commands to build/watch

Problem: `compile` and `toggle` are accurate but unintuitive — `compile`
sounds academic and `toggle` says nothing about what it toggles.

Solution: rename the public API and `:Preview` subcommands to `build`
(one-shot) and `watch` (live preview). Internal compiler functions are
unchanged. No aliases for old names — clean break.
This commit is contained in:
Barrett Ruth 2026-03-03 16:40:51 -05:00
parent 8c7bc61286
commit 3a36264f18
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
3 changed files with 13 additions and 13 deletions

View file

@ -1,8 +1,8 @@
local M = {}
local handlers = {
compile = function()
require('preview').compile()
build = function()
require('preview').build()
end,
stop = function()
require('preview').stop()
@ -10,8 +10,8 @@ local handlers = {
clean = function()
require('preview').clean()
end,
toggle = function()
require('preview').toggle()
watch = function()
require('preview').watch()
end,
open = function()
require('preview').open()
@ -33,7 +33,7 @@ local handlers = {
---@param args string
local function dispatch(args)
local subcmd = args ~= '' and args or 'compile'
local subcmd = args ~= '' and args or 'build'
local handler = handlers[subcmd]
if handler then
handler()
@ -58,7 +58,7 @@ function M.setup()
complete = function(lead)
return complete(lead)
end,
desc = 'Compile, stop, clean, toggle, open, or check status of document preview',
desc = 'Build, stop, clean, watch, open, or check status of document preview',
})
end

View file

@ -39,10 +39,10 @@
---@class preview
---@field setup fun(opts?: table)
---@field compile fun(bufnr?: integer)
---@field build fun(bufnr?: integer)
---@field stop fun(bufnr?: integer)
---@field clean fun(bufnr?: integer)
---@field toggle fun(bufnr?: integer)
---@field watch fun(bufnr?: integer)
---@field open fun(bufnr?: integer)
---@field status fun(bufnr?: integer): preview.Status
---@field statusline fun(bufnr?: integer): string
@ -144,7 +144,7 @@ function M.build_context(bufnr)
end
---@param bufnr? integer
function M.compile(bufnr)
function M.build(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
local name = M.resolve_provider(bufnr)
if not name then
@ -176,7 +176,7 @@ function M.clean(bufnr)
end
---@param bufnr? integer
function M.toggle(bufnr)
function M.watch(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
local name = M.resolve_provider(bufnr)
if not name then

View file

@ -17,7 +17,7 @@ describe('commands', function()
it('does not error on :Preview with no provider', function()
require('preview.commands').setup()
assert.has_no.errors(function()
vim.cmd('Preview compile')
vim.cmd('Preview build')
end)
end)
@ -42,10 +42,10 @@ describe('commands', function()
end)
end)
it('does not error on :Preview toggle with no provider', function()
it('does not error on :Preview watch with no provider', function()
require('preview.commands').setup()
assert.has_no.errors(function()
vim.cmd('Preview toggle')
vim.cmd('Preview watch')
end)
end)
end)