copilot-cmp icon indicating copy to clipboard operation
copilot-cmp copied to clipboard

fix pair does not work properly

Open fecet opened this issue 1 year ago • 3 comments

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

fecet avatar Jul 18 '23 07:07 fecet

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 ) ).

naquad avatar Jul 20 '23 12:07 naquad

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.

zbirenbaum avatar Aug 30 '23 19:08 zbirenbaum

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

KurisuNya avatar Nov 26 '23 09:11 KurisuNya