From 7078b97ee9f4ee86197a3023ae1974dbfdf12896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 17 Sep 2023 09:36:22 +0200 Subject: [PATCH] feat(nvim): add copilot-cmp --- modules/programs/nvim/plugins/coding.nix | 17 +++++++++++++++++ modules/programs/nvim/plugins/lua/nvim-cmp.lua | 17 ++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/programs/nvim/plugins/coding.nix b/modules/programs/nvim/plugins/coding.nix index a9e460f..8219567 100644 --- a/modules/programs/nvim/plugins/coding.nix +++ b/modules/programs/nvim/plugins/coding.nix @@ -89,6 +89,23 @@ with builtins; { plugin = friendly-snippets; } { plugin = lspkind-nvim; } { plugin = luasnip; } + { + plugin = copilot-cmp; + opts = { }; + dependencies = [ + { + plugin = copilot-lua; + opts = { + suggestion = { enabled = false; }; + panel = { enabled = false; }; + }; + conf = /* lua */ '' + require("copilot").setup(opts) + vim.cmd("Copilot disable") + ''; + } + ]; + } ]; } { diff --git a/modules/programs/nvim/plugins/lua/nvim-cmp.lua b/modules/programs/nvim/plugins/lua/nvim-cmp.lua index 437c4e9..c48297b 100644 --- a/modules/programs/nvim/plugins/lua/nvim-cmp.lua +++ b/modules/programs/nvim/plugins/lua/nvim-cmp.lua @@ -2,13 +2,23 @@ local cmp = require("cmp") local luasnip = require("luasnip") require("luasnip.loaders.from_vscode").lazy_load() +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 + cmp.setup({ formatting = { format = require("lspkind").cmp_format({ mode = "symbol", -- show only symbol annotations maxwidth = 50, -- prevent the popup from showing more than provided characters ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead - symbol_map = {}, + symbol_map = { + Copilot = "", + }, }), }, snippet = { @@ -24,8 +34,8 @@ cmp.setup({ [""] = cmp.mapping.abort(), [""] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() + if cmp.visible() and has_words_before() then + cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else @@ -46,6 +56,7 @@ cmp.setup({ { name = "async_path", priority = 1 }, { name = "buffer", priority = 1 }, { name = "luasnip", priority = 2 }, + { name = "copilot", group_index = 3 }, { name = "nvim_lsp", priority = 4 }, }, })