Created
April 4, 2025 02:56
-
-
Save aabccd021/9f2b7a37943f30748e91fae3f02eb9c2 to your computer and use it in GitHub Desktop.
neovim start lsp after direnv load
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local lsp_langs = { "ts_ls", "biome", "nixd" } | |
local direnv_lspstart_group = vim.api.nvim_create_augroup("StartLspAfterDirenv", { clear = true }) | |
vim.api.nvim_create_autocmd("BufEnter", { | |
group = vim.api.nvim_create_augroup("StartLsp", { clear = true }), | |
pattern = "*", | |
callback = function() | |
local result = vim.system( | |
{ "git", "-C", vim.fn.expand("%:p:h"), "rev-parse", "--show-toplevel" }, | |
{ text = true } | |
) | |
:wait() | |
if result.code ~= 0 then | |
vim.lsp.enable(lsp_langs) | |
return | |
end | |
local repo_root = result.stdout:gsub("%s+$", "") -- Remove trailing whitespace | |
if vim.fn.filereadable(repo_root .. "/.envrc") ~= 1 then | |
vim.lsp.enable(lsp_langs) | |
return | |
end | |
vim.api.nvim_create_autocmd("User", { | |
pattern = "DirenvLoaded", | |
group = direnv_lspstart_group, | |
callback = function() | |
end, | |
}) | |
end, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment