refactor(compiler): resolve output before args (#17)

Problem: presets that need the output path in their args function
(markdown, github) had to recompute it inline, duplicating the same
gsub expression already in the output field.

Solution: resolve output_file first in M.compile, then extend ctx with
output = output_file into a resolved_ctx before evaluating args and cwd.
Presets can now reference ctx.output directly. Add output? to the
preview.Context type annotation.
This commit is contained in:
Barrett Ruth 2026-03-03 15:12:14 -05:00 committed by GitHub
parent 4c22f84b31
commit 99263dec9f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 11 deletions

View file

@ -53,19 +53,21 @@ function M.compile(bufnr, name, provider, ctx)
M.stop(bufnr)
end
local output_file = ''
if provider.output then
output_file = eval_string(provider.output, ctx)
end
local resolved_ctx = vim.tbl_extend('force', ctx, { output = output_file })
local cmd = vim.list_extend({}, provider.cmd)
if provider.args then
vim.list_extend(cmd, eval_list(provider.args, ctx))
vim.list_extend(cmd, eval_list(provider.args, resolved_ctx))
end
local cwd = ctx.root
if provider.cwd then
cwd = eval_string(provider.cwd, ctx)
end
local output_file = ''
if provider.output then
output_file = eval_string(provider.output, ctx)
cwd = eval_string(provider.cwd, resolved_ctx)
end
if output_file ~= '' then