nvim: Use Ruff as Python LSP

Though Ruff is not an LSP in the LSP sense but using it this way
gives us formatting and linting via code actions. All other Python
LSP servers are garbage anyway.
This commit is contained in:
Sanchayan Maity 2023-10-25 17:52:04 +05:30
parent 0496c7a0a0
commit 940c66406f
Signed by: sanchayanmaity
GPG Key ID: 6F6A0609C12038F3
3 changed files with 19 additions and 4 deletions

View File

@ -1,7 +1,9 @@
vim.bo.textwidth = 0
vim.bo.formatprg = "black -q -"
local lsp_utils = require('lsp-utils')
local ruff_config = lsp_utils.ruff_config()
vim.keymap.set('n', 'gq', "ggVGgq<C-o><C-o>", { noremap=true, silent=true, buffer=0 })
vim.lsp.start(ruff_config)
vim.bo.textwidth = 0
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
buffer = 0,

View File

@ -11,7 +11,6 @@ nvim_lint.linters_by_ft = {
javascript = { 'eslint_d' },
lua = { 'luacheck' },
markdown = { 'vale' },
python = { 'ruff' },
sh = { 'shellcheck' },
typescript = { 'eslint_d' },
yaml = { 'yamllint' },

View File

@ -239,6 +239,20 @@ function M.ra_config()
}
end
function M.ruff_config()
local root_files = { 'pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', 'Pipfile' }
local root_directory = get_root_directory(root_files)
return {
name = "ruff",
cmd = { "ruff-lsp" },
filetypes = { 'python' },
capabilities = default_capabilities,
root_dir = root_directory,
single_file_support = true,
}
end
function M.scheme_config()
local root_files = { '.git' }
local root_directory = get_root_directory(root_files)