ray-x 2 years ago
parent 46ba7e9887
commit bd3dfe2ee2

@ -61,30 +61,34 @@ local codelens_hdlr = function(err, result, ctx, cfg)
_update_sign(v.range.start.line)
end
end
local codelens_au
function M.setup(bufnr)
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', {}),
buffer = bufnr or vim.api.nvim_win_get_buf(),
callback = function()
require('navigator.codelens').refresh()
end,
})
if codelens_au == nil then
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 })
codelens_au = 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('navigator.codelens').refresh()
end,
})
end
end
M.lsp_clients = {}
function M.refresh()
if next(vim.lsp.get_active_clients({ buffer = 0 })) == nil then
local bufnr = vim.api.nvim_get_current_buf()
if next(vim.lsp.get_active_clients({ buffer = bufnr })) == nil then
log('Must have a client running to use lsp code action')
return
end
if not lsphelper.check_capabilities('codeLensProvider') then
if not lsphelper.check_capabilities('codeLensProvider', bufnr) then
return
end
M.inline()

@ -39,13 +39,11 @@ M.on_attach = function(client, bufnr)
trace('attaching doc highlight: ', bufnr, client.name)
vim.defer_fn(function()
require('navigator.dochighlight').documentHighlight(bufnr)
end, 50) -- allow a bit time for it to settle down
end, 50) -- allow a bit time for it to settle down
else
log('skip doc highlight: ', bufnr, client.name)
end
require('navigator.lspclient.lspkind').init()
local config = require('navigator').config_values()
@ -67,11 +65,18 @@ M.on_attach = function(client, bufnr)
end
end
--- if code lens enabled
if _NgConfigValues.lsp.code_lens_action.enable then
if client.server_capabilities.codeLensProvider then
require('navigator.codelens').setup(bufnr)
end
end
if _NgConfigValues.lsp.code_action.enable then
if client.server_capabilities.codeActionProvider and client.name ~= 'null-ls' then
if client.server_capabilities.codeLensProvider and client.name ~= 'null-ls' then
log('code action enabled for client', client.server_capabilities.codeActionProvider)
api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
group = api.nvim_create_augroup('NGCodeActGroup_'..tostring(bufnr), {}),
group = api.nvim_create_augroup('NGCodeActGroup_' .. tostring(bufnr), {}),
buffer = bufnr,
callback = function()
require('navigator.codeAction').code_action_prompt(bufnr)

@ -624,11 +624,6 @@ local function setup(user_opts, cnt)
lsp_startup(ft, retry, lsp_opts)
--- if code lens enabled
if _NgConfigValues.lsp.code_lens_action.enable then
require('navigator.codelens').setup(bufnr)
end
-- _LoadedFiletypes[ft .. tostring(bufnr)] = true -- may prevent lsp config when reboot lsp
end

@ -118,28 +118,24 @@ local function extract_result(results_lsp)
end
end
function M.check_capabilities(feature, client_id)
local clients = lsp.get_active_clients({buffer = client_id or 0 })
function M.check_capabilities(feature, bufnr)
local clients = lsp.get_active_clients({ buffer = bufnr or vim.api.nvim_get_current_buf() })
local supported_client = false
for _, client in pairs(clients) do
-- supported_client = client.resolved_capabilities[feature]
supported_client = client.server_capabilities[feature]
if supported_client then
break
return client
end
end
if supported_client then
return true
if #clients == 0 then
log('LSP: no client attached')
else
if #clients == 0 then
log('LSP: no client attached')
else
trace('LSP: server does not support ' .. feature)
end
return false
trace('LSP: server does not support ' .. feature)
end
return false
end
function M.call_sync(method, params, opts, handler)

Loading…
Cancel
Save