From 152fe4a568da5a862bae21d45f620b5fc5de445b Mon Sep 17 00:00:00 2001 From: Daveanand Mannie Date: Fri, 28 Mar 2025 03:35:42 -0400 Subject: [PATCH] [UPDATE] split python config to the plugin level and added os specific ruff file --- lua/config/lazy.lua | 2 +- lua/plugins/langs/python.lua | 137 -------------------- lua/plugins/langs/python/nvim-lspconfig.lua | 53 ++++++++ lua/plugins/langs/python/venv-selector.lua | 13 ++ 4 files changed, 67 insertions(+), 138 deletions(-) delete mode 100644 lua/plugins/langs/python.lua create mode 100644 lua/plugins/langs/python/nvim-lspconfig.lua create mode 100644 lua/plugins/langs/python/venv-selector.lua diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua index f513604..b5b6e0f 100644 --- a/lua/config/lazy.lua +++ b/lua/config/lazy.lua @@ -18,7 +18,7 @@ require("lazy").setup({ -- add LazyVim and import its plugins { "LazyVim/LazyVim", import = "lazyvim.plugins" }, { import = "plugins" }, - { import = "plugins.langs" }, + { import = "plugins.langs.python" }, }, defaults = { -- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup. diff --git a/lua/plugins/langs/python.lua b/lua/plugins/langs/python.lua deleted file mode 100644 index da201d9..0000000 --- a/lua/plugins/langs/python.lua +++ /dev/null @@ -1,137 +0,0 @@ -return { - { - "neovim/nvim-lspconfig", - opts = { - inlay_hints = { enabled = false }, - servers = { - ruff = { - cmd_env = { RUFF_TRACE = "messages" }, - init_options = { - settings = { - logLevel = "error", - configuration = os.getenv("LOCALAPPDATA") .. "/nvim/ruff.toml", - configurationPreference = "filesystemFirst", - }, - }, - keys = { - { - "co", - LazyVim.lsp.action["source.organizeImports"], - desc = "Organize Imports", - }, - }, - }, - basedpyright = { - cmd_env = { RUFF_TRACE = "messages" }, - init_options = { - settings = { - logLevel = "error", - }, - }, - }, - }, - setup = { - basedpyright = function() - LazyVim.lsp.on_attach(function(client, _) - client.server_capabilities.hoverProvider = true - end, "basedpyright") - end, - }, - }, - }, - { - "neovim/nvim-lspconfig", - opts = function(_, opts) - local servers = { "basedpyright", "ruff" } - for _, server in ipairs(servers) do - opts.servers[server] = opts.servers[server] or {} - opts.servers[server].enabled = server == "basedpyright" or server == "ruff" - end - end, - }, - { - "nvim-neotest/neotest", - optional = true, - dependencies = { - "nvim-neotest/neotest-python", - }, - opts = { - adapters = { - ["neotest-python"] = { - -- Example settings for the adapter - -- runner = "pytest", - -- python = ".venv/bin/python", - }, - }, - }, - }, - { - "mfussenegger/nvim-dap", - optional = true, - dependencies = { - "mfussenegger/nvim-dap-python", - }, - 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() - if vim.fn.has("win32") == 1 then - require("dap-python").setup(LazyVim.get_pkg_path("debugpy", "/venv/Scripts/pythonw.exe")) - else - require("dap-python").setup(LazyVim.get_pkg_path("debugpy", "/venv/bin/python")) - end - end, - }, - { - "linux-cultist/venv-selector.nvim", - branch = "regexp", - cmd = "VenvSelect", - enabled = function() - return LazyVim.has("telescope.nvim") - end, - opts = { - settings = { - search = { - -- windows escaping sucks - cwd = { command = "$FD Scripts//python.exe$ $CWD --full-path --color never -HI -a -L" }, - }, - options = { - notify_user_on_venv_activation = true, - }, - }, - }, - ft = "python", - keys = { { "cv", ":VenvSelect", desc = "Select VirtualEnv", ft = "python" } }, - }, - { - "hrsh7th/nvim-cmp", - opts = function(_, opts) - opts.auto_brackets = opts.auto_brackets or {} - table.insert(opts.auto_brackets, "python") - end, - }, - { - "jay-babu/mason-nvim-dap.nvim", - optional = true, - opts = { - handlers = { - python = function() end, -- Avoid messing up DAP adapters provided by nvim-dap-python - }, - }, - }, -} diff --git a/lua/plugins/langs/python/nvim-lspconfig.lua b/lua/plugins/langs/python/nvim-lspconfig.lua new file mode 100644 index 0000000..e913c66 --- /dev/null +++ b/lua/plugins/langs/python/nvim-lspconfig.lua @@ -0,0 +1,53 @@ +-- INFO: for local ruff config +local os_info = require("os_info") +local config_path + +-- Determine the config path based on the OS +if os_info.is_linux then + config_path = os.getenv("HOME") .. "/.config/nvim/ruff.toml" +elseif os_info.is_windows then + config_path = os.getenv("LOCALAPPDATA") .. "\\nvim\\ruff.toml" +end + +return { + { + "neovim/nvim-lspconfig", + opts = { + inlay_hints = { enabled = false }, + servers = { + ruff = { + cmd_env = { RUFF_TRACE = "messages" }, + init_options = { + settings = { + logLevel = "error", + configuration = config_path, -- Use the dynamically set config_path + configurationPreference = "filesystemFirst", + }, + }, + keys = { + { + "co", + LazyVim.lsp.action["source.organizeImports"], + desc = "Organize Imports", + }, + }, + }, + basedpyright = { + cmd_env = { RUFF_TRACE = "messages" }, + init_options = { + settings = { + logLevel = "error", + }, + }, + }, + }, + setup = { + basedpyright = function() + LazyVim.lsp.on_attach(function(client, _) + client.server_capabilities.hoverProvider = true + end, "basedpyright") + end, + }, + }, + }, +} diff --git a/lua/plugins/langs/python/venv-selector.lua b/lua/plugins/langs/python/venv-selector.lua new file mode 100644 index 0000000..38c4a22 --- /dev/null +++ b/lua/plugins/langs/python/venv-selector.lua @@ -0,0 +1,13 @@ +return { + "linux-cultist/venv-selector.nvim", + lazy = false, + branch = "regexp", -- This is the regexp branch, use this for the new version + keys = { + { "cv", ":VenvSelect", desc = "Select VirtualEnv", ft = "python" }, + }, + opts = { + settings = { + options = { notify_user_on_venv_activation = true }, + }, + }, +}