From a111e23eec41aa7be09bb5024e30d89d86fc5a71 Mon Sep 17 00:00:00 2001 From: iGor milhit Date: Thu, 13 Aug 2026 07:32:40 +0200 Subject: [PATCH] filetypes: set rules for python filetype - Disables forlding. - Lets Ruff sort imports and format file content on save. Co-Authored-by: iGor milhit --- after/ftplugin/python.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 after/ftplugin/python.lua diff --git a/after/ftplugin/python.lua b/after/ftplugin/python.lua new file mode 100644 index 0000000..b64b458 --- /dev/null +++ b/after/ftplugin/python.lua @@ -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, +}) +