Files
2026-04-15 11:06:26 -03:00

68 lines
1.5 KiB
Lua

local augroup = vim.api.nvim_create_augroup("Vitruvio", { clear = true })
local post = function(url, file_path)
vim.fn.system({
"curl",
"-X",
"POST",
"-H",
"Content-Type: application/xml",
"--data-binary",
"@" .. file_path,
url,
})
end
local function get_snippet_path()
local paths = vim.api.nvim_get_runtime_file("vscode/vitruvio.code-snippets", true)
if #paths > 0 then
return paths[1]
end
return nil
end
local function main()
vim.api.nvim_create_user_command("VitruvioURL", function(opts)
vim.b.vitruvio_url = opts.fargs[1]
end, { nargs = 1 })
if vim.bo.filetype == "xml" then
local g = vim.api.nvim_create_augroup("VitruvioBufWritePost", { clear = true })
vim.api.nvim_create_autocmd("BufWritePost", {
group = g,
desc = "Live reload",
callback = function()
if vim.bo.filetype == "xml" then
local url = vim.b.vitruvio_url
if url then
local filename = vim.api.nvim_buf_get_name(0)
post(url, filename)
else
if not vim.b.notified then
print("É necessário atribuir um URL com :VitruvioURL")
vim.b.notified = true
end
end
end
end,
})
end
end
local function setup()
vim.api.nvim_create_autocmd("BufEnter", {
group = augroup,
desc = "Utilidades para o desenvolvedor do Vitruvio",
callback = main,
})
local snippet_path = get_snippet_path()
if snippet_path then
require("luasnip.loaders.from_vscode").load_standalone({
path = snippet_path,
})
end
end
return { setup = setup }