Open Hubro opened 6 months ago
Figured out a workaround using DIRENV_DIFF
, seems to solve all the problems I had:
return {
"direnv/direnv.vim",
commit = "ab2a7e08dd630060cd81d7946739ac7442a4f269",
init = function()
vim.g.direnv_silent_load = true
local cached_direnv_diff = nil
local group = vim.api.nvim_create_augroup("DirenvLoaded", { clear = true })
vim.api.nvim_create_autocmd({ "User" }, {
group = group,
pattern = "DirenvLoaded",
callback = function()
if vim.env.DIRENV_DIFF ~= cached_direnv_diff then
cached_direnv_diff = vim.env.DIRENV_DIFF
vim.notify("Loaded environment from direnv")
if vim.cmd.LspRestart ~= nil then
vim.notify("Restarting LSP servers")
vim.cmd.LspRestart()
end
end
end
})
end
}
I'm having an issue where my LSP servers can't find my project's dependencies, because
direnv
activates a Python virtualenv after my LSP servers have already started up.To fix this, I thought I'd use the
DirenvLoaded
event to restart my LSP servers whenever the direnv environment is loaded:Unexpected behavior:
.envrc
or notDirenvLoaded
fires every time I change focus to a different buffer (changing focus between two windows with the same buffer doesn't trigger the event)This behavior doesn't make any sense to me, so I'm assuming it's a bug.