aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Vigouroux <thomas.vigouroux@protonmail.com>2022-08-24 16:22:50 +0200
committerThomas Vigouroux <thomas.vigouroux@protonmail.com>2022-08-24 16:59:13 +0200
commit26ebf67c39d3776095706fafe34eea2e37013579 (patch)
tree79d329f87997dd56a076037405c844133fb0d1bf
parentb1eaa2b9a3bae46f6dcbab8dc3a84e0044b11317 (diff)
downloadrneovim-26ebf67c39d3776095706fafe34eea2e37013579.tar.gz
rneovim-26ebf67c39d3776095706fafe34eea2e37013579.tar.bz2
rneovim-26ebf67c39d3776095706fafe34eea2e37013579.zip
test(treesitter): make internal lang test pending when necessary
-rw-r--r--src/nvim/lua/executor.c3
-rw-r--r--src/nvim/lua/treesitter.c12
-rw-r--r--test/functional/helpers.lua1
-rw-r--r--test/functional/treesitter/language_spec.lua6
4 files changed, 20 insertions, 2 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 8cd0e9937b..38bc187f4f 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -1662,6 +1662,9 @@ static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
lua_pushcfunction(lstate, tslua_has_language);
lua_setfield(lstate, -2, "_ts_has_language");
+ lua_pushcfunction(lstate, tslua_remove_lang);
+ lua_setfield(lstate, -2, "_ts_remove_language");
+
lua_pushcfunction(lstate, tslua_inspect_lang);
lua_setfield(lstate, -2, "_ts_inspect_language");
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c
index 90b13181fb..8b47939169 100644
--- a/src/nvim/lua/treesitter.c
+++ b/src/nvim/lua/treesitter.c
@@ -21,6 +21,7 @@
#include "nvim/lib/kvec.h"
#include "nvim/log.h"
#include "nvim/lua/treesitter.h"
+#include "nvim/map.h"
#include "nvim/memline.h"
#include "tree_sitter/api.h"
@@ -210,6 +211,17 @@ int tslua_add_language(lua_State *L)
return 1;
}
+int tslua_remove_lang(lua_State *L)
+{
+ const char *lang_name = luaL_checkstring(L, 1);
+ bool present = pmap_has(cstr_t)(&langs, lang_name);
+ if (present) {
+ pmap_del(cstr_t)(&langs, lang_name);
+ }
+ lua_pushboolean(L, present);
+ return 1;
+}
+
int tslua_inspect_lang(lua_State *L)
{
const char *lang_name = luaL_checkstring(L, 1);
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 981cfc306e..93fb0f245e 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -761,6 +761,7 @@ function module.pending_c_parser(pending_fn)
pending_fn 'no C parser, skipping'
return true
end
+ module.exec_lua [[vim._ts_remove_language 'c']]
return false
end
diff --git a/test/functional/treesitter/language_spec.lua b/test/functional/treesitter/language_spec.lua
index 5eb72471c3..8aa8524a26 100644
--- a/test/functional/treesitter/language_spec.lua
+++ b/test/functional/treesitter/language_spec.lua
@@ -27,8 +27,10 @@ describe('treesitter language API', function()
eq("Error executing lua: .../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers",
pcall_err(exec_lua, "parser = vim.treesitter.inspect_language('borklang')"))
- matches("Error executing lua: Failed to load parser: uv_dlsym: .+",
- pcall_err(exec_lua, "parser = vim.treesitter.require_language('c', nil, false, 'borklang')"))
+ if not pending_c_parser(pending) then
+ matches("Error executing lua: Failed to load parser: uv_dlsym: .+",
+ pcall_err(exec_lua, 'vim.treesitter.require_language("c", nil, false, "borklang")'))
+ end
end)
it('inspects language', function()