diff --git a/lua/peter/plugins/core/treesitter.lua b/lua/peter/plugins/core/treesitter.lua index f01db52..af232a8 100644 --- a/lua/peter/plugins/core/treesitter.lua +++ b/lua/peter/plugins/core/treesitter.lua @@ -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() diff --git a/lua/peter/plugins/lsp/mason.lua b/lua/peter/plugins/lsp/mason.lua index d60e073..2d112ed 100644 --- a/lua/peter/plugins/lsp/mason.lua +++ b/lua/peter/plugins/lsp/mason.lua @@ -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]]) diff --git a/lua/peter/util/list.lua b/lua/peter/util/list.lua index 698768f..76f3607 100644 --- a/lua/peter/util/list.lua +++ b/lua/peter/util/list.lua @@ -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