Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sidebar): fix get_sources when blink.compat is installed #864

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rachartier
Copy link

Hello,

blink.cmp has a module: blink.compat. This module is used to work with nvim-cmp sources but does not "emulate" all the functions present in nvim-cmp.

As a result, when the autocmds in the sidebar are set up and used (like quitting the sidebar), it is checked whether require("cmp") exists. With blink.compat, it does indeed exist, but the get_sources function used afterward does not, which causes an error: Error executing lua callback: ...local/share/nvim/lazy/avante.nvim/lua/avante/sidebar.lua:1547: attempt to call method 'get_sources' (a nil value)

This small fix adds a check for the get_sources method. If it does not exist, the rest of the function is aborted.

@rachartier rachartier changed the title fix(cmp): fix get_sources when blink.compat is installed fix(sidebar): fix get_sources when blink.compat is installed Nov 17, 2024
for _, source in ipairs(cmp.core:get_sources()) do
if source.name == "avante_commands" or source.name == "avante_mentions" then
cmp.unregister_source(source.id)
if type(cmp.core.get_sources) == "function" then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not do this. probably better to have cmp backend (we should add support to blink fwiw)

then update the callback here instead of doing this (otherwise maintenance cost are too high)

Copy link
Collaborator

@aarnphm aarnphm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny

@doodleEsc
Copy link
Contributor

tried with blink.compat and it works fine with first time.

blink.cmp call function is_available(), but self.bufnr in cmp_avante.commands and cmp_avante.mentions will never change.

function commands_source:is_available() return api.nvim_get_current_buf() == self.bufnr end

I change is_available function

function commands_source:is_available() return vim.bo.filetype == "AvanteInput" end

#doodleEsc/avante.nvim@a5438d0

my LazyVim.nvim config, juse add avante_commands and avante_mentions in source.compat

  {

    "saghen/blink.cmp",
    opts = {
      sources = {
        compat = { "avante_commands", "avante_mentions" },
      },
    },
  },

it works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants