Skip to content

Commit

Permalink
tests: optionally enable treesitter-parsers for json,jsonc,lua.
Browse files Browse the repository at this point in the history
(enabling lua is most likely a nop, since it is already available by
default in newer neovim-versions)
  • Loading branch information
L3MON4D3 committed May 1, 2023
1 parent 40da0ef commit 75087f4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"
Expand All @@ -49,7 +74,9 @@ function M.session_setup_luasnip(opts)
ls.setup(vim.tbl_extend("force", {
store_selection_keys = "<Tab>"
}, ...))
]], setup_extend)
]],
setup_extend
)

if not no_snip_globals then
helpers.exec_lua([[
Expand Down
Binary file added tests/parsers/json.so
Binary file not shown.
Binary file added tests/parsers/jsonc.so
Binary file not shown.
Binary file added tests/parsers/lua.so
Binary file not shown.

0 comments on commit 75087f4

Please sign in to comment.