From b2dfdfd5ffdcdc4d9e4377ac7ea8597dbe64db05 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 17 Jun 2024 13:33:31 +0200 Subject: [PATCH] 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 --- nvim/.config/nvim/lua/plugins/config/lsp.lua | 22 ++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/config/lsp.lua b/nvim/.config/nvim/lua/plugins/config/lsp.lua index c67e77a..080a7c6 100644 --- a/nvim/.config/nvim/lua/plugins/config/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/config/lsp.lua @@ -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", "lua vim.diagnostic.goto_prev()", { buffer = bufnr, desc = "Previous diagnostic" }) map("n", "]d", "lua vim.diagnostic.goto_next()", { 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,