Skip to content

Commit 3b6f59f

Browse files
committed
fix: use option compress for get stats
1 parent 4c79e5d commit 3b6f59f

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

lua/codeme/init.lua

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,46 @@ end
9393

9494
--- Get stats from backend
9595
function M.get_stats(callback)
96-
local cmd = M.config.codeme_bin .. " api --compress"
96+
local cmd = M.config.codeme_bin .. " api --compact"
9797

9898
vim.fn.jobstart(cmd, {
9999
stdout_buffered = true,
100100
on_stdout = function(_, data)
101+
if not data or #data == 0 then
102+
return
103+
end
104+
105+
local json_str = table.concat(data, "\n")
106+
107+
-- Remove empty lines
108+
json_str = json_str:gsub("\n\n+", "\n")
109+
110+
-- Try to parse
111+
local ok, stats = pcall(vim.json.decode, json_str)
112+
113+
if ok and stats then
114+
callback(stats)
115+
else
116+
-- Debug: show what we got
117+
vim.notify(
118+
string.format("CodeMe: Failed to parse stats JSON\nFirst 200 chars: %s", json_str:sub(1, 200)),
119+
vim.log.levels.ERROR
120+
)
121+
end
122+
end,
123+
on_stderr = function(_, data)
101124
if data and #data > 0 then
102-
local filtered = vim.tbl_filter(function(line)
103-
return line ~= "" and (line:match("^%s*{") or line:match("[,}%]]%s*$"))
104-
end, data)
105-
106-
if #filtered > 0 then
107-
local json_str = table.concat(filtered, "")
108-
local ok, stats = pcall(vim.json.decode, json_str)
109-
if ok and stats then
110-
callback(stats)
111-
end
125+
local msg = table.concat(data, "\n"):gsub("^%s+", ""):gsub("%s+$", "")
126+
if msg ~= "" then
127+
vim.notify("CodeMe API error: " .. msg, vim.log.levels.WARN)
112128
end
113129
end
114130
end,
131+
on_exit = function(_, exit_code)
132+
if exit_code ~= 0 then
133+
vim.notify(string.format("CodeMe API exited with code %d", exit_code), vim.log.levels.ERROR)
134+
end
135+
end,
115136
})
116137
end
117138

0 commit comments

Comments
 (0)