aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/lua')
-rw-r--r--src/nvim/lua/converter.c6
-rw-r--r--src/nvim/lua/converter.h2
-rw-r--r--src/nvim/lua/executor.h16
-rw-r--r--src/nvim/lua/treesitter.c10
-rw-r--r--src/nvim/lua/treesitter.h2
-rw-r--r--src/nvim/lua/vim.lua1
-rw-r--r--src/nvim/lua/xdiff.h2
7 files changed, 27 insertions, 12 deletions
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c
index fd4cfc4c31..ca3c4f604a 100644
--- a/src/nvim/lua/converter.c
+++ b/src/nvim/lua/converter.c
@@ -1303,6 +1303,12 @@ void nlua_init_types(lua_State *const lstate)
void nlua_pop_keydict(lua_State *L, void *retval, field_hash hashy, Error *err)
{
+ if (!lua_istable(L, -1)) {
+ api_set_error(err, kErrorTypeValidation, "Expected lua table");
+ lua_pop(L, -1);
+ return;
+ }
+
lua_pushnil(L); // [dict, nil]
while (lua_next(L, -2)) {
// [dict, key, value]
diff --git a/src/nvim/lua/converter.h b/src/nvim/lua/converter.h
index 43a7e06019..1c9e60e4b2 100644
--- a/src/nvim/lua/converter.h
+++ b/src/nvim/lua/converter.h
@@ -6,8 +6,8 @@
#include <stdint.h>
#include "nvim/api/private/defs.h"
-#include "nvim/func_attr.h"
#include "nvim/eval.h"
+#include "nvim/func_attr.h"
typedef struct {
LuaRef func_ref;
diff --git a/src/nvim/lua/executor.h b/src/nvim/lua/executor.h
index ea774ac2e3..a1f66bd02b 100644
--- a/src/nvim/lua/executor.h
+++ b/src/nvim/lua/executor.h
@@ -1,13 +1,13 @@
#ifndef NVIM_LUA_EXECUTOR_H
#define NVIM_LUA_EXECUTOR_H
-#include <lua.h>
#include <lauxlib.h>
+#include <lua.h>
#include "nvim/api/private/defs.h"
-#include "nvim/func_attr.h"
#include "nvim/eval/typval.h"
#include "nvim/ex_cmds_defs.h"
+#include "nvim/func_attr.h"
#include "nvim/lua/converter.h"
// Generated by msgpack-gen.lua
@@ -19,12 +19,12 @@ EXTERN LuaRef nlua_empty_dict_ref INIT(= LUA_NOREF);
EXTERN int nlua_refcount INIT(= 0);
#define set_api_error(s, err) \
- do { \
- Error *err_ = (err); \
- err_->type = kErrorTypeException; \
- err_->set = true; \
- memcpy(&err_->msg[0], s, sizeof(s)); \
- } while (0)
+ do { \
+ Error *err_ = (err); \
+ err_->type = kErrorTypeException; \
+ err_->set = true; \
+ memcpy(&err_->msg[0], s, sizeof(s)); \
+ } while (0)
#define NLUA_CLEAR_REF(x) \
do { \
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c
index 37929093e3..bd978cc8ab 100644
--- a/src/nvim/lua/treesitter.c
+++ b/src/nvim/lua/treesitter.c
@@ -30,6 +30,7 @@
typedef struct {
TSQueryCursor *cursor;
int predicated_match;
+ int max_match_id;
} TSLua_cursor;
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -1055,6 +1056,8 @@ static int query_next_match(lua_State *L)
static int query_next_capture(lua_State *L)
{
+ // Upvalues are:
+ // [ cursor, node, query, current_match ]
TSLua_cursor *ud = lua_touserdata(L, lua_upvalueindex(1));
TSQueryCursor *cursor = ud->cursor;
@@ -1078,9 +1081,13 @@ static int query_next_capture(lua_State *L)
lua_pushinteger(L, capture.index+1); // [index]
push_node(L, capture.node, lua_upvalueindex(2)); // [index, node]
+ // Now check if we need to run the predicates
uint32_t n_pred;
ts_query_predicates_for_pattern(query, match.pattern_index, &n_pred);
- if (n_pred > 0 && capture_index == 0) {
+
+ if (n_pred > 0 && (ud->max_match_id < (int)match.id)) {
+ ud->max_match_id = match.id;
+
lua_pushvalue(L, lua_upvalueindex(4)); // [index, node, match]
set_match(L, &match, lua_upvalueindex(2));
lua_pushinteger(L, match.pattern_index+1);
@@ -1127,6 +1134,7 @@ static int node_rawquery(lua_State *L)
TSLua_cursor *ud = lua_newuserdata(L, sizeof(*ud)); // [udata]
ud->cursor = cursor;
ud->predicated_match = -1;
+ ud->max_match_id = -1;
lua_getfield(L, LUA_REGISTRYINDEX, TS_META_QUERYCURSOR);
lua_setmetatable(L, -2); // [udata]
diff --git a/src/nvim/lua/treesitter.h b/src/nvim/lua/treesitter.h
index 812166f67b..b69fb9dfae 100644
--- a/src/nvim/lua/treesitter.h
+++ b/src/nvim/lua/treesitter.h
@@ -1,9 +1,9 @@
#ifndef NVIM_LUA_TREESITTER_H
#define NVIM_LUA_TREESITTER_H
+#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
-#include <lauxlib.h>
#include "tree_sitter/api.h"
diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua
index 7a209f2d79..5ca4cc82a5 100644
--- a/src/nvim/lua/vim.lua
+++ b/src/nvim/lua/vim.lua
@@ -433,6 +433,7 @@ function vim.notify(msg, log_level, _opts)
end
+---@private
function vim.register_keystroke_callback()
error('vim.register_keystroke_callback is deprecated, instead use: vim.on_key')
end
diff --git a/src/nvim/lua/xdiff.h b/src/nvim/lua/xdiff.h
index cae7c98e81..b172d2f922 100644
--- a/src/nvim/lua/xdiff.h
+++ b/src/nvim/lua/xdiff.h
@@ -1,9 +1,9 @@
#ifndef NVIM_LUA_XDIFF_H
#define NVIM_LUA_XDIFF_H
+#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
-#include <lauxlib.h>
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "lua/xdiff.h.generated.h"