refactor: make it work on neovim version below 0.12
This commit is contained in:
parent
3ad6f73b57
commit
847d1b7190
3 changed files with 33 additions and 5 deletions
|
|
@ -50,4 +50,23 @@ function utils.indent(line, indent)
|
||||||
return string.rep(char, indent)
|
return string.rep(char, indent)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@generic T
|
||||||
|
---@param tbl T[]
|
||||||
|
---@return T[]
|
||||||
|
function utils.list_unique(tbl)
|
||||||
|
if vim.fn.has "nvim-0.12" == 1 then
|
||||||
|
return vim.list.unique(tbl)
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = #tbl, 1, -1 do
|
||||||
|
for j = 1, i - 1 do
|
||||||
|
if tbl[i] == tbl[j] then
|
||||||
|
table.remove(tbl, i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return tbl
|
||||||
|
end
|
||||||
|
|
||||||
return utils
|
return utils
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
local u = require "gopher._utils"
|
||||||
|
|
||||||
---@param option string
|
---@param option string
|
||||||
local function option_to_tag(option)
|
local function option_to_tag(option)
|
||||||
return option:match "^(.-)="
|
return option:match "^(.-)="
|
||||||
|
|
@ -32,12 +34,9 @@ function struct_tags.parse_args(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- todo: it's incompatible with vim lower 0.12
|
|
||||||
tags = vim.list.unique(tags)
|
|
||||||
options = vim.list.unique(options)
|
|
||||||
return {
|
return {
|
||||||
tags = table.concat(tags, ","),
|
tags = table.concat(u.list_unique(tags), ","),
|
||||||
options = table.concat(options, ","),
|
options = table.concat(u.list_unique(options), ","),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,4 +46,14 @@ utils["should add .indent() 2 tabs"] = function()
|
||||||
t.eq("\t\t", u.indent(line, indent))
|
t.eq("\t\t", u.indent(line, indent))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
utils["should .list_unique on list with duplicates"] = function()
|
||||||
|
local u = require "gopher._utils"
|
||||||
|
t.eq({ "json", "xml" }, u.list_unique { "json", "xml", "json" })
|
||||||
|
end
|
||||||
|
|
||||||
|
utils["should .list_unique on list with no duplicates"] = function()
|
||||||
|
local u = require "gopher._utils"
|
||||||
|
t.eq({ "json", "xml" }, u.list_unique { "json", "xml" })
|
||||||
|
end
|
||||||
|
|
||||||
return T
|
return T
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue