diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-04-04 12:58:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-04 13:58:16 +0200 |
commit | 090ade4af6344a7bc4ee56a8052c0739c0428c04 (patch) | |
tree | 03da56a9e250e1928541f5997c35907f147899f4 /src | |
parent | 469e6bfc56aa18350bfab13bef8a51b02a5b3c65 (diff) | |
download | rneovim-090ade4af6344a7bc4ee56a8052c0739c0428c04.tar.gz rneovim-090ade4af6344a7bc4ee56a8052c0739c0428c04.tar.bz2 rneovim-090ade4af6344a7bc4ee56a8052c0739c0428c04.zip |
refactor(treesitter): delegate region calculation to treesitter (#22576)
Diffstat (limited to 'src')
-rwxr-xr-x | src/nvim/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/nvim/lua/treesitter.c | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index cb688785df..c0466e3de9 100755 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -21,7 +21,7 @@ find_package(Iconv REQUIRED) find_package(Libtermkey 0.22 REQUIRED) find_package(Libvterm 0.3 REQUIRED) find_package(Msgpack 1.0.0 REQUIRED) -find_package(Treesitter REQUIRED) +find_package(Treesitter 0.20.8 REQUIRED) find_package(Unibilium 2.0 REQUIRED) target_link_libraries(main_lib INTERFACE diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 289a0cb9b4..ae3a7b6d75 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -64,6 +64,7 @@ static struct luaL_Reg tree_meta[] = { { "__tostring", tree_tostring }, { "root", tree_root }, { "edit", tree_edit }, + { "included_ranges", tree_get_ranges }, { "copy", tree_copy }, { NULL, NULL } }; @@ -512,6 +513,24 @@ static int tree_edit(lua_State *L) return 0; } +static int tree_get_ranges(lua_State *L) +{ + TSTree **tree = tree_check(L, 1); + if (!(*tree)) { + return 0; + } + + bool include_bytes = (lua_gettop(L) >= 2) && lua_toboolean(L, 2); + + uint32_t len; + TSRange *ranges = ts_tree_included_ranges(*tree, &len); + + push_ranges(L, ranges, len, include_bytes); + + xfree(ranges); + return 1; +} + // Use the top of the stack (without popping it) to create a TSRange, it can be // either a lua table or a TSNode static void range_from_lua(lua_State *L, TSRange *range) |