diff --git a/lua/astrocommunity/editing-support/nvim-regexplainer/nvim-regexplainer.lua b/lua/astrocommunity/editing-support/nvim-regexplainer/nvim-regexplainer.lua index d46f1aff8..0465019fa 100644 --- a/lua/astrocommunity/editing-support/nvim-regexplainer/nvim-regexplainer.lua +++ b/lua/astrocommunity/editing-support/nvim-regexplainer/nvim-regexplainer.lua @@ -1,3 +1,4 @@ +local utils = require "astrocommunity.utils" return { { "bennypowers/nvim-regexplainer", @@ -15,7 +16,7 @@ return { return end -- Add the "regex" parser to opts.ensure_installed. - table.insert(opts.ensure_installed, "regex") + utils.list_insert_unique(opts.ensure_installed, "regex") end, }, } diff --git a/lua/astrocommunity/pack/bash/bash.lua b/lua/astrocommunity/pack/bash/bash.lua index 03da72bad..27c8db251 100644 --- a/lua/astrocommunity/pack/bash/bash.lua +++ b/lua/astrocommunity/pack/bash/bash.lua @@ -1,3 +1,4 @@ +local utils = require "astrocommunity.utils" return { { "nvim-treesitter/nvim-treesitter", @@ -9,7 +10,7 @@ return { return end -- Add the "julia" and "toml" language to opts.ensure_installed. - table.insert(opts.ensure_installed, "bash") + utils.list_insert_unique(opts.ensure_installed, "bash") end, }, { @@ -18,7 +19,7 @@ return { -- Ensure that opts.ensure_installed exists and is a table if not opts.ensure_installed then opts.ensure_installed = {} end -- Add julia lsp and toml lsp to ensure_installed - table.insert(opts.ensure_installed, "bashls") + utils.list_insert_unique(opts.ensure_installed, "bashls") end, }, { @@ -27,7 +28,7 @@ return { -- Ensure that opts.ensure_installed exists and is a table if not opts.ensure_installed then opts.ensure_installed = {} end -- Add julia lsp and toml lsp to ensure_installed - vim.list_extend(opts.ensure_installed, { "shellcheck", "shfmt" }) + utils.list_insert_unique(opts.ensure_installed, { "shellcheck", "shfmt" }) end, }, { @@ -36,7 +37,7 @@ return { -- Ensure that opts.ensure_installed exists and is a table if not opts.ensure_installed then opts.ensure_installed = {} end -- Add julia lsp and toml lsp to ensure_installed - table.insert(opts.ensure_installed, "bash") + utils.list_insert_unique(opts.ensure_installed, "bash") end, }, } diff --git a/lua/astrocommunity/pack/go/go.lua b/lua/astrocommunity/pack/go/go.lua index 1decb057c..a1efe00bd 100644 --- a/lua/astrocommunity/pack/go/go.lua +++ b/lua/astrocommunity/pack/go/go.lua @@ -1,3 +1,4 @@ +local utils = require "astrocommunity.utils" return { -- Golang support { @@ -10,7 +11,7 @@ return { return end -- Add the "go" language to opts.ensure_installed. - table.insert(opts.ensure_installed, "go") + utils.list_insert_unique(opts.ensure_installed, "go") end, }, @@ -20,7 +21,7 @@ return { -- Ensure that opts.ensure_installed exists and is a table. if not opts.ensure_installed then opts.ensure_installed = {} end -- Add go lsps to opts.ensure_installed using vim.list_extend. - vim.list_extend(opts.ensure_installed, { "gomodifytags", "gofumpt", "iferr", "impl", "goimports" }) + utils.list_insert_unique(opts.ensure_installed, { "gomodifytags", "gofumpt", "iferr", "impl", "goimports" }) end, }, { @@ -28,7 +29,7 @@ return { opts = function(_, opts) -- Ensure that opts.ensure_installed exists and is a table. if not opts.ensure_installed then opts.ensure_installed = {} end - table.insert(opts.ensure_installed, "gopls") + utils.list_insert_unique(opts.ensure_installed, "gopls") end, }, { @@ -42,14 +43,14 @@ return { opts = function(_, opts) -- Ensure that opts.ensure_installed exists and is a table. if not opts.ensure_installed then opts.ensure_installed = {} end - table.insert(opts.ensure_installed, "delve") + utils.list_insert_unique(opts.ensure_installed, "delve") end, }, }, }, { "olexsmir/gopher.nvim", - init = function() table.insert(astronvim.lsp.skip_setup, "gopls") end, + init = function() utils.list_insert_unique(astronvim.lsp.skip_setup, "gopls") end, opts = function() return { server = require("astronvim.utils.lsp").config "gopls" } end, ft = "go", dependencies = { diff --git a/lua/astrocommunity/pack/json/json.lua b/lua/astrocommunity/pack/json/json.lua index bda626638..9232373e2 100644 --- a/lua/astrocommunity/pack/json/json.lua +++ b/lua/astrocommunity/pack/json/json.lua @@ -1,3 +1,4 @@ +local utils = require "astrocommunity.utils" return { { "nvim-treesitter/nvim-treesitter", @@ -8,7 +9,7 @@ return { elseif opts.ensure_installed == "all" then return end - vim.list_extend(opts.ensure_installed, { "json", "jsonc" }) + utils.list_insert_unique(opts.ensure_installed, { "json", "jsonc" }) end, }, { @@ -16,7 +17,16 @@ return { opts = function(_, opts) -- Ensure that opts.ensure_installed exists and is a table if not opts.ensure_installed then opts.ensure_installed = {} end - table.insert(opts.ensure_installed, "jsonls") + utils.list_insert_unique(opts.ensure_installed, "jsonls") + end, + }, + { + "jay-babu/mason-null-ls.nvim", + opts = function(_, opts) + -- Ensure that opts.ensure_installed exists and is a table. + if not opts.ensure_installed then opts.ensure_installed = {} end + -- Add go lsps to opts.ensure_installed using vim.list_extend. + utils.list_insert_unique(opts.ensure_installed, "prettier") end, }, } diff --git a/lua/astrocommunity/pack/julia/julia.lua b/lua/astrocommunity/pack/julia/julia.lua index 825a15c34..23af6808d 100644 --- a/lua/astrocommunity/pack/julia/julia.lua +++ b/lua/astrocommunity/pack/julia/julia.lua @@ -1,3 +1,4 @@ +local utils = require "astrocommunity.utils" return { { "nvim-treesitter/nvim-treesitter", @@ -9,7 +10,7 @@ return { return end -- Add the "julia" and "toml" language to opts.ensure_installed. - vim.list_extend(opts.ensure_installed, { "julia", "toml" }) + utils.list_insert_unique(opts.ensure_installed, { "julia", "toml" }) end, }, { @@ -18,7 +19,7 @@ return { -- Ensure that opts.ensure_installed exists and is a table if not opts.ensure_installed then opts.ensure_installed = {} end -- Add julia lsp and toml lsp to ensure_installed - vim.list_extend(opts.ensure_installed, { "julials", "taplo" }) + utils.list_insert_unique(opts.ensure_installed, { "julials", "taplo" }) end, }, { diff --git a/lua/astrocommunity/pack/lua/lua.lua b/lua/astrocommunity/pack/lua/lua.lua index 4c34dc77c..47819b72f 100644 --- a/lua/astrocommunity/pack/lua/lua.lua +++ b/lua/astrocommunity/pack/lua/lua.lua @@ -1,3 +1,4 @@ +local utils = require "astrocommunity.utils" return { { "nvim-treesitter/nvim-treesitter", @@ -8,7 +9,7 @@ return { elseif opts.ensure_installed == "all" then return end - vim.list_extend(opts.ensure_installed, { "lua", "luap" }) + utils.list_insert_unique(opts.ensure_installed, { "lua", "luap" }) end, }, { @@ -16,7 +17,7 @@ return { opts = function(_, opts) -- Ensure that opts.ensure_installed exists and is a table if not opts.ensure_installed then opts.ensure_installed = {} end - table.insert(opts.ensure_installed, "lua_ls") + utils.list_insert_unique(opts.ensure_installed, "lua_ls") end, }, { @@ -24,7 +25,7 @@ return { opts = function(_, opts) -- Ensure that opts.ensure_installed exists and is a table if not opts.ensure_installed then opts.ensure_installed = {} end - table.insert(opts.ensure_installed, "stylua") + utils.list_insert_unique(opts.ensure_installed, "stylua") end, }, } diff --git a/lua/astrocommunity/pack/nix/nix.lua b/lua/astrocommunity/pack/nix/nix.lua index 8f25b5c5d..3d6de0670 100644 --- a/lua/astrocommunity/pack/nix/nix.lua +++ b/lua/astrocommunity/pack/nix/nix.lua @@ -1,3 +1,4 @@ +local utils = require "astrocommunity.utils" return { { "nvim-treesitter/nvim-treesitter", @@ -9,7 +10,7 @@ return { return end -- Add the "nix" language to opts.ensure_installed. - table.insert(opts.ensure_installed, "nix") + utils.list_insert_unique(opts.ensure_installed, "nix") end, }, { @@ -17,7 +18,7 @@ return { opts = function(_, opts) -- Ensure that opts.ensure_installed exists and is a table. if not opts.ensure_installed then opts.ensure_installed = {} end - table.insert(opts.ensure_installed, "rnix") + utils.list_insert_unique(opts.ensure_installed, "rnix") end, }, { diff --git a/lua/astrocommunity/pack/python/python.lua b/lua/astrocommunity/pack/python/python.lua index 92ce1aff2..2313607f1 100644 --- a/lua/astrocommunity/pack/python/python.lua +++ b/lua/astrocommunity/pack/python/python.lua @@ -1,3 +1,4 @@ +local utils = require "astrocommunity.utils" return { { "nvim-treesitter/nvim-treesitter", @@ -9,7 +10,7 @@ return { return end -- Add the "python" and "toml" language to opts.ensure_installed. - vim.list_extend(opts.ensure_installed, { "python", "toml" }) + utils.list_insert_unique(opts.ensure_installed, { "python", "toml" }) end, }, { @@ -18,7 +19,7 @@ return { -- Ensure that opts.ensure_installed exists and is a table. if not opts.ensure_installed then opts.ensure_installed = {} end -- Add pyright lsp to opts.ensure_installed using table.insert. - vim.list_extend(opts.ensure_installed, { "pyright", "ruff_lsp" }) + utils.list_insert_unique(opts.ensure_installed, { "pyright", "ruff_lsp" }) end, }, { @@ -27,7 +28,7 @@ return { -- Ensure that opts.ensure_installed exists and is a table. if not opts.ensure_installed then opts.ensure_installed = {} end -- Add to opts.ensure_installed using vim.list_extend. - vim.list_extend(opts.ensure_installed, { "isort", "black" }) + utils.list_insert_unique(opts.ensure_installed, { "isort", "black" }) end, }, { @@ -36,7 +37,7 @@ return { -- Ensure that opts.ensure_installed exists and is a table. if not opts.ensure_installed then opts.ensure_installed = {} end -- Add to opts.ensure_installed using table.insert. - table.insert(opts.ensure_installed, "python") + utils.list_insert_unique(opts.ensure_installed, "python") end, }, { diff --git a/lua/astrocommunity/pack/rust/rust.lua b/lua/astrocommunity/pack/rust/rust.lua index 7cce36ccf..e7c974e8b 100644 --- a/lua/astrocommunity/pack/rust/rust.lua +++ b/lua/astrocommunity/pack/rust/rust.lua @@ -1,3 +1,4 @@ +local utils = require "astrocommunity.utils" return { { "nvim-treesitter/nvim-treesitter", @@ -9,13 +10,13 @@ return { return end -- Add the "rust" and "toml" language to opts.ensure_installed. - table.insert(opts.ensure_installed, { "rust", "toml" }) + utils.list_insert_unique(opts.ensure_installed, { "rust", "toml" }) end, }, { "simrat39/rust-tools.nvim", ft = { "rust" }, - init = function() table.insert(astronvim.lsp.skip_setup, "rust_analyzer") end, + init = function() utils.list_insert_unique(astronvim.lsp.skip_setup, "rust_analyzer") end, opts = function() return { server = require("astronvim.utils.lsp").config "rust_analyzer" } end, dependencies = { { @@ -23,7 +24,7 @@ return { opts = function(_, opts) -- Ensure that opts.ensure_installed exists and is a table. if not opts.ensure_installed then opts.ensure_installed = {} end - table.insert(opts.ensure_installed, "codelldb") + utils.list_insert_unique(opts.ensure_installed, "codelldb") end, }, }, @@ -34,7 +35,7 @@ return { -- Ensure that opts.ensure_installed exists and is a table. if not opts.ensure_installed then opts.ensure_installed = {} end -- Add rust and taplo lsps to opts.ensure_installed using vim.list_extend. - vim.list_extend(opts.ensure_installed, { "rust_analyzer", "taplo" }) + utils.list_insert_unique(opts.ensure_installed, { "rust_analyzer", "taplo" }) end, }, { diff --git a/lua/astrocommunity/pack/typescript/typescript.lua b/lua/astrocommunity/pack/typescript/typescript.lua index 46303a32f..7a743ef31 100644 --- a/lua/astrocommunity/pack/typescript/typescript.lua +++ b/lua/astrocommunity/pack/typescript/typescript.lua @@ -1,3 +1,4 @@ +local utils = require "astrocommunity.utils" return { { "nvim-treesitter/nvim-treesitter", @@ -9,7 +10,7 @@ return { return end -- Add the required file types to opts.ensure_installed. - vim.list_extend(opts.ensure_installed, { "javascript", "json", "typescript", "tsx" }) + utils.list_insert_unique(opts.ensure_installed, { "javascript", "json", "typescript", "tsx" }) end, }, { @@ -18,7 +19,7 @@ return { -- Ensure that opts.ensure_installed exists and is a table. if not opts.ensure_installed then opts.ensure_installed = {} end -- Add tsserver to opts.ensure_installed using vim.list_extend. - table.insert(opts.ensure_installed, "tsserver") + utils.list_insert_unique(opts.ensure_installed, "tsserver") end, }, { @@ -27,7 +28,7 @@ return { -- Ensure that opts.ensure_installed exists and is a table. if not opts.ensure_installed then opts.ensure_installed = {} end -- Add to opts.ensure_installed using vim.list_extend. - table.insert(opts.ensure_installed, "prettier") + utils.list_insert_unique(opts.ensure_installed, "prettier") end, }, { @@ -36,7 +37,7 @@ return { -- Ensure that opts.ensure_installed exists and is a table. if not opts.ensure_installed then opts.ensure_installed = {} end -- Add to opts.ensure_installed using table.insert. - table.insert(opts.ensure_installed, "js") + utils.list_insert_unique(opts.ensure_installed, "js") end, }, { @@ -50,12 +51,9 @@ return { ft = { "ts", "js", "tsx", "jsx" }, enabled = true, dependencies = { - { - "mxsdev/nvim-dap-vscode-js", - opts = { debugger_cmd = { "js-debug-adapter" }, adapters = { "pwa-node" } }, - }, + { "mxsdev/nvim-dap-vscode-js", opts = { debugger_cmd = { "js-debug-adapter" }, adapters = { "pwa-node" } } }, { "theHamsta/nvim-dap-virtual-text", config = true }, - { "rcarriga/nvim-dap-ui", config = true }, + { "rcarriga/nvim-dap-ui", config = true }, }, config = function() local dap = require "dap" @@ -101,7 +99,7 @@ return { }, { "jose-elias-alvarez/typescript.nvim", - init = function() table.insert(astronvim.lsp.skip_setup, "tsserver") end, + init = function() utils.list_insert_unique(astronvim.lsp.skip_setup, "tsserver") end, ft = { "typescript", "typescriptreact", diff --git a/lua/astrocommunity/utility/noice-nvim/noice-nvim.lua b/lua/astrocommunity/utility/noice-nvim/noice-nvim.lua index 9f9e0d5cc..c31b8c401 100644 --- a/lua/astrocommunity/utility/noice-nvim/noice-nvim.lua +++ b/lua/astrocommunity/utility/noice-nvim/noice-nvim.lua @@ -1,10 +1,11 @@ +local utils = require "astrocommunity.utils" return { { "nvim-treesitter/nvim-treesitter", opts = function(_, opts) if not opts.ensure_installed then opts.ensure_installed = {} end if type(opts.ensure_installed) == "table" then - vim.list_extend(opts.ensure_installed, { "bash", "markdown", "markdown_inline", "regex", "vim" }) + utils.list_insert_unique(opts.ensure_installed, { "bash", "markdown", "markdown_inline", "regex", "vim" }) end return opts end, diff --git a/lua/astrocommunity/utils.lua b/lua/astrocommunity/utils.lua new file mode 100644 index 000000000..dbc686140 --- /dev/null +++ b/lua/astrocommunity/utils.lua @@ -0,0 +1,10 @@ +local M = {} + +function M.list_insert_unique(tbl, vals) + if type(vals) ~= "table" then vals = { vals } end + for _, val in ipairs(vals) do + if not vim.tbl_contains(tbl, val) then table.insert(tbl, val) end + end +end + +return M