This commit is contained in:
raf 2026-04-02 07:53:01 +00:00 committed by GitHub
commit 226d275c83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,6 +23,9 @@ local cache = {
pending_request = false, pending_request = false,
} }
local direnv_env = {}
local unload_pending = false
local notification_queue = {} local notification_queue = {}
local pending_callbacks = {} local pending_callbacks = {}
@ -215,6 +218,25 @@ M.refresh_status = function()
M._get_rc_status(function() end) M._get_rc_status(function() end)
end end
--- Unload direnv environment by clearing tracked variables
M._unload = function()
if next(direnv_env) == nil then
return
end
unload_pending = true
vim.schedule(function()
if unload_pending then
for key, _ in pairs(direnv_env) do
vim.env[key] = nil
end
direnv_env = {}
unload_pending = false
notify("direnv environment unloaded", vim.log.levels.DEBUG)
end
end)
end
--- Initialize direnv for current directory --- Initialize direnv for current directory
--- @param path string Path to .envrc file --- @param path string Path to .envrc file
M._init = function(path) M._init = function(path)
@ -258,6 +280,9 @@ M._init = function(path)
return return
end end
unload_pending = false
direnv_env = {}
for key, value in pairs(env) do for key, value in pairs(env) do
if value == vim.NIL or value == nil then if value == vim.NIL or value == nil then
vim.env[key] = nil vim.env[key] = nil
@ -266,6 +291,7 @@ M._init = function(path)
value = tostring(value) value = tostring(value)
end end
vim.env[key] = value vim.env[key] = value
direnv_env[key] = true
end end
end end
@ -421,6 +447,7 @@ end
M.check_direnv = function() M.check_direnv = function()
local on_exit = function(status, path) local on_exit = function(status, path)
if status == nil or path == nil then if status == nil or path == nil then
M._unload()
return return
end end