debug completion
This commit is contained in:
parent
d33e9114a7
commit
f0594c6eca
@ -193,8 +193,59 @@ function M.trigger_completion()
|
||||
|
||||
-- Don't trigger completion if line is empty
|
||||
if not current_line or current_line:match("^%s*$") then
|
||||
debug_print("Skipping: empty line")
|
||||
clear_suggestion()
|
||||
-- Instead of skipping, let's ask for what should come next
|
||||
local context = {}
|
||||
local cursor_line = line
|
||||
|
||||
-- Add previous lines for context
|
||||
for i = 1, line - 1 do
|
||||
if lines[i] and #lines[i] > 0 then
|
||||
table.insert(context, string.format("L%d: %s", i, lines[i]))
|
||||
end
|
||||
end
|
||||
|
||||
-- Add empty current line with cursor position
|
||||
table.insert(context, string.format("L%d (current): ", cursor_line))
|
||||
table.insert(context, "^")
|
||||
|
||||
-- Add following lines for context
|
||||
for i = line + 1, #lines do
|
||||
if lines[i] and #lines[i] > 0 then
|
||||
table.insert(context, string.format("L%d: %s", i, lines[i]))
|
||||
end
|
||||
end
|
||||
|
||||
local full_context = table.concat(context, "\n")
|
||||
if #full_context == 0 then
|
||||
debug_print("Empty context, skipping completion request")
|
||||
return
|
||||
end
|
||||
|
||||
-- Special prompt for empty line suggestions
|
||||
local prompt = string.format([[I'm editing a %s file. Here's the context around line %d where my cursor (^) is on an empty line:
|
||||
|
||||
%s
|
||||
|
||||
Based on the surrounding code context, what would be the most appropriate code to add at the cursor position?
|
||||
Return ONLY the code that should be added, no explanation.]], vim.bo.filetype, cursor_line, full_context)
|
||||
|
||||
-- Get completion from Gemini
|
||||
api.get_response(prompt, nil, function(response, error)
|
||||
if error then
|
||||
debug_print("Completion error: %s", error)
|
||||
return
|
||||
end
|
||||
|
||||
if type(response) == "string" and #response > 0 then
|
||||
vim.schedule(function()
|
||||
-- Check if cursor position is still valid
|
||||
local new_cursor = vim.api.nvim_win_get_cursor(0)
|
||||
if new_cursor[1] == line then
|
||||
show_suggestion(response, 0) -- Start from column 0 since line is empty
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
return
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user