first commit
This commit is contained in:
66
lua/jasper/init.lua
Normal file
66
lua/jasper/init.lua
Normal file
@@ -0,0 +1,66 @@
|
||||
--- jasper/init.lua
|
||||
--- Public setup() entry point for the jasper.nvim plugin.
|
||||
|
||||
local M = {}
|
||||
|
||||
local config = require("jasper.config")
|
||||
local timer = require("jasper.timer")
|
||||
|
||||
--- Setup the plugin.
|
||||
---
|
||||
--- Call this from your Neovim config, e.g.:
|
||||
---
|
||||
--- require("jasper").setup()
|
||||
---
|
||||
--- or with options:
|
||||
---
|
||||
--- require("jasper").setup({
|
||||
--- -- Default inactivity timeout in minutes (overrides .jasper_config.json value)
|
||||
--- inactivity_timeout = 10,
|
||||
--- })
|
||||
---
|
||||
--- @param opts table|nil global plugin options
|
||||
function M.setup(opts)
|
||||
opts = opts or {}
|
||||
|
||||
local group = vim.api.nvim_create_augroup("Jasper", { clear = true })
|
||||
|
||||
vim.api.nvim_create_autocmd("VimEnter", {
|
||||
group = group,
|
||||
callback = function()
|
||||
-- Read the project config
|
||||
local project_cfg = config.load()
|
||||
if not project_cfg then
|
||||
-- No .jasper_config.json found: silently do nothing
|
||||
return
|
||||
end
|
||||
|
||||
if not project_cfg.attivita_id then
|
||||
vim.notify(
|
||||
"[Jasper] .jasper_config.json found but 'attivita_id' is missing",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
-- Merge: project file values < global setup() opts (global opts take priority)
|
||||
local effective_opts = {
|
||||
attivita_id = project_cfg.attivita_id,
|
||||
inactivity_timeout = opts.inactivity_timeout
|
||||
or project_cfg.inactivity_timeout
|
||||
or 10,
|
||||
}
|
||||
|
||||
timer.setup(effective_opts)
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("VimLeave", {
|
||||
group = group,
|
||||
callback = function()
|
||||
timer.teardown()
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user