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

feat: Add nvim-cmp integration #345

Merged
merged 1 commit into from
May 29, 2024
Merged

Conversation

deathbeam
Copy link
Collaborator

image

@deathbeam deathbeam added the enhancement New feature or request label May 28, 2024
@deathbeam deathbeam merged commit c3e8c23 into CopilotC-Nvim:canary May 29, 2024
1 check passed
@taketwo
Copy link
Contributor

taketwo commented May 29, 2024

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

@deathbeam
Copy link
Collaborator Author

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.

@deathbeam deathbeam deleted the nvim-cmp branch May 29, 2024 20:49
@taketwo
Copy link
Contributor

taketwo commented May 30, 2024

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
Copy link
Contributor

GitMurf commented May 30, 2024

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

image

@GitMurf
Copy link
Contributor

GitMurf commented May 30, 2024

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
Copy link
Collaborator Author

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
Copy link
Contributor

GitMurf commented May 30, 2024

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
Copy link
Contributor

GitMurf commented May 30, 2024

@deathbeam PR submitted: #346

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

Successfully merging this pull request may close these issues.

3 participants