From 1268abebfcd4591f1eacee89fe3b21e1e700950f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C5=A0tefka?= Date: Sat, 29 Oct 2022 23:16:55 +0200 Subject: [PATCH] Working config --- init.lua | 76 ++++++++++++++++++++++++++++++++++---- plugins/cmp.lua | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+), 8 deletions(-) create mode 100644 plugins/cmp.lua diff --git a/init.lua b/init.lua index bc34760..4512d44 100644 --- a/init.lua +++ b/init.lua @@ -55,9 +55,10 @@ local config = { diagnostics_enabled = true, -- enable diagnostics at start status_diagnostics_enabled = true, -- enable diagnostics in statusline - copilot_no_tab_map = true, - copilot_assume_mapped = true, - copilot_tab_fallback = "", + -- copilot_no_tab_map = true, + -- copilot_assume_mapped = true, + -- copilot_tab_fallback = "", + vimspector_enable_mappings = 'VISUAL_STUDIO', }, }, @@ -266,13 +267,16 @@ local config = { -- quick save -- [""] = { ":w!", desc = "Save File" }, -- change description but the same command }, + i = { + -- [""] = { "copilot#Accept('')", silent = true, expr = true }, + -- [""] = { "copilot#Accept('')" }, + -- Oopen cmp menu + [""] = { "cmp#complete()", silent = true, expr = true }, + }, t = { -- setting a mapping to false will disable it -- [""] = false, }, - i = { - [""] = { "copilot#Accept('')", silent = true, expr = true }, - } }, -- Configure plugins @@ -292,14 +296,43 @@ local config = { -- end, -- }, -- - { + { "folke/todo-comments.nvim", event = "BufRead", config = function() require("todo-comments").setup() end, }, - { "github/copilot.vim" }, + { + "zbirenbaum/copilot.lua", + -- event = "VimEnter", + event = "BufRead", + -- after = "feline.nvim", + config = function() + vim.defer_fn(function() + require("copilot").setup() + end, 100) + end, + }, + -- { "github/copilot.vim" }, + { + "zbirenbaum/copilot-cmp", + -- after = "copilot.lua", + after = { "nvim-cmp", "copilot.lua" }, + config = function() + -- astronvim.add_cmp_source("copilot_cmp") + astronvim.add_cmp_source({ name = "copilot", priority = 1050, keyword_length = -1, max_item_count = 4 }) + require("copilot_cmp").setup { + method = "getCompletionsCycling", + -- method = "getPanelCompletions", + formatters = { + label = require("copilot_cmp.format").format_label_text, + insert_text = require("copilot_cmp.format").format_insert_text, + preview = require("copilot_cmp.format").deindent, + }, + } + end, + }, { "puremourning/vimspector" }, { "lervag/vimtex" }, { "normen/vim-pio" }, @@ -383,6 +416,33 @@ local config = { buffer = 500, path = 250, }, + -- mappings = { + -- [""] = cmp.mapping(function(fallback) + -- if luasnip.expandable() then + -- luasnip.expand() + -- elseif luasnip.expand_or_jumpable() then + -- luasnip.expand_or_jump() + -- elseif has_words_before() then + -- cmp.complete() + -- else + -- fallback() + -- end + -- end, { + -- "i", + -- "s", + -- }), + -- [""] = cmp.mapping(function(fallback) + -- if luasnip.jumpable(-1) then + -- luasnip.jump(-1) + -- else + -- fallback() + -- end + -- end, { + -- "i", + -- "s", + -- }), + -- + -- } }, -- Modify which-key registration (Use this with mappings table in the above.) diff --git a/plugins/cmp.lua b/plugins/cmp.lua new file mode 100644 index 0000000..184e8ac --- /dev/null +++ b/plugins/cmp.lua @@ -0,0 +1,97 @@ +local kind_icons = { + NONE = "", + Array = "", + Boolean = "⊨", + Class = "", + Constructor = "", + Key = "", + Namespace = "", + Null = "NULL", + Number = "#", + Object = "⦿", + Package = "", + Property = "", + Reference = "", + Snippet = "", + String = "𝓐", + TypeParameter = "", + Unit = "", + + Text = "", + Method = "", + Function = "", + Field = "ﰠ", + Variable = "", + Interface = "", + Module = "", + Value = "", + Enum = "", + Keyword = "", + Color = "", + File = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "פּ", + Event = "", + Operator = "", + Copilot = "", +} +local cmp = require("cmp") +-- 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 +return { + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(_, vim_item) + vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + return vim_item + end, + }, + -- completion = { + -- keyword_length = 0, + -- }, + -- mapping = { + -- [""] = vim.schedule_wrap(function(fallback) + -- if cmp.visible() and has_words_before() then + -- cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) + -- else + -- fallback() + -- end + -- end), + -- [''] = cmp.mapping(function(fallback) + -- if vim.fn['vsnip#jumpable'](1) == 1 then + -- feedkey('(vsnip-jump-next)', '') + -- else + -- local copilot_keys = vim.fn['copilot#Accept']() + -- if copilot_keys ~= '' then + -- vim.api.nvim_feedkeys(copilot_keys, 'i', true) + -- else + -- fallback() + -- end + -- end + -- end, { 'i', 's' }), + -- }, +} +-- local cmp = require "cmp" +-- local luasnip = require "luasnip" +-- return { +-- preselect = cmp.PreselectMode.None, +-- mapping = { +-- [""] = cmp.mapping.confirm { select = false }, +-- [""] = cmp.mapping(function(fallback) +-- if luasnip.expandable() then +-- luasnip.expand() +-- elseif luasnip.expand_or_jumpable() then +-- luasnip.expand_or_jump() +-- fallback() +-- end +-- end, { +-- "i", +-- "s", +-- }), +-- }, +-- }