vim.uv and off page ts_context not loaded (#293)

* bugfix ts context not shown for off-page entries

* logs cleanup

* vim.loop -> vim.uv
pull/296/head
rayx 6 months ago committed by GitHub
parent 50973a602a
commit 5cf1459e03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"Lua.workspace.library": [
"${3rd}/luassert/library"
]
}

332
.tags

@ -0,0 +1,332 @@
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_OUTPUT_EXCMD number /number, pattern, mixed, or combineV2/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_PATTERN_LENGTH_LIMIT 96 /0 for no limit/
!_TAG_PROC_CWD /home/ray/github/ray-x/navigator.lua/ //
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
!_TAG_PROGRAM_VERSION 5.9.0 /227c65e76/
Custom_fold_text lua/navigator/foldts.lua 20;" f
Fix lua/navigator/protocal.txt 374;" f
["sumneko_lua"] issue130/init.lua 62;" f
["tsserver"] issue130/init.lua 71;" f
['<Tab>'] playground/init.lua 72;" f
['sumneko_lua'] playground/init_130.lua 34;" f
['sumneko_lua'] playground/init_131.lua 22;" f
['sumneko_lua'] playground/init_lsp_installer.lua 22;" f
['tsserver'] playground/init_130.lua 43;" f
['tsserver'] playground/init_131.lua 31;" f
['tsserver'] playground/init_lsp_installer.lua 31;" f
\x21 tests/fixtures/tests 133;" f
_ lua/navigator/util.lua 300;" f
_update_sign lua/navigator/codeAction.lua 44;" f
_update_sign lua/navigator/codelens.lua 26;" f
_update_virtual_text lua/navigator/codeAction.lua 27;" f
action_virtual_call_back lua/navigator/codeAction.lua 141;" f
add lua/navigator/lspclient/clients.lua 54;" f
add_highlight lua/navigator/lspclient/highlight.lua 34;" f unknown:M
add_locs lua/navigator/dochighlight.lua 15;" f
add_servers lua/navigator/lspclient/clients.lua 680;" f
add_workspace_folder lua/navigator/workspace.lua 9;" f unknown:M
adjust_foldend lua/navigator/foldlsp.lua 120;" f unknown:M
adjust_foldstart lua/navigator/foldlsp.lua 116;" f unknown:M
async thread.lua 4;" f
async_hdlr lua/navigator/reference.lua 139;" f unknown:M
async_ref lua/navigator/reference.lua 148;" f
autocmd lua/navigator/lspclient/mapping.lua 216;" f
before lua/navigator/dochighlight.lua 125;" f
buf_func lua/navigator/treesitter.lua 442;" f unknown:M
buf_ts lua/navigator/treesitter.lua 489;" f unknown:M
bufs_ts lua/navigator/treesitter.lua 511;" f unknown:M
call_async lua/navigator/lspwrapper.lua 153;" f unknown:M
call_hierarchy_handler lua/navigator/cclshierarchy.lua 12;" f
call_hierarchy_handler lua/navigator/hierarchy.lua 12;" f
call_sync lua/navigator/lspwrapper.lua 145;" f unknown:M
callback lua/navigator/lspwrapper.lua 155;" f
check_cap lua/navigator/lspclient/mapping.lua 84;" f
check_capabilities lua/navigator/lspwrapper.lua 121;" f unknown:M
check_lhs lua/navigator/lspwrapper.lua 31;" f
clear_all_buf lua/navigator/util.lua 380;" f unknown:M
clear_buf lua/navigator/util.lua 366;" f unknown:M
clear_diag_VT lua/navigator/diagnostics.lua 325;" f
clear_usage_highlights lua/navigator/treesitter.lua 612;" f unknown:M
cmd_nohl lua/navigator/dochighlight.lua 201;" f
cmp_kind lua/navigator/lspclient/lspkind.lua 128;" f unknown:lspkind
code_action lua/navigator/codeAction.lua 161;" f unknown:code_action
code_action_prompt lua/navigator/codeAction.lua 188;" f unknown:code_action
code_action_req lua/navigator/codeAction.lua 145;" f
codelens_hdlr lua/navigator/codelens.lua 49;" f
comp_kind lua/navigator/lspclient/lspkind.lua 120;" f unknown:lspkind
config lua/navigator/diagnostics.lua 474;" f unknown:M
config playground/init.lua 32;" f
config playground/init.lua 47;" f
config playground/init.lua 60;" f
config playground/init_131.lua 17;" f
config playground/init_131.lua 51;" f
config playground/init_lsp_installer.lua 17;" f
config playground/init_lsp_installer.lua 51;" f
config playground/init_ts_only.lua 35;" f
config playground/init_ts_only.lua 52;" f
config_values lua/navigator.lua 212;" f unknown:M
config_values lua/navigator.lua.bak 47;" f unknown:M
ctags lua/navigator/ctags.lua 133;" f
ctags_gen lua/navigator/ctags.lua 54;" f
ctags_symbols lua/navigator/ctags.lua 85;" f
curriedDot playground/js/curry.js 1;" f
cut lua/navigator/lru.lua 60;" f
debounce_trailing lua/navigator/debounce.lua 3;" f unknown:M
debug_folds lua/navigator/foldlsp.lua 82;" f unknown:M
def lua/navigator/definition.lua 145;" f
def_preview lua/navigator/definition.lua 41;" f
definition_hdlr README.md 759;" f
definition_hdlr doc/navigator.txt 662;" f
definition_hdlr lua/navigator/definition.lua 8;" f
del lua/navigator/lru.lua 95;" f
del_keymap lua/navigator/lspclient/mapping.lua 131;" f
delete lua/navigator/lru.lua 145;" f
deprecated lua/navigator.lua 117;" f unknown:M
diag_hdlr lua/navigator/diagnostics.lua 196;" f
diagnositc_config_sign lua/navigator/lspclient/highlight.lua 7;" f unknown:M
dirname lua/navigator/lspclient/clients.lua 85;" f
disable lua/navigator/codelens.lua 99;" f unknown:M
displayName playground/js/closure.js 3;" f
documentHighlight lua/navigator/dochighlight.lua 218;" f
document_symbol_handler lua/navigator/symbols.lua 43;" f unknown:M
document_symbols lua/navigator/symbols.lua 21;" f unknown:M
empty lua/navigator/util.lua 425;" f unknown:M
encoding lua/navigator/util.lua 436;" f unknown:M
entry_to_item lua/navigator/ctags.lua 9;" f
error lua/navigator/util.lua 203;" f unknown:M
error lua/navigator/util.lua 460;" f unknown:M
error_marker lua/navigator/diagnostics.lua 57;" f
exclude lua/navigator/util.lua 341;" f unknown:M
expand playground/init.lua 65;" f
extend_config lua/navigator.lua 138;" f
extend_config lua/navigator.lua.bak 27;" f
extension lua/navigator/render.lua 12;" f
extract_result lua/navigator/lspwrapper.lua 109;" f
file_exists lua/navigator/util.lua 75;" f unknown:M
filename lua/navigator/render.lua 5;" f
find_definition lua/navigator/treesitter.lua 75;" f unknown:M
find_ts_func_by_range lua/navigator/lspwrapper.lua 246;" f
fmt lua/navigator/util.lua 208;" f unknown:M
fnamemodify lua/navigator/lspwrapper.lua 56;" f
fold_handler lua/navigator/foldlsp.lua 90;" f unknown:M
folds_levels lua/navigator/foldts.lua 53;" f
format_hdl lua/navigator/formatting.lua 4;" f
func thread.lua 1;" f
get lua/navigator/lru.lua 112;" f
getArgs lua/navigator/util.lua 245;" f unknown:M
getDir lua/navigator/util.lua 119;" f
get_all_nodes lua/navigator/treesitter.lua 267;" f
get_base lua/navigator/util.lua 109;" f unknown:M
get_cfg lua/navigator/lspclient/clients.lua 685;" f
get_count lua/navigator/diagnostics.lua 49;" f
get_current_winid lua/navigator/codeAction.lua 23;" f
get_current_winid lua/navigator/util.lua 387;" f unknown:M
get_data_from_file lua/navigator/util.lua 36;" f unknown:M
get_definitions lua/navigator/treesitter.lua 111;" f
get_fold_indic lua/navigator/foldlsp.lua 130;" f unknown:M
get_fold_indic lua/navigator/foldts.lua 162;" f unknown:M
get_icon lua/navigator/treesitter.lua 27;" f
get_keymaps_help lua/navigator/lspclient/mapping.lua 333;" f unknown:M
get_line_diagnostic lua/navigator/diagnostics.lua 452;" f unknown:M
get_namespace lua/navigator/codeAction.lua 19;" f
get_node_at_line lua/navigator/treesitter.lua 561;" f unknown:M
get_node_at_pos lua/navigator/treesitter.lua 616;" f unknown:M
get_node_scope lua/navigator/treesitter.lua 632;" f unknown:M
get_pads lua/navigator/render.lua 17;" f
get_relative_path lua/navigator/util.lua 137;" f unknown:M
get_scope lua/navigator/treesitter.lua 151;" f
get_smallest_context lua/navigator/treesitter.lua 213;" f
get_symbol lua/navigator/definition.lua 36;" f
get_symbol lua/navigator/dochighlight.lua 11;" f
get_symbol lua/navigator/lspwrapper.lua 24;" f unknown:M
goto_adjacent_usage lua/navigator/treesitter.lua 230;" f unknown:M
goto_adjent_reference lua/navigator/dochighlight.lua 161;" f
goto_definition lua/navigator/treesitter.lua 35;" f unknown:M
goto_next_usage lua/navigator/treesitter.lua 256;" f unknown:M
goto_previous_usage lua/navigator/treesitter.lua 259;" f unknown:M
handle_document_highlight lua/navigator/dochighlight.lua 141;" f
handlers['textDocument/codeLens'] lua/navigator/codelens.lua 75;" f unknown:vim.lsp
handlers['textDocument/documentHighlight'] lua/navigator/dochighlight.lua 229;" f unknown:vim.lsp
hi_symbol lua/navigator/dochighlight.lua 46;" f
hide_diagnostic lua/navigator/diagnostics.lua 336;" f unknown:M
highlight_usages lua/navigator/treesitter.lua 588;" f unknown:M
i tests/fixtures/tests 122;" f
implementation lua/navigator/implementation.lua 24;" f unknown:M
implementation_handler lua/navigator/implementation.lua 18;" f
incoming_calls lua/navigator/cclshierarchy.lua 72;" f unknown:M
incoming_calls lua/navigator/hierarchy.lua 80;" f unknown:M
incoming_calls_handler lua/navigator/cclshierarchy.lua 54;" f
incoming_calls_handler lua/navigator/hierarchy.lua 63;" f
info lua/navigator.lua 7;" f
info lua/navigator/util.lua 197;" f unknown:M
info lua/navigator/util.lua 464;" f unknown:M
init lua/navigator/lazyloader.lua 2;" f
init lua/navigator/lspclient/lspkind.lua 132;" f unknown:lspkind
inline lua/navigator/codelens.lua 117;" f unknown:M
io_read lua/navigator/util.lua 64;" f unknown:M
key lua/navigator/treesitter.lua 263;" f
lines_from_locations lua/navigator/lspwrapper.lua 55;" f unknown:M
list_workspace_folders lua/navigator/workspace.lua 92;" f unknown:M
load lua/navigator/lazyloader.lua 46;" f
load_cfg lua/navigator/lspclient/clients.lua 372;" f
load_plugins playground/init.lua 26;" f
load_plugins playground/init_130.lua 13;" f
load_plugins playground/init_131.lua 10;" f
load_plugins playground/init_lsp_installer.lua 10;" f
load_plugins playground/init_ts_only.lua 26;" f
location_handler lua/navigator/implementation.lua 10;" f
locations_to_items lua/navigator/lspwrapper.lua 315;" f unknown:M
log lua/navigator/util.lua 194;" f unknown:M
lru_pairs lua/navigator/lru.lua 164;" f
lsp_startup lua/navigator/lspclient/clients.lua 462;" f
main README.md 36;" f
main doc/navigator.txt 86;" f
makeFreeSpace lua/navigator/lru.lua 105;" f
makeFunc playground/js/closure.js 1;" f
map lua/navigator/util.lua 91;" f unknown:M
match_parameter lua/navigator/signature.lua 5;" f
matches lua/navigator/foldts.lua 69;" f
merge lua/navigator/util.lua 84;" f unknown:M
mk_handler lua/navigator/util.lua 413;" f unknown:M
mynext lua/navigator/lru.lua 149;" f
nav_doc_hl lua/navigator/dochighlight.lua 208;" f
new lua/navigator/lru.lua 32;" f unknown:lru
new_list_view lua/navigator/gui.lua 10;" f unknown:M
node_in_range lua/navigator/treesitter.lua 547;" f
node_is_definination lua/navigator/treesitter.lua 51;" f
nohl lua/navigator/dochighlight.lua 34;" f
nv_ref_async lua/navigator/reference.lua 109;" f
nvim_0_6_1 lua/navigator/util.lua 391;" f unknown:M
nvim_0_8 lua/navigator/util.lua 402;" f unknown:M
oldval tests/fixtures/tests 124;" f
on_attach README.md 243;" f
on_attach README.md 303;" f
on_attach README.md 583;" f
on_attach doc/navigator.txt 247;" f
on_attach doc/navigator.txt 289;" f
on_attach doc/navigator.txt 505;" f
on_attach issue130/init.lua 72;" f unknown:options
on_attach lua/navigator.lua 26;" f
on_attach lua/navigator/foldlsp.lua 25;" f unknown:M
on_attach lua/navigator/foldts.lua 15;" f unknown:M
on_attach lua/navigator/lspclient/attach.lua 10;" f unknown:M
on_attach lua/navigator/lspclient/clients.lua 180;" f
on_attach lua/navigator/lspclient/clients.lua 204;" f
on_attach lua/navigator/lspclient/clients.lua 552;" f unknown:cfg
on_attach lua/navigator/lspclient/clients.lua 564;" f unknown:cfg
on_attach lua/navigator/lspclient/clients.lua 576;" f unknown:cfg
on_attach lua/navigator/lspclient/clients.lua 604;" f unknown:cfg
on_attach lua/navigator/lspclient/clients.lua 660;" f unknown:cfg
on_attach playground/init_130.lua 44;" f unknown:options
on_attach playground/init_131.lua 32;" f unknown:options
on_attach playground/init_lsp_installer.lua 32;" f unknown:options
on_confirm lua/navigator/workspace.lua 58;" f
on_exit lua/navigator/ctags.lua 73;" f
on_filetype lua/navigator/lspclient/clients.lua 806;" f
on_init lua/navigator/lspclient/clients.lua 594;" f unknown:cfg
on_input_filter lua/navigator/workspace.lua 65;" f
on_move lua/navigator/workspace.lua 99;" f
on_new_config lua/navigator/lspclient/clients.lua 247;" f
on_stdout lua/navigator/ctags.lua 69;" f
open_file lua/navigator/util.lua 326;" f unknown:M
open_log lua/navigator/util.lua 274;" f unknown:M
open_lsp_log lua/navigator/lspclient/config.lua 22;" f unknown:M
order_locations lua/navigator/lspwrapper.lua 262;" f
outgoing_calls lua/navigator/cclshierarchy.lua 89;" f unknown:M
outgoing_calls lua/navigator/hierarchy.lua 91;" f unknown:M
outgoing_calls_handler lua/navigator/cclshierarchy.lua 64;" f
outgoing_calls_handler lua/navigator/hierarchy.lua 72;" f
p lua/navigator/util.lua 259;" f unknown:M
pack lua/navigator/util.lua 279;" f unknown:table
partial lua/navigator/util.lua 419;" f unknown:M
path_cur lua/navigator/util.lua 23;" f unknown:M
path_sep lua/navigator/util.lua 12;" f unknown:M
prepare_for_render lua/navigator/render.lua 51;" f unknown:M
prepare_node lua/navigator/treesitter.lua 138;" f
printError lua/navigator/util.lua 263;" f unknown:M
prompt lua/navigator/workspace.lua 12;" f
prompt lua/navigator/workspace.lua 22;" f
prompt lua/navigator/workspace.lua 30;" f
quickfix_extract lua/navigator/util.lua 223;" f unknown:M
range_code_action lua/navigator/codeAction.lua 173;" f unknown:code_action
ref lua/navigator/reference.lua 202;" f
ref_hdlr lua/navigator/reference.lua 136;" f
ref_req lua/navigator/reference.lua 185;" f
ref_view lua/navigator/reference.lua 13;" f
refresh lua/navigator/codelens.lua 86;" f unknown:M
reload lua/navigator/util.lua 269;" f unknown:M
reload_lsp lua/navigator/lspclient/config.lua 7;" f unknown:M
remove_workspace_folder lua/navigator/workspace.lua 17;" f unknown:M
rename lua/navigator/rename.lua 6;" f unknown:M
render_action_virtual_text lua/navigator/codeAction.lua 79;" f unknown:code_action
request lua/navigator/lspwrapper.lua 464;" f unknown:M
root_dir lua/navigator/lspclient/clients.lua 120;" f
root_dir lua/navigator/lspclient/clients.lua 164;" f
root_dir lua/navigator/lspclient/clients.lua 187;" f
root_dir lua/navigator/lspclient/clients.lua 99;" f
round lua/navigator/util.lua 32;" f unknown:M
run_action lua/navigator/codelens.lua 105;" f unknown:M
select lua/navigator/gui.lua 59;" f unknown:M
set lua/navigator/lru.lua 122;" f
setNewest lua/navigator/lru.lua 84;" f
set_cmds lua/navigator/lspclient/mapping.lua 118;" f
set_diag_loclist lua/navigator/diagnostics.lua 383;" f unknown:M
set_event_handler lua/navigator/lspclient/mapping.lua 228;" f
set_keymap lua/navigator/lspclient/mapping.lua 135;" f
set_mapping lua/navigator/lspclient/mapping.lua 124;" f
set_virt_eol lua/navigator/util.lua 356;" f unknown:M
setup lua/navigator.lua 216;" f unknown:M
setup lua/navigator.lua.bak 51;" f unknown:M
setup lua/navigator/codelens.lua 64;" f unknown:M
setup lua/navigator/lspclient/clients.lua 19;" f
setup lua/navigator/lspclient/clients.lua 696;" f
setup lua/navigator/lspclient/mapping.lua 273;" f unknown:M
setup_fmt lua/navigator/lspclient/clients.lua 425;" f
setup_fold lua/navigator/foldts.lua 33;" f unknown:M
setup_plugin lua/navigator/foldlsp.lua 30;" f unknown:M
show lua/navigator/util.lua 283;" f unknown:M
show_buf_diagnostics lua/navigator/diagnostics.lua 351;" f unknown:M
show_diagnostics lua/navigator/diagnostics.lua 457;" f unknown:M
signature_handler lua/navigator/signature.lua 44;" f
slice_locations lua/navigator/lspwrapper.lua 280;" f
sort_select lua/navigator/codeAction.lua 154;" f
split lua/navigator/util.lua 212;" f unknown:M
split2 lua/navigator/util.lua 295;" f unknown:M
start_client lua/navigator.lua 243;" f unknown:vim.lsp
symbol_kind lua/navigator/lspclient/lspkind.lua 124;" f unknown:lspkind
symbol_to_items lua/navigator/lspwrapper.lua 425;" f unknown:M
symbols_to_items lua/navigator/lspwrapper.lua 75;" f unknown:M
testitem lua/navigator/ctags.lua 144;" f
throttle_leading lua/navigator/debounce.lua 14;" f unknown:M
title lua/navigator/protocal.txt 388;" f
title lua/navigator/protocal.txt 392;" f
toggle_diagnostics lua/navigator/diagnostics.lua 342;" f unknown:M
toggle_lspformat lua/navigator/lspclient/mapping.lua 254;" f unknown:M
trace lua/navigator/util.lua 200;" f unknown:M
trim_and_pad lua/navigator/util.lua 307;" f unknown:M
trim_level lua/navigator/foldts.lua 55;" f
ts_definition lua/navigator/lspwrapper.lua 207;" f
ts_functions lua/navigator/lspwrapper.lua 163;" f
type vim.toml 21;" f
type vim.toml 26;" f
type vim.toml 29;" f
type vim.toml 31;" f
unload lua/navigator/lspwrapper.lua 354;" f
update_capabilities lua/navigator/lspclient/clients.lua 442;" f
update_err_marker lua/navigator/diagnostics.lua 414;" f unknown:M
update_err_marker_async lua/navigator/diagnostics.lua 191;" f
update_folds lua/navigator/foldlsp.lua 62;" f unknown:M
warn lua/navigator.lua 3;" f
warn lua/navigator/util.lua 456;" f unknown:M
workspace_symbol lua/navigator/workspace.lua 28;" f unknown:M
workspace_symbol_handler lua/navigator/symbols.lua 103;" f unknown:M
workspace_symbol_live lua/navigator/workspace.lua 36;" f unknown:M
workspace_symbols lua/navigator/symbols.lua 9;" f unknown:M
~ lua/navigator/treesitter.lua 202;" f
~ lua/navigator/treesitter.lua 371;" f

