From 8d69ca734086ad0c8a111dd99dfbb5821d95eaf4 Mon Sep 17 00:00:00 2001 From: Jonas Widen Date: Sun, 16 Mar 2025 21:26:44 +0100 Subject: [PATCH] Added completion --- lua/gemini/completion.lua | 12 +++--------- lua/gemini/init.lua | 6 ++++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lua/gemini/completion.lua b/lua/gemini/completion.lua index b2be95a..a18a0d5 100644 --- a/lua/gemini/completion.lua +++ b/lua/gemini/completion.lua @@ -25,6 +25,7 @@ local function parse_completion_response(response) end function M.get_completion(params, callback) + vim.notify("Gemini completion triggered", vim.log.levels.INFO) local cursor = vim.api.nvim_win_get_cursor(0) local line = cursor[1] local col = cursor[2] @@ -44,14 +45,7 @@ function M.get_completion(params, callback) before_cursor ) - -- Check cache first - local cache_key = prefix .. before_cursor - if completion_cache[cache_key] then - vim.schedule(function() - callback(completion_cache[cache_key]) - end) - return - end + vim.notify("Sending completion request to Gemini", vim.log.levels.INFO) -- Get completion from Gemini api.get_response(prompt, nil, function(response, error) @@ -63,8 +57,8 @@ function M.get_completion(params, callback) return end + vim.notify("Received completion response", vim.log.levels.INFO) local items = parse_completion_response(response) - completion_cache[cache_key] = items vim.schedule(function() callback(items) end) diff --git a/lua/gemini/init.lua b/lua/gemini/init.lua index 5dd8246..07ca31d 100644 --- a/lua/gemini/init.lua +++ b/lua/gemini/init.lua @@ -85,8 +85,10 @@ function M.setup(opts) vim.notify("Chat history cleared", vim.log.levels.INFO) end, { desc = "Clear Gemini chat history" }) - -- Add default completion keymap - vim.keymap.set('i', '', function() + -- Change the completion keymap to a more unique combination + vim.keymap.set('i', '', function() + -- Force Gemini's omnifunc + vim.api.nvim_command('set omnifunc=v:lua.require\'gemini\'.complete') vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'n', true) end, { desc = 'Trigger Gemini completion' }) end