From 26febcf9d2d767e5651f4f20f21908e38a3c31e9 Mon Sep 17 00:00:00 2001 From: Dakota Walsh Date: Wed, 25 Sep 2024 09:50:38 +1200 Subject: [PATCH] Manual snippet expansion The automatic snippet expansion was a bit glitchy and caused some bugs. Having it be manual is fine actually. --- lua/lsp.lua | 22 +++------------------- lua/snippets.lua | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lua/lsp.lua b/lua/lsp.lua index 2ab039b..42248d5 100644 --- a/lua/lsp.lua +++ b/lua/lsp.lua @@ -14,18 +14,11 @@ add('hrsh7th/cmp-buffer') add('hrsh7th/cmp-path') add('hrsh7th/cmp-cmdline') add('hrsh7th/nvim-cmp') -add('saadparwaiz1/cmp_luasnip') -- Setup autocomplete local cmp = require('cmp') -local ls = require("luasnip") cmp.setup({ preselect = cmp.PreselectMode.None, - snippet = { - expand = function(args) - ls.lsp_expand(args.body) - end, - }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), @@ -37,14 +30,10 @@ cmp.setup({ end), [''] = cmp.mapping(function(fallback) if cmp.visible() then - if ls.expandable() then - ls.expand() + if cmp.get_active_entry() then + cmp.confirm() else - if cmp.get_active_entry() then - cmp.confirm() - else - fallback() - end + fallback() end else fallback() @@ -54,8 +43,6 @@ cmp.setup({ [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item({ behavior = cmp.SelectBehavior }) - elseif ls.locally_jumpable(1) then - ls.jump(1) else fallback() end @@ -64,8 +51,6 @@ cmp.setup({ [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item({ behavior = cmp.SelectBehavior }) - elseif ls.locally_jumpable(-1) then - ls.jump(-1) else fallback() end @@ -73,7 +58,6 @@ cmp.setup({ }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, - { name = 'luasnip' }, -- For luasnip users. }, { { name = 'buffer' }, }), diff --git a/lua/snippets.lua b/lua/snippets.lua index 7c81fc2..2f371d9 100644 --- a/lua/snippets.lua +++ b/lua/snippets.lua @@ -9,6 +9,29 @@ ls.config.set_config { -- updateevents = "TextChanged,TextChangedI", enable_autosnippets = true, } +-- +-- Open / Next +vim.keymap.set( + { "i", "s" }, + "", + function() ls.expand_or_jump() end, + { silent = true } +) + +-- Prev +vim.keymap.set( + { "i", "s" }, + "", + function() ls.jump(-1) end, + { silent = true } +) + +-- List options +vim.keymap.set({ "i", "s" }, "", function() + if ls.choice_active() then + ls.change_choice(1) + end +end, { silent = true }) -- Create s(trigger, nodes) local s = ls.s -- 2.45.2