@ -244,7 +244,8 @@ Nondefault configuration example:
```lua
require'navigator'.setup({
debug = false, -- log output, set to true and log path: ~/.cache/nvim/gh.log
debug = false, -- log output, set to true and log path: ~/.cache/nvim/gh.log
-- slowdownd startup and some actions
width = 0.75, -- max width ratio (number of cols for the floating window) / (window width)
height = 0.3, -- max list window height, 0.3 by default
preview_height = 0.35, -- max height of preview windows

@ -34,6 +34,7 @@ _NgConfigValues = {
treesitter_analysis = true, -- treesitter variable context
treesitter_navigation = true, -- bool|table
treesitter_analysis_max_num = 100, -- how many items to run treesitter analysis
treesitter_analysis_max_fnum = 20, -- how many files to run treesitter analysis
treesitter_analysis_condense = true, -- short format of function
treesitter_analysis_depth = 3, -- max depth
transparency = 50, -- 0 ~ 100 blur the main window, 100: fully transparent, 0: opaque, set to nil to disable it

@ -3,6 +3,7 @@ local util = require('navigator.util')
local log = util.log
local partial = util.partial
local lsphelper = require('navigator.lspwrapper')
local uv = vim.uv or vim.loop
local cwd = vim.loop.cwd()
local path_sep = require('navigator.util').path_sep()

@ -1,9 +1,14 @@
local M = {}
local uv = vim.uv or vim.loop
function M.debounce_trailing(ms, fn)
local timer = vim.loop.new_timer()
local timer = uv.new_timer()
return function(...)
local argv = {...}
if timer:is_active() then
timer:stop()
return
end
timer:start(ms, 0, function()
timer:stop()
fn(unpack(argv))
@ -12,7 +17,7 @@ function M.debounce_trailing(ms, fn)
end
function M.throttle_leading(ms, fn)
local timer = vim.loop.new_timer()
local timer = uv.new_timer()
local running = false
return function(...)
if not running then

@ -7,7 +7,8 @@ local lsphelper = require('navigator.lspwrapper')
local path_sep = require('navigator.util').path_sep()
local path_cur = require('navigator.util').path_cur()
local cwd = vim.loop.cwd()
local uv = vim.uv or vim.loop
local cwd = uv.cwd()
local in_method = 'callHierarchy/incomingCalls'
local out_method = 'callHierarchy/outgoingCalls'

@ -4,7 +4,8 @@ capabilities.textDocument.completion.completionItem.snippetSupport = true
function M.reload_lsp()
vim.cmd("LspStop")
local timer = vim.loop.new_timer()
local uv = vim.uv or vim.loop
local timer = uv.new_timer()
local i = 0
timer:start(500, 100, function()
if i >= 5 then

@ -5,7 +5,8 @@ local on_attach = require('navigator.lspclient.attach').on_attach
local library = {}
local function add(lib)
for _, p in pairs(vfn.expand(lib, false, true)) do
p = vim.loop.fs_realpath(p)
local uv = vim.uv or vim.loop
p = uv.fs_realpath(p)
if p then
library[p] = true
end

@ -9,9 +9,10 @@ local log = require('navigator.util').log
local lerr = require('navigator.util').error
local trace = require('navigator.util').trace
local symbol_kind = require('navigator.lspclient.lspkind').symbol_kind
local cwd = vim.loop.cwd()
local is_win = vim.loop.os_uname().sysname:find('Windows')
local uv = vim.uv or vim.loop
local cwd = uv.cwd()
local os_name = uv.os_uname().sysname
local is_win = os_name:find('Windows') or os_name:find('MINGW')
local path_sep = require('navigator.util').path_sep()
local path_cur = require('navigator.util').path_cur()
@ -264,24 +265,6 @@ local function find_ts_func_by_range(funcs, range)
return result
end
local function order_locations(locations)
table.sort(locations, function(i, j)
if i == nil or j == nil or i.uri == nil or j.uri == nil then
-- log(i, j)
return false
end
if i.uri == j.uri then
if i.range and i.range.start then
return i.range.start.line < j.range.start.line
end
return false
else
return i.uri < j.uri
end
end)
return locations
end
local function slice_locations(locations, max_items)
local cut = -1
if #locations > max_items then
@ -326,43 +309,54 @@ end
function M.locations_to_items(locations, ctx)
ctx = ctx or {}
local max_items = ctx.max_items or 100000 --
local max_items = ctx.max_items or 1000 --
trace(ctx, max_items)
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.log.levels.WARN)
return
end
local width = 4
local width = 4 -- text max width
local items = {}
-- items and locations may not matching
local uri_def = {}
order_locations(locations)
local second_part
locations, second_part = slice_locations(locations, max_items)
if second_part and #second_part > 0 then
log('second part', #locations, #second_part)
trace(#locations, locations[1], #second_part, second_part and second_part[1])
end
trace(locations)
vim.cmd([[set eventignore+=FileType]])
local now = uv.now()
local unload_bufnrs = {}
local file_cnt = {}
for i, loc in ipairs(locations) do
local looptimer = uv.now()
local item = lsp.util.locations_to_items({ loc }, enc)[1]
item.range = locations[i].range or locations[i].targetRange
item.uri = locations[i].uri or locations[i].targetUri
item.definition = locations[i].definition
if is_win then
log(item.uri) -- file:///C:/path/to/file
log(cwd)
trace(item.uri, cwd) -- file:///C:/path/to/file
end
-- only load top 30 file.
local proj_file = item.uri:find(cwd) or is_win or i < _NgConfigValues.treesitter_analysis_max_num
file_cnt[item.uri] = (file_cnt[item.uri] or 0) + 1
-- only load top 30 file.items
local proj_file = (item.uri:find(cwd) or is_win) and i < _NgConfigValues.treesitter_analysis_max_num and table.getn(file_cnt) < _NgConfigValues.treesitter_analysis_max_fnum -- getn deprecated, but it is the best solution for getting dict size
local unload, def
local context = ''
if TS_analysis_enabled and proj_file and not ctx.no_show then
if not proj_file then
trace('not proj file', i, item.uri)
end
if TS_analysis_enabled and not ctx.no_show and proj_file then
local ts_context = nts.ref_context
local bufnr = vim.uri_to_bufnr(item.uri)
@ -371,8 +365,8 @@ function M.locations_to_items(locations, ctx)
vim.fn.bufload(bufnr)
unload = bufnr
end
context = ts_context({ bufnr = bufnr, pos = item.range }) or ''
log(context)
context = ts_context({ bufnr = bufnr, pos = item.range }) or 'not found'
trace('ts ctx', i, context, uv.now() - looptimer)
-- TODO: unload buffers
if unload then
@ -405,6 +399,7 @@ function M.locations_to_items(locations, ctx)
table.insert(unload_bufnrs, unload)
end
end
trace('perf: ts ctx', i, uv.now() - looptimer, uv.now() - now)
trace(uri_def[item.uri], item.range) -- set to log if need to get all in rnge
local def1 = uri_def[item.uri]
if def1 and def1.start and item.range then
@ -426,11 +421,18 @@ function M.locations_to_items(locations, ctx)
item.display_filename = filename or item.filename
item.call_by = context -- find_ts_func_by_range(funcs, item.range)
item.rpath = util.get_relative_path(cwd, gutil.add_pec(item.filename))
if is_win then
-- windows C: vs c: -- log(item.filename, filename, cwd .. path_sep, path_cur)
item.display_filename = item.rpath or item.display_filename
end
width = math.max(width, #item.text)
item.symbol_name = M.get_symbol(item.text, item.range)
item.lhs = check_lhs(item.text, item.symbol_name)
table.insert(items, item)
trace('perf: ts render', uv.now() - looptimer, uv.now() - now)
loop_timer = uv.now()
end
trace(uri_def)

@ -6,15 +6,45 @@ local lsp = require('navigator.lspwrapper')
local trace = require('navigator.util').trace
-- local partial = util.partial
-- local cwd = vim.loop.cwd()
local uv = vim.loop
-- local lsphelper = require "navigator.lspwrapper"
local locations_to_items = lsphelper.locations_to_items
local function order_locations(locations)
table.sort(locations, function(i, j)
if i == nil or j == nil or i.uri == nil or j.uri == nil then
-- log(i, j)
return false
end
if i.uri == j.uri then
if i.range and i.range.start then
return i.range.start.line < j.range.start.line
end
return false
else
return i.uri < j.uri
end
end)
return locations
end
local function warmup_treesitter(options)
local api = vim.api
local parsers = require('nvim-treesitter.parsers')
local bufnr = options.bufnr or api.nvim_get_current_buf()
local parser = parsers.get_parser(bufnr)
if not parser then
log('err: ts not loaded ' .. vim.o.ft)
return
end
end
local M = {}
local ref_view = function(err, locations, ctx, cfg)
cfg = cfg or {}
local truncate = cfg and cfg.truncate or 20
local opts = {}
trace('arg1', err, ctx, locations)
trace('ref_view', err, ctx, #locations, cfg, locations)
-- log(#locations, locations[1])
if ctx.combine then
-- wait for both reference and definition LSP request
@ -45,16 +75,16 @@ local ref_view = function(err, locations, ctx, cfg)
if references and references.result and #references.result > 0 then
local refs = references.result
order_locations(refs)
vim.list_extend(locations, refs)
end
err = nil
trace(locations)
-- lets de-dup first 10 elements. some lsp does not recognize definition and reference difference
locations = util.dedup(locations)
trace(locations)
end
-- log("num", num)
-- log("bfnr", bufnr)
-- log('num bufnr: ', num, bufnr)
if err ~= nil then
vim.notify(
'lsp ref callback error' .. vim.inspect(err) .. vim.inspect(ctx) .. vim.inspect(locations),
@ -63,12 +93,6 @@ local ref_view = function(err, locations, ctx, cfg)
log('ref callback error, lsp may not ready', err, ctx, vim.inspect(locations))
return
end
if type(locations) ~= 'table' then
log(locations)
log('ctx', ctx)
vim.notify('incorrect setup' .. vim.inspect(locations), vim.log.levels.WARN)
return
end
if locations == nil or vim.tbl_isempty(locations) then
vim.notify('References not found', vim.log.levels.INFO)
return
@ -76,8 +100,11 @@ local ref_view = function(err, locations, ctx, cfg)
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)
local thread_items = {}
if vim.fn.empty(second_part) == 0 then
thread_items = vim.deepcopy(items)
end
log('splits: ', #locations, #items, #second_part)
local ft = vim.api.nvim_buf_get_option(ctx.bufnr or 0, 'ft')
@ -114,12 +141,12 @@ local ref_view = function(err, locations, ctx, cfg)
-- trace("update items", listview.ctrl.class)
local nv_ref_async
nv_ref_async = vim.loop.new_async(vim.schedule_wrap(function()
log('$$$$$$$$ seperate thread... $$$$$$$$')
nv_ref_async = uv.new_async(vim.schedule_wrap(function()
if vim.tbl_isempty(second_part) then
return
end
ctx.max_items = #second_part
log('$$$$$$$$ --- seperate thread... --- $$$$$$$$')
ctx.max_items = #second_part -- proccess all the rest
local items2 = locations_to_items(second_part, ctx)
vim.list_extend(thread_items, items2)
@ -128,17 +155,17 @@ local ref_view = function(err, locations, ctx, cfg)
log('thread data size', #data)
listview.ctrl:on_data_update(data)
if nv_ref_async then
vim.loop.close(nv_ref_async)
uv.close(nv_ref_async)
else
log('invalid asy', nv_ref_async)
log('invalid ref_async')
end
end))
vim.defer_fn(function()
vim.loop.new_thread(function(asy)
uv.new_thread(function(asy)
asy:send()
end, nv_ref_async)
end, 100)
end, 10)
return listview, items, width
end
@ -149,7 +176,7 @@ local ref_hdlr = function(err, locations, ctx, cfg)
if ctx.no_show then
return ref_view(err, locations, ctx, cfg)
end
M.async_hdlr = vim.loop.new_async(vim.schedule_wrap(function()
M.async_hdlr = uv.new_async(vim.schedule_wrap(function()
ref_view(err, locations, ctx, cfg)
if M.async_hdlr:is_active() then
M.async_hdlr:close()
@ -173,7 +200,7 @@ local async_ref = function()
end
end
results.definitions = { error = err, result = result, ctx = ctx, config = config }
log(result)
log('number of result', #result)
ctx = ctx or {}
ctx.results = results
ctx.combine = true
@ -199,7 +226,7 @@ end
-- a function from smjonas/inc-rename.nvim
-- https://github.com/smjonas/inc-rename.nvim/blob/main/lua/inc_rename/init.lua
local function fetch_lsp_references(bufnr, params, callback)
local clients = vim.lsp.get_active_clients({
local clients = vim.lsp.get_clients({
bufnr = bufnr,
})
clients = vim.tbl_filter(function(client)
@ -224,7 +251,7 @@ local function fetch_lsp_references(bufnr, params, callback)
'textDocument/references',
params,
function(err, result, ctx, cfg)
log(result)
trace(result)
if err then
log('[nav-rename] Error while finding references: ' .. err.message)
return
@ -245,6 +272,19 @@ local ref_req = function()
-- do not call it twice
_NgConfigValues.closer()
end
local warmup_ts
if _NgConfigValues.treesitter_analysis then
warmup_ts = uv.new_async(function()
warmup_treesitter(cfg)
if warmup_ts:is_active() then
warmup_ts:close()
end
end)
vim.defer_fn(function()
warmup_ts:send()
end, 5)
end
-- lsp.call_async("textDocument/references", ref_params, ref_hdlr) -- return asyncresult, canceller
local bufnr = vim.api.nvim_get_current_buf()
local ref_params = vim.lsp.util.make_position_params()

@ -150,7 +150,7 @@ function M.prepare_for_render(items, opts)
-- log(item.text, item.symbol_name, item.uri)
-- log(item.text)
if item.definition then
log('definition', item)
log('definition', item.call_by, item.symbol_name, item.text)
if opts.side_panel then
ts_report = _NgConfigValues.icons.value_definition
else

@ -22,12 +22,11 @@ end
local api = vim.api
local util = require('navigator.util')
local M = {}
local cwd = vim.loop.cwd()
local log = require('navigator.util').log
local lerr = require('navigator.util').error
local trace = function(...) end
trace = log
local uv = vim.uv or vim.loop
local cwd = uv.cwd()
local log = util.log
local lerr = util.error
local trace = util.trace
local get_icon = function(kind)
if kind == nil or _NgConfigValues.icons.match_kinds[kind] == nil then
@ -79,7 +78,7 @@ end
-- use lsp range to find def
function M.find_definition(range, bufnr)
if not range or not range.start then
lerr('find_def incorrect range', range)
lerr('find_def incorrect range'..vim.inspect(range))
return
end
bufnr = bufnr or api.nvim_get_current_buf()
@ -92,8 +91,7 @@ function M.find_definition(range, bufnr)
local node_at_point =
root:named_descendant_for_range(symbolpos[1], symbolpos[2], symbolpos[1], symbolpos[2])
if not node_at_point then
lerr('no node at cursor')
return
return log('Err: no node at cursor', range)
end
local definition = locals.find_definition(node_at_point, bufnr)
@ -123,9 +121,9 @@ function M.get_tsnode_at_pos(pos, bufnr, ignore_injected_langs)
end
local cursor_range = { pos.start.line, pos.start.character }
local buf = bufnr
local root_lang_tree = parsers.get_parser(buf)
local root_lang_tree = parsers.get_parser(bufnr)
if not root_lang_tree then
log('Err: ts not loaded ' .. vim.o.ft, bufnr)
return
end
@ -169,12 +167,14 @@ local transform_line = function(line)
end
function M.ref_context(opts)
if not parsers.has_parser() then
local options = opts or {}
local bufnr = options.bufnr or api.nvim_get_current_buf()
local parser = parsers.get_parser(bufnr)
if not parser then
log('err: ts not loaded ' .. vim.o.ft)
return
end
local options = opts or {}
local bufnr = options.bufnr or 0
local pos = options.pos
if not pos then
pos = { start = vim.lsp.util.make_position_params().position }
@ -195,7 +195,7 @@ function M.ref_context(opts)
while expr do
local line = ts_utils._get_line_for_node(expr, type_patterns, transform_fn, bufnr)
log(line)
trace('line', line)
if line ~= '' and not vim.tbl_contains(lines, line) then
table.insert(lines, 1, line)
end
@ -204,11 +204,15 @@ function M.ref_context(opts)
break
end
end
if #lines == 0 then
log('no lines found')
return ''
end
local text = table.concat(lines, separator)
local text_len = #text
if text_len > indicator_size then
local str = text:sub(1, text_len)
local str = text:sub(1, text_len) -- copy string
return util.sub_match(str)
end
@ -306,7 +310,7 @@ local function get_definitions(bufnr)
and node:parent():type() == 'qualified_type'
and string.find(node:parent():parent():type(), 'interface')
then
log('add node', node)
trace('add node', node)
nodes_set[start] = { node = node, type = match or 'field' }
end
end
@ -450,7 +454,7 @@ function M.goto_adjacent_usage(bufnr, delta)
local def_node, scope = ts_locals.find_definition(node_at_point, bufnr)
local usages = ts_locals.find_usages(def_node, scope, bufnr)
log(usages)
trace(usages)
local index = index_of(usages, node_at_point)
if not index then

@ -8,9 +8,11 @@ local guihua = require('guihua.util')
local nvim_0_8
local vfn = vim.fn
local api = vim.api
local uv = vim.uv or vim.loop
local os_name = uv.os_uname().sysname
local is_win = os_name:find('Windows') or os_name:find('MINGW')
M.path_sep = function()
local is_win = vim.loop.os_uname().sysname:find('Windows')
if is_win then
return '\\'
else
@ -21,7 +23,6 @@ end
local path_sep = M.path_sep()
M.path_cur = function()
local is_win = vim.loop.os_uname().sysname:find('Windows')
if is_win then
return '.\\'
else
@ -139,23 +140,29 @@ local function getDir(path)
end
function M.get_relative_path(base_path, my_path)
M.log('rel path', base_path, my_path)
M.trace('rel path', base_path, my_path)
base_path = string.lower(base_path)
my_path = string.lower(my_path)
local base_data = getDir(base_path)
if base_data == nil then
M.log('base data is nil')
return
end
local my_data = getDir(my_path)
if my_data == nil then
if vim.fn.empty(my_data) == 1 then
M.log('my data is nil', my_path)
return
end
local base_len = #base_data
local my_len = #my_data
if base_len > my_len then
M.log('incorrect dir format: base data', base_data, 'my data', my_data)
return my_path
end
if base_data[1] ~= my_data[1] then
M.log('base data is not same', base_data[1], my_data[1])
return my_path
end
@ -277,9 +284,10 @@ function M.open_log()
local path = vim.lsp.get_log_path()
vim.cmd('edit ' .. path)
end
function table.pack(...)
return { n = select('#', ...), ... }
if not table.pack then
table.pack = function(...)
return { n = select('#', ...), ... }
end
end
function M.show(...)
local string = ''
@ -481,10 +489,7 @@ function M.info(msg)
end
function M.dedup(locations)
local m = 10
if m > #locations then
m = #locations
end
local m = math.min(10, #locations) -- dedup first 10 elements
local dict = {}
local del = {}
for i = 1, m, 1 do
@ -553,7 +558,7 @@ function M.sub_match(str)
if j % 2 == 1 then
str = str .. [[']]
end
str = str .. ''
str = str .. '󰇘'
return str
end

Loading…
Cancel
Save