nvim: Fix ruff lsp

We now make use of the ruff-inbuilt LSP offering since it just entered
beta.
We also disable all rules in pyright LSP that ruff takes care of, and in
turn disable hover capability in ruff since it's worse than pyright
(still).
More information here:
https://github.com/astral-sh/ruff/tree/main/crates/ruff_server#setup
and here:
https://github.com/astral-sh/ruff/blob/main/crates/ruff_server/docs/setup/NEOVIM.md
This commit is contained in:
Marty Oehme 2024-06-17 13:33:31 +02:00
parent 8dbfa2dd13
commit b2dfdfd5ff
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -34,7 +34,7 @@ local servers = {
filetypes = { "markdown", "quarto" },
},
basedpyright = {},
ruff_lsp = {},
ruff = {},
serve_d = {},
tailwindcss = {},
taplo = {},
@ -54,7 +54,7 @@ require("mason-tool-installer").setup({
start_delay = 3000,
})
local function on_attach(client, bufnr)
local function on_attach(_, bufnr)
local map = vim.keymap.set
map("n", "[d", "<cmd>lua vim.diagnostic.goto_prev()<cr>", { buffer = bufnr, desc = "Previous diagnostic" })
map("n", "]d", "<cmd>lua vim.diagnostic.goto_next()<cr>", { buffer = bufnr, desc = "Next diagnostic" })
@ -167,21 +167,35 @@ local python_path
-- ensure python virtualenv is determined automatically on lsp start
lspconfig.basedpyright.setup({
on_attach = function(client, bufnr)
on_attach(client, bufnr)
if python_path == nil then
python_path, _ = vim.fn.expand(require("core.util").get_python_venv_bin(client.config.root_dir))
end
vim.g["python3_host_prog"] = python_path
-- print(string.format("[PYTHON VENV]: %s", vim.inspect(python_path)))
client.config.settings.python = {} or client.config.settings.python
client.config.settings.python.pythonPath = python_path
on_attach(client, bufnr)
end,
settings = {
-- disable imports and linting since, we use ruff for that
pyright = {
disableOrganizeImports = true,
},
python = {
analysis = {
ignore = { "*" },
},
},
},
})
lspconfig.ruff_lsp.setup({
lspconfig.ruff.setup({
on_attach = function(client, bufnr)
on_attach(client, bufnr)
client.server_capabilities.hoverProvider = false -- we use pyright for hover info
if python_path == nil then
python_path, _ = vim.fn.expand(require("core.util").get_python_venv_bin(client.config.root_dir))
end
vim.g["python3_host_prog"] = python_path
client.config.settings.python = {} or client.config.settings.python
client.config.settings.python.pythonPath = python_path
end,