fix: fall back to /tmp for buffers without a backing file (#60)
* fix: fall back to /tmp for buffers without a backing file
Problem: markdown and gfm presets fail when the buffer has no file on
disk (e.g. unnamed buffer with `ft=markdown`, or a named buffer whose
path doesn't exist yet) because `build_context` passes a nonexistent
path to pandoc and `compile` guards reject empty buffer names.
Solution: `build_context` now detects missing files and redirects
`ctx.file` to `/tmp/{bufnr}-{name}`. `compile` writes buffer contents
to that temp path via `vim.fn.writefile` instead of `:silent! update`.
* test: update unnamed buffer tests for tmpfile fallback
Problem: the unnamed buffer guard tests expected a "no file name"
warning that no longer exists after the tmpfile fallback change.
Solution: update assertions to expect the downstream messages that
unnamed buffers now reach ("no provider configured", "no output file").
This commit is contained in:
parent
272153a158
commit
f185ae78f7
3 changed files with 48 additions and 32 deletions
|
|
@ -126,43 +126,43 @@ describe('preview', function()
|
|||
return msg
|
||||
end
|
||||
|
||||
it('compile warns on unnamed buffer', function()
|
||||
local bufnr = helpers.create_buffer({}, 'typst')
|
||||
it('compile falls through to provider check on unnamed buffer', function()
|
||||
local bufnr = helpers.create_buffer({}, 'lua')
|
||||
local msg = capture_notify(function()
|
||||
preview.compile(bufnr)
|
||||
end)
|
||||
assert.is_not_nil(msg)
|
||||
assert.is_truthy(msg:find('no file name'))
|
||||
assert.is_truthy(msg:find('no provider configured'))
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('toggle warns on unnamed buffer', function()
|
||||
local bufnr = helpers.create_buffer({}, 'typst')
|
||||
it('toggle falls through to provider check on unnamed buffer', function()
|
||||
local bufnr = helpers.create_buffer({}, 'lua')
|
||||
local msg = capture_notify(function()
|
||||
preview.toggle(bufnr)
|
||||
end)
|
||||
assert.is_not_nil(msg)
|
||||
assert.is_truthy(msg:find('no file name'))
|
||||
assert.is_truthy(msg:find('no provider configured'))
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('clean warns on unnamed buffer', function()
|
||||
local bufnr = helpers.create_buffer({}, 'typst')
|
||||
it('clean falls through to provider check on unnamed buffer', function()
|
||||
local bufnr = helpers.create_buffer({}, 'lua')
|
||||
local msg = capture_notify(function()
|
||||
preview.clean(bufnr)
|
||||
end)
|
||||
assert.is_not_nil(msg)
|
||||
assert.is_truthy(msg:find('no file name'))
|
||||
assert.is_truthy(msg:find('no provider configured'))
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('open warns on unnamed buffer', function()
|
||||
local bufnr = helpers.create_buffer({}, 'typst')
|
||||
it('open warns no output on unnamed buffer', function()
|
||||
local bufnr = helpers.create_buffer({}, 'lua')
|
||||
local msg = capture_notify(function()
|
||||
preview.open(bufnr)
|
||||
end)
|
||||
assert.is_not_nil(msg)
|
||||
assert.is_truthy(msg:find('no file name'))
|
||||
assert.is_truthy(msg:find('no output file'))
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue