Skip to content

Commit 9dd15af

Browse files
committed
add util function opts
1 parent b7c29df commit 9dd15af

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

lua/plugins/lsp.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ return {
207207
{
208208
"WhoIsSethDaniel/mason-tool-installer.nvim",
209209
config = function()
210-
local plugin = require("lazy.core.config").spec.plugins["nvim-lspconfig"]
211-
local Plugin = require("lazy.core.plugin")
212-
local opts = Plugin.values(plugin, "opts", false)
210+
local opts = Util.opts("nvim-lspconfig")
213211
local ensure_installed = vim.tbl_keys(opts.servers or {})
214212
vim.list_extend(ensure_installed, opts.ensure_installed)
215213
require("mason-tool-installer").setup({

lua/plugins/mini.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,25 @@ return {
7171

7272
{
7373
"echasnovski/mini.surround",
74-
event = "LazyFile",
74+
keys = function(_, keys)
75+
vim.print(keys)
76+
-- Populate the keys based on the user's options
77+
-- https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/coding/mini-surround.lua
78+
local opts = Util.opts("mini.surround")
79+
local mappings = {
80+
{ opts.mappings.add, desc = "Add Surrounding", mode = { "n", "v" } },
81+
{ opts.mappings.delete, desc = "Delete Surrounding" },
82+
{ opts.mappings.find, desc = "Find Right Surrounding" },
83+
{ opts.mappings.find_left, desc = "Find Left Surrounding" },
84+
{ opts.mappings.highlight, desc = "Highlight Surrounding" },
85+
{ opts.mappings.replace, desc = "Replace Surrounding" },
86+
{ opts.mappings.update_n_lines, desc = "Update `MiniSurround.config.n_lines`" },
87+
}
88+
mappings = vim.tbl_filter(function(m)
89+
return m[1] and #m[1] > 0
90+
end, mappings)
91+
return vim.list_extend(mappings, keys)
92+
end,
7593
opts = {
7694
mappings = {
7795
add = "gsa", -- Add surrounding in Normal and Visual modes

lua/util/init.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ setmetatable(M, {
99
end,
1010
})
1111

12+
-- https://github.com/LazyVim/LazyVim/blob/25abbf546d564dc484cf903804661ba12de45507/lua/lazyvim/util/init.lua#L118-L126
13+
---@param name string
14+
function M.opts(name)
15+
local plugin = require("lazy.core.config").spec.plugins[name]
16+
if not plugin then
17+
return {}
18+
end
19+
local Plugin = require("lazy.core.plugin")
20+
return Plugin.values(plugin, "opts", false)
21+
end
22+
1223
---@param long_format? boolean
1324
function M.modeline(long_format)
1425
local tabstop = vim.bo.tabstop

0 commit comments

Comments
 (0)