first commit

This commit is contained in:
2026-04-17 17:32:58 +02:00
commit fc8a13bd96
8 changed files with 680 additions and 0 deletions

53
lua/jasper/config.lua Normal file
View File

@@ -0,0 +1,53 @@
--- jasper/config.lua
--- Reads the .jasper_config.json file from the project root.
---
--- Expected format:
--- {
--- "attivita_id": 12345,
--- "inactivity_timeout": 10 -- optional, minutes
--- }
local M = {}
--- Walk up from `cwd` looking for .jasper_config.json.
--- @return string|nil absolute path to the config file, or nil
local function find_config_file()
local path = vim.fn.getcwd()
while true do
local candidate = path .. "/.jasper_config.json"
if vim.fn.filereadable(candidate) == 1 then
return candidate
end
local parent = vim.fn.fnamemodify(path, ":h")
if parent == path then
break -- reached filesystem root
end
path = parent
end
return nil
end
--- Load and decode .jasper_config.json.
--- @return table|nil decoded config, or nil if not found / invalid
function M.load()
local config_file = find_config_file()
if not config_file then
return nil
end
local lines = vim.fn.readfile(config_file)
if not lines or #lines == 0 then
vim.notify("[Jasper] .jasper_config.json is empty", vim.log.levels.WARN)
return nil
end
local ok, data = pcall(vim.fn.json_decode, table.concat(lines, "\n"))
if not ok or type(data) ~= "table" then
vim.notify("[Jasper] .jasper_config.json is not valid JSON", vim.log.levels.WARN)
return nil
end
return data
end
return M