diff --git a/lua/navigator/cclshierarchy.lua b/lua/navigator/cclshierarchy.lua index 10f3d44..cfdd4d2 100644 --- a/lua/navigator/cclshierarchy.lua +++ b/lua/navigator/cclshierarchy.lua @@ -1,25 +1,24 @@ -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 partial = util.partial -local lsphelper = require "navigator.lspwrapper" +local lsphelper = require('navigator.lspwrapper') local cwd = vim.loop.cwd() -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 M = {} local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_message) log('call_hierarchy') log('call_hierarchy', direction, err, result) - assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags") + assert(#vim.lsp.buf_get_clients() > 0, '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) + log('hierarchy error', ctx, 'dir', direction, 'result', result, 'err', err) + vim.notify('ERROR: ' .. error_message, vim.lsp.log_levels.WARN) return end - -- local funcs = vim.lsp.util.locations_to_items(result) -- log(funcs) local items = {} for _, call_hierarchy in pairs(result) do @@ -31,8 +30,8 @@ local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_me local bufnr = vim.uri_to_bufnr(call_hierarchy.uri) local row = range.start.line - local line = (vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false) or {""})[1] - local fn = "" + local line = (vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false) or { '' })[1] + local fn = '' if line ~= nil then fn = line:sub(range.start.character, range['end'].character + 1) end @@ -43,34 +42,34 @@ local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_me text = kind .. fn, range = range, lnum = range.start.line + 1, - col = range.start.character + col = range.start.character, }) end 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_tags") + assert(#vim.lsp.buf_get_clients() > 0, 'Must have a client running to use lsp_tags') - local results = call_hierarchy_handler_from(err, result, ctx, cfg, "Incoming calls not found") + local results = call_hierarchy_handler_from(err, result, ctx, cfg, 'Incoming calls not found') - local ft = vim.api.nvim_buf_get_option(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 -- err, method, result, client_id, bufnr 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(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_tags") + assert(#vim.lsp.buf_get_clients() > 0, 'Must have a client running to use lsp_tags') -- if not lsphelper.check_capabilities("call_hierarchy") then -- return -- end @@ -82,16 +81,16 @@ function M.incoming_calls(bang, opts) -- params['callee'] = true log(params) log(opts) - lsphelper.call_sync("$ccls/call", params, opts, partial(incoming_calls_handler, bang)) + lsphelper.call_sync('$ccls/call', 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") + assert(#vim.lsp.buf_get_clients() > 0, 'Must have a client running to use lsp_tags') local params = vim.lsp.util.make_position_params() params['levels'] = 2 params['callee'] = true log(params) - lsphelper.call_sync("$ccls/call", params, opts, partial(outgoing_calls_handler, bang)) + lsphelper.call_sync('$ccls/call', params, opts, partial(outgoing_calls_handler, bang)) end M.incoming_calls_call = partial(M.incoming_calls, 0) diff --git a/lua/navigator/implementation.lua b/lua/navigator/implementation.lua index 7fbb8fb..6096e60 100644 --- a/lua/navigator/implementation.lua +++ b/lua/navigator/implementation.lua @@ -1,37 +1,36 @@ -local util = require "navigator.util" +local util = require('navigator.util') local mk_handler = util.mk_handler -local lsphelper = require "navigator.lspwrapper" -local gui = require "navigator.gui" +local lsphelper = require('navigator.lspwrapper') +local gui = require('navigator.gui') local M = {} -local location = require("guihua.location") +local location = require('guihua.location') local partial = util.partial local locations_to_items = lsphelper.locations_to_items local log = util.log -- dataformat should be same as reference local function location_handler(err, locations, ctx, cfg, msg) if err ~= nil then - vim.notify("ERROR: " .. tostring(err) .. " " .. msg, vim.lsp.log_levels.WARN) + vim.notify('ERROR: ' .. tostring(err) .. ' ' .. msg, vim.lsp.log_levels.WARN) return end - return locations_to_items(locations) + return locations_to_items(locations, ctx) end local function implementation_handler(bang, err, result, ctx, cfg) - local results = location_handler(err, result, ctx, cfg, "Implementation not found") - local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft") - gui.new_list_view({items = results, ft = ft, api = 'Implementation'}) + local results = location_handler(err, result, ctx, cfg, 'Implementation not found') + local ft = vim.api.nvim_buf_get_option(ctx.bufnr, 'ft') + gui.new_list_view({ items = results, ft = ft, api = 'Implementation' }) end function M.implementation(bang, opts) - if not lsphelper.check_capabilities("implementation") then + if not lsphelper.check_capabilities('implementation') then return end local params = vim.lsp.util.make_position_params() - log("impel params", params) + log('impel params', params) - lsphelper.call_sync("textDocument/implementation", params, opts, - partial(implementation_handler, bang)) + lsphelper.call_sync('textDocument/implementation', params, opts, partial(implementation_handler, bang)) end M.implementation_call = partial(M.implementation, 0) diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index 1d34a30..a73aa0d 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -405,6 +405,7 @@ local function load_cfg(ft, client, cfg, loaded) -- need to verify the lsp server is up end +-- run setup for lsp clients local function lsp_startup(ft, retry, user_lsp_opts) retry = retry or false local clients = vim.lsp.get_active_clients() or {} @@ -468,7 +469,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) if lspconfig[lspclient].document_config and lspconfig[lspclient].document_config.default_config then default_config = lspconfig[lspclient].document_config.default_config else - vim.notify('missing document config for client: ' .. vim.inspect(lspclient), vim.lsp.log_levels.WARN) + vim.notify('missing document config for client: ' .. vim.inspect(lspclient), vim.lsp.log_levels.WARN) goto continue end @@ -694,7 +695,6 @@ local function setup(user_opts) end _LoadedFiletypes[ft] = true - -- _LoadedFiletypes[ft] = vim.tbl_extend("keep", _LoadedFiletypes[ft] or {}, {ft}) end -- append lsps to servers diff --git a/lua/navigator/lspwrapper.lua b/lua/navigator/lspwrapper.lua index 3ac0d0d..889278d 100644 --- a/lua/navigator/lspwrapper.lua +++ b/lua/navigator/lspwrapper.lua @@ -101,7 +101,6 @@ function M.symbols_to_items(result) table.insert(locations, item) end end - -- local items = locations_to_items(locations) -- log(locations[1]) return locations end @@ -311,15 +310,18 @@ local function test_locations() log(locations, second_part) end -function M.locations_to_items(locations, max_items) - max_items = max_items or 100000 -- +function M.locations_to_items(locations, ctx) + ctx = ctx or {} + local max_items = ctx.max_items or 100000 -- + local client_id = ctx.client_id or 1 + local enc = util.encoding(client_id) if not locations or vim.tbl_isempty(locations) then vim.notify('list not avalible', vim.lsp.log_levels.WARN) return end local width = 4 - local items = {} -- lsp.util.locations_to_items(locations) + local items = {} -- items and locations may not matching local uri_def = {} @@ -331,12 +333,10 @@ function M.locations_to_items(locations, max_items) vim.cmd([[set eventignore+=FileType]]) - local cut = -1 - local unload_bufnrs = {} for i, loc in ipairs(locations) do local funcs = nil - local item = lsp.util.locations_to_items({ loc })[1] + local item = lsp.util.locations_to_items({ loc }, enc)[1] -- log(item) item.range = locations[i].range or locations[i].targetRange item.uri = locations[i].uri or locations[i].targetUri @@ -425,7 +425,7 @@ function M.symbol_to_items(locations) return end - local items = {} -- lsp.util.locations_to_items(locations) + local items = {} -- items and locations may not matching table.sort(locations, function(i, j) if i.definition then @@ -441,7 +441,7 @@ function M.symbol_to_items(locations) end end) for i, _ in ipairs(locations) do - local item = {} -- lsp.util.locations_to_items({loc})[1] + local item = {} item.uri = locations[i].uri item.range = locations[i].range item.filename = assert(vim.uri_to_fname(item.uri)) diff --git a/lua/navigator/reference.lua b/lua/navigator/reference.lua index 604bc55..bc2d4f0 100644 --- a/lua/navigator/reference.lua +++ b/lua/navigator/reference.lua @@ -67,7 +67,8 @@ local ref_view = function(err, locations, ctx, cfg) return end - local items, width, second_part = locations_to_items(locations, truncate) + ctx.max_items = truncate + local items, width, second_part = locations_to_items(locations, ctx) local thread_items = vim.deepcopy(items) log('splits: ', #items, #second_part) @@ -100,7 +101,7 @@ local ref_view = function(err, locations, ctx, cfg) if vim.tbl_isempty(second_part) then return end - local items2 = locations_to_items(second_part) + local items2 = locations_to_items(second_part, ctx) vim.list_extend(thread_items, items2)