zbirenbaum / copilot-cmp

Lua plugin to turn github copilot into a cmp source
MIT License
1.08k stars 39 forks source link

Pressing tab is causing the auto complete to automatically show suggestions #16

Closed augustocdias closed 1 year ago

augustocdias commented 1 year ago

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

zbirenbaum commented 1 year ago

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),
  },
})
augustocdias commented 1 year ago

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

zbirenbaum commented 1 year ago

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?

augustocdias commented 1 year ago

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.

zbirenbaum commented 1 year ago

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

augustocdias commented 1 year ago

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

zbirenbaum commented 1 year ago

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

Can you supply your full cmp config?

augustocdias commented 1 year ago

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

zbirenbaum commented 1 year ago

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...

augustocdias commented 1 year ago

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

augustocdias commented 1 year ago

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()
zbirenbaum commented 1 year ago

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.

augustocdias commented 1 year ago

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