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 M = {}
local handlers = { local handlers = {
compile = function() build = function()
require('preview').compile() require('preview').build()
end, end,
stop = function() stop = function()
require('preview').stop() require('preview').stop()
@ -10,8 +10,8 @@ local handlers = {
clean = function() clean = function()
require('preview').clean() require('preview').clean()
end, end,
toggle = function() watch = function()
require('preview').toggle() require('preview').watch()
end, end,
open = function() open = function()
require('preview').open() require('preview').open()
@ -33,7 +33,7 @@ local handlers = {
---@param args string ---@param args string
local function dispatch(args) local function dispatch(args)
local subcmd = args ~= '' and args or 'compile' local subcmd = args ~= '' and args or 'build'
local handler = handlers[subcmd] local handler = handlers[subcmd]
if handler then if handler then
handler() handler()
@ -58,7 +58,7 @@ function M.setup()
complete = function(lead) complete = function(lead)
return complete(lead) return complete(lead)
end, 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 end

View file

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

View file

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