diff options
| author | Stephan Seitz <stephan.seitz@fau.de> | 2020-08-29 11:37:26 +0200 |
|---|---|---|
| committer | Thomas Vigouroux <39092278+vigoux@users.noreply.github.com> | 2020-08-31 22:16:27 +0200 |
| commit | bc365219671a132458a6f1259cd58799bd54d3f7 (patch) | |
| tree | d15540d21b929c59309a71c3f1db924fece85a94 /lua | |
| parent | Fix(modules): simplify configs.setup (diff) | |
| download | nvim-treesitter-bc365219671a132458a6f1259cd58799bd54d3f7.tar nvim-treesitter-bc365219671a132458a6f1259cd58799bd54d3f7.tar.gz nvim-treesitter-bc365219671a132458a6f1259cd58799bd54d3f7.tar.bz2 nvim-treesitter-bc365219671a132458a6f1259cd58799bd54d3f7.tar.lz nvim-treesitter-bc365219671a132458a6f1259cd58799bd54d3f7.tar.xz nvim-treesitter-bc365219671a132458a6f1259cd58799bd54d3f7.tar.zst nvim-treesitter-bc365219671a132458a6f1259cd58799bd54d3f7.zip | |
feat(refactor.navigation): allow a `fallback_function` for goto_definition
`fallback_function` is called when nvim-treesitter can not resolve the
variable under the cursor.
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/refactor/navigation.lua | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lua/nvim-treesitter/refactor/navigation.lua b/lua/nvim-treesitter/refactor/navigation.lua index 98ef37802..112a1e412 100644 --- a/lua/nvim-treesitter/refactor/navigation.lua +++ b/lua/nvim-treesitter/refactor/navigation.lua @@ -8,16 +8,23 @@ local api = vim.api local M = {} -function M.goto_definition(bufnr) +function M.goto_definition(bufnr, fallback_function) local bufnr = bufnr or api.nvim_get_current_buf() local node_at_point = ts_utils.get_node_at_cursor() if not node_at_point then return end - local definition, _ = locals.find_definition(node_at_point, bufnr) - ts_utils.goto_node(definition) + local definition = locals.find_definition(node_at_point, bufnr) + + if fallback_function and definition.id == node_at_point.id then + fallback_function() + else + ts_utils.goto_node(definition) + end end +function M.goto_definition_lsp_fallback(bufnr) M.goto_definition(bufnr, vim.lsp.buf.definition) end + function M.list_definitions(bufnr) local bufnr = bufnr or api.nvim_get_current_buf() local definitions = locals.get_definitions(bufnr) @@ -57,7 +64,6 @@ function M.goto_adjacent_usage(bufnr, delta) local target_index = (index + delta + #usages - 1) % #usages + 1 ts_utils.goto_node(usages[target_index]) - return usages[target_index] end function M.goto_next_usage(bufnr) return M.goto_adjacent_usage(bufnr, 1) end |
