X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/7bd5fa10e6ed23f8664207ff3103a6171ac64452..7d854464d9b1bd386b0eaf25f38ac3b96dd1fc18:/nvim/lua/plugins/lang/python.lua diff --git a/nvim/lua/plugins/lang/python.lua b/nvim/lua/plugins/lang/python.lua index 480d567..09ee671 100644 --- a/nvim/lua/plugins/lang/python.lua +++ b/nvim/lua/plugins/lang/python.lua @@ -1,65 +1,46 @@ return { - { - "nvim-treesitter/nvim-treesitter", - opts = function(_, opts) - if type(opts.ensure_installed) == "table" then - vim.list_extend(opts.ensure_installed, { "ninja", "python", "rst", "toml" }) - end - end, + { "nvim-treesitter/nvim-treesitter", + opts = { ensure_installed = { "ninja", "rst" } }, }, - { - "neovim/nvim-lspconfig", + { "neovim/nvim-lspconfig", opts = { - ---@type lspconfig.options servers = { - pyright = {}, - ruff_lsp = { - root_dir = function(fname) - return require("lspconfig.util").root_pattern("pyproject.toml", "setup.cfg", "ruff.toml")(fname) - end, + ruff = { + cmd_env = { RUFF_TRACE = "messages" }, + init_options = { + settings = { + logLevel = "error", + }, + }, keys = { { "co", - function() - vim.lsp.buf.code_action({ - apply = true, - context = { - only = { "source.organizeImports" }, - diagnostics = {}, - }, - }) - end, + rmz.lsp.action["source.organizeImports"], desc = "Organize Imports", }, }, }, - pylsp = { - settings = { - pylsp = { - plugins = { - autopep8 = { enabled = false }, - flake8 = { enabled = false }, - mccabe = { enabled = false }, - pycodestyle = { enabled = false }, - pydocstyle = { enabled = false }, - pyflakes = { enabled = false }, -- covered by flake8 - } - } - } - } }, setup = { - ruff_lsp = function() - require("lazyvim.util").lsp.on_attach(function(client, _) - if client.name == "ruff_lsp" then - -- Disable hover in favor of Pyright - client.server_capabilities.hoverProvider = false - end - end) + ["ruff"] = function() + rmz.lsp.on_attach(function(client, _) + -- Disable hover in favor of Pyright + client.server_capabilities.hoverProvider = false + end, "ruff") end, }, }, }, + { + "neovim/nvim-lspconfig", + opts = function(_, opts) + local servers = { "pyright", "ruff"} + 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", dependencies = { @@ -76,7 +57,6 @@ return { "mfussenegger/nvim-dap", dependencies = { "mfussenegger/nvim-dap-python", - -- stylua: ignore keys = { { "dPt", function() require('dap-python').test_method() end, desc = "Debug Method", ft = "python" }, { "dPc", function() require('dap-python').test_class() end, desc = "Debug Class", ft = "python" }, @@ -87,22 +67,34 @@ return { end, }, }, - { - "linux-cultist/venv-selector.nvim", + { "jay-babu/mason-nvim-dap.nvim", + opts = { + handlers = { + python = function() end, + }, + ensure_installed = { "python" }, + }, + }, + { "linux-cultist/venv-selector.nvim", enabled = false, + -- TODO needs fd to be installed (I don't know what that is) + branch = "regexp", -- Use this branch for the new version cmd = "VenvSelect", - opts = function(_, opts) - if require("lazyvim.util").has("nvim-dap-python") then - opts.dap_enabled = true - end - return vim.tbl_deep_extend("force", opts, { - name = { - "venv", - ".venv", - "env", - ".env", + opts = { + settings = { + options = { + notify_user_on_venv_activation = true, }, - }) + }, + }, + -- Call config for python files and load the cached venv automatically + ft = "python", + keys = { { "cv", ":VenvSelect", desc = "Select VirtualEnv", ft = "python" } }, + }, + { "hrsh7th/nvim-cmp", + optional = true, + opts = function(_, opts) + opts.auto_brackets = opts.auto_brackets or {} + table.insert(opts.auto_brackets, "python") end, - keys = { { "cv", ":VenvSelect", desc = "Select VirtualEnv" } }, }, }