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

Snippet only on one line

Open Ganitzsh opened this issue 3 years ago • 16 comments
trafficstars

Hello again!

First a little follow-up on #3, it seems it's working much better now, I'm now using 0.7 and I have the latest version of your plugins.

I'm now facing another issue, but I'm not certain it's related to your plugin specifically. What happens is that the snippets suggested only cover one line: Screenshot 2022-04-21 at 15 35 13

This suggestion from copilot is not displaying more than one line, and I'm sure it's not supposed to be that short, and it doesn't matter if I select it, it remains short.

In comparison, here is a snippet related to typescript in this case: Screenshot 2022-04-21 at 15 36 29

This one generates the expected snippet on multiple lines.

My config is the following:

Packer:

      {
         "zbirenbaum/copilot.lua",
         event = { "VimEnter" },
         config = function()
            vim.defer_fn(function()
               require("copilot").setup()
            end, 100)
         end,
      },
      {
         "zbirenbaum/copilot-cmp",
         after = { "copilot.lua", "nvim-cmp" },
      },

nvim-cmp:

   snippet = {
      expand = function(args)
         require("luasnip").lsp_expand(args.body)
      end,
   },
   formatting = {
      format = function(entry, vim_item)
         local icons = require "plugins.configs.lspkind_icons"
         vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind)

         vim_item.menu = ({
            nvim_lsp = "[LSP]",
            nvim_lua = "[Lua]",
            buffer = "[BUF]",
         })[entry.source.name]

         return vim_item
      end,
   },
   mapping = {
      ["<C-p>"] = cmp.mapping.select_prev_item(),
      ["<C-n>"] = cmp.mapping.select_next_item(),
      ["<C-d>"] = cmp.mapping.scroll_docs(-4),
      ["<C-f>"] = cmp.mapping.scroll_docs(4),
      ["<C-Space>"] = cmp.mapping.complete(),
      ["<C-e>"] = cmp.mapping.close(),
      ["<CR>"] = cmp.mapping.confirm {
         behavior = cmp.ConfirmBehavior.Replace,
         select = true,
      },
      ["<Tab>"] = cmp.mapping(function(fallback)
         if cmp.visible() then
            cmp.select_next_item()
         elseif require("luasnip").expand_or_jumpable() then
            vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "")
         else
            fallback()
         end
      end, { "i", "s" }),
      ["<S-Tab>"] = cmp.mapping(function(fallback)
         if cmp.visible() then
            cmp.select_prev_item()
         elseif require("luasnip").jumpable(-1) then
            vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-jump-prev", true, true, true), "")
         else
            fallback()
         end
      end, { "i", "s" }),
   },
   sources = {
      { name = "copilot" },
      { name = "nvim_lsp" },
      { name = "luasnip" },
      { name = "buffer" },
      { name = "nvim_lua" },
      { name = "path" },
   },

Ganitzsh avatar Apr 21 '22 13:04 Ganitzsh

Okay it seems the issue is coming from copilot: https://github.com/github/feedback/discussions/13303

Ganitzsh avatar Apr 25 '22 08:04 Ganitzsh

Okay it seems the issue is coming from copilot: github/feedback#13303

Yeah copilot is buggy. The actual codex api is better, and I could write something without these issues, but I haven't had a chance to implement a minimal LSP with it, and likely won't for at least a couple weeks. Also, waaaay less people have access to to the actual openai codex beta I think.

I'm still not sure how microsoft managed to make copilot worse than just the vanilla API calls, but I am somewhat impressed.

zbirenbaum avatar Apr 25 '22 08:04 zbirenbaum

I'm still not sure how microsoft managed to make copilot worse than just the vanilla API calls, but I am somewhat impressed.

Having experience with Microsoft APIs, I'm not suprised tbh. Okay so I guess there's nothing to do but wait, right?

Ganitzsh avatar Apr 25 '22 09:04 Ganitzsh

Hello there! So apparently Microsoft has rolled out an update. I see you also updated the copilot.lua. Copilot's suggestions are now back on cmp.

However I still have the same issue: Screenshot 2022-05-20 at 11 06 51

Here you can see my first suggestion is only the first line, I'm starting to doubt Copilot is the problem here. Do you think some plugins I'm using could be the reason? I'm thinking maybe the setting to close brackets and parenthesis automatically might cause this.

Ganitzsh avatar May 20 '22 09:05 Ganitzsh

Hello there! So apparently Microsoft has rolled out an update. I see you also updated the copilot.lua. Copilot's suggestions are now back on cmp.

However I still have the same issue: Screenshot 2022-05-20 at 11 06 51

Here you can see my first suggestion is only the first line, I'm starting to doubt Copilot is the problem here. Do you think some plugins I'm using could be the reason? I'm thinking maybe the setting to close brackets and parenthesis automatically might cause this.

