Skip to content

Commit

Permalink
feat(completion): added more mappings for copilot-lua-cmp (#150)
Browse files Browse the repository at this point in the history
* feat: added mappings for Copilot completion pack

It is very useful to accept Co-pilot suggestions one word at a time or even a whole line.  Copilot offers these features but they have not been exposed.  VS Code, by default uses Ctrl+Right to accept a word.  I've added similar vim-like controls:

* Ctrl+Right/L for accepting a word
* Ctrl+Down/J for accepting a line
* Ctrl+C to dismiss the suggestion

* fix formatting

---------

Co-authored-by: Micah Halter <micah@mehalter.com>
  • Loading branch information
Cthutu and mehalter authored Apr 28, 2023
1 parent 1f4d5b1 commit 872b1e5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lua/astrocommunity/completion/copilot-lua-cmp/copilot-lua-cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ return {
if copilot.is_visible() then copilot.prev() end
end)

opts.mapping["<C-right>"] = cmp.mapping(function()
if copilot.is_visible() then copilot.accept_word() end
end)

opts.mapping["<C-l>"] = cmp.mapping(function()
if copilot.is_visible() then copilot.accept_word() end
end)

opts.mapping["<C-down>"] = cmp.mapping(function()
if copilot.is_visible() then copilot.accept_line() end
end)

opts.mapping["<C-j>"] = cmp.mapping(function()
if copilot.is_visible() then copilot.accept_line() end
end)

opts.mapping["<C-c>"] = cmp.mapping(function()
if copilot.is_visible() then copilot.dismiss() end
end)

return opts
end,
},
Expand Down

2 comments on commit 872b1e5

@JustRayCB
Copy link

Choose a reason for hiding this comment

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

Hi from this commit, I have a conflict when I use copilot and cmp. I can't do <C-j> when I want to go to the next item in the cmp text box. I think it's because of line 54.
Since I added copilot-cmp to my astronvim config using

 { import = "astrocommunity.completion.copilot-lua-cmp" },

When I remove this line, the <C-j> from cmp text box command works fine.
Let me know if you need further information.

@adrianord
Copy link

Choose a reason for hiding this comment

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

@Cthutu @mehalter , I am having the same issue as @JustRayCB , because of these changes I am no longer able to use <C-j> to move to the next item in the cmp box.

Please sign in to comment.