filetypes: set rules for python filetype

- Disables forlding.
- Lets Ruff sort imports and format file content on save.

Co-Authored-by: iGor milhit <igor@milhit.ch>
main
iGor milhit 2026-08-13 07:32:40 +02:00
parent ccecc89a42
commit a111e23eec
Signed by: igor
GPG Key ID: 692D97C3D0228A99
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
-- Deactivate fold for python files
vim.opt.foldlevel = 99
-- Ruff import sorting and formatting
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = 0,
callback = function()
-- Tri des imports via code action Ruff
local clients = vim.lsp.get_clients({ bufnr = 0 })
for _, c in ipairs(clients) do
if c.name == "ruff" then
vim.lsp.buf.code_action({
context = { only = { "source.organizeImports.ruff" } },
apply = true,
})
break
end
end
-- Formatage du code
vim.lsp.buf.format({ async = false })
end,
})