feat: Add telemetry endpoint for tracking active Neovim session via FocusGained

This commit is contained in:
Riz Ashraf committed 2026-09-12 23:08:56 +01:00
1 parent 491db39447
commit 4d69f5e771
2 files changed
+68

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
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