diff --git a/lua/lazyvim/plugins/extras/lang/python.lua b/lua/lazyvim/plugins/extras/lang/python.lua index 399f28e3..a06b63d7 100644 --- a/lua/lazyvim/plugins/extras/lang/python.lua +++ b/lua/lazyvim/plugins/extras/lang/python.lua @@ -2,11 +2,12 @@ if lazyvim_docs then -- LSP Server to use for Python. -- Set to "basedpyright" to use basedpyright instead of pyright. vim.g.lazyvim_python_lsp = "pyright" - vim.g.lazyvim_python_ruff = "ruff_lsp" + -- Set to "ruff_lsp" to use the old LSP implementation version. + vim.g.lazyvim_python_ruff = "ruff" end local lsp = vim.g.lazyvim_python_lsp or "pyright" -local ruff = vim.g.lazyvim_python_ruff or "ruff_lsp" +local ruff = vim.g.lazyvim_python_ruff or "ruff" return { recommended = function() @@ -30,22 +31,22 @@ return { "neovim/nvim-lspconfig", opts = { servers = { - pyright = { - enabled = lsp == "pyright", - }, - basedpyright = { - enabled = lsp == "basedpyright", - }, - [lsp] = { - enabled = true, + ruff = { + cmd_env = { RUFF_TRACE = "messages" }, + init_options = { + settings = { + logLevel = "error", + }, + }, + keys = { + { + "co", + LazyVim.lsp.action["source.organizeImports"], + desc = "Organize Imports", + }, + }, }, ruff_lsp = { - enabled = ruff == "ruff_lsp", - }, - ruff = { - enabled = ruff == "ruff", - }, - [ruff] = { keys = { { "co", @@ -65,6 +66,16 @@ return { }, }, }, + { + "neovim/nvim-lspconfig", + opts = function(_, opts) + local servers = { "pyright", "basedpyright", "ruff", "ruff_lsp", ruff, lsp } + for _, server in ipairs(servers) do + opts.servers[server] = opts.servers[server] or {} + opts.servers[server].enabled = server == lsp or server == ruff + end + end, + }, { "nvim-neotest/neotest", optional = true, diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index 0747547f..076344dd 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -196,6 +196,9 @@ return { local server_opts = vim.tbl_deep_extend("force", { capabilities = vim.deepcopy(capabilities), }, servers[server] or {}) + if server_opts.enabled == false then + return + end if opts.setup[server] then if opts.setup[server](server, server_opts) then