Skip to content

Commit 3a23ad7

Browse files
committed
feat: support nested directory for tmpfile_format
1 parent cde4da5 commit 3a23ad7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lua/conform/runner.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,15 @@ local function run_formatter(bufnr, formatter, config, ctx, input_lines, opts, c
375375
uv.fs_write(fd, buffer_text)
376376
uv.fs_close(fd)
377377
callback = util.wrap_callback(callback, function()
378-
log.debug("Cleaning up temp file %s", ctx.filename)
379-
uv.fs_unlink(ctx.filename)
378+
local rel_dirname = vim.fs.dirname(vim.fs.relpath(ctx.dirname, ctx.filename))
379+
if rel_dirname ~= "." then
380+
local dirname = vim.fs.joinpath(ctx.dirname, rel_dirname)
381+
log.debug("Cleaning up temp dir %s", dirname)
382+
uv.fs_rmdir(dirname)
383+
else
384+
log.debug("Cleaning up temp file %s", ctx.filename)
385+
uv.fs_unlink(ctx.filename)
386+
end
380387
end)
381388
end
382389

0 commit comments

Comments
 (0)