zbirenbaum / copilot-cmp

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

Strip newline characters from suggestions #82

Closed mystilleef closed 10 months ago

mystilleef commented 11 months ago

This is hard to reproduce, but I'm having issues with copilot-cmp sometimes appending a newline character to suggestions, opening a new line, and placing the cursor on it.

For 99% of users, this is not what they expect.

This issue only seems to happen with the copilot-cmp source. Other sources don't append the mysterious newline character and neither does copilot.lua.

I'm assuming stripping newline characters from suggestions may resolve this issue. My <cr> mapping is very simple and presented below.

{
...
  mapping = cmp.mapping.preset.insert({
    ["<cr>"] = cmp.mapping.confirm({behavior = cmp.ConfirmBehavior.Replace, select = true})
  })
...
}
yngwi commented 11 months ago

I was just thinking the same. I have to delete newlines after completions very frequently. My mapping is the same as yours as well.

mystilleef commented 11 months ago

I was just thinking the same. I have to delete newlines after completions very frequently. My mapping is the same as yours as well.

I created a fork that fixes the newline issues and some weird insertion behaviors I was having. All this was through trial and error, as I didn't have much time to familiarize myself with the code base.

It would be best if you used cmp.ConfirmBehavior.Insert. Using cmp.ConfirmBehavior.Replace doesn't work properly anymore because I'm bypassing the formatting copilot-cmp does which gave me insertion bugs when using cmp.select_next_item.

You can test to see if this helps.

https://github.com/mystilleef/copilot-cmp

zbirenbaum commented 10 months ago

I was just thinking the same. I have to delete newlines after completions very frequently. My mapping is the same as yours as well.

I created a fork that fixes the newline issues and some weird insertion behaviors I was having. All this was through trial and error, as I didn't have much time to familiarize myself with the code base.

It would be best if you used cmp.ConfirmBehavior.Insert. Using cmp.ConfirmBehavior.Replace doesn't work properly anymore because I'm bypassing the formatting copilot-cmp does which gave me insertion bugs when using cmp.select_next_item.

You can test to see if this helps.

https://github.com/mystilleef/copilot-cmp

If you make improvements please feel free to PR them. I took a look at your fork and there are a number of changes that could be merged in.

As for the main post: Newlines are already explicitly stripped. There's lots of formatting edge cases that are a pain to deal with since they are dependent on an individual's particular cmp and vim indentation configuration. Any newline inserts are likely not coming from the completion, but some setting in cmp as as the above comment explained.

mystilleef commented 10 months ago

My changes break cmp.ConfirmBehavior.Replace. That's why I didn't create a PR. I'll try to look more into it when I have time.