CopilotC-Nvim / CopilotChat.nvim

Chat with GitHub Copilot in Neovim
https://copilotc-nvim.github.io/CopilotChat.nvim/
GNU General Public License v3.0
1.44k stars 67 forks source link

feat: Add nvim-cmp integration #345

Closed deathbeam closed 3 months ago

deathbeam commented 3 months ago

image

taketwo commented 3 months ago

Any hints regarding where require("CopilotChat.integrations.cmp").setup() should be called? As part of cmp setup? Or as part of CopilotChat setup?

deathbeam commented 3 months ago

Any hints regarding where require("CopilotChat.integrations.cmp").setup() should be called? As part of cmp setup? Or as part of CopilotChat setup?

As part of copilot chat setup ideally but it doesnt rly matter when you call it as long as both plugins will get loaded at some point as all this does is registers the source and filetype to nvim-cmp so it do not requires calling setup on either copilot chat or nvim cmp beforehand.

taketwo commented 3 months ago

Got it. I added it as a part of CopilotChat setup with lazy and it works, like so:

    config = function(_, opts)
      require('CopilotChat').setup(opts)
      require('CopilotChat.integrations.cmp').setup()
    end,
GitMurf commented 3 months ago

@deathbeam with the new nvim-cmp integration when you select/accept an item from the cmp list it lists / unhides the buffer.

image

GitMurf commented 3 months ago

You should be able to add something like the following... but keep in mind it still will flash as listed for a split second and then unlist again. So maybe you can find a better way 🤷‍♂️

---Executed after the item was selected.
---@param completion_item lsp.CompletionItem
---@param callback fun(completion_item: lsp.CompletionItem|nil)
function Source:execute(completion_item, callback)
  callback(completion_item)
  -- reset the buffer listed to false
  vim.api.nvim_set_option_value('buflisted', false, { buf = 0 })
end
deathbeam commented 3 months ago

You should be able to add something like the following... but keep in mind it still will flash as listed for a split second and then unlist again. So maybe you can find a better way 🤷‍♂️

---Executed after the item was selected.
---@param completion_item lsp.CompletionItem
---@param callback fun(completion_item: lsp.CompletionItem|nil)
function Source:execute(completion_item, callback)
  callback(completion_item)
  -- reset the buffer listed to false
  vim.api.nvim_set_option_value('buflisted', false, { buf = 0 })
end

Hmm thats pretty annoying. But split second is probably fine, better than it staying there. Not sure if its worth trying to find the root cause as it sounds like nvim-cmp bug, so your workaround should be good enough for now. Do you want to PR it?

GitMurf commented 3 months ago

I will submit a PR.

Also I have some notes that said I researched it a bit and it is an upstream thing from nvim-cmp that is outside of our control... FYI.

GitMurf commented 3 months ago

@deathbeam PR submitted: #346