Compare commits

...

5 Commits

Author SHA1 Message Date
41dcce182a
fix: force a full reparse of ts source
PERF: This will impact performance, something to keep an eye on.

Prior to this commit, some parsers like php were failing in tests. By
forcing a full reparse, the php parser among others get the correct
tree.
2024-05-13 14:32:06 -05:00
81d0c78475
test: improve treesitter setup 2024-05-13 14:22:41 -05:00
94758d5394
refactor: move .luarc.json to toplevel 2024-05-13 13:40:00 -05:00
25db9a0912
test: actually call nvim-treesitter.configs setup 2024-05-13 13:40:00 -05:00
7c2e60f9e8
test: use sync install for ts parsers 2024-05-13 13:40:00 -05:00
7 changed files with 50 additions and 59 deletions

View File

@ -3,4 +3,4 @@
"it",
"describe"
]
}
}

View File

@ -256,13 +256,6 @@ local function find_tag_node(opt)
local name_tag_pattern = opt.name_tag_pattern
local skip_tag_pattern = opt.skip_tag_pattern
local find_child = opt.find_child or false
--- PERF: Some parsers don't seemingly pick up their trees correctly, so we have to reparse the
--- entire source. This is slow, see if we can avoid this.
if target and target:has_changes() then
local parser = vim.treesitter.get_parser()
_ = (parser and parser:parse(true) or nil)
target = ts_utils.get_node_at_cursor()
end
local node
if find_child then
node = find_child_match({
@ -381,7 +374,7 @@ M.close_tag = function()
if not buf_parser then
return
end
buf_parser:parse()
buf_parser:parse(true)
local result, tag_name = check_close_tag()
if result == true and tag_name ~= nil then
vim.api.nvim_put({ string.format("</%s>", tag_name) }, "", true, false)
@ -394,7 +387,7 @@ M.close_slash_tag = function()
if not buf_parser then
return
end
buf_parser:parse()
buf_parser:parse(true)
local result, tag_name = check_close_tag(true)
if result == true and tag_name ~= nil then
vim.api.nvim_put({ string.format("%s>", tag_name) }, "", true, true)

View File

@ -44,6 +44,41 @@ function M.load_plugin(plugin_name, plugin_clone_args)
print(("[LOAD PLUGIN] Loaded plugin '%s'"):format(plugin_name))
end
function M.setup_treesitter()
print("[TREESITTER] Setting up nvim-treesitter")
local parser_cfgs = require("nvim-treesitter.parsers").get_parser_configs()
for parser_name, parser_cfg in pairs({
rescript = {
install_info = {
url = "https://github.com/rescript-lang/tree-sitter-rescript",
branch = "main",
files = { "src/parser.c" },
generate_requires_npm = false,
requires_generate_from_grammar = true,
use_makefile = true,
},
},
}) do
parser_cfgs[parser_name] = parser_cfg
end
require("nvim-treesitter.configs").setup({
sync_install = true,
ensure_installed = {
"html",
"javascript",
"typescript",
"svelte",
"vue",
"tsx",
"php",
"glimmer",
"rescript",
"embedded_template",
},
})
print("[TREESITTER] Done setting up nvim-treesitter")
end
---Do the initial setup. Downloads plugins, ensures the minimal init does not pollute the filesystem by keeping
---everything self contained to the CWD of the minimal init file. Run prior to running tests, reproducing issues, etc.
---@param plugins? MinPlugins
@ -59,28 +94,21 @@ function M.setup(plugins)
"config",
"state",
}
local clean = (vim.env.TEST_CLEANUP and vim.env.TEST_CLEANUP:lower() or true)
if clean then
vim.fn.delete(xdg_root:get(), "rf")
elseif clean == "false" or clean == "0" then
print("[CLEANUP]: `TEST_CLEANUP` was disabled, not cleaning " .. xdg_root:get())
end
for _, std_path in pairs(std_paths) do
local xdg_str = "XDG_" .. std_path:upper() .. "_HOME"
local xdg_path = xdg_root:push(std_path):get()
print(("[SETUP] Set vim.env.%-3s -> %s"):format(xdg_str, xdg_path))
print(("[SETUP] Set vim.env.%s -> %s"):format(xdg_str, xdg_path))
vim.env[xdg_str] = xdg_path
---@diagnostic disable-next-line: param-type-mismatch
vim.fn.mkdir(vim.fn.stdpath(std_path), "p")
vim.fn.mkdir(xdg_path, "p")
end
-- Ignore cleanups if specified in the environment
-- NOTE: Cleanup the xdg cache on exit so new runs of the minimal init doesn't share any previous state, e.g. shada
vim.api.nvim_create_autocmd("VimLeave", {
callback = function()
if vim.env.TEST_NO_CLEANUP and vim.env.TEST_NO_CLEANUP:lower() == "true" then
print("[CLEANUP]: `TEST_NO_CLEANUP` was specified, not removing: " .. xdg_root)
else
print("[CLEANUP]: `TEST_NO_CLEANUP` not specified, removing " .. xdg_root)
vim.fn.delete(xdg_root:get(), "rf")
end
end,
})
-- Empty the package path so we use only the plugins specified
vim.opt.packpath = {}
@ -91,6 +119,9 @@ function M.setup(plugins)
end
end
-- Setup nvim-treesitter
M.setup_treesitter()
-- Ensure `nvim-ts-autotag` is registed on the runtimepath and set it up
utils.rtp_register_ts_autotag()
require("nvim-ts-autotag").setup({
@ -99,6 +130,7 @@ function M.setup(plugins)
enable_close = true,
enable_close_on_slash = true,
})
print("[SETUP] Finished setting up minimal init")
end
@ -107,5 +139,4 @@ M.setup({
["popup.nvim"] = "https://github.com/nvim-lua/popup.nvim",
["nvim-treesitter"] = "https://github.com/nvim-treesitter/nvim-treesitter",
["playground"] = "https://github.com/nvim-treesitter/playground",
["nvim-treesitter-rescript"] = "https://github.com/nkrkv/nvim-treesitter-rescript",
})

View File

@ -1,9 +1,5 @@
local helpers = require("tests.utils.helpers")
helpers.setup_nvim_treesitter({
highlight = { enable = true },
})
local data = {
{
name = "1 html close tag after inputting /",

View File

@ -1,9 +1,5 @@
local helpers = require("tests.utils.helpers")
helpers.setup_nvim_treesitter({
highlight = { enable = true },
})
local data = {
{
name = "1 html close tag",

View File

@ -1,12 +1,4 @@
local helpers = require("tests.utils.helpers")
helpers.setup_nvim_treesitter({
highlight = {
use_languagetree = false,
enable = true,
},
fold = { enable = false },
})
local data = {
{

View File

@ -35,23 +35,6 @@ M.feed = function(text, num)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(result, true, false, true), "x", true)
end
M.setup_nvim_treesitter = function(opts)
opts = vim.tbl_deep_extend("keep", opts or {}, {
ensure_installed = {
"html",
"javascript",
"typescript",
"svelte",
"vue",
"tsx",
"php",
"glimmer",
"rescript",
"embedded_template",
},
})
end
M.Test_filter = function(data)
local run_data = {}
for _, value in pairs(data) do