Skip to content

Instantly share code, notes, and snippets.

@Chattille
Last active June 20, 2024 12:29
Show Gist options
  • Save Chattille/adbd1f296b03bc3f85bb7f8d6f648c6f to your computer and use it in GitHub Desktop.
Save Chattille/adbd1f296b03bc3f85bb7f8d6f648c6f to your computer and use it in GitHub Desktop.
Refresh Codelens on LSP attachment in Neovim
-- trigger upon LSP attachment
vim.api.nvim_create_autocmd('User', {
pattern = 'LspAttached',
once = true,
callback = vim.lsp.codelens.refresh,
})
-- ... servers and enhanced_opts ...
for _, lsp in ipairs(servers) do
local opts = {
on_attach = function(_, bufnr)
-- refresh codelens on TextChanged and InsertLeave as well
vim.api.nvim_create_autocmd({ 'TextChanged', 'InsertLeave' }, {
buffer = bufnr,
callback = vim.lsp.codelens.refresh,
})
-- trigger codelens refresh
vim.api.nvim_exec_autocmds('User', { pattern = 'LspAttached' })
end,
}
if enhanced_opts[lsp] then
enhanced_opts[lsp](opts)
end
require('lspconfig').setup(opts)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment