mirror of
https://github.com/jiriks74/presence.nvim
synced 2025-06-24 05:08:58 +02:00
Move autocmd to autoload and validate setup opts
This commit is contained in:
parent
a656ba5361
commit
f3151560a7
3 changed files with 37 additions and 15 deletions
lua/presence
|
@ -6,6 +6,18 @@ local DiscordRPC = require("presence.discord")
|
|||
|
||||
function Presence:setup(options)
|
||||
options = options or {}
|
||||
self.options = options
|
||||
|
||||
-- Initialize logger with provided options
|
||||
self.log = Log {
|
||||
level = options.log_level or vim.g.presence_log_level,
|
||||
}
|
||||
|
||||
self.log:debug("Setting up plugin...")
|
||||
|
||||
-- Warn on any duplicate user-defined options
|
||||
self:check_dup_options("auto_update")
|
||||
self:check_dup_options("log_level")
|
||||
|
||||
-- Ensure auto-update config is reflected in its global var setting
|
||||
if options.auto_update ~= nil or not vim.g.presence_auto_update then
|
||||
|
@ -15,12 +27,8 @@ function Presence:setup(options)
|
|||
vim.api.nvim_set_var("presence_auto_update", should_auto_update)
|
||||
end
|
||||
|
||||
-- Initialize logger with provided options
|
||||
self.log = Log {
|
||||
level = options.log_level or vim.g.presence_log_level,
|
||||
}
|
||||
|
||||
self.log:debug("Setting up plugin...")
|
||||
-- Set autocommands
|
||||
vim.fn["presence#SetAutoCmds"]()
|
||||
|
||||
-- Internal state
|
||||
self.is_connected = false
|
||||
|
@ -46,6 +54,19 @@ function Presence:setup(options)
|
|||
return self
|
||||
end
|
||||
|
||||
-- Check and warn for duplicate user-defined options
|
||||
function Presence:check_dup_options(option)
|
||||
local g_variable = "presence_"..option
|
||||
|
||||
if self.options[option] ~= nil and vim.g[g_variable] ~= nil then
|
||||
local warning_fmt = "Duplicate options set: `g:%s` and setup option `%s`"
|
||||
local warning_msg = string.format(warning_fmt, g_variable, option)
|
||||
|
||||
self.log:warn(warning_msg)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function Presence:connect(on_done)
|
||||
self.log:debug("Connecting to Discord...")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue