go.nvim/lua/go/codelens.lua

54 lines
1.4 KiB
Lua
Raw Normal View History

2022-07-30 06:00:09 +00:00
local utils = require('go.utils')
local codelens = require('vim.lsp.codelens')
local M = {}
function M.setup()
2022-07-30 06:00:09 +00:00
utils.log('enable codelens')
vim.api.nvim_set_hl(0, 'LspCodeLens', { link = 'WarningMsg', default = true })
vim.api.nvim_set_hl(0, 'LspCodeLensText', { link = 'WarningMsg', default = true })
vim.api.nvim_set_hl(0, 'LspCodeLensSign', { link = 'WarningMsg', default = true })
vim.api.nvim_set_hl(0, 'LspCodeLensSeparator', { link = 'Boolean', default = true })
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI', 'InsertLeave' }, {
2022-07-30 06:00:09 +00:00
group = vim.api.nvim_create_augroup('gonvim__codelenses', {}),
pattern = { '*.go', '*.mod' },
2022-07-30 06:00:09 +00:00
callback = function()
require('go.codelens').refresh()
end,
})
end
function M.run_action()
2022-07-30 06:00:09 +00:00
local guihua = utils.load_plugin('guihua.lua', 'guihua.gui')
local original_select = vim.ui.select
if guihua then
2022-07-30 06:00:09 +00:00
vim.ui.select = require('guihua.gui').select
end
codelens.run()
vim.defer_fn(function()
vim.ui.select = original_select
end, 1000)
end
function M.refresh()
local found = false
2022-07-30 06:00:09 +00:00
if _GO_NVIM_CFG.lsp_codelens ~= false then
if not found then
2023-01-31 23:26:04 +00:00
for _, lsp in pairs(vim.lsp.get_active_clients()) do
if lsp.name == 'gopls' then
found = true
break
end
end
end
if not found then
return
end
2022-07-30 06:00:09 +00:00
vim.lsp.codelens.refresh()
end
end
return M