From: Samir Benmendil Date: Sat, 20 Jan 2024 17:21:20 +0000 (+0000) Subject: nvim: get python lang from lazyvim X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/e1b33d1f3aa562c5c33e0bb8e4e42fb01120548a?ds=inline nvim: get python lang from lazyvim * dap * neotest * lsp --- diff --git a/nvim/lua/plugins/lang/python.lua b/nvim/lua/plugins/lang/python.lua new file mode 100644 index 0000000..537d032 --- /dev/null +++ b/nvim/lua/plugins/lang/python.lua @@ -0,0 +1,90 @@ +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, + }, + { + "neovim/nvim-lspconfig", + opts = { + ---@type lspconfig.options + servers = { + pyright = {}, + ruff_lsp = { + keys = { + { + "co", + function() + vim.lsp.buf.code_action({ + apply = true, + context = { + only = { "source.organizeImports" }, + diagnostics = {}, + }, + }) + end, + desc = "Organize Imports", + }, + }, + }, + }, + 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) + end, + }, + }, + }, + { + "nvim-neotest/neotest", + dependencies = { + "nvim-neotest/neotest-python", + }, + opts = { + adapters = { + ["neotest-python"] = { }, + }, + }, + }, + { + "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" }, + }, + config = function() + local path = require("mason-registry").get_package("debugpy"):get_install_path() + require("dap-python").setup(path .. "/venv/bin/python") + end, + }, + }, + { + "linux-cultist/venv-selector.nvim", + 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", + }, + }) + end, + keys = { { "cv", ":VenvSelect", desc = "Select VirtualEnv" } }, + }, +}