|
|
@ -1,16 +1,16 @@
|
|
|
|
local log = require"guihua.log".info
|
|
|
|
local log = require('guihua.log').info
|
|
|
|
local trace = require"guihua.log".trace
|
|
|
|
local trace = require('guihua.log').trace
|
|
|
|
local M = {}
|
|
|
|
local M = {}
|
|
|
|
local clone = require'guihua.util'.clone
|
|
|
|
local clone = require('guihua.util').clone
|
|
|
|
local function filename(url)
|
|
|
|
local function filename(url)
|
|
|
|
if url == nil then
|
|
|
|
if url == nil then
|
|
|
|
return ''
|
|
|
|
return ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return url:match("^.+/(.+)$") or url
|
|
|
|
return url:match('^.+/(.+)$') or url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function extension(url)
|
|
|
|
local function extension(url)
|
|
|
|
local ext = url:match("^.+(%..+)$") or "txt"
|
|
|
|
local ext = url:match('^.+(%..+)$') or 'txt'
|
|
|
|
return string.sub(ext, 2)
|
|
|
|
return string.sub(ext, 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -38,7 +38,6 @@ local function get_pads(win_width, text, postfix)
|
|
|
|
i = i + rem * 10
|
|
|
|
i = i + rem * 10
|
|
|
|
-- log(i)
|
|
|
|
-- log(i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if i > 3 then
|
|
|
|
if i > 3 then
|
|
|
@ -52,18 +51,18 @@ end
|
|
|
|
function M.prepare_for_render(items, opts)
|
|
|
|
function M.prepare_for_render(items, opts)
|
|
|
|
opts = opts or {}
|
|
|
|
opts = opts or {}
|
|
|
|
if items == nil or #items < 1 then
|
|
|
|
if items == nil or #items < 1 then
|
|
|
|
vim.notify("no item found or empty fields", vim.lsp.log_levels.INFO)
|
|
|
|
vim.notify('no item found or empty fields', vim.lsp.log_levels.INFO)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local item = clone(items[1])
|
|
|
|
local item = clone(items[1])
|
|
|
|
local display_items = {item}
|
|
|
|
local display_items = { item }
|
|
|
|
local last_summary_idx = 1
|
|
|
|
local last_summary_idx = 1
|
|
|
|
local total_ref_in_file = 1
|
|
|
|
local total_ref_in_file = 1
|
|
|
|
local total = opts.total
|
|
|
|
local total = opts.total
|
|
|
|
local icon = " "
|
|
|
|
local icon = ' '
|
|
|
|
local lspapi = opts.api or "∑"
|
|
|
|
local lspapi = opts.api or '∑'
|
|
|
|
|
|
|
|
|
|
|
|
local ok, devicons = pcall(require, "nvim-web-devicons")
|
|
|
|
local ok, devicons = pcall(require, 'nvim-web-devicons')
|
|
|
|
if ok then
|
|
|
|
if ok then
|
|
|
|
local fn = filename(items[1].filename)
|
|
|
|
local fn = filename(items[1].filename)
|
|
|
|
local ext = extension(fn)
|
|
|
|
local ext = extension(fn)
|
|
|
@ -85,7 +84,7 @@ function M.prepare_for_render(items, opts)
|
|
|
|
local space
|
|
|
|
local space
|
|
|
|
local trim
|
|
|
|
local trim
|
|
|
|
local lspapi_display = lspapi
|
|
|
|
local lspapi_display = lspapi
|
|
|
|
items[i].symbol_name = items[i].symbol_name or "" -- some LSP API does not have range for this
|
|
|
|
items[i].symbol_name = items[i].symbol_name or '' -- some LSP API does not have range for this
|
|
|
|
|
|
|
|
|
|
|
|
local fn = display_items[last_summary_idx].filename
|
|
|
|
local fn = display_items[last_summary_idx].filename
|
|
|
|
local dfn = items[i].display_filename
|
|
|
|
local dfn = items[i].display_filename
|
|
|
@ -103,13 +102,18 @@ function M.prepare_for_render(items, opts)
|
|
|
|
if trim and opts.width > 50 and #dfn > opts.width - 20 then
|
|
|
|
if trim and opts.width > 50 and #dfn > opts.width - 20 then
|
|
|
|
local fn1 = string.sub(dfn, 1, opts.width - 50)
|
|
|
|
local fn1 = string.sub(dfn, 1, opts.width - 50)
|
|
|
|
local fn2 = string.sub(dfn, #dfn - 10, #dfn)
|
|
|
|
local fn2 = string.sub(dfn, #dfn - 10, #dfn)
|
|
|
|
display_items[last_summary_idx].display_filename = fn1 .. "" .. fn2
|
|
|
|
display_items[last_summary_idx].display_filename = fn1 .. '' .. fn2
|
|
|
|
space = ' '
|
|
|
|
space = ' '
|
|
|
|
-- log("trim", fn1, fn2)
|
|
|
|
-- log("trim", fn1, fn2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local api_disp = string.format("%s %s%s%s %i", icon,
|
|
|
|
local api_disp = string.format(
|
|
|
|
display_items[last_summary_idx].display_filename, space,
|
|
|
|
'%s %s%s%s %i',
|
|
|
|
lspapi_display, total_ref_in_file)
|
|
|
|
icon,
|
|
|
|
|
|
|
|
display_items[last_summary_idx].display_filename,
|
|
|
|
|
|
|
|
space,
|
|
|
|
|
|
|
|
lspapi_display,
|
|
|
|
|
|
|
|
total_ref_in_file
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if total then
|
|
|
|
if total then
|
|
|
|
api_disp = api_disp .. ' of: ' .. tostring(total)
|
|
|
|
api_disp = api_disp .. ' of: ' .. tostring(total)
|
|
|
@ -118,20 +122,17 @@ function M.prepare_for_render(items, opts)
|
|
|
|
display_items[last_summary_idx].text = api_disp
|
|
|
|
display_items[last_summary_idx].text = api_disp
|
|
|
|
total_ref_in_file = total_ref_in_file + 1
|
|
|
|
total_ref_in_file = total_ref_in_file + 1
|
|
|
|
else
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
|
|
lspapi_display = lspapi
|
|
|
|
lspapi_display = lspapi
|
|
|
|
item = clone(items[i])
|
|
|
|
item = clone(items[i])
|
|
|
|
|
|
|
|
|
|
|
|
space, trim = get_pads(opts.width, icon .. ' ' .. item.display_filename,
|
|
|
|
space, trim = get_pads(opts.width, icon .. ' ' .. item.display_filename, lspapi_display .. ' 12 of 33')
|
|
|
|
lspapi_display .. ' 12 of 33')
|
|
|
|
|
|
|
|
if trim and opts.width > 52 and #item.display_filename > opts.width - 20 then
|
|
|
|
if trim and opts.width > 52 and #item.display_filename > opts.width - 20 then
|
|
|
|
item.display_filename = string.sub(item.display_filename, 1, opts.width - 52) .. ""
|
|
|
|
item.display_filename = string.sub(item.display_filename, 1, opts.width - 52)
|
|
|
|
.. string.sub(item.display_filename,
|
|
|
|
.. ''
|
|
|
|
#item.display_filename - 10,
|
|
|
|
.. string.sub(item.display_filename, #item.display_filename - 10, #item.display_filename)
|
|
|
|
#item.display_filename)
|
|
|
|
|
|
|
|
space = ' '
|
|
|
|
space = ' '
|
|
|
|
end
|
|
|
|
end
|
|
|
|
item.text = string.format("%s %s%s%s 1", icon, item.display_filename, space, lspapi_display)
|
|
|
|
item.text = string.format('%s %s%s%s 1', icon, item.display_filename, space, lspapi_display)
|
|
|
|
|
|
|
|
|
|
|
|
trace(item.text)
|
|
|
|
trace(item.text)
|
|
|
|
table.insert(display_items, item)
|
|
|
|
table.insert(display_items, item)
|
|
|
@ -140,14 +141,16 @@ function M.prepare_for_render(items, opts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- content of code lines
|
|
|
|
-- content of code lines
|
|
|
|
item = clone(items[i])
|
|
|
|
item = clone(items[i])
|
|
|
|
item.text = require'navigator.util'.trim_and_pad(item.text)
|
|
|
|
item.text = require('navigator.util').trim_and_pad(item.text)
|
|
|
|
item.text = string.format("%4i: %s", item.lnum, item.text)
|
|
|
|
item.text = string.format('%4i: %s', item.lnum, item.text)
|
|
|
|
local ts_report = ""
|
|
|
|
local ts_report = ''
|
|
|
|
if item.lhs then
|
|
|
|
if item.lhs then
|
|
|
|
ts_report = _NgConfigValues.icons.value_changed
|
|
|
|
ts_report = _NgConfigValues.icons.value_changed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log(item)
|
|
|
|
if item.definition then
|
|
|
|
if item.definition then
|
|
|
|
|
|
|
|
log('definition', item)
|
|
|
|
ts_report = ts_report .. _NgConfigValues.icons.value_definition .. ' '
|
|
|
|
ts_report = ts_report .. _NgConfigValues.icons.value_definition .. ' '
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local header_len = #ts_report + 4 -- magic number 2
|
|
|
|
local header_len = #ts_report + 4 -- magic number 2
|
|
|
@ -155,7 +158,7 @@ function M.prepare_for_render(items, opts)
|
|
|
|
|
|
|
|
|
|
|
|
item.text = item.text:gsub('%s*[%[%(%{]*%s*$', '')
|
|
|
|
item.text = item.text:gsub('%s*[%[%(%{]*%s*$', '')
|
|
|
|
if item.call_by ~= nil and #item.call_by > 0 then
|
|
|
|
if item.call_by ~= nil and #item.call_by > 0 then
|
|
|
|
trace("call_by:", #item.call_by)
|
|
|
|
trace('call_by:', #item.call_by)
|
|
|
|
for _, value in pairs(item.call_by) do
|
|
|
|
for _, value in pairs(item.call_by) do
|
|
|
|
if value.node_text then
|
|
|
|
if value.node_text then
|
|
|
|
local txt = value.node_text:gsub('%s*[%[%(%{]*%s*$', '')
|
|
|
|
local txt = value.node_text:gsub('%s*[%[%(%{]*%s*$', '')
|
|
|
@ -183,15 +186,15 @@ function M.prepare_for_render(items, opts)
|
|
|
|
if #ts_report > 1 then
|
|
|
|
if #ts_report > 1 then
|
|
|
|
space, trim = get_pads(win_width, item.text, ts_report)
|
|
|
|
space, trim = get_pads(win_width, item.text, ts_report)
|
|
|
|
if trim then
|
|
|
|
if trim then
|
|
|
|
item.text = string.sub(item.text, 1, opts.width - 20) .. ""
|
|
|
|
item.text = string.sub(item.text, 1, opts.width - 20) .. ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if #space + #item.text + #ts_report >= win_width then
|
|
|
|
if #space + #item.text + #ts_report >= win_width then
|
|
|
|
if #item.text + #ts_report > win_width then
|
|
|
|
if #item.text + #ts_report > win_width then
|
|
|
|
trace("exceeding", #item.text, #ts_report, win_width)
|
|
|
|
trace('exceeding', #item.text, #ts_report, win_width)
|
|
|
|
space = ' '
|
|
|
|
space = ' '
|
|
|
|
else
|
|
|
|
else
|
|
|
|
local remain = win_width - #item.text - #ts_report
|
|
|
|
local remain = win_width - #item.text - #ts_report
|
|
|
|
trace("remain", remain)
|
|
|
|
trace('remain', remain)
|
|
|
|
space = string.rep(' ', remain)
|
|
|
|
space = string.rep(' ', remain)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|