diff --git a/nvim/.config/nvim/lua/plugins/coding.lua b/nvim/.config/nvim/lua/plugins/coding.lua index 7efd74f..b55e416 100644 --- a/nvim/.config/nvim/lua/plugins/coding.lua +++ b/nvim/.config/nvim/lua/plugins/coding.lua @@ -14,11 +14,10 @@ return { config = function() require("copilot").setup({ suggestion = { - auto_trigger = true, - debounce = 100, - keymap = { - accept = "", - }, + enabled = false, + }, + panel = { + enabled = false, }, filetypes = { typescriptreact = true, @@ -41,8 +40,12 @@ return { server_opts_overrides = {}, }) end, - dependencies = { - "zbirenbaum/copilot-cmp", - }, + }, + { + "zbirenbaum/copilot-cmp", + after = { "copilot.lua" }, + config = function() + require("copilot_cmp").setup() + end, }, } diff --git a/nvim/.config/nvim/lua/plugins/completion.lua b/nvim/.config/nvim/lua/plugins/completion.lua index e75bffc..b835a3d 100644 --- a/nvim/.config/nvim/lua/plugins/completion.lua +++ b/nvim/.config/nvim/lua/plugins/completion.lua @@ -28,25 +28,44 @@ return { documentation = cmp.config.window.bordered(), }, mapping = cmp.mapping.preset.insert({ + -- https://github.com/zbirenbaum/copilot-cmp?tab=readme-ov-file#tab-completion-configuration-highly-recommended + [""] = vim.schedule_wrap(function(fallback) + local has_words_before = function() + if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then + return false + end + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 + and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") + == nil + end + + if cmp.visible() and has_words_before() then + cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) + else + fallback() + end + end), [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.complete(), [""] = cmp.mapping.abort(), [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }), - sources = cmp.config.sources({ + sources = { { name = "copilot", group_index = 2 }, - { name = "nvim_lsp" }, - { name = "buffer" }, - }), + { name = "nvim_lsp", group_index = 2 }, + { name = "buffer", group_index = 2 }, + }, formatting = { format = lspkind.cmp_format({ - mode = "text_symbol", -- show only symbol annotations + mode = "symbol_text", -- show only symbol annotations maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) -- can also be a function to dynamically calculate max width such as -- maxwidth = function() return math.floor(0.45 * vim.o.columns) end, ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first) show_labelDetails = true, -- show labelDetails in menu. Disabled by default + symbol_map = { Copilot = "" }, -- The function below will be called before any actual modifications from lspkind -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))