|
|
|
@ -5,7 +5,7 @@ local codelens = require('vim.lsp.codelens')
|
|
|
|
|
|
|
|
|
|
local log = require('navigator.util').log
|
|
|
|
|
local trace = require('navigator.util').trace
|
|
|
|
|
|
|
|
|
|
-- trace = log
|
|
|
|
|
local lsphelper = require('navigator.lspwrapper')
|
|
|
|
|
local api = vim.api
|
|
|
|
|
local M = {}
|
|
|
|
@ -62,9 +62,10 @@ local codelens_hdlr = function(err, result, ctx, cfg)
|
|
|
|
|
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 })
|
|
|
|
|
log('setup for ****** ', bufnr)
|
|
|
|
|
vim.api.nvim_set_hl(0, 'LspCodeLens', { link = 'DiagnosticsHint', default = true })
|
|
|
|
|
vim.api.nvim_set_hl(0, 'LspCodeLensText', { link = 'DiagnosticsInformation', default = true })
|
|
|
|
|
vim.api.nvim_set_hl(0, 'LspCodeLensSign', { link = 'DiagnosticsInformation', 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', {}),
|
|
|
|
@ -73,14 +74,6 @@ function M.setup(bufnr)
|
|
|
|
|
require('navigator.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 = bufnr or vim.api.nvim_get_current_buf() }
|
|
|
|
|
on_codelens(err, result, ctx, cfg)
|
|
|
|
|
codelens_hdlr(err, result, ctx, cfg)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
M.lsp_clients = {}
|
|
|
|
@ -93,7 +86,7 @@ function M.refresh()
|
|
|
|
|
if not lsphelper.check_capabilities('codeLensProvider') then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
vim.lsp.codelens.refresh()
|
|
|
|
|
M.inline()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local virtual_types_ns = api.nvim_create_namespace('ng_virtual_types')
|
|
|
|
@ -108,12 +101,13 @@ function M.run_action()
|
|
|
|
|
local original_select = vim.ui.select
|
|
|
|
|
vim.ui.select = require('guihua.gui').select
|
|
|
|
|
|
|
|
|
|
log('codeaction')
|
|
|
|
|
log('codelens action')
|
|
|
|
|
|
|
|
|
|
codelens.run()
|
|
|
|
|
vim.defer_fn(function()
|
|
|
|
|
vim.ui.select = original_select
|
|
|
|
|
end, 1000)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
M.inline = function()
|
|
|
|
@ -131,42 +125,20 @@ M.inline = function()
|
|
|
|
|
|
|
|
|
|
local bufnr = api.nvim_get_current_buf()
|
|
|
|
|
local parameter = lsp.util.make_position_params()
|
|
|
|
|
local response = lsp.buf_request_sync(bufnr, 'textDocument/codeLens', parameter)
|
|
|
|
|
|
|
|
|
|
-- Clear previous highlighting
|
|
|
|
|
api.nvim_buf_clear_namespace(bufnr, virtual_types_ns, 0, -1)
|
|
|
|
|
|
|
|
|
|
if response then
|
|
|
|
|
log(response)
|
|
|
|
|
for _, v in ipairs(response) do
|
|
|
|
|
if v == nil or v.result == nil then
|
|
|
|
|
return
|
|
|
|
|
end -- no response
|
|
|
|
|
for _, vv in pairs(v.result) do
|
|
|
|
|
local start_line = -1
|
|
|
|
|
for _, vvv in pairs(vv.range) do
|
|
|
|
|
start_line = tonumber(vvv.line)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local cmd = vv.command
|
|
|
|
|
local msg = _NgConfigValues.icons.code_action_icon .. ' '
|
|
|
|
|
if cmd then
|
|
|
|
|
local txt = cmd.title or ''
|
|
|
|
|
txt = txt .. ' ' .. (cmd.command or '') .. ' '
|
|
|
|
|
msg = msg .. txt .. ' '
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
log(msg)
|
|
|
|
|
api.nvim_buf_set_extmark(bufnr, virtual_types_ns, start_line, -1, {
|
|
|
|
|
virt_text = { { msg, 'LspCodeLensText' } },
|
|
|
|
|
virt_text_pos = 'overlay',
|
|
|
|
|
hl_mode = 'combine',
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local on_codelens = vim.lsp.handlers['textDocument/codeLens']
|
|
|
|
|
lsp.buf_request(bufnr, 'textDocument/codeLens', parameter, function(err, response, ctx, _)
|
|
|
|
|
-- Clear previous highlighting
|
|
|
|
|
api.nvim_buf_clear_namespace(bufnr, virtual_types_ns, 0, -1)
|
|
|
|
|
|
|
|
|
|
if response then
|
|
|
|
|
trace(response)
|
|
|
|
|
|
|
|
|
|
on_codelens(err, response, ctx, _)
|
|
|
|
|
|
|
|
|
|
codelens_hdlr (err, response, ctx, _)
|
|
|
|
|
end
|
|
|
|
|
-- else
|
|
|
|
|
-- api.nvim_command("echohl WarningMsg | echo 'VirtualTypes: No response' | echohl None")
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return M
|
|
|
|
|