From 28d245510ffd8f4818b618b0c2338e183e19b764 Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 5 Aug 2022 19:48:27 +1000 Subject: [PATCH] using neovim 0.7 API --- lua/navigator/codelens.lua | 24 +++++++++++++----------- lua/navigator/lspclient/clients.lua | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lua/navigator/codelens.lua b/lua/navigator/codelens.lua index 7adda45..29d4094 100644 --- a/lua/navigator/codelens.lua +++ b/lua/navigator/codelens.lua @@ -61,21 +61,23 @@ local codelens_hdlr = function(err, result, ctx, cfg) end end -function M.setup() - vim.cmd('highlight! link LspCodeLens LspDiagnosticsHint') - vim.cmd('highlight! link LspCodeLensText LspDiagnosticsInformation') - vim.cmd('highlight! link LspCodeLensTextSign LspDiagnosticsSignInformation') - vim.cmd('highlight! link LspCodeLensTextSeparator Boolean') - - vim.cmd('augroup navigator.codelenses') - vim.cmd(' autocmd!') - vim.cmd("autocmd BufEnter,CursorHold,InsertLeave lua require('navigator.codelens').refresh()") - vim.cmd('augroup end') +function M.setup(bufnr) + vim.api.nvim_set_hl(0, 'LspCodeLens', { link = 'LspDiagnosticsHint', default = true }) + vim.api.nvim_set_hl(0, 'LspCodeLensText', { link = 'LspDiagnosticsInformation', default = true }) + vim.api.nvim_set_hl(0, 'LspCodeLensSign', { link = 'LspDiagnosticsInformation', default = true }) + vim.api.nvim_set_hl(0, 'LspCodeLensSeparator', { link = 'Boolean', default = true }) + vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI', 'InsertLeave' }, { + group = vim.api.nvim_create_augroup('nv__codelenses', {}), + buffer = bufnr or vim.api.nvim_win_get_buf(), + callback = function() + require('go.codelens').refresh() + end, + }) local on_codelens = vim.lsp.handlers['textDocument/codeLens'] vim.lsp.handlers['textDocument/codeLens'] = function(err, result, ctx, cfg) -- trace(err, result, ctx.client_id, ctx.bufnr, cfg or {}) cfg = cfg or {} - ctx = ctx or { bufnr = vim.api.nvim_get_current_buf() } + ctx = ctx or { bufnr = bufnr or vim.api.nvim_get_current_buf() } on_codelens(err, result, ctx, cfg) codelens_hdlr(err, result, ctx, cfg) end diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index ab7c6f2..aa760e3 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -628,7 +628,7 @@ local function setup(user_opts, cnt) --- if code lens enabled if _NgConfigValues.lsp.code_lens_action.enable then - require('navigator.codelens').setup() + require('navigator.codelens').setup(bufnr) end -- _LoadedFiletypes[ft .. tostring(bufnr)] = true -- may prevent lsp config when reboot lsp @@ -658,7 +658,7 @@ local function on_filetype() _NG_Loaded[bufnr] = _NG_Loaded[bufnr] + 1 -- do not hook and trigger filetype event multiple times end if _NG_Loaded[bufnr] == true then - _NG_Loaded = 1 -- record the count + _NG_Loaded[bufnr] = 1 -- record the count end -- as setup will send filetype event as well