Review and cleanup
This commit is contained in:
		@@ -274,24 +274,30 @@ function M.trigger_completion()
 | 
			
		||||
    if not vim.b.gemini_completion_enabled then return end
 | 
			
		||||
    if vim.fn.pumvisible() ~= 0 then return end
 | 
			
		||||
    
 | 
			
		||||
    -- Get current line and cursor position
 | 
			
		||||
    local cursor = vim.api.nvim_win_get_cursor(0)
 | 
			
		||||
    local line = cursor[1] - 1
 | 
			
		||||
    local col = cursor[2]
 | 
			
		||||
    local current_line = vim.api.nvim_get_current_line()
 | 
			
		||||
    
 | 
			
		||||
    -- Check filetype exclusions
 | 
			
		||||
    local config = require("gemini.config")
 | 
			
		||||
    if vim.tbl_contains(config.options.completion.exclude_filetypes, vim.bo.filetype) then
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Get context
 | 
			
		||||
    local visible_lines, relative_cursor = get_visible_lines()
 | 
			
		||||
    local context = get_context_around_cursor(visible_lines, relative_cursor, config.options.completion.max_context_lines)
 | 
			
		||||
    local visible_lines = vim.api.nvim_buf_get_lines(0, math.max(0, line - 10), line + 10, false)
 | 
			
		||||
    local context, detected_file_type = get_context_around_cursor(visible_lines, 10, current_suggestion.max_context_lines)
 | 
			
		||||
    
 | 
			
		||||
    -- Create prompt for API
 | 
			
		||||
    local prompt = table.concat(context, "\n") .. "\nPlease complete the following line:\n" .. current_line
 | 
			
		||||
    -- Create a very specific prompt for raw completion
 | 
			
		||||
    local prompt = string.format([[
 | 
			
		||||
You are an autocomplete engine. Respond ONLY with the direct completion text.
 | 
			
		||||
DO NOT include:
 | 
			
		||||
- Explanations
 | 
			
		||||
- Markdown formatting
 | 
			
		||||
- Code block markers
 | 
			
		||||
- Additional newlines
 | 
			
		||||
- Any other text
 | 
			
		||||
 | 
			
		||||
Language: %s
 | 
			
		||||
Context:
 | 
			
		||||
%s
 | 
			
		||||
Complete this line:
 | 
			
		||||
%s]], detected_file_type, table.concat(context, "\n"), current_line)
 | 
			
		||||
    
 | 
			
		||||
    -- Make API request
 | 
			
		||||
    api.get_response(prompt, nil, function(response, error)
 | 
			
		||||
@@ -301,15 +307,12 @@ function M.trigger_completion()
 | 
			
		||||
        end
 | 
			
		||||
        
 | 
			
		||||
        if response then
 | 
			
		||||
            -- Extract the completion suggestion
 | 
			
		||||
            local suggestion = response:gsub("^%s*(.-)%s*$", "%1") -- Trim whitespace
 | 
			
		||||
            
 | 
			
		||||
            -- Show the suggestion
 | 
			
		||||
            -- Show the raw suggestion directly
 | 
			
		||||
            vim.schedule(function()
 | 
			
		||||
                -- Only show if cursor position hasn't changed
 | 
			
		||||
                local new_cursor = vim.api.nvim_win_get_cursor(0)
 | 
			
		||||
                if new_cursor[1] - 1 == line and new_cursor[2] == col then
 | 
			
		||||
                    show_suggestion(suggestion, col)
 | 
			
		||||
                    show_suggestion(response, col)
 | 
			
		||||
                end
 | 
			
		||||
            end)
 | 
			
		||||
        end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user