Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lua/peter/plugins/core/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ return {
---@param opts peter.treesitter.Config
config = function(_, opts)
local nts = require("nvim-treesitter")
local list = require("peter.util.list")
local autocmds = require("peter.util.autocmds")

nts.setup(opts --[[@as TSConfig]])

local ensure_installed = list.uniq(opts.ensure_installed or {})
local ensure_installed = vim.list.unique(opts.ensure_installed or {})

local already_installed = nts.get_installed()

Expand Down
3 changes: 1 addition & 2 deletions lua/peter/plugins/lsp/mason.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ return {

---@param opts peter.mason.Opts
config = function(_, opts)
local list = require("peter.util.list")
opts.ensure_installed = list.uniq(opts.ensure_installed or {})
opts.ensure_installed = vim.list.unique(opts.ensure_installed or {})

require("mason").setup(opts --[[@as MasonSettings]])

Expand Down
27 changes: 12 additions & 15 deletions lua/peter/util/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@ local M = {}
--
--[[ ---------------------------------------------------------------------- ]]

---Remove duplicate elements from a list.
---@param list any[] List to remove duplicates from.
---@return any[] new_list List with duplicates removed.
function M.uniq(list)
local hash = {}
local ret = {}

for _, v in ipairs(list) do
if not hash[v] then
ret[#ret + 1] = v
hash[v] = true
end
end

return ret
---Removes duplicate values from a list-like table without modifying the original
---table.
---
---The input table is not modified. A new table is created by this function.
---
---For in-place deduplication, see `:h vim.list.unique`.
---
---@generic T
---@param t T[]
---@return T[] t A new, deduplicated list.
function M.uniq_copy(t)
return vim.list.unique(vim.deepcopy(t))
end

return M