diff --git a/README.md b/README.md index 232e1084..e8ef2bb4 100644 --- a/README.md +++ b/README.md @@ -96,16 +96,25 @@ Markdown Oxide's features are implemented in the form of a language server aimin Modify your lsp `on_attach` function. ```lua + local function check_codelens_support() + local clients = vim.lsp.get_active_clients({ bufnr = 0 }) + for _, c in ipairs(clients) do + if c.server_capabilities.codeLensProvider then + return true + end + end + return false + end + -- refresh codelens on TextChanged and InsertLeave as well - vim.api.nvim_create_autocmd({ 'TextChanged', 'InsertLeave', 'CursorHold', 'LspAttach' }, { - buffer = bufnr, - callback = function () - if vim.lsp.codelens.get(bufnr) then -- refresh only if there are servers supporting codelens - vim.lsp.codelens.refresh() - end - end + vim.api.nvim_create_autocmd({ 'TextChanged', 'InsertLeave', 'CursorHold', 'LspAttach', 'BufEnter' }, { + buffer = bufnr, + callback = function () + if check_codelens_support() then + vim.lsp.codelens.refresh({bufnr = 0}) + end + end }) - -- trigger codelens refresh vim.api.nvim_exec_autocmds('User', { pattern = 'LspAttached' }) ```