yetone / avante.nvim

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

bug: Make sure to build avante #612

Closed twilwa closed 1 month ago

twilwa commented 1 month ago

Describe the bug

Freshly installed avante.nvim, attempted the build="make BUILD_FROM_SOURCE=true" modification as well as build="make", still getting the following after a successful open + attempt to avante ask

E5108: Error executing lua: ...ocal/share/Kickstart/lazy/avante.nvim/lua/avante/llm.lua:61: Make sure to build avante (missing avante_templates) stack traceback: [C]: in function 'error' ...cal/share/Kickstart/lazy/avante.nvim/lua/avante/path.lua:75: in function 'get' ...ocal/share/Kickstart/lazy/avante.nvim/lua/avante/llm.lua:61: in function 'stream' .../share/Kickstart/lazy/avante.nvim/lua/avante/sidebar.lua:1299: in function 'handle_submit' .../share/Kickstart/lazy/avante.nvim/lua/avante/sidebar.lua:1353: in function <.../share/Kickstart/lazy/avante.nvim/lua/avante/sidebar.lua:1343>

To reproduce

install via lazy as directed in README.md:

.config/Kickstart/lua/custom/plugins:

 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
    },
    -- 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,
                },
            },
        },
    },
}

Expected behavior

Ask succeeds.

Environment

NVIM v0.10.0 Build type: Release LuaJIT 2.1.1713484068 Run "nvim -V1 -v" for more info

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{
        "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
        },
        -- 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,
                    },
                },
            },
        },
    },
})

note: i'm unable to use the default leader key \ or the remapped leader key <space> from my other configs to test if aa works. :AvanteAsk works normally in this case. I noticed a build step occur in this repro that doesn't seem to be occuring in my kickstart.nvim config.
kozer commented 1 month ago

I have the same issue. I resolved it by running: :AvanteBuild I'm not sure if this can resolved if we replace "make" with "AvanteBuild" as well cc: @twilwa

twilwa commented 1 month ago

:AvanteBuild doesn't provide any terminal feedback when I just run it with neovim open and the error persists, did you modify the default config at all?

dir01 commented 1 month ago

For me the issue was in a wrong architecture (I use x86), so I had to :AvanteBuild source=true But it also failed (silently) After some digging I figured the problem was with outdated version of rustc After upgrading rust :AvanteBuild source=true succeeded and the issue is now resolved for me

rodrigc commented 1 month ago

@twilwa you can also verify outside of neovim, by checking out https://github.com/yetone/avante.nvim/ into a separate directory and then in that directory, type:

make BUILD_FROM_SOURCE=true

If you don't have the correct versions of cargo and rustc, then the compilation will fail, and it might be easier to see why.

nekowasabi commented 1 month ago

If you run make BUILD_FROM_SOURCE=true and then start neovim, after about one second, neovim exits without outputting any error messages.

rodrigc commented 1 month ago

@nekowasabi on your computer, what directory were you in when you ran make BUILD_FROM_SOURCE=true. Did this command succeed? What version of cargo and rustc do you have?

nekowasabi commented 1 month ago

@rodrigc The environment is as follows

rodrigc commented 1 month ago

@nekowasabi That version of cargo and rustc look good. If you ran the make in the directory /Users/nekowasabi/.config/nvim/plugged/avante.nvim, and the command worked, that should be enough. Are you sure cargo built something? If it did, there is something else wrong.

yetone commented 1 month ago

Sorry, the specific reason was not found because theoretically everything should work fine if you have build = "make" in your lazy config. I also couldn't reproduce it locally using Lazy.nvim, but you can manually fix this issue with the following steps:

  1. (Important) Update avante.nvim to the latest version

  2. Go to the location of avante.nvim: a. lazy.nvim

      cd ~/.local/share/nvim/lazy/avante.nvim

    b. packer.nvim

      cd ~/.local/share/nvim/site/pack/packer/start/avante.nvim

    c. vim-plug

      cd ~/.config/nvim/plugged/avante.nvim

    d. Others follow similarly

  3. Manually execute the make command:

    make
  4. Check if the make command successfully downloaded all dependencies:

    ls ./build/

    Normally, there should be several files in the ./build/ directory:

    ls ./build/
    avante_repo_map.dylib  avante_templates.dylib  avante_tokenizers.dylib 
rodrigc commented 1 month ago

@nekowasabi No worries, thanks for your detailed analysis. Glad you got it to work.

The make step can fail for various reasons, and currently the plugin does not show the output of the build step, so it can be difficult to figure out what is going on.

I ran into these two problems:

  1. cargo and rustc were not in my PATH, so the build step never worked
  2. I put cargo in my PATH, but it was cargo/rustc version 1.75, which was too old, and the compilation failed

