diff --git a/README.md b/README.md index fdb85fa..a25dd0b 100644 --- a/README.md +++ b/README.md @@ -258,6 +258,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_navigation = true, -- bool|table false: use lsp to navigate between symbol ']r/[r', table: a list of + --lang using TS navigation treesitter_analysis_max_num = 100, -- how many items to run treesitter analysis treesitter_analysis_condense = true, -- condense form for treesitter analysis -- this value prevent slow in large projects, e.g. found 100000 reference in a project diff --git a/lua/navigator.lua b/lua/navigator.lua index a43b0c7..4de99e1 100755 --- a/lua/navigator.lua +++ b/lua/navigator.lua @@ -31,6 +31,7 @@ _NgConfigValues = { end, ts_fold = false, 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_condense = true, -- short format of function treesitter_analysis_depth = 3, -- max depth diff --git a/lua/navigator/treesitter.lua b/lua/navigator/treesitter.lua index ea59634..39eedaf 100644 --- a/lua/navigator/treesitter.lua +++ b/lua/navigator/treesitter.lua @@ -394,11 +394,16 @@ end local lsp_reference = require('navigator.dochighlight').goto_adjent_reference function M.goto_adjacent_usage(bufnr, delta) - local opt = { forward = true } + local opt = { forward = delta > 0 } -- log(delta) - if delta < 0 then - opt.forward = false + + local en = _NgConfigValues.treesitter_navigation + + if type(en) == 'table' then + en = vim.tbl_contains(en, vim.o.ft) end + if en == false then return lsp_reference(opt) end + bufnr = bufnr or api.nvim_get_current_buf() local node_at_point = ts_utils.get_node_at_cursor() if not node_at_point then @@ -408,6 +413,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) local index = utils.index_of(usages, node_at_point) if not index then