From c897b5729526f91748091e5fbbe8a9ef60f406e6 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Thu, 16 Sep 2021 22:54:40 +0200 Subject: [PATCH] Feat: moving forward but no completion yep --- nvim/.config/nvim/init.lua | 2 +- nvim/.config/nvim/lua/comp.lua | 78 ---------------------- nvim/.config/nvim/lua/completion.lua | 98 ++++++++++++++++++++++++++++ nvim/.config/nvim/lua/plugins.lua | 34 ++++++++-- nvim/.config/nvim/lua/settings.lua | 3 +- 5 files changed, 127 insertions(+), 88 deletions(-) delete mode 100644 nvim/.config/nvim/lua/comp.lua create mode 100644 nvim/.config/nvim/lua/completion.lua diff --git a/nvim/.config/nvim/init.lua b/nvim/.config/nvim/init.lua index 18b0952..8eb9c0c 100644 --- a/nvim/.config/nvim/init.lua +++ b/nvim/.config/nvim/init.lua @@ -2,4 +2,4 @@ require('plugins') require('settings') require('mappings') --- require('lualine') +require('lsp') diff --git a/nvim/.config/nvim/lua/comp.lua b/nvim/.config/nvim/lua/comp.lua deleted file mode 100644 index bbec87b..0000000 --- a/nvim/.config/nvim/lua/comp.lua +++ /dev/null @@ -1,78 +0,0 @@ --- Configuration for nvim-compe - -local utils = require('utils') - -vim.cmd [[set shortmess+=c]] -utils.opt('o', 'completeopt', 'menuone,noselect') - -require'compe'.setup { - enabled = true; - autocomplete = true; - debug = false; - min_length = 1; - preselect = 'enable'; - throttle_time = 80; - source_timeout = 200; - incomplete_delay = 400; - allow_prefix_unmatch = false; - max_abbr_width = 1000; - max_kind_width = 1000; - max_menu_width = 1000000; - documentation = true; - - - source = { - path = true; - buffer = true; - calc = false; - vsnip = true; - nvim_lsp = true; - nvim_lua = false; - spell = true; - tags = true; - snippets_nvim = false; - treesitter = true; - }; -} - -local t = function(str) - return vim.api.nvim_replace_termcodes(str, true, true, true) -end - -local check_back_space = function() - local col = vim.fn.col('.') - 1 - if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then - return true - else - return false - end -end - --- Use (s-)tab to: ---- move to prev/next item in completion menuone ---- jump to prev/next snippet's placeholder -_G.tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif vim.fn.call("vsnip#available", {1}) == 1 then - return t "(vsnip-expand-or-jump)" - elseif check_back_space() then - return t "" - else - return vim.fn['compe#complete']() - end -end -_G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then - return t "(vsnip-jump-prev)" - else - return t "" - end -end - -utils.map("i", "", "v:lua.tab_complete()", {expr = true}) -utils.map("s", "", "v:lua.tab_complete()", {expr = true}) -utils.map("i", "", "v:lua.s_tab_complete()", {expr = true}) -utils.map("s", "", "v:lua.s_tab_complete()", {expr = true}) diff --git a/nvim/.config/nvim/lua/completion.lua b/nvim/.config/nvim/lua/completion.lua new file mode 100644 index 0000000..26ff989 --- /dev/null +++ b/nvim/.config/nvim/lua/completion.lua @@ -0,0 +1,98 @@ +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_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil +end + +local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) +end + +local lsp_symbols = { + Text = "  (Text) ", + Method = "  (Method)", + Function = "  (Function)", + Constructor = "  (Constructor)", + Field = " ﴲ (Field)", + Variable = "[] (Variable)", + Class = "  (Class)", + Interface = " ﰮ (Interface)", + Module = "  (Module)", + Property = " 襁 (Property)", + Unit = "  (Unit)", + Value = "  (Value)", + Enum = " 練 (Enum)", + Keyword = "  (Keyword)", + Snippet = "  (Snippet)", + Color = "  (Color)", + File = "  (File)", + Reference = "  (Reference)", + Folder = "  (Folder)", + EnumMember = "  (EnumMember)", + Constant = " ﲀ (Constant)", + Struct = " ﳤ (Struct)", + Event = "  (Event)", + Operator = "  (Operator)", + TypeParameter = "  (TypeParameter)", +} + +local cmp = require'cmp' +cmp.setup{ + completion = { + completeopt = "menuone,noinsert,noselect", + }, + formatting = { + format = function(entry, vim_item) + -- fancy icons and a name of kind + vim_item.kind = lsp_symbols[vim_item.kind] + -- set a name for each source + vim_item.menu = ({ + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + vsnip = "[vSnip]", + path = "[Path]", + spell = "[Spell]", + })[entry.source.name] + return vim_item + end, + }, + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + mapping = { + -- [""] = cmp.mapping.confirm({select = true, behavior = cmp.ConfirmBehavior.Replace}), + [""] = cmp.mapping.confirm({select = true, behavior = cmp.ConfirmBehavior.Insert}), + [""] = cmp.mapping(function(fallback) + if vim.fn.pumvisible() == 1 then + feedkey("", "n") + elseif vim.fn["vsnip#available"]() == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + end + end, { "i", "s" }), + + [""] = cmp.mapping(function() + if vim.fn.pumvisible() == 1 then + feedkey("", "n") + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s" }), + }, + source = { + { name = 'buffer' }, + { name = 'vsnip' }, + { name = 'path' }, + { name = 'spell' }, + } +} + +vim.cmd [[autocmd FileType TelescopePrompt lua require('cmp').setup.buffer { enabled = false }]] +vim.g.vsnip_snippet_dir = '~/.config/nvim/vsnips' diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index afcf8cb..a6ca439 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -1,3 +1,6 @@ +-- Only required if you have packer configured as `opt` +vim.cmd [[packadd packer.nvim]] + return require('packer').startup(function() use 'morhetz/gruvbox' @@ -46,20 +49,37 @@ return require('packer').startup(function() use 'tpope/vim-repeat' use 'neovim/nvim-lspconfig' - use 'hrsh7th/nvim-compe' - use 'hrsh7th/vim-vsnip' - use 'hrsh7th/vim-vsnip-integ' - use 'rafamadriz/friendly-snippets' + use { + "hrsh7th/nvim-cmp", + event = 'InsertEnter', + config = [[require('completion')]], + requires = { + -- 'hrsh7th/vim-vsnip-integ', + 'rafamadriz/friendly-snippets', + }, + } + use {"hrsh7th/vim-vsnip", after = "nvim-cmp"} + use {"hrsh7th/cmp-vsnip", after = "nvim-cmp"} + use {"hrsh7th/cmp-buffer", after = "nvim-cmp"} + use {'hrsh7th/cmp-path', after = "nvim-cmp"} + use {"hrsh7th/cmp-nvim-lsp", after = "nvim-cmp"} + use {'f3fora/cmp-spell', after = "nvim-cmp"} use 'nvim-lua/popup.nvim' - use 'nvim-lua/plenary.nvim' - use 'nvim-telescope/telescope.nvim' + use { + 'nvim-telescope/telescope.nvim', + requires = { {'nvim-lua/plenary.nvim'} } + } - use 'lervag/vimtex' + use { + 'lervag/vimtex', + } -- Highlight on Yank use 'machakann/vim-highlightedyank' -- Autoclose parenthesis use 'jiangmiao/auto-pairs' + use 'kyazdani42/nvim-web-devicons' + end) diff --git a/nvim/.config/nvim/lua/settings.lua b/nvim/.config/nvim/lua/settings.lua index 655ca43..4a5fc33 100644 --- a/nvim/.config/nvim/lua/settings.lua +++ b/nvim/.config/nvim/lua/settings.lua @@ -26,8 +26,7 @@ opt.cursorline = true -- highlight current line opt.ignorecase = true -- Ignore case on search opt.smartcase = true -- ignore lowercse for the whoel pattern -opt.completeopt = 'menuone,noselect,noinsert' -- completion options -opt.shortmess = 'c' -- don't show completion messages +-- opt.completeopt = 'menu,noselect,noinsert' -- completion options opt.spell = true opt.spelllang = {'fr', 'en'}