feat(plugins): integrate ruff via mason-tool-installer and configure Python formatting
This commit is contained in:
1 parent
96d6dc2270
commit
c442ad6ac9
1 file changed
+39
-23
+39
-23
@@ -79,27 +79,43 @@ end
|
|||||||
|
|
||||||
---@type LazySpec
|
---@type LazySpec
|
||||||
return {
|
return {
|
||||||
"stevearc/conform.nvim",
|
-- ruff is both the import sorter and the formatter used for python below
|
||||||
init = function()
|
{
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
||||||
group = vim.api.nvim_create_augroup("user_lsp_safe_actions", { clear = true }),
|
optional = true,
|
||||||
desc = "Apply all safe LSP code actions (source.*, quickfix) before save",
|
opts = function(_, opts)
|
||||||
callback = function(args)
|
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "ruff" })
|
||||||
if vim.bo[args.buf].buftype ~= "" then return end
|
end,
|
||||||
if vim.g.disable_autoformat or vim.b[args.buf].disable_autoformat then return end
|
},
|
||||||
apply_safe_actions(args.buf)
|
{
|
||||||
end,
|
"stevearc/conform.nvim",
|
||||||
})
|
init = function()
|
||||||
end,
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
opts = function(_, opts)
|
group = vim.api.nvim_create_augroup("user_lsp_safe_actions", { clear = true }),
|
||||||
-- Skip format-on-save for JavaScript buffers (.js/.mjs/.cjs); manual
|
desc = "Apply all safe LSP code actions (source.*, quickfix) before save",
|
||||||
-- :Format / <Leader>lf still works. Wraps the astrocommunity pack's
|
callback = function(args)
|
||||||
-- format_on_save so its autoformat toggle handling is preserved.
|
if vim.bo[args.buf].buftype ~= "" then return end
|
||||||
local pack_format_on_save = opts.format_on_save
|
if vim.g.disable_autoformat or vim.b[args.buf].disable_autoformat then return end
|
||||||
opts.format_on_save = function(bufnr)
|
apply_safe_actions(args.buf)
|
||||||
if vim.bo[bufnr].filetype == "javascript" then return end
|
end,
|
||||||
if type(pack_format_on_save) == "function" then return pack_format_on_save(bufnr) end
|
})
|
||||||
return pack_format_on_save
|
end,
|
||||||
end
|
opts = function(_, opts)
|
||||||
end,
|
-- Python: ruff sorts imports (I001), then reformats. ruff always emits
|
||||||
|
-- 4-space indentation, so mixed tab/space indentation is normalized on
|
||||||
|
-- save instead of surviving to raise TabError at runtime.
|
||||||
|
if not opts.formatters_by_ft then opts.formatters_by_ft = {} end
|
||||||
|
opts.formatters_by_ft.python = { "ruff_organize_imports", "ruff_format" }
|
||||||
|
|
||||||
|
-- Skip format-on-save for JavaScript buffers (.js/.mjs/.cjs); manual
|
||||||
|
-- :Format / <Leader>lf still works. Wraps the astrocommunity pack's
|
||||||
|
-- format_on_save so its autoformat toggle handling is preserved.
|
||||||
|
local pack_format_on_save = opts.format_on_save
|
||||||
|
opts.format_on_save = function(bufnr)
|
||||||
|
if vim.bo[bufnr].filetype == "javascript" then return end
|
||||||
|
if type(pack_format_on_save) == "function" then return pack_format_on_save(bufnr) end
|
||||||
|
return pack_format_on_save
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user