fixup(ts): put ts_query_cursor_set_match_limit behind feature guard

This is a fixup for #14915, which used the above-mentioned call to
restore the behavior of the pre-release version of tree-sitter to
that of 0.19.5. However, this function was introduced after 0.19.5,
breaking distro builds that link against 0.19.5 instead of the tag
specified in neovim's build script.

Now the function should only be called when it is available _and_
needed. Once tree-sitter is bumped to 0.19.6 (when this is released),
this guard can be removed again.

Fixes #14923 (among others)
This commit is contained in:
Christian Clason 2021-06-29 15:59:57 +02:00
parent f83c25942d
commit 7e8a8482e8
2 changed files with 20 additions and 0 deletions

View File

@ -393,6 +393,22 @@ include_directories(SYSTEM ${LIBLUV_INCLUDE_DIRS})
find_package(TreeSitter REQUIRED)
include_directories(SYSTEM ${TreeSitter_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_INCLUDES "${TreeSitter_INCLUDE_DIRS}")
list(APPEND CMAKE_REQUIRED_LIBRARIES "${TreeSitter_LIBRARIES}")
check_c_source_compiles("
#include <tree_sitter/api.h>
int
main(void)
{
TSQueryCursor *cursor = ts_query_cursor_new();
ts_query_cursor_set_match_limit(cursor, 32);
return 0;
}
" TS_HAS_SET_MATCH_LIMIT)
if(TS_HAS_SET_MATCH_LIMIT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNVIM_TS_HAS_SET_MATCH_LIMIT")
endif()
# Note: The test lib requires LuaJIT; it will be skipped if LuaJIT is missing.
option(PREFER_LUA "Prefer Lua over LuaJIT in the nvim executable." OFF)

View File

@ -1073,7 +1073,11 @@ static int node_rawquery(lua_State *L)
// TODO(bfredl): these are expensive allegedly,
// use a reuse list later on?
TSQueryCursor *cursor = ts_query_cursor_new();
// TODO(clason): API introduced after tree-sitter release 0.19.5
// remove guard when minimum ts version is bumped to 0.19.6+
#ifdef NVIM_TS_HAS_SET_MATCH_LIMIT
ts_query_cursor_set_match_limit(cursor, 32);
#endif
ts_query_cursor_exec(cursor, query, node);
bool captures = lua_toboolean(L, 3);