yetone / avante.nvim

Use your Neovim like using Cursor AI IDE!
Apache License 2.0
6.56k stars 238 forks source link

bug: Apply Diff Patch Not Working When Pressing 'a' or 'A' #588

Closed marvindore closed 1 month ago

marvindore commented 1 month ago

Describe the bug

After getting a code suggestion from the llm, I try to apply the change so that it creates the diff patch but only my cursor jumps to my code, the code patch diff does not get inserted. I am using Lazy for package manager and accessing the deepseek model locally via ollama.

To reproduce

return {
  "yetone/avante.nvim",
  event = "VeryLazy",
  lazy = false,
  version = false, -- set this if you want to always pull the latest change
  opts = {
    -- add any opts here
       provider = "ollama",
       vendors = {
         ---@type AvanteProvider
         ollama = {
           ["local"] = true,
           endpoint = "127.0.0.1:11434/v1",
           model = "deepseek-coder-v2:16b",
           parse_curl_args = function(opts, code_opts)
             return {
               url = opts.endpoint .. "/chat/completions",
               headers = {
                 ["Accept"] = "application/json",
                 ["Content-Type"] = "application/json",
               },
               body = {
                 model = opts.model,
                 messages = require("avante.providers").copilot.parse_message(code_opts), -- you can make your own message, but this is very advanced
                 max_tokens = 2048,
                 stream = true,
               },
             }
           end,
           parse_response_data = function(data_stream, event_state, opts)
             require("avante.providers").openai.parse_response(data_stream, event_state, opts)
           end,
         },
       },
  },
  -- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
  build = "make",
  -- build = "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false" -- for windows
  dependencies = {
    "stevearc/dressing.nvim",
    "nvim-lua/plenary.nvim",
    "MunifTanjim/nui.nvim",
    --- The below dependencies are optional,
    "nvim-tree/nvim-web-devicons", -- or echasnovski/mini.icons
    "zbirenbaum/copilot.lua", -- for providers='copilot'
    {
      -- support for image pasting
      "HakonHarnes/img-clip.nvim",
      event = "VeryLazy",
      opts = {
        -- recommended settings
        default = {
          embed_image_as_base64 = false,
          prompt_for_file_name = false,
          drag_and_drop = {
            insert_mode = true,
          },
          -- required for Windows users
          use_absolute_path = true,
        },
      },
    },
    {
  -- Make sure to set this up properly if you have lazy=true
  'MeanderingProgrammer/render-markdown.nvim',
  opts = {
    file_types = { "markdown", "Avante" },
  },
  ft = { "markdown", "Avante" },
},

}, }

Expected behavior

I expect that after pressing the 'a' key a diff would be created in my code file.

Environment

Neovim version: v0.11.0-dev-757+g5931f780e Platform: Fedora40

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    -- add any other plugins here
  },
})
ddillert commented 1 month ago

Currently, the internal pattern matching logic expects this exact format in the result buffer:

Even minor deviations from this pattern, such as those produced by deepseek-coder-v2:16, can cause the system to fail. For example, if the result is " Replace lines: 5-7" (with a leading space) or "Replace line: 5" (singular), the changes won't be applied because the system doesn't recognize these variations.

I've addressed the most common variations in #589.

Please feel free to share any additional patterns you encounter or let me know if you suspect a different cause for the issue.

marvindore commented 1 month ago

@ddillert thank you so much for the quick response, I can confirm that is indeed what is happening. When I switch over to using openai the functionality begins to work.