copilot-cmp icon indicating copy to clipboard operation
copilot-cmp copied to clipboard

Pressing tab is causing the auto complete to automatically show suggestions

Open augustocdias opened this issue 3 years ago • 4 comments
trafficstars

So sometimes when I'm indenting something the simple fact of pressing tab in the blank causes suggestions to popup which can be quite annoying...

Would be nice to be able to disable this behavior. My cmp triggers automatically when I start typing something, so that would be the intended behavior for me

augustocdias avatar Aug 05 '22 14:08 augustocdias

This is configurable in your cmp config. Unlike other completion sources, copilot can use other lines above or below an empty line to provide a completion. I don't like the tab behavior either though, so I wrote this into my config so that the menu still appears, but tab does not select it unless a character other than whitespace has actually been typed. I'll put this in the readme, I thought I had but this post made me realize I hadn't and should really put it there.

local has_words_before = function()
  if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then return false end
  local line, col = unpack(vim.api.nvim_win_get_cursor(0))
  return col ~= 0 and vim.api.nvim_buf_get_text(0, line-1, 0, line-1, col, {})[1]:match("^%s*$") == nil
end
cmp.setup({
  mapping = {
    ["<Tab>"] = vim.schedule_wrap(function(fallback)
      if cmp.visible() and has_words_before() then
        cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
      else
        fallback()
      end
    end),
  },
})

zbirenbaum avatar Aug 05 '22 23:08 zbirenbaum

This didn't work for me... I'm having the same behavior

augustocdias avatar Aug 08 '22 07:08 augustocdias

This didn't work for me... I'm having the same behavior

Are you entering the menu when you try to tab or it is just showing up?

zbirenbaum avatar Aug 10 '22 19:08 zbirenbaum

It opens the popup for the auto complete. Then I press Esc for it to close. It doesn't matter if I select an option or not. It will go alway only if I select an option or press Esc to close it.

augustocdias avatar Aug 10 '22 21:08 augustocdias

Is this still a problem? I haven't had any issues with it or been able to reproduce it after using the above snippet.

zbirenbaum avatar Sep 30 '22 00:09 zbirenbaum

Unfortunately yes. The snippet didn't work for me.

augustocdias avatar Sep 30 '22 04:09 augustocdias

Unfortunately yes. The snippet didn't work for me.

Can you supply your full cmp config?

zbirenbaum avatar Sep 30 '22 06:09 zbirenbaum

The snippet is not there as of now... This is from the last time I used it. I can test again next week

https://github.com/augustocdias/dotfiles/blob/main/.config/nvim/lua/setup/cmp.lua

augustocdias avatar Sep 30 '22 07:09 augustocdias

Unfortunately yes. The snippet didn't work for me.

The commented code with has_words_before under your tab mapping didn't match mine. It needs to be in the outermost if statement. Something like:

if has_words_before()
    if visible()
    elseif jumpable()
    end
else
    fallback()
end

I'm on mobile so that's not perfect but you should get the idea. I can link my config if you want. If you copy and paste it it's pretty much guaranteed to work...

zbirenbaum avatar Sep 30 '22 08:09 zbirenbaum

I'll be back to work next week and I'll try it. Thanks

augustocdias avatar Sep 30 '22 10:09 augustocdias

I'm trying but I'm not managing to see copilot suggestions anymore :(

and I have no idea why...

here's how I set it up:

               use( {
                    'zbirenbaum/copilot-cmp',
                    module = 'copilot_cmp',
                    requires = { 'zbirenbaum/copilot.lua' },
                })

and then on my cmp config:

        require('copilot').setup({
            filetypes = {
                markdown = false,
            },
        })
        require('copilot_cmp').setup()

augustocdias avatar Oct 07 '22 11:10 augustocdias

I'm trying but I'm not managing to see copilot suggestions anymore :(

and I have no idea why...

Can you check your node version? If it's anything above 16 then that's why.

zbirenbaum avatar Oct 08 '22 05:10 zbirenbaum

You're right. And everything is working as expected now. Thanks

augustocdias avatar Oct 11 '22 07:10 augustocdias