]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/lang/python.lua
480d567b18e2633679af065d6ea08c483bc9e24c
[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 dap = { justMyCode = false }},
72 },
73 },
74 },
75 {
76 "mfussenegger/nvim-dap",
77 dependencies = {
78 "mfussenegger/nvim-dap-python",
79 -- stylua: ignore
80 keys = {
81 { "<leader>dPt", function() require('dap-python').test_method() end, desc = "Debug Method", ft = "python" },
82 { "<leader>dPc", function() require('dap-python').test_class() end, desc = "Debug Class", ft = "python" },
83 },
84 config = function()
85 local path = require("mason-registry").get_package("debugpy"):get_install_path()
86 require("dap-python").setup(path .. "/venv/bin/python")
87 end,
88 },
89 },
90 {
91 "linux-cultist/venv-selector.nvim",
92 cmd = "VenvSelect",
93 opts = function(_, opts)
94 if require("lazyvim.util").has("nvim-dap-python") then
95 opts.dap_enabled = true
96 end
97 return vim.tbl_deep_extend("force", opts, {
98 name = {
99 "venv",
100 ".venv",
101 "env",
102 ".env",
103 },
104 })
105 end,
106 keys = { { "<leader>cv", "<cmd>:VenvSelect<cr>", desc = "Select VirtualEnv" } },
107 },
108 }