From 30a074d5f3bd7cc8b7ae9a2281437f98776efe79 Mon Sep 17 00:00:00 2001 From: aleidk Date: Sun, 1 Oct 2023 17:23:04 -0300 Subject: [PATCH] update completition configuration --- config/alacritty/alacritty.yml | 4 +- config/nvim/init.lua | 1 - config/nvim/lua/aleidk/IDE/completion.lua | 44 ------------ config/nvim/lua/aleidk/IDE/init.lua | 1 - config/nvim/lua/aleidk/constants.lua | 2 +- .../nvim/lua/aleidk/plugins/colorscheme.lua | 10 ++- config/nvim/lua/aleidk/plugins/completion.lua | 72 +++++++++++++++++++ config/nvim/lua/aleidk/plugins/luasnip.lua | 27 +++++++ 8 files changed, 111 insertions(+), 50 deletions(-) delete mode 100644 config/nvim/lua/aleidk/IDE/completion.lua delete mode 100644 config/nvim/lua/aleidk/IDE/init.lua create mode 100644 config/nvim/lua/aleidk/plugins/completion.lua create mode 100644 config/nvim/lua/aleidk/plugins/luasnip.lua diff --git a/config/alacritty/alacritty.yml b/config/alacritty/alacritty.yml index 19759f3..4ff033b 100644 --- a/config/alacritty/alacritty.yml +++ b/config/alacritty/alacritty.yml @@ -14,8 +14,8 @@ import: # Any items in the `env` entry below will be added as # environment variables. Some entries may override variables # set by alacritty itself. -#env: -# TERM variable +env: + TERM: xterm-256color # # This value is used to set the `$TERM` environment variable for # each instance of Alacritty. If it is not present, alacritty will diff --git a/config/nvim/init.lua b/config/nvim/init.lua index 4cbee4e..a9b3bcc 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -24,4 +24,3 @@ require("lazy").setup("aleidk.plugins") require("aleidk.keymaps") require("aleidk.autocmds") -require("aleidk.IDE") diff --git a/config/nvim/lua/aleidk/IDE/completion.lua b/config/nvim/lua/aleidk/IDE/completion.lua deleted file mode 100644 index 9bed8cd..0000000 --- a/config/nvim/lua/aleidk/IDE/completion.lua +++ /dev/null @@ -1,44 +0,0 @@ --- nvim-cmp setup -local cmp = require("cmp") -local luasnip = require("luasnip") - -luasnip.config.setup({}) - -cmp.setup({ - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete({}), - [""] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { "i", "s" }), - }), - sources = { - { name = "nvim_lsp" }, - { name = "luasnip" }, - }, -}) diff --git a/config/nvim/lua/aleidk/IDE/init.lua b/config/nvim/lua/aleidk/IDE/init.lua deleted file mode 100644 index 4a64e65..0000000 --- a/config/nvim/lua/aleidk/IDE/init.lua +++ /dev/null @@ -1 +0,0 @@ -require("aleidk.IDE.completion") diff --git a/config/nvim/lua/aleidk/constants.lua b/config/nvim/lua/aleidk/constants.lua index ba67ee5..0d9495c 100644 --- a/config/nvim/lua/aleidk/constants.lua +++ b/config/nvim/lua/aleidk/constants.lua @@ -50,7 +50,7 @@ return { Package = " ", Property = " ", Reference = " ", - Snippet = " ", + Snippet = " ", String = " ", Struct = " ", Text = " ", diff --git a/config/nvim/lua/aleidk/plugins/colorscheme.lua b/config/nvim/lua/aleidk/plugins/colorscheme.lua index d69819e..412d3c8 100644 --- a/config/nvim/lua/aleidk/plugins/colorscheme.lua +++ b/config/nvim/lua/aleidk/plugins/colorscheme.lua @@ -1,4 +1,4 @@ -return { +return { -- Change colors.none if not using a transparent background "catppuccin/nvim", priority = 1000, lazy = false, @@ -7,7 +7,15 @@ return { transparent_background = true, integrations = { fidget = true, + cmp = true, }, + custom_highlights = function(colors) + return { + Pmenu = { bg = colors.none, blend = 0 }, + FloatBorder = { bg = colors.none }, + CmpItemMenu = { fg = colors.text, bg = colors.none }, + } + end, }, config = function(_, opts) diff --git a/config/nvim/lua/aleidk/plugins/completion.lua b/config/nvim/lua/aleidk/plugins/completion.lua new file mode 100644 index 0000000..0f5652c --- /dev/null +++ b/config/nvim/lua/aleidk/plugins/completion.lua @@ -0,0 +1,72 @@ +return { + "hrsh7th/nvim-cmp", + version = false, -- last release is way too old + event = "InsertEnter", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "saadparwaiz1/cmp_luasnip", + }, + opts = function() + vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true }) + local cmp = require("cmp") + local defaults = require("cmp.config.default")() + local window_opts = { + border = "rounded", + side_padding = 1, + winhighlight = "Normal:Pmenu,FloatBorder:FloatBorder,CursorLine:PmenuSel,Search:None", + } + return { + completion = { + completeopt = "menu,menuone,noinsert", + }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), + [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), + [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), + [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), + [""] = 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. + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }), + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(_, item) + local icons = require("aleidk.constants").icons.kinds + if icons[item.kind] then + item.kind = icons[item.kind] .. item.kind + end + return item + end, + }, + window = { + completion = cmp.config.window.bordered(window_opts), + documentation = cmp.config.window.bordered(window_opts), + }, + experimental = { + ghost_text = { + hl_group = "CmpGhostText", + }, + }, + sorting = defaults.sorting, + } + end, +} diff --git a/config/nvim/lua/aleidk/plugins/luasnip.lua b/config/nvim/lua/aleidk/plugins/luasnip.lua new file mode 100644 index 0000000..bf6d8ef --- /dev/null +++ b/config/nvim/lua/aleidk/plugins/luasnip.lua @@ -0,0 +1,27 @@ +return { + "L3MON4D3/LuaSnip", + dependencies = { + "rafamadriz/friendly-snippets", + config = function() + require("luasnip.loaders.from_vscode").lazy_load() + end, + }, + opts = { + history = true, + delete_check_events = "TextChanged", + }, + -- stylua: ignore + keys = { + { + "", + function() + return require("luasnip").jumpable(1) and "luasnip-jump-next" or "" + end, + expr = true, + silent = true, + mode = "i", + }, + { "", function() require("luasnip").jump(1) end, mode = "s" }, + { "", function() require("luasnip").jump(-1) end, mode = { "i", "s" } }, + }, +}