If avante placed the output of the build command in a popup window, that might help people figure things out.

yetone commented 1 month ago

What operating system are you? Because I suspect that the previously precompiled artifacts did not include darwin-x86_64, which caused this issue. I just fixed it: https://github.com/yetone/avante.nvim/pull/637

rodrigc commented 1 month ago

My system is:

sw_vers
ProductName:        macOS
ProductVersion:     14.6.1
BuildVersion:       23G93
NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1720049189

Yes, I am on darwin-x86_64 (Intel i9), so looks like https://github.com/yetone/avante.nvim/issues/637 addresses one issue I had.

My advice would be to put the make command in a popup window, so that errors can be seen more easily, but that is not a big deal.

I have started using avante.nvim on my project, and it is amazing!! Thanks for it, @yetone !

yetone commented 1 month ago

‌‌‌‌‌‌I feel that this issue has been resolved. If the same problem occurs again, I will reopen this issue.

nekowasabi commented 1 month ago

@rodrigc @yetone It worked. Thank you!!

itsdaiego commented 4 weeks ago

Maybe I'm doing something wrong, but although everything seems to be executed smoothly:

LUA_VERSION=luajit bash ./build.sh
+ mkdir -p /Users/daiego/.vim/plugged/avante.nvim/build
+ curl -L https://github.com/yetone/avante.nvim/releases/download/v0.0.8/avante_lib-darwin-aarch64-luajit.tar.gz
+ tar -zxv -C /Users/daiego/.vim/plugged/avante.nvim/build
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0 8556k    0 16384    0     0  15240      0  0:09:34  0:00:01  0:09:33 15240x avante_repo_map.dylib
x avante_templates.dylib
100 8556k  100 8556k    0     0  6635k      0  0:00:01  0:00:01 --:--:-- 38.9M

I still get the error around "avante_repo_map", I'm using an M1 chip (arm64), not sure if that's supported atm or not.

I also tried to build from source and although everything runs fine, as soon as I open neovim I see the error popup again.

rodrigc commented 4 weeks ago

@itsdaiego there have been a few changes to avante.nvim in the past 24 hours. Have you updated? What version do you have?

If you want to try building from source, what versions of cargo and rustc are in your PATH? If your rust tools are OK, try building manually with:

make BUILD_FROM_SOURCE=true in the avante.nvim directory mentioned here: https://github.com/yetone/avante.nvim/issues/612#issuecomment-2375729928

itsdaiego commented 4 weeks ago

Rustc version image

building from source: image

Plug Update

image

Then I open neovim:

image

I feel like I'm forgetting to do something 😅 , but I cant figure out what it is

twilwa commented 3 weeks ago

I beleive the latest update resolved this error for me, just as an extra data point if anyone finds it helpful.

dsuttonpreece commented 3 weeks ago

Maybe I'm doing something wrong, but although everything seems to be executed smoothly:

LUA_VERSION=luajit bash ./build.sh
+ mkdir -p /Users/daiego/.vim/plugged/avante.nvim/build
+ curl -L https://github.com/yetone/avante.nvim/releases/download/v0.0.8/avante_lib-darwin-aarch64-luajit.tar.gz
+ tar -zxv -C /Users/daiego/.vim/plugged/avante.nvim/build
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0 8556k    0 16384    0     0  15240      0  0:09:34  0:00:01  0:09:33 15240x avante_repo_map.dylib
x avante_templates.dylib
100 8556k  100 8556k    0     0  6635k      0  0:00:01  0:00:01 --:--:-- 38.9M

I still get the error around "avante_repo_map", I'm using an M1 chip (arm64), not sure if that's supported atm or not.

I also tried to build from source and although everything runs fine, as soon as I open neovim I see the error popup again.

Working on my macbook air m1, but weirdly I get the same error as the op when running it inside a ubuntu image in parallels. It builds fine too, but even using make BUILD_FROM_SOURCE=true it still throws an error.

Any ideas? Previous comment said linux is working but maybe not ubuntu?

twilwa commented 3 weeks ago

i'm on pop, which should be ubuntu-equivalent -- quick note that it functioned normally when i used the minimal config and built correctly, but when i received the error, it didn't appear to perform the build step at all, so perhaps your error is slightly different than mine

itsdaiego commented 3 weeks ago

Just an update, in my case was a setup mistake, I wasn't loading avante_lib (I use Plug), after loading both avante and avante_lib I'm able to install it without any errors 👍🏽

retarpt commented 3 weeks ago

@itsdaiego Can you elaborate, please? I think I'm doing this, but I don't quite understand how.

