├── README.md ├── chadrc.lua ├── configs ├── lspconfig.lua └── null-ls.lua ├── mappings.lua └── plugins.lua /README.md: -------------------------------------------------------------------------------- 1 | # How to use 2 | 3 | To install this for your neovim configuration 4 | 5 | ``` 6 | $ git clone git@github.com:dreamsofcode-io/neovim-python.git ~/.config/nvim/lua/custom 7 | ``` 8 | 9 | Then open up neovim and let everything install. 10 | 11 | Restart Neovim and install the treesitter syntax 12 | 13 | ``` 14 | :TSInstall python 15 | ``` 16 | -------------------------------------------------------------------------------- /chadrc.lua: -------------------------------------------------------------------------------- 1 | ---@type ChadrcConfig 2 | local M = {} 3 | M.ui = {theme = 'catppuccin'} 4 | M.plugins = "custom.plugins" 5 | M.mappings = require "custom.mappings" 6 | return M 7 | -------------------------------------------------------------------------------- /configs/lspconfig.lua: -------------------------------------------------------------------------------- 1 | local config = require("plugins.configs.lspconfig") 2 | 3 | local on_attach = config.on_attach 4 | local capabilities = config.capabilities 5 | 6 | local lspconfig = require("lspconfig") 7 | 8 | local servers = { 9 | "pyright", 10 | "ruff_lsp", 11 | } 12 | 13 | for _, lsp in ipairs(servers) do 14 | lspconfig[lsp].setup({ 15 | on_attach = on_attach, 16 | capabilities = capabilities, 17 | filetypes = {"python"}, 18 | }) 19 | end 20 | -------------------------------------------------------------------------------- /configs/null-ls.lua: -------------------------------------------------------------------------------- 1 | local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) 2 | local null_ls = require('null-ls') 3 | 4 | local opts = { 5 | sources = { 6 | null_ls.builtins.formatting.black, 7 | null_ls.builtins.diagnostics.mypy.with({ 8 | extra_args = function() 9 | local virtual = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") or "/usr" 10 | return { "--python-executable", virtual .. "/bin/python3" } 11 | end, 12 | }), 13 | }, 14 | on_attach = function(client, bufnr) 15 | if client.supports_method("textDocument/formatting") then 16 | vim.api.nvim_clear_autocmds({ 17 | group = augroup, 18 | buffer = bufnr, 19 | }) 20 | vim.api.nvim_create_autocmd("BufWritePre", { 21 | group = augroup, 22 | buffer = bufnr, 23 | callback = function() 24 | vim.lsp.buf.format({ bufnr = bufnr }) 25 | end, 26 | }) 27 | end 28 | end, 29 | } 30 | return opts 31 | -------------------------------------------------------------------------------- /mappings.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | M.dap = { 4 | plugin = true, 5 | n = { 6 | ["db"] = {" DapToggleBreakpoint "} 7 | } 8 | } 9 | 10 | M.dap_python = { 11 | plugin = true, 12 | n = { 13 | ["dpr"] = { 14 | function() 15 | require('dap-python').test_method() 16 | end 17 | } 18 | } 19 | } 20 | 21 | return M 22 | -------------------------------------------------------------------------------- /plugins.lua: -------------------------------------------------------------------------------- 1 | local plugins = { 2 | { 3 | "nvim-neotest/nvim-nio", 4 | }, 5 | { 6 | "rcarriga/nvim-dap-ui", 7 | dependencies = "mfussenegger/nvim-dap", 8 | config = function() 9 | local dap = require("dap") 10 | local dapui = require("dapui") 11 | dapui.setup() 12 | dap.listeners.after.event_initialized["dapui_config"] = function() 13 | dapui.open() 14 | end 15 | dap.listeners.before.event_terminated["dapui_config"] = function() 16 | dapui.close() 17 | end 18 | dap.listeners.before.event_exited["dapui_config"] = function() 19 | dapui.close() 20 | end 21 | end 22 | }, 23 | { 24 | "mfussenegger/nvim-dap", 25 | config = function(_, opts) 26 | require("core.utils").load_mappings("dap") 27 | end 28 | }, 29 | { 30 | "mfussenegger/nvim-dap-python", 31 | ft = "python", 32 | dependencies = { 33 | "mfussenegger/nvim-dap", 34 | "rcarriga/nvim-dap-ui", 35 | "nvim-neotest/nvim-nio", 36 | }, 37 | config = function(_, opts) 38 | local path = "~/.local/share/nvim/mason/packages/debugpy/venv/bin/python" 39 | require("dap-python").setup(path) 40 | require("core.utils").load_mappings("dap_python") 41 | end, 42 | }, 43 | { 44 | "nvimtools/none-ls.nvim", 45 | ft = {"python"}, 46 | opts = function() 47 | return require "custom.configs.null-ls" 48 | end, 49 | }, 50 | { 51 | "williamboman/mason.nvim", 52 | opts = { 53 | ensure_installed = { 54 | "black", 55 | "debugpy", 56 | "mypy", 57 | "ruff-lsp", 58 | "pyright", 59 | }, 60 | }, 61 | }, 62 | { 63 | "neovim/nvim-lspconfig", 64 | config = function() 65 | require "plugins.configs.lspconfig" 66 | require "custom.configs.lspconfig" 67 | end, 68 | }, 69 | } 70 | return plugins 71 | --------------------------------------------------------------------------------