From 1e43afd1180bf86e7256ff42814897526f705c7b Mon Sep 17 00:00:00 2001 From: He4eT Date: Thu, 4 Apr 2024 01:58:13 +0200 Subject: [PATCH] nvim: inline nvim-cmp config --- nvim/init.lua | 104 +++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/nvim/init.lua b/nvim/init.lua index b17d986..904c386 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,3 +1,5 @@ +-- npx @johnnymorganz/stylua-bin ./init.lua + -- Leader keymaps local leader = ' ' vim.g.mapleader = leader @@ -333,9 +335,60 @@ require('lazy').setup({ 'hrsh7th/nvim-cmp', dependencies = { 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-path', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip', }, + config = function() + local luasnip = require 'luasnip' + + luasnip.config.setup { + -- https://stackoverflow.com/questions/70366949/ + region_check_events = 'CursorHold,InsertLeave', + delete_check_events = 'TextChanged,InsertEnter', + } + + local cmp = require 'cmp' + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert { + [''] = cmp.mapping.complete {}, + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }, + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = 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' }, + { name = 'path' }, + }, + } + end, }, { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', @@ -543,7 +596,6 @@ local servers = { }, tsserver = { on_attach = on_attach, - capabilities = capabilities, init_options = { plugins = { { @@ -586,54 +638,4 @@ vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'solid', }) --- nvim-cmp setup -local cmp = require 'cmp' -local luasnip = require 'luasnip' - -luasnip.config.setup { - -- https://stackoverflow.com/questions/70366949/ - region_check_events = 'CursorHold,InsertLeave', - delete_check_events = 'TextChanged,InsertEnter', -} - -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.Insert, - 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' }, - }, -} - --- npx @johnnymorganz/stylua-bin ./init.lua -- vim: ts=2 sts=2 sw=2 et