-- lua/chatgpt_nvim/config.lua -- Changed to use YAML for configuration instead of JSON. -- Reads from .chatgpt_config.yaml and uses lyaml to parse it. -- If no config file is found, uses default values. local M = {} local uv = vim.loop -- Attempt to require lyaml for YAML parsing. -- Make sure lyaml is installed (e.g., via luarocks install lyaml) local ok_yaml, lyaml = pcall(require, "lyaml") local function get_config_path() local cwd = vim.fn.getcwd() local config_path = cwd .. "/.chatgpt_config.yaml" return config_path end function M.load() local path = get_config_path() local fd = uv.fs_open(path, "r", 438) -- 438 = 0o666 if not fd then -- Return some default configuration if no file found return { initial_prompt = "", directories = { "." }, } end local stat = uv.fs_fstat(fd) local data = uv.fs_read(fd, stat.size, 0) uv.fs_close(fd) if data and ok_yaml then local ok, result = pcall(lyaml.load, data) if ok and type(result) == "table" then local config = result[1] if type(config) == "table" then return { initial_prompt = config.initial_prompt or "", directories = config.directories or { "." }, } end end end -- Fallback if decode fails return { initial_prompt = "", directories = { "." }, } end return M