zbirenbaum / copilot-cmp

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

Snippet only on one line #10

Closed Ganitzsh closed 11 months ago

Ganitzsh commented 2 years ago

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 commented 2 years ago

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

zbirenbaum commented 2 years ago

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.

Ganitzsh commented 2 years ago

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 commented 2 years ago

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.

Hunter-Thompson commented 2 years ago

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 commented 2 years ago

@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
Ganitzsh commented 2 years ago

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?

Hunter-Thompson commented 2 years ago

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?

zbirenbaum commented 2 years ago

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.

Ganitzsh commented 2 years ago

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

zbirenbaum commented 2 years ago

@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 ]])
Ganitzsh commented 2 years ago

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.

cj commented 2 years ago

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

Ganitzsh commented 1 year ago

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.

zbirenbaum commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

Ganitzsh commented 1 year ago

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

zbirenbaum commented 1 year ago

@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

Ganitzsh commented 1 year ago

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 commented 1 year ago

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.

zbirenbaum commented 1 year ago

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!

Glyphack commented 1 year ago

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.

Ganitzsh commented 1 year ago

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?

zbirenbaum commented 1 year ago

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!

Ganitzsh commented 1 year ago

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.

zbirenbaum commented 1 year ago

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.

Ganitzsh commented 1 year ago

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.

zbirenbaum commented 1 year ago

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.

Ganitzsh commented 1 year ago

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.
zbirenbaum commented 1 year ago

Can you try it with the copilot suggestion module in copilot.lua? It aims to replicate copilot.vim's ghost text. If it works it would make things easier to debug.

If the file is more than just that line, would you mind confirming supports statement with copilot.vim as well when you have a chance?

primeapple commented 1 year ago

I have the same issue here.

