diff --git a/tests/helpers.lua b/tests/helpers.lua index a5aeb483e..1970e8dc8 100644 --- a/tests/helpers.lua +++ b/tests/helpers.lua @@ -31,6 +31,12 @@ function M.session_setup_luasnip(opts) or false local setup_extend = opts.setup_extend ~= nil and opts.setup_extend or {} + local setup_parsers + if opts.setup_parsers ~= nil then + setup_parsers = opts.setup_parsers + else + setup_parsers = false + end -- stylua: ignore helpers.exec("set rtp+=" .. os.getenv("LUASNIP_SOURCE")) @@ -41,6 +47,25 @@ function M.session_setup_luasnip(opts) ("luafile %s/plugin/luasnip.lua"):format(os.getenv("LUASNIP_SOURCE")) ) + if setup_parsers then + -- adding the lua-parser, is either a nop or adds the parser on + -- versions where it does not exist by default. + exec_lua[[ + ts_lang_add = + (vim.treesitter.language and vim.treesitter.language.add) + and function(lang, path) + vim.treesitter.language.add(lang, {path = path}) + end + or vim.treesitter.require_language + + -- this is a nop on new versions of neovim, where the lua-parser is shipped by default. + ts_lang_add("lua", os.getenv("LUASNIP_SOURCE") .. "/tests/parsers/lua.so") + + ts_lang_add("json", os.getenv("LUASNIP_SOURCE") .. "/tests/parsers/json.so") + ts_lang_add("jsonc", os.getenv("LUASNIP_SOURCE") .. "/tests/parsers/jsonc.so") + ]] + end + helpers.exec_lua([[ -- MYVIMRC might not be set when nvim is loaded like this. vim.env.MYVIMRC = "/.vimrc" @@ -49,7 +74,9 @@ function M.session_setup_luasnip(opts) ls.setup(vim.tbl_extend("force", { store_selection_keys = "" }, ...)) - ]], setup_extend) + ]], + setup_extend + ) if not no_snip_globals then helpers.exec_lua([[ diff --git a/tests/parsers/json.so b/tests/parsers/json.so new file mode 100755 index 000000000..16b4d2a8b Binary files /dev/null and b/tests/parsers/json.so differ diff --git a/tests/parsers/jsonc.so b/tests/parsers/jsonc.so new file mode 100755 index 000000000..c871b1477 Binary files /dev/null and b/tests/parsers/jsonc.so differ diff --git a/tests/parsers/lua.so b/tests/parsers/lua.so new file mode 100755 index 000000000..0b96bc715 Binary files /dev/null and b/tests/parsers/lua.so differ