zbirenbaum / copilot-cmp

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

Insert the first word or the first line only #63

Closed xuyangy closed 1 year ago

xuyangy commented 1 year ago

When I type I want a b, assume the first completion item is beautiful dog. If I press Enter, I will accept that as a whole and I will have I want a beautiful dog.

What I want is another mapping, say <C-w> to accept only the first space separated word, i.e. when I press <C-w>, I want to have I want a beautiful. Then I can type cat and I will have I want a beautiful cat.

So basically I want to intercept the completion text, split it by space or by newline and insert the splitted first word or first line into the buffer instead of the whole completion text.

After inserting the first word or newline, the completion suggestions will be updated and hopefully better ones.

MunifTanjim commented 1 year ago

Use copilot.lua directly (instead of via nvim-cmp). It has accept_word and accept_line support.

xuyangy commented 1 year ago

@MunifTanjim I knew that copilot.lua has the accept_word and accept_line support and that's super nice. But I normally use copilot-cmp, mainly for it's syntax highlighting in the preview. It will be super nice if copilot-cmp can support accept_word and accept_line as well.

I though this probably should be supported by nvim-cmp and asked https://github.com/hrsh7th/nvim-cmp/issues/1536. But it seems that this feature is against nvim-cmp disciplines.

pbogut commented 9 months ago

I know its not really feasible to implement it as different shortcut etc, but it would be nice If we could have an copilot-cmp option that would allow user to select if he wants to have suggestions for a line and maybe a word.

It could return up to 3 completion items for every copilot suggestion, like one item would be only word, second would be line, and third would be whole snippet. For me I accept whole snippets very rarely, most of the time I just take first line as its most likely to be useful anyway.

For a test I replaced this line with text = splitText[1], and it seams to be working fine.

@zbirenbaum Is it something that you would consider adding, or would you accept PR for functionality like that?