On lua it works fine, on Typescript it only shows the completion for your current line :(

Unsure if others still have this issue?

SebastienElet commented 1 year ago

@primeapple same for me since I use this plugin 😞

I have multiline on lua/rust… but not on typescript

superDross commented 1 year ago

Same but with Python, usually only the function declaration line and nothing more.

Edit: this seems to be a specific issue with the plugin as I am getting full completion when using copilot.vim

crazyhulk commented 1 year ago

I have the same issue here on golang.

JulioHC00 commented 1 year ago

Same here for python, using LunarVim

image

benlieb commented 1 year ago

Same in ruby...

Ganitzsh commented 1 year ago

Hey there! @zbirenbaum I've tried everything you've suggested and I get the same problem no matter what. I decided to give it some time to see if the copilot's updates would change anything but it seems like the problem remains. Visual Studio code is still working as expected, I think it's a shame that GitHub is not supporting neovim officially with the Lua API, but ow well. Not sure what you want to do with that issue, maybe you can pin it? It seems it's impacting quite a few people by now. And also maybe you can reach out to GitHub to ask them if they'd like to help who knows 😂

zbirenbaum commented 1 year ago

Hey there! @zbirenbaum I've tried everything you've suggested and I get the same problem no matter what. I decided to give it some time to see if the copilot's updates would change anything but it seems like the problem remains. Visual Studio code is still working as expected, I think it's a shame that GitHub is not supporting neovim officially with the Lua API, but ow well. Not sure what you want to do with that issue, maybe you can pin it? It seems it's impacting quite a few people by now. And also maybe you can reach out to GitHub to ask them if they'd like to help who knows 😂

I can reach out to GitHub tomorrow through the discussions, but unfortunately the last few times I have done so weren't particularly helpful.

I've done a fairly extensive amount of testing on this since I have the issue consistently with a few langs I use for work but it's just an issue with the data copilot returns. The methodology for requesting completions actually got updated recently but the issue has persisted.

Unless someone can confirm that copilot.vim or copilot.lua's vtext doesn't run into this problem I'm afraid it's not on my end. That said, I'll make a post on the GitHub discussions and link this there.

I saw around when this issue was opened you had sent in a ticket and they acknowledged the issue. Has there been any communication since then on that end?

johnf commented 1 year ago

FYI I've been subscribed to the GitHub discussion on this for ages. It has people complaining every day that one-line snippets don't work. It's across many editors, including VSCode. It is almost certainly a Copilot issue. It seems a bit random, and javascript is most impacted. One tip seems to be if you close the curly race to a function, you're more likely to get multiline suggestions for the content. Frustratingly there seems to be no response from GitHub at all. If anyone knows someone that works there, I'd suggest reaching out.

Ganitzsh commented 1 year ago

@zbirenbaum Unfortunately nope, nothing new from GitHub. I guess my configuration is also triggering the broken responses in a way and that's why I don't see issues on VSCode that often.

gleitz commented 1 year ago

If anyone is interested in the underlying reason that changing indentationMode causes single or multi-line suggestions, you can see my findings here. It all has to do with the stop parameter that is sent to the completions endpoint and whether it is one or three newlines.

I'm still curious if anyone knows how to pass parameters like indentationMode into the extension. Or, better, yet, if there is a way to override or patch the extension to always send a stop of three newlines.

primeapple commented 12 months ago

If anyone is interested in the underlying reason that changing indentationMode causes single or multi-line suggestions, you can see my findings here. It all has to do with the stop parameter that is sent to the completions endpoint and whether it is one or three newlines.

I'm still curious if anyone knows how to pass parameters like indentationMode into the extension. Or, better, yet, if there is a way to override or patch the extension to always send a stop of three newlines.

For a short term fix, see here: https://github.com/orgs/community/discussions/40522#discussioncomment-6676897

paulodiovani commented 11 months ago

I have the same issue, using latest versions.

For a short term fix, see here: https://github.com/orgs/community/discussions/40522#discussioncomment-6676897

But that is a fix of VS Code. I couldn't find a why to do the same fo Neovim.

primeapple commented 11 months ago

But that is a fix of VS Code. I couldn't find a why to do the same fo Neovim.

It's literally written there:

I could apply the same hack to copilot.lua plugin for neovim. The file you need to change this in, is in copilot/dist/agent.js

zbirenbaum commented 11 months ago

I have the same issue, using latest versions.

For a short term fix, see here: https://github.com/orgs/community/discussions/40522#discussioncomment-6676897

But that is a fix of VS Code.

I couldn't find a why to do the same fo Neovim.

The agent.js file is an off spec lsp distributed by microsoft/GitHub. Copilot.lua, copilot.vim, and the VsCode extensions just interface with it to provide results. Problems like this aren't actually issues with copilot-cmp and there's nothing I can change about the plug-in to fix them.

I'm working on my own version of agent.js (it's mostly functional but I think it gets rate limited and breaks after a bit) so some of these issues can be fixed in a less hacky way, but it's a large undertaking and won't be fully polished for a bit.

paulodiovani commented 11 months ago

But that is a fix of VS Code. I couldn't find a why to do the same fo Neovim.

It's literally written there:

I could apply the same hack to copilot.lua plugin for neovim. The file you need to change this in, is in copilot/dist/agent.js

Ok, I missed that somehow. I did the change, but the completion stopped working completely...

$ rg --only-matching '.{21}\["(\\n)+"\]' ~/.config/nvim/pack/github/start/copilot.lua/copilot/dist/agent.js
2:n.multiline||(h.stop=["\n\n\n"]

2023-08-22_10-56-33

My completion.lua config:

-- luacheck: globals vim

-- GitHub Copilot config
require('copilot').setup({
  suggestion = { enabled = false, auto_trigger = false },
  panel = { enabled = false },
})

require('copilot_cmp').setup()

-- Set up nvim-cmp.
local cmp = require 'cmp'

---@cast cmp -nil
cmp.setup({
  completion = {
    autocomplete = false,
  },
  snippet = {
    -- REQUIRED - you must specify a snippet engine
    expand = function(args)
      -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
      require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
      -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
      -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
    end,
  },
  window = {
    -- completion = cmp.config.window.bordered(),
    -- documentation = cmp.config.window.bordered(),
  },
  mapping = cmp.mapping.preset.insert({
    ['<C-b>'] = cmp.mapping.scroll_docs(-4),
    ['<C-f>'] = cmp.mapping.scroll_docs(4),
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.abort(),
    -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
  }),
  sources = cmp.config.sources({
    { name = 'nvim_lsp' },
    -- { name = 'vsnip' }, -- For vsnip users.
    { name = 'luasnip' }, -- For luasnip users.
    -- { name = 'ultisnips' }, -- For ultisnips users.
    -- { name = 'snippy' }, -- For snippy users.
    { name = 'copilot' },
  }, {
    { name = 'buffer' },
  })
})

-- Set configuration for specific filetype.
-- cmp.setup.filetype('gitcommit', {
--   sources = cmp.config.sources({
--     -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git).
--     { name = 'git' },
--   }, {
--     { name = 'buffer' },
--   })
-- })

