From 7ef56e9e48cd2b0e9cc74cd988568a6a292728fe Mon Sep 17 00:00:00 2001 From: Jonas Widen Date: Mon, 17 Mar 2025 07:45:40 +0100 Subject: [PATCH] debug completion --- lua/gemini/completion.lua | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lua/gemini/completion.lua b/lua/gemini/completion.lua index 4281f30..047eb74 100644 --- a/lua/gemini/completion.lua +++ b/lua/gemini/completion.lua @@ -58,24 +58,15 @@ local function show_suggestion(suggestion, start_col) local line = vim.api.nvim_win_get_cursor(0)[1] - 1 local line_text = vim.api.nvim_buf_get_lines(0, line, line + 1, true)[1] - -- Get text after cursor on current line - local input_after_cursor = string.sub(line_text, start_col + 1) + -- Get text before cursor on current line + local input_before_cursor = string.sub(line_text, 1, start_col) local first_line = suggestion_lines[1] - -- Find the longest common prefix between the existing text and suggestion - local common_length = 0 - while common_length < #input_after_cursor and common_length < #first_line do - if string.sub(input_after_cursor, common_length + 1, common_length + 1) == - string.sub(first_line, common_length + 1, common_length + 1) then - common_length = common_length + 1 - else - break - end + -- If the suggestion starts with what's already typed, remove that part + if vim.startswith(first_line, input_before_cursor) then + first_line = string.sub(first_line, #input_before_cursor + 1) end - -- Only show the part of suggestion that doesn't overlap - first_line = string.sub(first_line, common_length + 1) - if first_line == "" and #suggestion_lines == 1 then return end current_suggestion.text = suggestion @@ -103,7 +94,7 @@ local function show_suggestion(suggestion, start_col) }) end - debug_print("Showing suggestion: '%s' (common length: %d)", first_line, common_length) + debug_print("Showing suggestion: '%s'", first_line) end function M.accept_suggestion()