fix: decouple python env setup from config init

Problem: setup_python_env() is called from check_required_runtime()
during config.setup(), which runs on the very first :CP command. The
uv sync and nix build calls use vim.system():wait(), blocking the
Neovim event loop. During the block the UI is frozen and
vim.schedule-based log messages never render, so the user sees an
unresponsive editor with no feedback.

Solution: remove setup_python_env() from check_required_runtime() so
config init is instant. Call it lazily from run_scraper() instead,
only when a scraper subprocess is actually needed. Use vim.notify +
vim.cmd.redraw() before blocking calls so the notification renders
immediately via a forced screen repaint, rather than being queued
behind vim.schedule.
This commit is contained in:
Barrett Ruth 2026-02-18 17:48:06 -05:00 committed by Barrett Ruth
parent 622620f6d0
commit 49e4233b3f
2 changed files with 13 additions and 5 deletions

View file

@ -129,7 +129,8 @@ local function discover_nix_python()
end
local plugin_path = M.get_plugin_path()
logger.log('Building Python environment with nix...', nil, true)
vim.notify('[cp.nvim] Building Python environment with nix...', vim.log.levels.INFO)
vim.cmd.redraw()
local result = vim
.system(
{ 'nix', 'build', plugin_path .. '#pythonEnv', '--no-link', '--print-out-paths' },
@ -177,6 +178,8 @@ function M.setup_python_env()
if vim.fn.executable('uv') == 1 then
local plugin_path = M.get_plugin_path()
logger.log('Python env: uv sync (dir=' .. plugin_path .. ')')
vim.notify('[cp.nvim] Setting up Python environment...', vim.log.levels.INFO)
vim.cmd.redraw()
local env = vim.fn.environ()
env.VIRTUAL_ENV = ''
@ -264,10 +267,6 @@ function M.check_required_runtime()
return false, timeout.reason
end
if not M.setup_python_env() then
return false, 'no Python environment available (install uv or nix)'
end
return true
end