Skip to content

Commit

Permalink
fix: handle nil values in nested config #81
Browse files Browse the repository at this point in the history
  • Loading branch information
Allaman committed May 4, 2024
1 parent e0c4019 commit 63016fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lua/core/plugins/themes/catppuccin.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
local catppuccin = require("catppuccin")
local utils = require("utils.functions")

local harpoon_enabled = utils.safe_nested_config(vim.g.config.plugins, "harpoon", "enabled")
local trouble_enabled = utils.safe_nested_config(vim.g.config.plugins, "trouble", "enabled")

catppuccin.setup({
default_integrations = false,
Expand All @@ -10,10 +14,10 @@ catppuccin.setup({
dropbar = { enabled = true },
fidget = false,
gitsigns = true,
harpoon = (vim.g.config.plugins.harpoon.enabled or false),
harpoon = harpoon_enabled,
headlines = true,
indent_blankline = { enabled = true },
lsp_trouble = (vim.g.config.plugins.harpoon.trouble or false),
lsp_trouble = trouble_enabled,
markdown = true,
mason = true,
mini = true,
Expand Down
16 changes: 16 additions & 0 deletions lua/utils/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,20 @@ M.startLSP = function(lsp_name)
require("lspconfig")[lsp_name].setup({})
end

---check if nested config is not nil
---@param config any
---@param ... string
---@return any
M.safe_nested_config = function(config, ...)
local elements = { ... }
local node = config
for i = 1, #elements do
node = node[elements[i]]
if node == nil then
return nil
end
end
return node
end

return M

0 comments on commit 63016fb

Please sign in to comment.