Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions rc.d/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,34 @@ require("lazy").setup({
{ "fladson/vim-kitty" },
})

-------------------------------------------------------------------------------
-- Python Virtualenv Auto-activation
-------------------------------------------------------------------------------
local function activate_virtualenv()
if vim.env.VIRTUAL_ENV then
return
end

local venv_paths = { "venv", ".venv" }
local cwd = vim.fn.getcwd()

for _, venv_name in ipairs(venv_paths) do
local venv_path = cwd .. "/" .. venv_name
local python_path = venv_path .. "/bin/python"

if vim.fn.isdirectory(venv_path) == 1 and vim.fn.executable(python_path) == 1 then
vim.env.VIRTUAL_ENV = venv_path
vim.env.PATH = venv_path .. "/bin:" .. vim.env.PATH
Comment on lines +530 to +536
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code uses Unix-specific path separators ("/bin/python"). While this may be intentional if the configuration is only used on Unix-like systems, consider using vim.fn.has('win32') to check the platform and use appropriate path separators, or use path manipulation functions that handle this automatically. This would make the configuration more portable.

Suggested change
for _, venv_name in ipairs(venv_paths) do
local venv_path = cwd .. "/" .. venv_name
local python_path = venv_path .. "/bin/python"
if vim.fn.isdirectory(venv_path) == 1 and vim.fn.executable(python_path) == 1 then
vim.env.VIRTUAL_ENV = venv_path
vim.env.PATH = venv_path .. "/bin:" .. vim.env.PATH
-- Determine platform-specific settings
local is_windows = vim.fn.has("win32") == 1 or vim.fn.has("win64") == 1
local path_sep = is_windows and "\\" or "/"
local python_dir = is_windows and "Scripts" or "bin"
local python_exe = is_windows and "python.exe" or "python"
local path_list_sep = is_windows and ";" or ":"
for _, venv_name in ipairs(venv_paths) do
local venv_path = cwd .. path_sep .. venv_name
local python_path = venv_path .. path_sep .. python_dir .. path_sep .. python_exe
if vim.fn.isdirectory(venv_path) == 1 and vim.fn.executable(python_path) == 1 then
vim.env.VIRTUAL_ENV = venv_path
vim.env.PATH = venv_path .. path_sep .. python_dir .. path_list_sep .. vim.env.PATH

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PATH modification prepends the venv bin directory without checking if it's already in PATH. If the function is called multiple times (e.g., if a DirChanged autocmd is added), this could lead to duplicate PATH entries. Consider checking if the path is already present before prepending, or removing the old venv path before adding the new one.

Copilot uses AI. Check for mistakes.
return
end
end
end

vim.api.nvim_create_autocmd("VimEnter", {
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The virtualenv activation only runs on VimEnter, which means if the user changes directories (e.g., with :cd or :tcd), the virtualenv won't be updated for the new directory. Consider also adding a DirChanged autocmd to re-run the activation when the working directory changes, ensuring the correct virtualenv is activated when navigating between different Python projects.

Suggested change
vim.api.nvim_create_autocmd("VimEnter", {
vim.api.nvim_create_autocmd({ "VimEnter", "DirChanged" }, {

Copilot uses AI. Check for mistakes.
Comment on lines +541 to +542
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The autocmd is not assigned to an augroup, which is inconsistent with other autocmds in this file (e.g., line 661 uses vim.api.nvim_create_augroup). Consider creating an augroup with clear = true to ensure the autocmd doesn't get duplicated if the config is reloaded.

Suggested change
vim.api.nvim_create_autocmd("VimEnter", {
local venv_augroup = vim.api.nvim_create_augroup("PythonVirtualenvAutoActivation", { clear = true })
vim.api.nvim_create_autocmd("VimEnter", {
group = venv_augroup,

Copilot uses AI. Check for mistakes.
callback = activate_virtualenv,
desc = "Auto-activate Python virtualenv if present",
})

-------------------------------------------------------------------------------
-- Interface
-------------------------------------------------------------------------------
Expand Down