29 lines
962 B
Lua
29 lines
962 B
Lua
local function send_telemetry(event)
|
|
local session_id = vim.v.servername
|
|
if not session_id or session_id == '' then return end
|
|
|
|
local file = vim.api.nvim_buf_get_name(0)
|
|
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
|
|
|
local payload = string.format(
|
|
'{"session_id": "%s", "event": "%s", "file": "%s", "line": %d, "col": %d}',
|
|
session_id:gsub("\\", "\\\\"), event, file:gsub("\\", "\\\\"), row, col
|
|
)
|
|
|
|
vim.fn.jobstart({
|
|
"curl", "-s", "-X", "POST", "http://127.0.0.1:3000/nvim/telemetry",
|
|
"-H", "Content-Type: application/json",
|
|
"-d", payload
|
|
}, { detach = true })
|
|
end
|
|
|
|
local group = vim.api.nvim_create_augroup("GeminiTelemetry", { clear = true })
|
|
|
|
local events = { "FocusGained", "BufEnter", "VimEnter" }
|
|
for _, event in ipairs(events) do
|
|
vim.api.nvim_create_autocmd(event, {
|
|
group = group,
|
|
callback = function() send_telemetry(event) end
|
|
})
|
|
end
|