]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/lang/python.lua
aee447408359e0c64712599ec45084f3d911d635
[dotfiles.git] / nvim / lua / plugins / lang / python.lua
1 return {
2 {
3 "nvim-treesitter/nvim-treesitter",
4 opts = function(_, opts)
5 if type(opts.ensure_installed) == "table" then
6 vim.list_extend(opts.ensure_installed, { "ninja", "python", "rst", "toml" })
7 end
8 end,
9 },
10 {
11 "neovim/nvim-lspconfig",
12 opts = {
13 ---@type lspconfig.options
14 servers = {
15 pyright = {},
16 ruff_lsp = {
17 root_dir = function(fname)
18 return require("lspconfig.util").root_pattern("pyproject.toml", "setup.cfg", "ruff.toml")(fname)
19 end,
20 keys = {
21 {
22 "<leader>co",
23 function()
24 vim.lsp.buf.code_action({
25 apply = true,
26 context = {
27 only = { "source.organizeImports" },
28 diagnostics = {},
29 },
30 })
31 end,
32 desc = "Organize Imports",
33 },
34 },
35 },
36 pylsp = {
37 settings = {
38 pylsp = {
39 plugins = {
40 autopep8 = { enabled = false },
41 flake8 = { enabled = false },
42 mccabe = { enabled = false },
43 pycodestyle = { enabled = false },
44 pydocstyle = { enabled = false },
45 pyflakes = { enabled = false }, -- covered by flake8
46 }
47 }
48 }
49 }
50 },
51 setup = {
52 ruff_lsp = function()
53 require("lazyvim.util").lsp.on_attach(function(client, _)
54 if client.name == "ruff_lsp" then
55 -- Disable hover in favor of Pyright
56 client.server_capabilities.hoverProvider = false
57 end
58 end)
59 end,
60 },
61 },
62 },
63 {
64 "nvim-neotest/neotest",
65 dependencies = {
66 "nvim-neotest/neotest-python",
67 },
68 opts = {
69 adapters = {
70 ["neotest-python"] = { },
71 },
72 },
73 },
74 {
75 "mfussenegger/nvim-dap",
76 dependencies = {
77 "mfussenegger/nvim-dap-python",
78 -- stylua: ignore
79 keys = {
80 { "<leader>dPt", function() require('dap-python').test_method() end, desc = "Debug Method", ft = "python" },
81 { "<leader>dPc", function() require('dap-python').test_class() end, desc = "Debug Class", ft = "python" },
82 },
83 config = function()
84 local path = require("mason-registry").get_package("debugpy"):get_install_path()
85 require("dap-python").setup(path .. "/venv/bin/python")
86 end,
87 },
88 },
89 {
90 "linux-cultist/venv-selector.nvim",
91 cmd = "VenvSelect",
92 opts = function(_, opts)
93 if require("lazyvim.util").has("nvim-dap-python") then
94 opts.dap_enabled = true
95 end
96 return vim.tbl_deep_extend("force", opts, {
97 name = {
98 "venv",
99 ".venv",
100 "env",
101 ".env",
102 },
103 })
104 end,
105 keys = { { "<leader>cv", "<cmd>:VenvSelect<cr>", desc = "Select VirtualEnv" } },
106 },
107 }