debug completion
This commit is contained in:
parent
60d779640b
commit
9e92bac51d
@ -9,6 +9,11 @@ local current_suggestion = {
|
|||||||
timer = nil
|
timer = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Debug function
|
||||||
|
local function debug_print(...)
|
||||||
|
vim.notify(string.format(...), vim.log.levels.INFO)
|
||||||
|
end
|
||||||
|
|
||||||
-- Helper function to clear suggestion
|
-- Helper function to clear suggestion
|
||||||
local function clear_suggestion()
|
local function clear_suggestion()
|
||||||
if current_suggestion.timer then
|
if current_suggestion.timer then
|
||||||
@ -56,6 +61,8 @@ local function show_suggestion(suggestion, start_col)
|
|||||||
virt_text_pos = 'inline',
|
virt_text_pos = 'inline',
|
||||||
virt_text_hide = true,
|
virt_text_hide = true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
debug_print("Showing suggestion: %s", suggestion)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.accept_suggestion()
|
function M.accept_suggestion()
|
||||||
@ -93,8 +100,9 @@ function M.trigger_completion()
|
|||||||
vim.fn.timer_stop(current_suggestion.timer)
|
vim.fn.timer_stop(current_suggestion.timer)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Start a new timer for debouncing
|
debug_print("Triggering completion...")
|
||||||
current_suggestion.timer = vim.fn.timer_start(100, function()
|
|
||||||
|
-- Get current buffer and cursor info
|
||||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||||
local line = cursor[1]
|
local line = cursor[1]
|
||||||
local col = cursor[2]
|
local col = cursor[2]
|
||||||
@ -120,11 +128,14 @@ function M.trigger_completion()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
debug_print("Getting completion for: %s", prefix)
|
||||||
|
|
||||||
-- Construct context from buffer
|
-- Construct context from buffer
|
||||||
local context = {}
|
local context = {}
|
||||||
|
|
||||||
-- Add previous lines for context
|
-- Add up to 10 previous lines for context
|
||||||
for i = 1, line - 1 do
|
local start_line = math.max(1, line - 10)
|
||||||
|
for i = start_line, line - 1 do
|
||||||
table.insert(context, lines[i])
|
table.insert(context, lines[i])
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -136,13 +147,16 @@ function M.trigger_completion()
|
|||||||
|
|
||||||
-- Construct prompt for Gemini
|
-- Construct prompt for Gemini
|
||||||
local prompt = string.format(
|
local prompt = string.format(
|
||||||
"Complete this code. Provide only the completion that would naturally follow, no explanation:\n%s",
|
"Complete this code. Return ONLY the completion that would naturally follow, no explanation:\n%s",
|
||||||
full_context
|
full_context
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Get completion from Gemini
|
-- Get completion from Gemini
|
||||||
api.get_response(prompt, nil, function(response, error)
|
api.get_response(prompt, nil, function(response, error)
|
||||||
if error then return end
|
if error then
|
||||||
|
debug_print("Completion error: %s", error)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if type(response) == "string" then
|
if type(response) == "string" then
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
@ -154,7 +168,6 @@ function M.trigger_completion()
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Setup function to create highlight group and keymaps
|
-- Setup function to create highlight group and keymaps
|
||||||
@ -175,6 +188,7 @@ function M.setup()
|
|||||||
|
|
||||||
-- Set up autocommand for real-time completion
|
-- Set up autocommand for real-time completion
|
||||||
vim.api.nvim_create_autocmd("TextChangedI", {
|
vim.api.nvim_create_autocmd("TextChangedI", {
|
||||||
|
pattern = "*",
|
||||||
callback = function()
|
callback = function()
|
||||||
M.trigger_completion()
|
M.trigger_completion()
|
||||||
end
|
end
|
||||||
@ -182,10 +196,13 @@ function M.setup()
|
|||||||
|
|
||||||
-- Clear suggestion on cursor move
|
-- Clear suggestion on cursor move
|
||||||
vim.api.nvim_create_autocmd({'CursorMovedI', 'CursorMoved'}, {
|
vim.api.nvim_create_autocmd({'CursorMovedI', 'CursorMoved'}, {
|
||||||
|
pattern = "*",
|
||||||
callback = function()
|
callback = function()
|
||||||
clear_suggestion()
|
clear_suggestion()
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
debug_print("Gemini completion setup complete")
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
@ -46,20 +46,11 @@ function M.setup(opts)
|
|||||||
-- Set up completion
|
-- Set up completion
|
||||||
require("gemini.completion").setup()
|
require("gemini.completion").setup()
|
||||||
|
|
||||||
-- Auto-trigger completion after a short delay when typing
|
-- Remove the existing TextChangedI autocmd as it's now handled in completion.lua
|
||||||
vim.api.nvim_create_autocmd("TextChangedI", {
|
-- Instead, just ensure the completion is available
|
||||||
callback = function()
|
vim.keymap.set('i', '<C-g><C-g>', function()
|
||||||
-- Cancel any existing timer
|
|
||||||
if vim.b.completion_timer then
|
|
||||||
vim.fn.timer_stop(vim.b.completion_timer)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Start new timer
|
|
||||||
vim.b.completion_timer = vim.fn.timer_start(500, function()
|
|
||||||
require("gemini.completion").trigger_completion()
|
require("gemini.completion").trigger_completion()
|
||||||
end)
|
end, { desc = 'Trigger Gemini completion' })
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("Gemini", function(opts)
|
vim.api.nvim_create_user_command("Gemini", function(opts)
|
||||||
if opts.args == "" then
|
if opts.args == "" then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user