change the way checking total number of clients attached #167

serverCapcities
ray-x 2 years ago
parent 8dbac5efc9
commit 8b43ed23e2

@ -13,7 +13,7 @@ local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_me
log('call_hierarchy')
log('call_hierarchy', direction, err, result, ctx, cfg)
assert(#vim.lsp.buf_get_clients() > 0, 'Must have a client running to use lsp_tags')
assert(next(vim.lsp.buf_get_clients()), 'Must have a client running to use lsp_tags')
if err ~= nil then
log('hierarchy error', ctx, 'dir', direction, 'result', result, 'err', err)
vim.notify('ERROR: ' .. error_message, vim.lsp.log_levels.WARN)
@ -52,7 +52,8 @@ local call_hierarchy_handler_from = partial(call_hierarchy_handler, 'from')
local call_hierarchy_handler_to = partial(call_hierarchy_handler, 'to')
local function incoming_calls_handler(bang, err, result, ctx, cfg)
assert(#vim.lsp.buf_get_clients() > 0, 'Must have a client running to use lsp_tags')
local bufnr = vim.api.nvim_get_current_buf()
assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp_tags')
local results = call_hierarchy_handler_from(err, result, ctx, cfg, 'Incoming calls not found')
@ -69,7 +70,8 @@ local function outgoing_calls_handler(bang, err, result, ctx, cfg)
end
function M.incoming_calls(bang, opts)
assert(#vim.lsp.buf_get_clients() > 0, 'Must have a client running to use lsp_tags')
local bufnr = vim.api.nvim_get_current_buf()
assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp_tags')
-- if not lsphelper.check_capabilities("call_hierarchy") then
-- return
-- end
@ -85,7 +87,8 @@ function M.incoming_calls(bang, opts)
end
function M.outgoing_calls(bang, opts)
assert(#vim.lsp.buf_get_clients() > 0, 'Must have a client running to use lsp_tags')
local bufnr = vim.api.nvim_get_current_buf()
assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp_tags')
local params = vim.lsp.util.make_position_params()
params['levels'] = 2
params['callee'] = true

@ -92,7 +92,7 @@ end
M.lsp_clients = {}
function M.refresh()
if #vim.lsp.buf_get_clients() < 1 then
if next(vim.lsp.buf_get_clients(0)) == nil then
log('Must have a client running to use lsp code action')
return
end
@ -130,7 +130,8 @@ M.inline = function()
if vim.fn.getcmdwintype() == ':' then
return
end
if #vim.lsp.buf_get_clients() == 0 then
if next(vim.lsp.buf_get_clients(0)) == nil then
return
end

@ -39,7 +39,7 @@ local function get_symbol()
end
local function def_preview(timeout_ms)
assert(#vim.lsp.buf_get_clients() > 0, 'Must have a client running')
assert(next(vim.lsp.buf_get_clients(0)), 'Must have a client running')
local method = 'textDocument/definition'
local params = vim.lsp.util.make_position_params()
local result = vim.lsp.buf_request_sync(0, method, params, timeout_ms or 1000)

@ -385,14 +385,16 @@ M.set_diag_loclist = function()
log('great, no errors!')
return
end
local clients = vim.lsp.buf_get_clients(0)
local bufnr = vim.api.nvim_get_current_buf()
local clients = vim.lsp.buf_get_clients(bufnr)
local cfg = { open = diag_cnt > 0 }
for _, client in pairs(clients) do
cfg.client_id = client['id']
break
end
if not vim.tbl_isempty(vim.lsp.buf_get_clients(0)) then
if not vim.tbl_isempty(vim.lsp.buf_get_clients(bufnr)) then
local err_cnt = get_count(0, [[Error]])
if err_cnt > 0 and _NgConfigValues.lsp.disply_diagnostic_qf then
if diagnostic.set_loclist then

@ -1,5 +1,5 @@
local log = require"navigator.util".log
local mk_handler = require"navigator.util".mk_handler
local log = require('navigator.util').log
local mk_handler = require('navigator.util').mk_handler
local lsp = vim.lsp
local api = vim.api
@ -18,7 +18,7 @@ M.servers_supporting_folding = {
texlab = true,
clangd = false,
gopls = true,
julials = false
julials = false,
}
M.active_folding_clients = {}
@ -29,11 +29,11 @@ function M.on_attach()
end
function M.setup_plugin()
api.nvim_command("augroup FoldingCommand")
api.nvim_command("autocmd! * <buffer>")
api.nvim_command('augroup FoldingCommand')
api.nvim_command('autocmd! * <buffer>')
api.nvim_command("autocmd BufEnter <buffer> lua require'navigator.foldlsp'.update_folds()")
api.nvim_command("autocmd BufWritePost <buffer> lua require'navigator.foldlsp'.update_folds()")
api.nvim_command("augroup end")
api.nvim_command('augroup end')
-- vim.cmd([[
--
@ -43,7 +43,7 @@ function M.setup_plugin()
--
-- ]])
local clients = vim.lsp.buf_get_clients()
local clients = vim.lsp.buf_get_clients(0)
for _, client in pairs(clients) do
local client_id = client['id']
@ -73,9 +73,8 @@ function M.update_folds()
-- XXX: better to pass callback in this method or add it directly in the config?
-- client.config.callbacks['textDocument/foldingRange'] = M.fold_handler
local current_bufnr = api.nvim_get_current_buf()
local params = {uri = vim.uri_from_bufnr(current_bufnr)}
client.request('textDocument/foldingRange', {textDocument = params}, M.fold_handler,
current_bufnr)
local params = { uri = vim.uri_from_bufnr(current_bufnr) }
client.request('textDocument/foldingRange', { textDocument = params }, M.fold_handler, current_bufnr)
end
end
end
@ -93,7 +92,7 @@ M.fold_handler = mk_handler(function(err, result, ctx, config)
-- params: err, method, result, client_id, bufnr
-- XXX: handle err?
if err or result == nil or #result == 0 then
vim.notify(string.format("%s %s ", tostring(err), vim.inspect(ctx)), vim.lsp.log_levels.WARN)
vim.notify(string.format('%s %s ', tostring(err), vim.inspect(ctx)), vim.lsp.log_levels.WARN)
return
end
M.debug_folds()
@ -160,13 +159,12 @@ function M.get_fold_indic(lnum)
-- without any marker.
return fold_level
elseif is_foldstart then
return string.format(">%d", fold_level)
return string.format('>%d', fold_level)
elseif is_foldend then
return string.format("<%d", fold_level)
return string.format('<%d', fold_level)
else
return fold_level
end
end
return M

@ -1,24 +1,26 @@
local gui = require "navigator.gui"
local util = require "navigator.util"
local gui = require('navigator.gui')
local util = require('navigator.util')
local log = util.log
local trace = util.trace
local partial = util.partial
local lsphelper = require "navigator.lspwrapper"
local lsphelper = require('navigator.lspwrapper')
local path_sep = require"navigator.util".path_sep()
local path_cur = require"navigator.util".path_cur()
local path_sep = require('navigator.util').path_sep()
local path_cur = require('navigator.util').path_cur()
local cwd = vim.loop.cwd()
local M = {}
local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_message)
if not result then
vim.notify ("No call hierarchy items found", vim.lsp.log_levels.WARN)
vim.notify('No call hierarchy items found', vim.lsp.log_levels.WARN)
return
end
trace('call_hierarchy', result)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
local bufnr = vim.api.nvim_get_current_buf()
assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp_tags')
if err ~= nil then
log("dir", direction, "result", result, "err", err, ctx)
vim.notify("ERROR: " .. error_message, vim.lsp.log_levels.WARN)
log('dir', direction, 'result', result, 'err', err, ctx)
vim.notify('ERROR: ' .. error_message, vim.lsp.log_levels.WARN)
return
end
@ -28,14 +30,14 @@ local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_me
local call_hierarchy_item = call_hierarchy_call[direction]
local kind = ''
if call_hierarchy_item.kind then
kind = require'navigator.lspclient.lspkind'.symbol_kind(call_hierarchy_item.kind) .. ' '
kind = require('navigator.lspclient.lspkind').symbol_kind(call_hierarchy_item.kind) .. ' '
end
-- for _, range in pairs(call_hierarchy_call.fromRanges) do
range = call_hierarchy_item.range or call_hierarchy_item.selectionRange
local filename = assert(vim.uri_to_fname(call_hierarchy_item.uri))
local display_filename = filename:gsub(cwd .. path_sep, path_cur, 1)
call_hierarchy_item.detail = call_hierarchy_item.detail or ""
call_hierarchy_item.detail = call_hierarchy_item.detail:gsub("\n", "")
call_hierarchy_item.detail = call_hierarchy_item.detail or ''
call_hierarchy_item.detail = call_hierarchy_item.detail:gsub('\n', '')
trace(range, call_hierarchy_item)
local disp_item = {
@ -45,7 +47,7 @@ local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_me
text = kind .. call_hierarchy_item.name .. '' .. call_hierarchy_item.detail,
range = range,
lnum = range.start.line + 1,
col = range.start.character
col = range.start.character,
}
table.insert(items, disp_item)
@ -54,43 +56,46 @@ local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_me
return items
end
local call_hierarchy_handler_from = partial(call_hierarchy_handler, "from")
local call_hierarchy_handler_to = partial(call_hierarchy_handler, "to")
local call_hierarchy_handler_from = partial(call_hierarchy_handler, 'from')
local call_hierarchy_handler_to = partial(call_hierarchy_handler, 'to')
local function incoming_calls_handler(bang, err, result, ctx, cfg)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp hierarchy")
local results = call_hierarchy_handler_from(err, result, ctx, cfg, "Incoming calls not found")
local bufnr = vim.api.nvim_get_current_buf()
assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp hierarchy')
local results = call_hierarchy_handler_from(err, result, ctx, cfg, 'Incoming calls not found')
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
gui.new_list_view({items = results, ft = ft, api = ''})
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, 'ft')
gui.new_list_view({ items = results, ft = ft, api = '' })
end
local function outgoing_calls_handler(bang, err, result, ctx, cfg)
local results = call_hierarchy_handler_to(err, result, ctx, cfg, "Outgoing calls not found")
local results = call_hierarchy_handler_to(err, result, ctx, cfg, 'Outgoing calls not found')
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
gui.new_list_view({items = results, ft = ft, api = ''})
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, 'ft')
gui.new_list_view({ items = results, ft = ft, api = '' })
-- fzf_locations(bang, "", "Outgoing Calls", results, false)
end
function M.incoming_calls(bang, opts)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp hierarchy")
if not lsphelper.check_capabilities("call_hierarchy") then
local bufnr = vim.api.nvim_get_current_buf()
assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp hierarchy')
if not lsphelper.check_capabilities('call_hierarchy') then
return
end
local params = vim.lsp.util.make_position_params()
lsphelper.call_sync("callHierarchy/incomingCalls", params, opts, partial(incoming_calls_handler, bang))
lsphelper.call_sync('callHierarchy/incomingCalls', params, opts, partial(incoming_calls_handler, bang))
end
function M.outgoing_calls(bang, opts)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
if not lsphelper.check_capabilities("call_hierarchy") then
local bufnr = vim.api.nvim_get_current_buf()
assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp_tags')
if not lsphelper.check_capabilities('call_hierarchy') then
return
end
local params = vim.lsp.util.make_position_params()
lsphelper.call_sync("callHierarchy/outgoingCalls", params, opts, partial(outgoing_calls_handler, bang))
lsphelper.call_sync('callHierarchy/outgoingCalls', params, opts, partial(outgoing_calls_handler, bang))
end
M.incoming_calls_call = partial(M.incoming_calls, 0)

Loading…
Cancel
Save