54 lines
1.3 KiB
Lua
54 lines
1.3 KiB
Lua
-- plugin/gemini/init.lua
|
|
|
|
local api = require("gemini.api")
|
|
|
|
local function gemini_query(prompt)
|
|
local response = api.get_response(prompt)
|
|
|
|
if response then
|
|
-- Display the response in a new buffer
|
|
local new_buf = vim.api.nvim_create_buf(false, true) -- Create a scratch buffer
|
|
vim.api.nvim_buf_set_lines(new_buf, 0, 0, false, vim.split(response, "\n"))
|
|
local new_win = vim.api.nvim_open_win(new_buf, true, {
|
|
relative = "editor",
|
|
width = 80,
|
|
height = 20,
|
|
row = 5,
|
|
col = vim.o.columns / 2 - 40,
|
|
border = "rounded",
|
|
title = "Google AI Response",
|
|
})
|
|
end
|
|
end
|
|
|
|
vim.api.nvim_create_user_command("Gemini", function(opts)
|
|
local prompt = opts.args
|
|
if prompt == "" then
|
|
vim.notify("Please provide a prompt for Gemini.", vim.log.levels.WARN)
|
|
return
|
|
end
|
|
gemini_query(prompt)
|
|
end, {
|
|
desc = "Query Google AI",
|
|
nargs = "+", -- Require at least one argument
|
|
complete = "shellcmd", -- Optional: Enable completion
|
|
})
|
|
|
|
-- Keymapping example (optional)
|
|
vim.keymap.set("n", "<leader>g", function()
|
|
vim.ui.input({ prompt = "Gemini Query: " }, function(input)
|
|
if input then
|
|
gemini_query(input)
|
|
end
|
|
end)
|
|
end, { desc = "Query Google AI (via Input)" })
|
|
|
|
-- Optional setup function if you want to add configuration
|
|
local function setup()
|
|
-- Add any setup logic here (e.g., reading configuration options)
|
|
end
|
|
|
|
return {
|
|
setup = setup,
|
|
}
|