-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
  mapping = cmp.mapping.preset.cmdline(),
  sources = {
    { name = 'buffer' }
  }
})

-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
  mapping = cmp.mapping.preset.cmdline(),
  sources = cmp.config.sources({
    { name = 'path' }
  }, {
    { name = 'cmdline' }
  })
})

-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local lspconfig = require('lspconfig')
local servers = { 'bashls', 'lua_ls', 'solargraph', 'tsserver', 'vimls' }

for _, lsp in ipairs(servers) do
  lspconfig[lsp].setup({
    capabilities = capabilities,

    on_attach = function(_, bufnr)
      -- Enable completion triggered by <c-x><c-o>
      vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
      vim.api.nvim_buf_set_option(bufnr, 'tagfunc', 'v:lua.vim.lsp.tagfunc')

      -- Mappings.
      -- See `:help vim.lsp.*` for documentation on any of the below functions
      local bufopts = { noremap=true, silent=true, buffer=bufnr }
      vim.keymap.set({ 'n', 'i' }, '<Leader><F2>', vim.lsp.buf.rename, bufopts)
      vim.keymap.set({ 'n', 'i' }, '<F12>', vim.lsp.buf.definition, bufopts)
      vim.keymap.set('n', '<Leader><F12>', vim.lsp.buf.type_definition, bufopts)
      vim.keymap.set({ 'n', 'i' }, '<F9>', vim.lsp.buf.hover, bufopts)
      vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
      vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
      vim.keymap.set('n', '<Leader>rn', vim.lsp.buf.rename, bufopts)
      vim.keymap.set('n', '<Leader>ca', vim.lsp.buf.code_action, bufopts)
    end
  })
end

local lspkind = require('lspkind')
cmp.setup {
  formatting = {
    format = lspkind.cmp_format({
      mode = 'symbol_text',
      maxwidth = 50,
      ellipsis_char = '...',
    })
  }
}
Ganitzsh commented 11 months ago

I've been using VS Code now for a month, for what it's worth, it does exactly the same thing now (it wasn't always doing it back then). I also came across a LinkedIn post from GitHub demonstrating how to use copilot in JS and the same was shown (each new line gave a suggestion until the end of the scope)

So my 2 cents here for JS/TS devs out there wondering if it's a normal behaviour, don't bother trying to "fix" it, it ain't broken. @zbirenbaum You mentioned it in the early days of this thread, seems like it's not going to change anytime soon.

zbirenbaum commented 11 months ago

I've been using VS Code now for a month, for what it's worth, it does exactly the same thing now (it wasn't always doing it back then). I also came across a LinkedIn post from GitHub demonstrating how to use copilot in JS and the same was shown (each new line gave a suggestion until the end of the scope)

So my 2 cents here for JS/TS devs out there wondering if it's a normal behaviour, don't bother trying to "fix" it, it ain't broken. @zbirenbaum You mentioned it in the early days of this thread, seems like it's not going to change anytime soon.

Yeah I think this is right. There was a bug for a short period due to changes in cmp where sent multilines weren't appearing but that was fixed a while ago. Anything referenced here that is still a problem isn't fixable in copilot-cmp so i'm going to close this for now.

paulodiovani commented 10 months ago

After a recent update, it has been working... sometimes.

image