2022-07-30 06:00:09 +00:00
|
|
|
local utils = require('go.utils')
|
|
|
|
local codelens = require('vim.lsp.codelens')
|
2021-08-21 10:52:23 +00:00
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M.setup()
|
2022-07-30 06:00:09 +00:00
|
|
|
utils.log('enable codelens')
|
2022-08-05 09:34:44 +00:00
|
|
|
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 })
|
2022-07-31 01:29:38 +00:00
|
|
|
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI', 'InsertLeave' }, {
|
2022-07-30 06:00:09 +00:00
|
|
|
group = vim.api.nvim_create_augroup('gonvim__codelenses', {}),
|
2022-07-31 14:57:32 +00:00
|
|
|
pattern = { '*.go', '*.mod' },
|
2022-07-30 06:00:09 +00:00
|
|
|
callback = function()
|
|
|
|
require('go.codelens').refresh()
|
|
|
|
end,
|
|
|
|
})
|
2021-08-21 10:52:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.run_action()
|
2022-07-30 06:00:09 +00:00
|
|
|
local guihua = utils.load_plugin('guihua.lua', 'guihua.gui')
|
2021-12-16 23:05:37 +00:00
|
|
|
local original_select = vim.ui.select
|
2021-08-21 10:52:23 +00:00
|
|
|
|
2021-12-16 23:05:37 +00:00
|
|
|
if guihua then
|
2022-07-30 06:00:09 +00:00
|
|
|
vim.ui.select = require('guihua.gui').select
|
2021-08-21 10:52:23 +00:00
|
|
|
end
|
|
|
|
|
2021-12-16 23:05:37 +00:00
|
|
|
codelens.run()
|
|
|
|
vim.defer_fn(function()
|
|
|
|
vim.ui.select = original_select
|
|
|
|
end, 1000)
|
2021-08-21 10:52:23 +00:00
|
|
|
end
|
|
|
|
|
2021-08-23 02:24:48 +00:00
|
|
|
function M.refresh()
|
2022-07-31 14:57:32 +00:00
|
|
|
local found = false
|
2022-07-30 06:00:09 +00:00
|
|
|
if _GO_NVIM_CFG.lsp_codelens ~= false then
|
2022-07-31 14:57:32 +00:00
|
|
|
if not found then
|
2023-01-31 23:26:04 +00:00
|
|
|
for _, lsp in pairs(vim.lsp.get_active_clients()) do
|
2022-07-31 14:57:32 +00:00
|
|
|
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()
|
2021-08-23 02:24:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-21 10:52:23 +00:00
|
|
|
return M
|