@Ganitzsh, you are right. The autopair plugin is messing with the Cmp.

   -- misc plugins
   ["windwp/nvim-autopairs"] = {
      after = "nvim-cmp",
      config = function()
         require("plugins.configs.others").autopairs()
      end,
   },

Removing the above snippet fixed this issue.

Hunter-Thompson avatar May 20 '22 12:05 Hunter-Thompson

@ganitzsh I managed to make them both work in harmony.

From:

   cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())

To:

   cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = { tex = "" } })

EDIT:

After this it seems to be working, but there are a couple of bugs.

  1. Indentation doesnt work. the first line of the snippet starts at the beginning.
  2. autopair messes up the last pair right after the suggestion

Hunter-Thompson avatar May 20 '22 12:05 Hunter-Thompson

No luck here, just tried to disable autopairs and still getting incomplete suggestions. I'll try to learn a bit more about coding plugins for neovim and try to debug this properly. I'm using nvchad, so I'll have to go through most of the plugins to find the culprit.

Thanks @Hunter-Thompson for this, I think this could be added to the README in a new FAQ section maybe?

Ganitzsh avatar May 23 '22 07:05 Ganitzsh

I use nvchad also, if you find a solution do add it here : )

   autopairs.setup {
      fast_wrap = {},
      disable_filetype = { "TelescopePrompt", "vim" },
   }

I wonder if CMP is its own filetype? Autopair has a disable filetype option which works well with TelescopePrompt. Maybe something can be done here?

Hunter-Thompson avatar May 23 '22 11:05 Hunter-Thompson

Oh my, both of you are NvChad users? Of course its another repo I maintain causing problems with my own repo :laughing:

@Ganitzsh completely disabling autopairs didn't work? I was going to look into @Hunter-Thompson's filetype idea but if disabling autopairs didn't fix the problem adding an exclusion won't either.

zbirenbaum avatar May 25 '22 16:05 zbirenbaum

@zbirenbaum yep didn't work, removed and cleaned but still happening

Ganitzsh avatar May 25 '22 17:05 Ganitzsh

@Ganitzsh can you try using the following cmp config and see if it fixes the issue? I did some looking around but it's hard to figure out if this is a config issue or a plugin issue. You may need to make some small changes for the lspkind stuff but it should be fairly managable. If you are just using icons and don't have lspkind installed, you can just install lspkind and change the local lspkind to be require("lspkind"):

local present, cmp = pcall(require, "cmp")

local lspkind = require("custom.plugins.completion_plugins.cmp_configs.lspkind")
if not present then
  return
end

