diff --git a/lua/nvim-ts-autotag/config/ft.lua b/lua/nvim-ts-autotag/config/ft.lua index a227996..760a167 100644 --- a/lua/nvim-ts-autotag/config/ft.lua +++ b/lua/nvim-ts-autotag/config/ft.lua @@ -1,3 +1,5 @@ +local utils = require("nvim-ts-autotag.utils") + ---@alias nvim-ts-autotag.FiletypeConfigPattern string[] A single array of patterns ---@alias nvim-ts-autotag.FiletypeConfig.filetype string The supported filetype for a given Filetype Config @@ -83,7 +85,7 @@ function FiletypeConfig:extend(filetype, patterns) new.filetype = filetype for pat_key, pats in pairs(patterns or {}) do for _, pat in ipairs(pats) do - if not vim.list_contains(new.patterns[pat_key], pat) then + if not utils.list_contains(new.patterns[pat_key], pat) then table.insert(new.patterns[pat_key], pat) end end diff --git a/lua/nvim-ts-autotag/internal.lua b/lua/nvim-ts-autotag/internal.lua index f6b50ff..adf479c 100644 --- a/lua/nvim-ts-autotag/internal.lua +++ b/lua/nvim-ts-autotag/internal.lua @@ -214,7 +214,7 @@ local function check_close_tag(close_slash_tag) }) if tag_node ~= nil then local tag_name = get_tag_name(tag_node) - if tag_name ~= nil and vim.list_contains(ts_tag.skip_tag_pattern, tag_name) then + if tag_name ~= nil and utils.list_contains(ts_tag.skip_tag_pattern, tag_name) then return false end if tag_node ~= nil then diff --git a/lua/nvim-ts-autotag/utils.lua b/lua/nvim-ts-autotag/utils.lua index 9b93ac6..fb3e85d 100644 --- a/lua/nvim-ts-autotag/utils.lua +++ b/lua/nvim-ts-autotag/utils.lua @@ -7,6 +7,25 @@ M.get_node_text = function(node) return vim.split(txt, "\n") or {} end +-- Stolen from nvim `0.10.0` for `0.9.5` users +--- Checks if a list-like table (integer keys without gaps) contains `value`. +--- +--- +---@param t table Table to check (must be list-like, not validated) +---@param value any Value to compare +---@return boolean `true` if `t` contains `value` +M.list_contains = function(t, value) + vim.validate({ t = { t, "t" } }) + --- @cast t table + + for _, v in ipairs(t) do + if v == value then + return true + end + end + return false +end + M.verify_node = function(node, node_tag) local txt = get_node_text(node, vim.api.nvim_get_current_buf()) if txt:match(string.format("^<%s>", node_tag)) and txt:match(string.format("$", node_tag)) then diff --git a/tests/utils/helpers.lua b/tests/utils/helpers.lua index d86591e..9657591 100644 --- a/tests/utils/helpers.lua +++ b/tests/utils/helpers.lua @@ -72,7 +72,7 @@ local compare_text = function(linenr, text_after, name, cursor_add, end_cursor) end return true end - +local islist = vim.islist or vim.tbl_islist M.Test_withfile = function(test_data, cb) for _, value in pairs(test_data) do it("test " .. value.name, function() @@ -82,7 +82,7 @@ M.Test_withfile = function(test_data, cb) linenr = value.linenr, colnr = 0, } - if not vim.islist(value.before) then + if not islist(value.before) then value.before = { value.before } end for index, text in pairs(value.before) do @@ -95,7 +95,7 @@ M.Test_withfile = function(test_data, cb) end end end - if not vim.islist(value.after) then + if not islist(value.after) then value.after = { value.after } end vim.bo.filetype = value.filetype or "text" diff --git a/tests/utils/paths.lua b/tests/utils/paths.lua index 25d942a..ca3c58f 100644 --- a/tests/utils/paths.lua +++ b/tests/utils/paths.lua @@ -7,8 +7,9 @@ local M = {} local function search_dir_up(test_file) -- This is the path of the directory of the current file local cur_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p") + local uv = vim.uv or vim.loop ---@diagnostic disable-next-line: param-type-mismatch - while not vim.uv.fs_stat(cur_dir .. "/" .. test_file, nil) and cur_dir ~= "/" do + while not uv.fs_stat(cur_dir .. "/" .. test_file, nil) and cur_dir ~= "/" do cur_dir = vim.fn.fnamemodify(cur_dir, ":h") end if cur_dir == "/" then diff --git a/tests/utils/utils.lua b/tests/utils/utils.lua index dc9b322..e60ab3f 100644 --- a/tests/utils/utils.lua +++ b/tests/utils/utils.lua @@ -6,9 +6,7 @@ M.paths = path_utils --- Register the main plugin (`nvim-ts-autotag`) on the runtimepath if it hasn't already been --- registered M.rtp_register_ts_autotag = function() - if not vim.list_contains(vim.opt.runtimepath, path_utils.static.ts_autotag_dir()) then - vim.opt.runtimepath:append(path_utils.static.ts_autotag_dir()) - end + vim.opt.runtimepath:append(path_utils.static.ts_autotag_dir()) end return M