Review and cleanup
This commit is contained in:
parent
34e43ab82e
commit
81c200df66
@ -177,7 +177,17 @@ function M.accept_suggestion()
|
||||
end
|
||||
vim.api.nvim_win_set_cursor(0, {final_line + 1, final_col})
|
||||
|
||||
-- Clear suggestion and cache for the current context
|
||||
clear_suggestion()
|
||||
current_suggestion.cache = {} -- Clear cache to force new suggestions
|
||||
|
||||
-- Schedule next completion after a short delay
|
||||
vim.defer_fn(function()
|
||||
if vim.b.gemini_completion_enabled then
|
||||
M.trigger_completion()
|
||||
end
|
||||
end, 100)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
@ -203,7 +213,7 @@ function M.trigger_completion()
|
||||
vim.fn.timer_stop(current_suggestion.timer)
|
||||
end
|
||||
|
||||
-- Set up debounce timer with shorter delay
|
||||
-- Set up debounce timer
|
||||
current_suggestion.timer = vim.fn.timer_start(150, function()
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
local line = cursor[1]
|
||||
@ -211,6 +221,12 @@ function M.trigger_completion()
|
||||
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||
local current_line = lines[line]
|
||||
|
||||
-- Don't trigger if at end of file or empty line
|
||||
if not current_line or current_line == "" then
|
||||
clear_suggestion()
|
||||
return
|
||||
end
|
||||
|
||||
-- Get text before cursor
|
||||
local prefix = string.sub(current_line, 1, col)
|
||||
|
||||
@ -248,7 +264,8 @@ function M.trigger_completion()
|
||||
|
||||
Return ONLY the completion text that would naturally continue from the cursor position.
|
||||
Focus on completing the current statement or block.
|
||||
Consider the syntax, style, and patterns in the surrounding code.]], file_type, full_context)
|
||||
Consider the syntax, style, and patterns in the surrounding code.
|
||||
Do not repeat any text that appears before the cursor.]], file_type, full_context)
|
||||
|
||||
-- Check cache and rate limiting
|
||||
local cache_key = get_cache_key(prompt)
|
||||
@ -270,8 +287,9 @@ Consider the syntax, style, and patterns in the surrounding code.]], file_type,
|
||||
end
|
||||
|
||||
if type(response) == "string" and #response > 0 then
|
||||
-- Clean up response
|
||||
-- Clean up response and remove any leading whitespace/indentation
|
||||
response = vim.trim(response)
|
||||
response = response:gsub("^%s+", "")
|
||||
current_suggestion.cache[cache_key] = response
|
||||
|
||||
vim.schedule(function()
|
||||
|
Loading…
x
Reference in New Issue
Block a user