vim.opt.completeopt = "menuone,noselect"
cmp.setup({
  snippet = {
    expand = function(args)
      require("luasnip").lsp_expand(args.body)
    end,
  },
  style = {
    winhighlight = "NormalFloat:NormalFloat,FloatBorder:FloatBorder",
  },
  formatting = {
    format = lspkind.cmp_format({ with_text = false, maxwidth = 50 }),
  },
  window = {
    completion = {
      border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
      scrollbar = "║",
      winhighlight = 'Normal:CmpMenu,FloatBorder:CmpMenuBorder,CursorLine:CmpSelection,Search:None',
      autocomplete = {
        require("cmp.types").cmp.TriggerEvent.InsertEnter,
        require("cmp.types").cmp.TriggerEvent.TextChanged,
      },
    },
    documentation = {
      border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
      winhighlight = "NormalFloat:NormalFloat,FloatBorder:FloatBorder",
      scrollbar = "║",
    },
  },
  mapping = {
    ["<PageUp>"] = function()
      for _ = 1, 10 do
        cmp.mapping.select_prev_item()(nil)
      end
    end,
    ["<PageDown>"] = function()
      for _ = 1, 10 do
        cmp.mapping.select_next_item()(nil)
      end
    end,
    ["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
    ["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
    ["<C-d>"] = cmp.mapping.scroll_docs(-4),
    ["<C-f>"] = cmp.mapping.scroll_docs(4),
    ["<C-s>"] = cmp.mapping.complete({
        config = {
          sources = {
            { name = 'copilot' },
          }
        }
      }),
    ["<C-e>"] = cmp.mapping.close(),
    ["<CR>"] = cmp.mapping.confirm({
      behavior = cmp.ConfirmBehavior.Replace,
      select = false,
    }),
    ["<Tab>"] = function(fallback)
      if cmp.visible() then
        cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
      else
        fallback()
      end
    end,
    ["<S-Tab>"] = function(fallback)
      if cmp.visible() then
        cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
      else
        fallback()
      end
    end,
  },
  experimental = {
    native_menu = false,
    ghost_text = true,
  },
  sources = {
    { name = "copilot", group_index = 2 },
    { name = "nvim_lsp", group_index = 2 },
    { name = "path", group_index = 2 },
    { name = 'orgmode', group_index = 2 },
    { name = 'neorg', group_index = 2 },
    { name = "nvim_lua", group_index = 2 },
    -- { name = "luasnip", group_index = 2 },
    -- { name = "buffer", group_index = 5 },
  },
  sorting = {
    comparators = {
      cmp.config.compare.recently_used,
      cmp.config.compare.offset,
      cmp.config.compare.score,
      cmp.config.compare.sort_text,
      cmp.config.compare.length,
      cmp.config.compare.order,
    },
  },
  preselect = cmp.PreselectMode.Item,
})

--set max height of items
vim.cmd([[ set pumheight=6 ]])

zbirenbaum avatar May 26 '22 18:05 zbirenbaum

Hey there! Sorry for the delay, I confirm it's now working for the most part. I noticed most of the issues I have are with TypeScript, but I'll keep monitoring. This one's resolved, thanks.

Ganitzsh avatar Jun 21 '22 08:06 Ganitzsh

@zbirenbaum I seem to be having the same issue with the latest version of NvChad image

cj avatar Jul 22 '22 19:07 cj

I have no issues with other languages, but it still happens when I use TypeScript. Not sure what's wrong there, if it can help.

It worked for a bit again like 2 weeks ago for a day, then it stopped.

Ganitzsh avatar Aug 17 '22 18:08 Ganitzsh

Yeah I noticed it in JS and TS a day ago. Doesn't seem to happen for anything else though. I'll check to see if it's just copilot results being one line or if it's a bug on the plugin end

zbirenbaum avatar Aug 17 '22 18:08 zbirenbaum

Ok a couple updates here. I have confirmed that the issue is not in my handling, but in the response itself. This may be fixed in the most recent version of copilot, but I am currently trying to reverse engineer what the changes were, as updating the copilot js code caused a massive series of unhandled exceptions and got my CPU running as hot as a stress test. Once I figure out what has happened, I can update, and hopefully this will be solved.

zbirenbaum avatar Aug 20 '22 21:08 zbirenbaum

I haven't seen this problem for a bit. Is anyone still having it or is this safe to close?

zbirenbaum avatar Sep 30 '22 00:09 zbirenbaum

Okay I subscribed to test but I still have the issue with JS/TS:

Screenshot 2022-09-30 at 15 42 41

No problem on single lined suggestions: Screenshot 2022-09-30 at 15 48 59

It's a fresh install, I removed everything back when Copilot started to be a paid service.

No issues with Lua:

Screenshot 2022-09-30 at 15 46 11

My guess is that some characters are breaking the formatting. The problem is not only n the preview, but when I select the snippet too.

UPDATE: I have the exact same issue in VS Code. I have to say, at this point I have no idea what's happening. On macOS where does the server gets installed? I'm suspecting I have an old server running somehow

Ganitzsh avatar Sep 30 '22 13:09 Ganitzsh

@Ganitzsh Microsoft has pushed versions of copilot that cause major problems at multiple points, so I manually include and update the copilot lsp myself after testing it. For a while I debated autoupdating, but the issues were too frequent. If you are also having the same issue on VSCode, it is likely not fixed in any version, as VSCode includes its lsp inside of the extension itself.

The vscode extension should be located in ~/.vscode/extensions, their lsp version should be in there. If you want to try a different copilot version, go to wherever packer installs copilot.lua, and replace the agent.js file in copilot/dist with a different one. ver_update.sh in the project root will automatically pull the latest version from copilot.vim and replace the current one, so you can try using that to test it. Since I can't reliably reproduce this, I can't really do it myself.

This is almost certainly not an issue with copilot.lua, but with the copilot lsp itself.... I'm tempted to close this since it's upstream, but I'll leave it up to you @Ganitzsh

zbirenbaum avatar Sep 30 '22 21:09 zbirenbaum

Thanks for all this, yeah we can close it, it's definitely not an issue of this plug-in.

It's very random at this point and it happened that it worked for a week then stopped again.

Ganitzsh avatar Oct 01 '22 10:10 Ganitzsh

FYI I opened a ticket with the Support team, they confirmed that it was a currently known issue and it is being worked on internally. No ETA can be given, as it seems to be a problem inherent to the model which is biased in some languages. I'll just throw another update here as soon as the issue is resolved, hopefully sooner than later.

Ganitzsh avatar Oct 04 '22 19:10 Ganitzsh

FYI I opened a ticket with the Support team, they confirmed that it was a currently known issue and it is being worked on internally. No ETA can be given, as it seems to be a problem inherent to the model which is biased in some languages. I'll just throw another update here as soon as the issue is resolved, hopefully sooner than later.

Ahh that’s unfortunate, but I did think it was likely to be the case. Thanks for letting me know and keeping track of the issue!

zbirenbaum avatar Oct 05 '22 21:10 zbirenbaum

Hey I was experiencing this issue for a couple of days thanks for all the info here. I'm having this issue with Python but works fine on Lua.

Glyphack avatar Oct 06 '22 06:10 Glyphack

Here we go again! @zbirenbaum The GitHub support came back to me and gave me a temporary fix for VS Code, where they suggested me to add the following configuration:

"github.copilot.advanced": {
    "indentationMode": {
      "javascript": "client",
      "typescript": "client",
    }
  }

I confirm it works, but I'm not sure how I can replicate it with copilot-cmp, I went through the README again but couldn't find the equivalent for advanced.indentationMode.

Can you add support for this or is it specific to the VS Code plugin?

Ganitzsh avatar Oct 11 '22 07:10 Ganitzsh

Here we go again! @zbirenbaum The GitHub support came back to me and gave me a temporary fix for VS Code, where they suggested me to add the following configuration:

"github.copilot.advanced": {
    "indentationMode": {
      "javascript": "client",
      "typescript": "client",
    }
  }

I confirm it works, but I'm not sure how I can replicate it with copilot-cmp, I went through the README again but couldn't find the equivalent for advanced.indentationMode.

Can you add support for this or is it specific to the VS Code plugin?

Some of those types of options are available from outside vscode, It depends on if they implemented them in the lsp or the vscode client extension. Ill take a look tomorrow, thanks for the info, that’s super helpful!

zbirenbaum avatar Oct 11 '22 07:10 zbirenbaum

Alright, thanks! In the meantime I asked if they could give me a Vim equivalent, hopefully if it's not possible they might implement it, if they have a fix too I'll let you know here. It might make things easier to implement it.

Ganitzsh avatar Oct 11 '22 07:10 Ganitzsh

I just pushed a fix. @Ganitzsh Let me know how it works for you. I found the advanced.indentationMethod field inside the lsp, but I couldn't get it to do anything whatsoever. I did find some code inside that actually handles the indentation within the lsp after receiving the completion. My life would be a million times easier if they would just release the damn source code, it's honestly ridiculous that they don't since the valuable part of copilot is the model itself. If you are in contact with them again, feel free to let them know I'd be happy to write a fix and dedicated vim support.

Indentation is by far the most frustrating part of working with copilot and cmp. I need to make an issue in cmp about the execution functions now triggering at the wrong times after a recent update, which broke a bunch of stuff, including possibly this, but it looks like its probably on the copilot end this time.

zbirenbaum avatar Oct 11 '22 23:10 zbirenbaum

Thanks for the quick reaction @zbirenbaum unfortunately it doesn't seem to work, still doesn't show multi-line suggestions, also now going through copilot's suggestions throws this error: Screenshot 2022-10-12 at 10 48 08

I updated everything, including cmp itself, not sure what caused it.

The support told me they will try to come back to me with a fix for vim, hopefully they deliver.

Ganitzsh avatar Oct 12 '22 08:10 Ganitzsh

Thanks for the quick reaction @zbirenbaum unfortunately it doesn't seem to work, still doesn't show multi-line suggestions, also now going through copilot's suggestions throws this error:

Screenshot 2022-10-12 at 10 48 08

I updated everything, including cmp itself, not sure what caused it.

The support told me they will try to come back to me with a fix for vim, hopefully they deliver.

Sorry about that, there was a brief period right around when you posted that one of the options was broken after I did a really large refactor and cleanup to account for some of the cmp changes and be a bit more defensive against copilot's formatting. That option has since been removed as it was a hacky solution for a problem that doesn't appear to exist anymore and shouldn't be necessary.

It should be working since this morning, could you try syncing? I'm getting multi line completions well formatted on the current version.

Realistically I need to implement unit tests for this repo. Since I recently got some huge help maintaining copilot.lua, once work slows down a little I'll take a crack at writing up tests here.

zbirenbaum avatar Oct 13 '22 08:10 zbirenbaum

No worries, just updated and the error is gone.

Unfortunately I still have the issue, this is VS Code (with the fix mentioned yesterday):

Screenshot 2022-10-13 at 10 44 39

And this is nvim with the latest version of copilot.lua and copilot-cmp:

Screenshot 2022-10-13 at 10 45 05

The support got back to me with this about vim:

With plain Vim (not Neovim), this was caused by a change to the brand new ghost text API.
The latest version of Copilot.vim should fix it for you.

Ganitzsh avatar Oct 13 '22 08:10 Ganitzsh