nvim/qml: add autoformatting script

This commit is contained in:
kossLAN 2025-01-31 01:43:21 -05:00
parent f3f07ab618
commit 01444ab8a5
Signed by: kossLAN
SSH key fingerprint: SHA256:bdV0x+wdQHGJ6LgmstH3KV8OpWY+OOFmJcPcB0wQPV8
2 changed files with 28 additions and 0 deletions

View file

@ -117,6 +117,7 @@ with final.pkgs.lib; let
stylua # lua formatter stylua # lua formatter
rustfmt # rust formatter rustfmt # rust formatter
prettierd # typescript/javascript formatter prettierd # typescript/javascript formatter
qt6.qtdeclarative
# google-java-format # java formatter based off google guidelines # google-java-format # java formatter based off google guidelines
# misc # misc

27
nvim/ftplugin/qml.lua Normal file
View file

@ -0,0 +1,27 @@
if vim.fn.executable('qmlformat') ~= 1 then
return
end
-- Stupid conform doesn't support qmlformat, and I don't want to download a
-- whole new fucking plugin so uh yea this is it ig.
vim.api.nvim_create_autocmd('BufWritePre', {
pattern = '*.qml',
callback = function()
local bufnr = vim.api.nvim_get_current_buf()
local filename = vim.api.nvim_buf_get_name(bufnr)
local cmd = string.format('qmlformat -i "%s"', filename)
local output = vim.fn.system(cmd)
local error_code = vim.v.shell_error
if error_code ~= 0 then
vim.notify(
string.format('qmlformat failed (code %d):\nCommand: %s\nOutput: %s', error_code, cmd, output),
vim.log.levels.ERROR
)
end
vim.api.nvim_buf_set_option(bufnr, 'modified', false)
vim.cmd('edit!')
end,
})