zbirenbaum / copilot-cmp

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

fix pair does not work properly #81

Open fecet opened 11 months ago

fecet commented 11 months ago

I tried the example mentioned at README, but the behavior seems not properly: cop

I am using ConfirmBehavior.Replace and default config for copilot-cmp

naquad commented 11 months ago

From what I see in the code the whole fix pair thing is broken, unfortunately :( It doesn't know about ', ", language-specific pairs (i.e. Python's """ / '''' or Lua's [===[). Also, it does not account for the inline comments or text in quotes (hence if there's an unclosed pair character in the string, sort of if ("A sad smile (" == you will get an extra ) ).

zbirenbaum commented 10 months ago

From what I see in the code the whole fix pair thing is broken, unfortunately :( It doesn't know about ', ", language-specific pairs (i.e. Python's """ / '''' or Lua's [===[). Also, it does not account for the inline comments or text in quotes (hence if there's an unclosed pair character in the string, sort of if ("A sad smile (" == you will get an extra ) ).

This kind of hits the nail on the head. Fix pairs exists to address a problem that really should't be this plugin's responsibility. Keeping up with every language's unique pair strings isn't really reasonable. I would accept PRs for something like this but haven't seen any. I'm debating taking it out completely and maybe including a config option to allow people to inject their own handlers for fix pairs type functionality, but I had extensive support for this type of thing in the past, but it didn't seem like people were too interested in using it since there were still numerous issues regarding things that should be addressed using it.

KurisuNya commented 7 months ago

From what I see in the code the whole fix pair thing is broken, unfortunately :( It doesn't know about ', ", language-specific pairs (i.e. Python's """ / '''' or Lua's [===[). Also, it does not account for the inline comments or text in quotes (hence if there's an unclosed pair character in the string, sort of if ("A sad smile (" == you will get an extra ) ).

This kind of hits the nail on the head. Fix pairs exists to address a problem that really should't be this plugin's responsibility. Keeping up with every language's unique pair strings isn't really reasonable. I would accept PRs for something like this but haven't seen any. I'm debating taking it out completely and maybe including a config option to allow people to inject their own handlers for fix pairs type functionality, but I had extensive support for this type of thing in the past, but it didn't seem like people were too interested in using it since there were still numerous issues regarding things that should be addressed using it.

Why not just count the paired chars, and add the text after cursor if the count is incorrect. Like this:

if not pattern.check_pairs(text) then
  if pattern.check_pairs(text .. ctx.cursor_after_line) then
    text = text .. ctx.cursor_after_line
  end
end