diff --git a/lua/install-plugins.lua b/lua/install-plugins.lua index 650793f..042e6f6 100644 --- a/lua/install-plugins.lua +++ b/lua/install-plugins.lua @@ -325,6 +325,20 @@ return require('packer').startup(function(use) require('plugins.typescript-nvim') end, } + use { + 'zbirenbaum/copilot.lua', + cmd = 'Copilot', + event = 'InsertEnter', + config = function() + require('plugins.copilot') + end, + } + use { + 'zbirenbaum/copilot-cmp', + config = function () + require('copilot_cmp').setup() + end + } use 'ziglang/zig.vim' use { 'akinsho/bufferline.nvim', diff --git a/lua/plugins/copilot.lua b/lua/plugins/copilot.lua new file mode 100644 index 0000000..4a371e5 --- /dev/null +++ b/lua/plugins/copilot.lua @@ -0,0 +1,4 @@ +require('copilot').setup({ + suggestion = { enabled = false }, + panel = { enabled = false }, +}); diff --git a/lua/plugins/nvim-cmp.lua b/lua/plugins/nvim-cmp.lua index daf6d78..d80680f 100644 --- a/lua/plugins/nvim-cmp.lua +++ b/lua/plugins/nvim-cmp.lua @@ -1,6 +1,12 @@ local cmp = require('cmp') local lspkind = require('lspkind') +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({ experimental = { ghost_text = true }, snippet = { @@ -23,8 +29,8 @@ cmp.setup({ [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. [""] = 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 }) else fallback() end @@ -48,6 +54,7 @@ cmp.setup({ priority = 100, group_index = 1, }, + { name = "copilot", group_index = 2 }, { name = 'buffer', priority = 80, @@ -64,8 +71,21 @@ cmp.setup({ -- { name = 'snippy' }, -- For snippy users. }), sorting = { + priority_weight = 2, comparators = { - function(...) return require('cmp_buffer'):compare_locality(...) end, + require("copilot_cmp.comparators").prioritize, + require("copilot_cmp.comparators").score, + -- Below is the default comparitor list and order for nvim-cmp + cmp.config.compare.offset, + -- cmp.config.compare.scopes, --this is commented in nvim-cmp too + cmp.config.compare.exact, + cmp.config.compare.score, + cmp.config.compare.recently_used, + cmp.config.compare.locality, + cmp.config.compare.kind, + cmp.config.compare.sort_text, + cmp.config.compare.length, + cmp.config.compare.order,function(...) return require('cmp_buffer'):compare_locality(...) end, } }, formatting = { @@ -73,6 +93,7 @@ cmp.setup({ mode = 'symbol_text', maxwidth = 50, ellipsis_char = '…', + symbol_map = { Copilot = '🤖' }, }) } })