zbirenbaum / copilot-cmp

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

clear previous suggestions #20

Closed dklymenk closed 1 year ago

dklymenk commented 1 year ago

Hello.

I noticed that suggestions are cached per line per buffer pretty much indefinitely, which makes for a pretty confusing experience sometimes as this cache is not cleared when the context changes and the options are not sorted by relevancy. DeepinScreenshot_select-area_20220827154601

I would assume that such behaviour is useful for debugging. If that is so, we can probably add a toggle for this feature that is exposed via config.

Either way, the PR makes it so on every getCompletionsCycling run the existing_matches is cleared. I did not notice any unwanted behaviour with change during my testing.

zbirenbaum commented 1 year ago

The cached lines submitted are not included if they aren't text matched with the label unless you have some really strange comparators set. The reason for this was a bug in cmp's caching where if you type a part of a completion, backspace a bit, and then type a letter again, the copilot completion would just disappear until it pings a server the next time.

I ran into some pretty severe bugs each time I tried to remove the caching. Maybe I could shift it to a system where it returns cached completions only until cursor changes lines and then clears it.

dklymenk commented 1 year ago

I am actually not using comparators at all. I think for me the suggestions are displayed in the order the cmp sources are defined in: copilot > nvim_lsp > path > luasnip and so on. So my copilot results are always on top, which has worked ok for me so far.

I don't think I have the issue you are describing with backspace and retyping of the letter. Here is an example of how it works with my fix.

https://user-images.githubusercontent.com/64093836/187072271-3ec0d627-b237-43b3-b0ce-a52b5c173149.mp4

Could you please give my change a try and see if you still have those issues you have described.

Thanks.

zbirenbaum commented 1 year ago

I am actually not using comparators at all. I think for me the suggestions are displayed in the order the cmp sources are defined in: copilot > nvim_lsp > path > luasnip and so on. So my copilot results are always on top, which has worked ok for me so far.

I don't think I have the issue you are describing with backspace and retyping of the letter. Here is an example of how it works with my fix.

https://user-images.githubusercontent.com/64093836/187072271-3ec0d627-b237-43b3-b0ce-a52b5c173149.mp4

Could you please give my change a try and see if you still have those issues you have described.

Thanks.

The default cmp comparators aren't necessarily great, and if you are having issues with poor matches being ranked first, I would look into that. I'll give this a try in a bit though.

zbirenbaum commented 1 year ago

I forgot to merge this before doing a bunch of big changes, but to be honest for what you are doing here this isn't the best solution. I tested out removing the caching and it seems cmp has fixed it on their end so it is no longer necessary. Can you close this PR, update, and then submit a new PR using the following code?

https://gist.githubusercontent.com/zbirenbaum/48b153de46e2e5849478ffd4471338f2/raw/7ee343fb4c5614ba276bedee38f0f8ee2e51c3c0/completion_functions.lua

I can also give you a patch you can apply, but I think just running wget on that url from the directory completion_functions.lua is in would be easier.

zbirenbaum commented 1 year ago

Looks perfect, I'll merge now

dklymenk commented 1 year ago

It looks perfect because it's yours :D

I am currently on a road and have a very bad connection, so I wasn't able to validate that the change works. I would advice to double check if everything is functional on master.

Thanks.