From 7da4ea01fab73c1301ff231cc9cbda49a6c256ec Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Sat, 18 Nov 2023 16:41:39 -0700 Subject: [PATCH] Incorporate snippets. --- jrpotter/neovim/default.nix | 2 ++ jrpotter/neovim/lua/init/cmp.lua | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/jrpotter/neovim/default.nix b/jrpotter/neovim/default.nix index ad8634f..3937dfc 100644 --- a/jrpotter/neovim/default.nix +++ b/jrpotter/neovim/default.nix @@ -84,6 +84,8 @@ in nvim-treesitter pkgs.vimPlugins.cmp-buffer pkgs.vimPlugins.cmp-nvim-lsp + pkgs.vimPlugins.cmp_luasnip + pkgs.vimPlugins.luasnip ]; viAlias = true; vimAlias = true; diff --git a/jrpotter/neovim/lua/init/cmp.lua b/jrpotter/neovim/lua/init/cmp.lua index 8d5c90d..ebd6c1a 100644 --- a/jrpotter/neovim/lua/init/cmp.lua +++ b/jrpotter/neovim/lua/init/cmp.lua @@ -2,9 +2,15 @@ local M = {} local cmp = require('cmp') local cmp_buffer = require('cmp_buffer') +local luasnip = require("luasnip") function M.setup() cmp.setup { + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, sources = { { name = 'nvim_lsp', @@ -46,7 +52,21 @@ function M.setup() end, { 'i', 's' }), [''] = cmp.mapping(function(fallback) - if cmp.visible() then cmp.confirm() else fallback() end + if cmp.get_active_entry() then + cmp.confirm() + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + + [''] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end end, { 'i', 's' }), }, }