Skip to content

Commit

Permalink
Merge pull request #175 from PriceHiller/fix/0.9.5-funcs
Browse files Browse the repository at this point in the history
fix: use `0.9.5` compatible vim funcs
  • Loading branch information
PriceHiller committed May 20, 2024
2 parents eed5c76 + 5121204 commit cb57b07
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lua/nvim-ts-autotag/config/ft.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-ts-autotag/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions lua/nvim-ts-autotag/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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<any,any>

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("</%s>$", node_tag)) then
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion tests/utils/paths.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions tests/utils/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cb57b07

Please sign in to comment.