Skip to content

Commit

Permalink
refactor: config
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Dec 15, 2024
1 parent e9a1792 commit 1473f18
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
21 changes: 20 additions & 1 deletion lua/persisted/config.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
return {
local defaults = {
autostart = true, -- Automatically start the plugin on load?

-- Function to determine if a session should be saved
Expand Down Expand Up @@ -33,3 +33,22 @@ return {
},
},
}

local M = {
config = vim.deepcopy(defaults),
}

---@param opts? table
M.setup = function(opts)
opts = opts or {}
M.config = vim.tbl_deep_extend("force", vim.deepcopy(defaults), opts)
end

return setmetatable(M, {
__index = function(_, key)
if key == "setup" then
return M.setup
end
return rawget(M.config, key)
end,
})
5 changes: 2 additions & 3 deletions lua/persisted/init.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local config = require("persisted.config")
local utils = require("persisted.utils")

local M = {}

local config
local start_args = vim.fn.argc() > 0 or vim.g.started_with_stdin

local e = vim.fn.fnameescape
Expand Down Expand Up @@ -220,8 +220,7 @@ end
---Setup the plugin
---@param opts? table
function M.setup(opts)
config = vim.tbl_deep_extend("force", require("persisted.config"), opts or {})
M.config = config
config.setup(opts)

vim.fn.mkdir(config.save_dir, "p")

Expand Down
3 changes: 1 addition & 2 deletions lua/telescope/_extensions/persisted.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ local _actions = require("telescope._extensions.persisted.actions")
local _finders = require("telescope._extensions.persisted.finders")

local persisted = require("persisted")
local config = require("persisted.config")
local utils = require("persisted.utils")

local config = persisted.config

local telescope_opts = {}

---Escapes special characters before performing string substitution
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/_extensions/persisted/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local actions_state = require("telescope.actions.state")
local transform_mod = require("telescope.actions.mt").transform_mod

local persisted = require("persisted")
local config = persisted.config
local config = require("persisted.config")

local M = {}

Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/_extensions/persisted/finders.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local config = require("persisted").config
local config = require("persisted.config")
local finders = require("telescope.finders")

local M = {}
Expand Down

0 comments on commit 1473f18

Please sign in to comment.