diff --git a/lua/navigator/cclshierarchy.lua b/lua/navigator/cclshierarchy.lua index a8b337d..1109f56 100644 --- a/lua/navigator/cclshierarchy.lua +++ b/lua/navigator/cclshierarchy.lua @@ -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 diff --git a/lua/navigator/codelens.lua b/lua/navigator/codelens.lua index 49f6ebd..994f297 100644 --- a/lua/navigator/codelens.lua +++ b/lua/navigator/codelens.lua @@ -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 diff --git a/lua/navigator/definition.lua b/lua/navigator/definition.lua index 87873d8..b491dd6 100644 --- a/lua/navigator/definition.lua +++ b/lua/navigator/definition.lua @@ -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) diff --git a/lua/navigator/diagnostics.lua b/lua/navigator/diagnostics.lua index 13c2e35..a3f291b 100644 --- a/lua/navigator/diagnostics.lua +++ b/lua/navigator/diagnostics.lua @@ -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 diff --git a/lua/navigator/foldlsp.lua b/lua/navigator/foldlsp.lua index b826046..43f3f6b 100644 --- a/lua/navigator/foldlsp.lua +++ b/lua/navigator/foldlsp.lua @@ -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! * ") + api.nvim_command('augroup FoldingCommand') + api.nvim_command('autocmd! * ') api.nvim_command("autocmd BufEnter lua require'navigator.foldlsp'.update_folds()") api.nvim_command("autocmd BufWritePost 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 diff --git a/lua/navigator/hierarchy.lua b/lua/navigator/hierarchy.lua index d71532a..36badd5 100644 --- a/lua/navigator/hierarchy.lua +++ b/lua/navigator/hierarchy.lua @@ -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)