diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter.lua | 10 | ||||
| -rw-r--r-- | lua/nvim-treesitter/configs.lua | 13 | ||||
| -rw-r--r-- | lua/nvim-treesitter/node_movement.lua | 72 | ||||
| -rw-r--r-- | lua/nvim-treesitter/state.lua | 8 |
4 files changed, 18 insertions, 85 deletions
diff --git a/lua/nvim-treesitter.lua b/lua/nvim-treesitter.lua index 5c0dfac75..100324e36 100644 --- a/lua/nvim-treesitter.lua +++ b/lua/nvim-treesitter.lua @@ -5,6 +5,7 @@ local utils = require'nvim-treesitter.utils' local info = require'nvim-treesitter.info' local configs = require'nvim-treesitter.configs' local state = require'nvim-treesitter.state' +local ts_utils = require'nvim-treesitter.ts_utils' local M = {} @@ -55,4 +56,13 @@ function M.statusline(indicator_size) end end +function M.get_buf_state() + local bufnr = api.nvim_get_current_buf() + return state.exposed_state(bufnr) +end + +function M.get_node_api() + return ts_utils +end + return M diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index 31f01a72a..f79fed00c 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -228,19 +228,6 @@ local config = { is_supported = function(ft) return queries.get_query(ft, 'locals') end - }, - node_movement = { - enable = false, - disable = {}, - is_supported = function(ft) - return queries.get_query(ft, 'locals') - end, - keymaps = { - parent_scope = "<a-k>", - child_scope = "<a-j>", - next_scope = "<a-l>", - previous_scope = "<a-h>", - }, } }, ensure_installed = nil diff --git a/lua/nvim-treesitter/node_movement.lua b/lua/nvim-treesitter/node_movement.lua deleted file mode 100644 index f6f15fced..000000000 --- a/lua/nvim-treesitter/node_movement.lua +++ /dev/null @@ -1,72 +0,0 @@ -local api = vim.api - -local configs = require'nvim-treesitter.configs' -local state = require'nvim-treesitter.state' -local ts_utils = require'nvim-treesitter.ts_utils' - -local M = {} - -local NodeMovementKind = { - parent_scope = 'parent', - child_scope = 'child', - next_scope = 'next', - previous_scope = 'previous', -} - -local get_node_fn = { - [NodeMovementKind.parent_scope] = function(node, curpos) - return ts_utils.parent_scope(node, curpos) - end, - [NodeMovementKind.child_scope] = function(node, curpos) - return ts_utils.nested_scope(node, curpos) - end, - [NodeMovementKind.next_scope] = function(node) - return ts_utils.next_scope(node) - end, - [NodeMovementKind.previous_scope] = function(node) - return ts_utils.previous_scope(node) - end, -} - -M.do_node_movement = function(kind) - local buf = api.nvim_get_current_buf() - - local buf_state = state.get_buf_state(buf) - if not buf_state then return end - - local current_node = buf_state.current_node - if not current_node then return end - - local destination_node = get_node_fn[kind](current_node, buf_state.cursor_pos) - - if destination_node then - local row, col = destination_node:start() - vim.fn.setpos(".", { buf, row+1, col+1, 0 }) - end -end - -function M.parent_scope() M.do_node_movement(NodeMovementKind.parent_scope) end -function M.child_scope() M.do_node_movement(NodeMovementKind.child_scope) end -function M.next_scope() M.do_node_movement(NodeMovementKind.next_scope) end -function M.previous_scope() M.do_node_movement(NodeMovementKind.previous_scope) end - -function M.attach(bufnr) - local bufnr = bufnr or api.nvim_get_current_buf() - - local config = configs.get_module('node_movement') - for funcname, mapping in pairs(config.keymaps) do - local cmd = string.format(":lua require'nvim-treesitter.node_movement'.%s()<CR>", funcname) - api.nvim_buf_set_keymap(bufnr, 'n', mapping, cmd, { silent = true }) - end -end - -function M.detach(bufnr) - local buf = bufnr or api.nvim_get_current_buf() - - local config = configs.get_module('node_movement') - for _, mapping in pairs(config.keymaps) do - api.nvim_buf_del_keymap(buf, 'n', mapping) - end -end - -return M diff --git a/lua/nvim-treesitter/state.lua b/lua/nvim-treesitter/state.lua index 9da07ae10..d682bd28f 100644 --- a/lua/nvim-treesitter/state.lua +++ b/lua/nvim-treesitter/state.lua @@ -111,4 +111,12 @@ function M.get_buf_state(bufnr) return buffers[bufnr] end +function M.exposed_state(bufnr) + local buf_state = buffers[bufnr] + return { + cursor_pos = buf_state.cursor_pos, + current_node = buf_state.current_node + } +end + return M |
