From 4d6fff0bf2c9e58b3fd3c69addff408587996e48 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Mon, 12 May 2025 22:43:42 -0700 Subject: [PATCH] Add code action for organizing imports in python. --- after/ftplugin/python.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 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..7e25731 --- /dev/null +++ b/after/ftplugin/python.lua @@ -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({ + "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" +})