itsdaiego commented 2 weeks ago

@retarpt I literally load avante_lib then avante as follows:

lua << EOF
require('avante_lib').load()
require('avante').setup({
  provider = "claude", -- Recommend using Claude
  auto_suggestions_provider = "claude", -- Since auto-suggestions are a high-frequency operation and therefore expensive, it is recommended to specify an inexpensive provider or even a free provider: copilot
  claude = {
    endpoint = "https://api.anthropic.com",
    model = "claude-3-5-sonnet-20240620",
    temperature = 0,
    max_tokens = 4096,
  },
  behaviour = {
    auto_suggestions = false, -- Experimental stage
    auto_set_highlight_group = true,
    auto_set_keymaps = true,
    auto_apply_diff_after_generation = false,
    support_paste_from_clipboard = false,
  },
  mappings = {
    --- @class AvanteConflictMappings
    diff = {
      ours = "co",
      theirs = "ct",
      all_theirs = "ca",
      both = "cb",
      cursor = "cc",
      next = "]x",
      prev = "[x",
    },
    suggestion = {
      accept = "<M-l>",
      next = "<M-]>",
      prev = "<M-[>",
      dismiss = "<C-]>",
    },
    jump = {
      next = "]]",
      prev = "[[",
    },
    submit = {
      normal = "<CR>",
      insert = "<C-s>",
    },
    sidebar = {
      switch_windows = "<Tab>",
      reverse_switch_windows = "<S-Tab>",
    },
  },
  hints = { enabled = true },
  windows = {
    ---@type "right" | "left" | "top" | "bottom"
    position = "right", -- the position of the sidebar
    wrap = true, -- similar to vim.o.wrap
    width = 50, -- default % based on available width
    sidebar_header = {
      align = "center", -- left, center, right for title
      rounded = true,
    },
  },
  highlights = {
    ---@type AvanteConflictHighlights
    diff = {
      current = "DiffText",
      incoming = "DiffAdd",
    },
  },
  --- @class AvanteConflictUserConfig
  diff = {
    autojump = true,
    ---@type string | fun(): any
    list_opener = "copen",
  },
})
EOF

Hopefully that will work for you as well 🙏🏽

Make sure you are building the lib correctly though

hanumanman commented 2 weeks ago

Please include the required rust version in the install document.

ryanxcharles commented 1 week ago

@retarpt I literally load avante_lib then avante as follows:

lua << EOF
require('avante_lib').load()
require('avante').setup({
  provider = "claude", -- Recommend using Claude
  auto_suggestions_provider = "claude", -- Since auto-suggestions are a high-frequency operation and therefore expensive, it is recommended to specify an inexpensive provider or even a free provider: copilot
  claude = {
    endpoint = "https://api.anthropic.com",
    model = "claude-3-5-sonnet-20240620",
    temperature = 0,
    max_tokens = 4096,
  },
  behaviour = {
    auto_suggestions = false, -- Experimental stage
    auto_set_highlight_group = true,
    auto_set_keymaps = true,
    auto_apply_diff_after_generation = false,
    support_paste_from_clipboard = false,
  },
  mappings = {
    --- @class AvanteConflictMappings
    diff = {
      ours = "co",
      theirs = "ct",
      all_theirs = "ca",
      both = "cb",
      cursor = "cc",
      next = "]x",
      prev = "[x",
    },
    suggestion = {
      accept = "<M-l>",
      next = "<M-]>",
      prev = "<M-[>",
      dismiss = "<C-]>",
    },
    jump = {
      next = "]]",
      prev = "[[",
    },
    submit = {
      normal = "<CR>",
      insert = "<C-s>",
    },
    sidebar = {
      switch_windows = "<Tab>",
      reverse_switch_windows = "<S-Tab>",
    },
  },
  hints = { enabled = true },
  windows = {
    ---@type "right" | "left" | "top" | "bottom"
    position = "right", -- the position of the sidebar
    wrap = true, -- similar to vim.o.wrap
    width = 50, -- default % based on available width
    sidebar_header = {
      align = "center", -- left, center, right for title
      rounded = true,
    },
  },
  highlights = {
    ---@type AvanteConflictHighlights
    diff = {
      current = "DiffText",
      incoming = "DiffAdd",
    },
  },
  --- @class AvanteConflictUserConfig
  diff = {
    autojump = true,
    ---@type string | fun(): any
    list_opener = "copen",
  },
})
EOF

Hopefully that will work for you as well 🙏🏽

Make sure you are building the lib correctly though

I just want to add that this solution worked for me. Avante doesn't provide Packer installation instructions, and it's critical to add the avante_lib line before loading avante to avoid errors.