From 9eda1d231a381968c3b594ba5d75e1127d230688 Mon Sep 17 00:00:00 2001 From: Jonas Widen Date: Sun, 16 Mar 2025 21:48:01 +0100 Subject: [PATCH] Added completion --- lua/gemini/completion.lua | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lua/gemini/completion.lua b/lua/gemini/completion.lua index d40ffa6..cbcdecd 100644 --- a/lua/gemini/completion.lua +++ b/lua/gemini/completion.lua @@ -76,19 +76,28 @@ function M.trigger_completion() local line = cursor[1] local col = cursor[2] - -- Get current buffer content for context - local lines = vim.api.nvim_buf_get_lines(0, math.max(0, line - 10), line, false) - local prefix = table.concat(lines, "\n") + -- Get entire buffer content + local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) - -- Get current line up to cursor - local current_line = vim.api.nvim_get_current_line() - local before_cursor = string.sub(current_line, 1, col) + -- Split into before and after cursor + local before_lines = {} + local after_lines = {} + + -- Copy lines before cursor + for i = 1, line - 1 do + table.insert(before_lines, lines[i]) + end + -- Add current line up to cursor + local current_line = lines[line] + table.insert(before_lines, string.sub(current_line, 1, col)) + + -- Combine all lines before cursor + local prefix = table.concat(before_lines, "\n") -- Construct prompt for Gemini local prompt = string.format( - "Complete this code. Only provide the completion, no explanation:\n%s\n%s", - prefix, - before_cursor + "Complete this code. Only provide the completion, no explanation:\n%s", + prefix ) -- Get completion from Gemini