From 82615d77798bf614996600be3684f4f4141446aa Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Sat, 19 Sep 2026 01:28:53 +0200 Subject: wow it seems to work --- lua/aotrix/plugins/build.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lua/aotrix') diff --git a/lua/aotrix/plugins/build.lua b/lua/aotrix/plugins/build.lua index 80b4398..f178e4e 100644 --- a/lua/aotrix/plugins/build.lua +++ b/lua/aotrix/plugins/build.lua @@ -71,6 +71,7 @@ return { local addCommandToJsonFile = function(commandBlock, commandsFilePath, directory) local current_json = readJsonFromFile(commandsFilePath) + local is_new_file = false if current_json ~= nil then if current_json[directory] == nil then current_json[directory] = {} @@ -80,12 +81,19 @@ return { command = tostring(commandBlock.command()), description = tostring(commandBlock.description()) }) + else + is_new_file = true end local file, error = io.open(commandsFilePath, 'w') + if is_new_file and file ~= nil then file:write("{}") end if file then local indent = vim.bo.expandtab and (' '):rep(vim.o.shiftwidth) or '\t' - file:write(vim.json.encode(current_json, {indent = indent})) + if current_json ~= nil then + json_content = vim.json.encode(current_json, + {indent = indent}) + file:write(json_content) + end file:close() else print("Error in writeTableToJsonFile: " .. error) -- cgit v1.2.3