Open
Description
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:
local group = vim.api.nvim_create_augroup("DirenvLoaded", { clear = true })
vim.api.nvim_create_autocmd({ "User" }, {
group = group,
pattern = "DirenvLoaded",
callback = function()
vim.notify("Loaded environment from direnv")
if vim.cmd.LspRestart ~= nil then
vim.notify("Restarting LSP servers")
vim.cmd.LspRestart()
end
end
})
Unexpected behavior:
- Fires when I open nvim, no matter if the current directory has a
.envrc
or not - If I'm in a project that uses direnv,
DirenvLoaded
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.
$ nvim --version
NVIM v0.10.0-dev-2295+g672556525
Build type: RelWithDebInfo
LuaJIT 2.1.1707061634
Run "nvim -V1 -v" for more info
Metadata
Metadata
Assignees
Labels
No labels