Add code action for organizing imports in python.

This commit is contained in:
Drew Galbraith 2025-05-12 22:43:42 -07:00
parent 9da90d53fa
commit 4d6fff0bf2
1 changed files with 22 additions and 0 deletions

22
after/ftplugin/python.lua Normal file
View File

@ -0,0 +1,22 @@
local organize_imports = function()
local cur_buf = vim.api.nvim_get_current_buf()
local cur_buf_name = vim.api.nvim_buf_get_name(cur_buf)
local params = { command = "source.organizeImports.ruff", arguments = { cur_buf_name } }
vim.lsp.buf_request_sync(cur_buf, 'textDocument/codeAction', params)
end
require("which-key").add({
"<leader>co",
function()
vim.lsp.buf.code_action({
apply = true,
context = {
only = { "source.organizeImports" }, -- Or the specific ruff identifier if known
},
bufnr = vim.api.nvim_get_current_buf(),
})
end
,
name = "Organize Imports"
})