[Neovim] How to organize imports on save (with configuration options) #25512
-
|
Hello! In Neovim, how can I configure Ruff to automatically sort imports on file save? I have the following in my vim.lsp.config("ruff", {
init_options = {
settings = {
lineLength = 100,
configurationPreference = "filesystemFirst",
configuration = {
fix = true,
format = {
["docstring-code-format"] = true,
},
lint = {
isort = {
["combine-as-imports"] = true,
},
pycodestyle = {
["max-doc-length"] = 100,
},
pydocstyle = {
convention = "numpy",
},
},
},
},
},
})
vim.lsp.enable("ruff")and I have Formatting works fine, but import sorting does not happen. I know I could use formatters_by_ft = {
python = { "ruff_fix", "ruff_organize_imports", "ruff_format" }
}to make this happen, but then the Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This is expected because There are couple of solutions:
|
Beta Was this translation helpful? Give feedback.
This is expected because
conform.nvimuses the command-line to invokeruffexecutable. So, the language server is a different interface than the command-line and the settings that you pass to the language server viavim.lsp.configis only recognized by the server that's running in the background. Whileconform.nvimwill invoke theruffcommand on each run. This is whyruffas run viaconform.nvimwill not pickup the options specified invim.lsp.config. Does that make sense?There are couple of solutions:
pyproject.toml/ru…