bug fix for #166 not all items shown in listview. Also add flag allow control when the ts info will be added

update readme
neovim_0.6^2
ray-x 2 years ago
parent 309afcd681
commit 8d77c3ab1e

@ -262,6 +262,8 @@ require'navigator'.setup({
-- this kepmap gK will override "gD" mapping function declaration() in default kepmap
-- please check mapping.lua for all keymaps
treesitter_analysis = true, -- treesitter variable context
treesitter_analysis_max_num = 100, -- how many items to run treesitter analysis
-- this value prevent slow in large projects, e.g. found 100000 reference in a project
transparency = 50, -- 0 ~ 100 blur the main window, 100: fully transparent, 0: opaque, set to nil or 100 to disable it
lsp_signature_help = true, -- if you would like to hook ray-x/lsp_signature plugin in navigator

@ -28,6 +28,7 @@ _NgConfigValues = {
end,
ts_fold = false,
treesitter_analysis = true, -- treesitter variable context
treesitter_analysis_max_num = 100, -- how many items to run treesitter analysis
transparency = 50, -- 0 ~ 100 blur the main window, 100: fully transparent, 0: opaque, set to nil to disable it
lsp_signature_help = true, -- if you would like to hook ray-x/lsp_signature plugin in navigator
-- setup here. if it is nil, navigator will not init signature help

@ -162,7 +162,7 @@ function M.call_async(method, params, handler, bufnr)
-- results_lsp, canceller
end
local function ts_functions(uri)
local function ts_functions(uri, optional)
local unload_bufnr
local ts_enabled, _ = pcall(require, 'nvim-treesitter.locals')
if not ts_enabled or not TS_analysis_enabled then
@ -187,6 +187,9 @@ local function ts_functions(uri)
ts_nodes_time:delete(uri)
end
end
if optional then
return
end
local unload = false
if not api.nvim_buf_is_loaded(bufnr) then
trace('! load buf !', uri, bufnr)
@ -206,7 +209,7 @@ local function ts_functions(uri)
return funcs, unload_bufnr
end
local function ts_definition(uri, range)
local function ts_definition(uri, range, optional)
local unload_bufnr
local ts_enabled, _ = pcall(require, 'nvim-treesitter.locals')
if not ts_enabled or not TS_analysis_enabled then
@ -224,6 +227,9 @@ local function ts_definition(uri, range)
log('ts def from cache')
return tsnodes
end
if optional then
return
end
local ts_def = require('navigator.treesitter').find_definition
local bufnr = vim.uri_to_bufnr(uri)
local x = os.clock()
@ -314,6 +320,13 @@ end
-- log(locations, second_part)
-- end
local function ts_optional(i, unload_buf_size)
if unload_buf_size then
return unload_buf_size > _NgConfigValues.treesitter_analysis_max_num
end
return i > _NgConfigValues.treesitter_analysis_max_num
end
function M.locations_to_items(locations, ctx)
ctx = ctx or {}
local max_items = ctx.max_items or 100000 --
@ -353,14 +366,14 @@ function M.locations_to_items(locations, ctx)
local proj_file = item.uri:find(cwd) or is_win or i < 30
local unload, def
if TS_analysis_enabled and proj_file then
funcs, unload = ts_functions(item.uri)
funcs, unload = ts_functions(item.uri, ts_optional(i, #unload_bufnrs))
if unload then
table.insert(unload_bufnrs, unload)
end
if not uri_def[item.uri] then
-- find def in file
def, unload = ts_definition(item.uri, item.range)
def, unload = ts_definition(item.uri, item.range, ts_optional(i, #unload_bufnrs))
if def and def.start then
uri_def[item.uri] = def
if def.start then -- find for the 1st time
@ -421,7 +434,7 @@ function M.locations_to_items(locations, ctx)
vim.cmd([[set eventignore-=FileType]])
trace(items)
return items, width + 24, second_part -- TODO handle long line?
return items, width + 30, second_part -- TODO handle long line?
end
function M.symbol_to_items(locations)

@ -14,9 +14,9 @@ local ref_view = function(err, locations, ctx, cfg)
local truncate = cfg and cfg.truncate or 20
local opts = {}
trace('arg1', err, ctx, locations)
trace(locations)
log(#locations, locations[1])
if ctx.combine then
-- wait for both request
-- wait for both reference and definition LSP request
if ctx.results == nil then
return
end
@ -29,7 +29,7 @@ local ref_view = function(err, locations, ctx, cfg)
if _NgConfigValues.debug then
local logctx = { results = {} }
logctx = vim.tbl_extend('keep', logctx, ctx)
log(logctx, 'result size', #ctx.results, 'item', ctx.results[1])
log(logctx, 'result size', 'def', #ctx.results.definitions, 'ref', #ctx.results.references)
end
if definitions.error and references.error then
vim.notify('lsp ref callback error' .. vim.inspect(ctx.result), vim.lsp.log_levels.WARN)
@ -115,11 +115,13 @@ local ref_view = function(err, locations, ctx, cfg)
if vim.tbl_isempty(second_part) then
return
end
ctx.max_items = #second_part
local items2 = locations_to_items(second_part, ctx)
vim.list_extend(thread_items, items2)
local data = require('navigator.render').prepare_for_render(thread_items, opts)
log('thread data size', #data)
listview.ctrl:on_data_update(data)
if nv_ref_async then
vim.loop.close(nv_ref_async)

@ -179,12 +179,13 @@ function M.prepare_for_render(items, opts)
if #ts_report > 1 then
space, trim = get_pads(win_width, item.text, ts_report)
if trim then
item.text = string.sub(item.text, 1, opts.width - 20) .. ''
local _, j = string.gsub(item.text, [["]], "")
local ts_r = ts_report or ''
item.text = string.sub(item.text, 1, math.max(1, opts.width - math.max(20, #ts_r)))
local _, j = string.gsub(item.text, [["]], '')
if j % 2 == 1 then
item.text = item.text .. '"'
end
_, j = string.gsub(item.text, [[']], "")
_, j = string.gsub(item.text, [[']], '')
if j % 2 == 1 then
item.text = item.text .. [[']]
end

@ -448,7 +448,7 @@ local function get_all_nodes(bufnr, filter, summary)
-- hack for lua and maybe other language aswell
local parent = tsdata:parent()
if parent ~= nil then
log(parent:type(), vim.treesitter.get_node_text(parent, bufnr), item.node_text, item.type)
log(parent:type(), vim.treesitter.get_node_text(parent, bufnr):sub(1, 30), item.node_text, item.type)
end
if
parent ~= nil

Loading…
Cancel
Save