44 lines
1.9 KiB
Lua
44 lines
1.9 KiB
Lua
-- gemini-integration.lua
|
|
-- Registers the active Neovim instance for the Antigravity MCP Server
|
|
vim.api.nvim_create_autocmd({"VimEnter", "FocusGained", "BufEnter"}, {
|
|
callback = function(ev)
|
|
-- Only register if Neovim has an active UI attached (ignore headless/embedded instances)
|
|
if #vim.api.nvim_list_uis() > 0 then
|
|
local server_name = vim.v.servername
|
|
if server_name then
|
|
-- 1. Legacy Disk Write (Fallback)
|
|
local home = os.getenv("HOME") or os.getenv("USERPROFILE")
|
|
if home then
|
|
os.execute("mkdir -p " .. home .. "/.gemini")
|
|
local path = home .. "/.gemini/active_nvim.txt"
|
|
local f = io.open(path, "w")
|
|
if f then
|
|
f:write(server_name)
|
|
f:close()
|
|
end
|
|
end
|
|
|
|
-- 2. V2 Telemetry Push (WebSockets & Cross-OS Sync via Rust Server)
|
|
local file = vim.api.nvim_buf_get_name(0)
|
|
local cursor = vim.api.nvim_win_get_cursor(0)
|
|
local row, col = cursor[1], cursor[2]
|
|
local payload = string.format(
|
|
'{"session_id": "%s", "event": "%s", "file": "%s", "line": %d, "col": %d}',
|
|
server_name:gsub("\\", "\\\\"), ev.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
|
|
end
|
|
end,
|
|
desc = "Register active Neovim instance for Gemini CLI",
|
|
})
|
|
|
|
-- Load UI & Keymaps
|
|
local ui = dofile("C:/Users/reazul.ashraf/workspace/rust/mcp-memory/gemini-ui.lua")
|
|
ui.setup()
|
|
_G.gemini = ui -- Expose globally so Agent can call it via execute_lua
|