Added completion
This commit is contained in:
		| @@ -76,19 +76,28 @@ function M.trigger_completion() | |||||||
|     local line = cursor[1] |     local line = cursor[1] | ||||||
|     local col = cursor[2] |     local col = cursor[2] | ||||||
|      |      | ||||||
|     -- Get current buffer content for context |     -- Get entire buffer content | ||||||
|     local lines = vim.api.nvim_buf_get_lines(0, math.max(0, line - 10), line, false) |     local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) | ||||||
|     local prefix = table.concat(lines, "\n") |  | ||||||
|      |      | ||||||
|     -- Get current line up to cursor |     -- Split into before and after cursor | ||||||
|     local current_line = vim.api.nvim_get_current_line() |     local before_lines = {} | ||||||
|     local before_cursor = string.sub(current_line, 1, col) |     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 |     -- Construct prompt for Gemini | ||||||
|     local prompt = string.format( |     local prompt = string.format( | ||||||
|         "Complete this code. Only provide the completion, no explanation:\n%s\n%s", |         "Complete this code. Only provide the completion, no explanation:\n%s", | ||||||
|         prefix, |         prefix | ||||||
|         before_cursor |  | ||||||
|     ) |     ) | ||||||
|      |      | ||||||
|     -- Get completion from Gemini |     -- Get completion from Gemini | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user