Skip to content

Commit

Permalink
[vim] use builtin snippet engine
Browse files Browse the repository at this point in the history
  • Loading branch information
antonk52 committed May 2, 2024
1 parent 18b2b57 commit 28fef51
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 156 deletions.
12 changes: 0 additions & 12 deletions nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ local plugins = {
'antonk52/markdowny.nvim',
opts = { filetypes = { 'markdown', 'hgcommit', 'gitcommit' } },
},
{
'L3MON4D3/LuaSnip',
tag = 'v2.0.0',
config = function()
require('antonk52.snippets').setup()
vim.api.nvim_del_user_command('LuaSnipUnlinkCurrent')
vim.api.nvim_del_user_command('LuaSnipListAvailable')
end,
event = 'VeryLazy',
},
{
'hrsh7th/nvim-cmp',
dependencies = {
Expand All @@ -98,8 +88,6 @@ local plugins = {
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-nvim-lua',
'hrsh7th/cmp-nvim-lsp-signature-help',
'saadparwaiz1/cmp_luasnip',
'L3MON4D3/LuaSnip',
'zbirenbaum/copilot.lua',
},
config = function()
Expand Down
18 changes: 8 additions & 10 deletions nvim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
{
"LuaSnip": { "branch": "master", "commit": "0b4950a237ce441a6a3a947d501622453f6860ea" },
"barbecue.nvim": { "branch": "main", "commit": "cd7e7da622d68136e13721865b4d919efd6325ed" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "3d8912ebeb56e5ae08ef0906e3a54de1c66b92f1" },
"cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"colorizer": { "branch": "master", "commit": "85855b38011114929f4058efc97af1059ab3e41d" },
"conform.nvim": { "branch": "master", "commit": "4660e534bf7678ee0f85879aa75fdcb6855612c2" },
"conform.nvim": { "branch": "master", "commit": "12b3995537f52ba2810a9857e8ca256881febbda" },
"copilot.lua": { "branch": "master", "commit": "f7612f5af4a7d7615babf43ab1e67a2d790c13a6" },
"dressing.nvim": { "branch": "master", "commit": "5162edb1442a729a885c45455a07e9a89058be2f" },
"git.nvim": { "branch": "main", "commit": "cc116ae91efd307836d24b868916f50a94c6daf9" },
"github-nvim-theme": { "branch": "main", "commit": "d92e1143e5aaa0d7df28a26dd8ee2102df2cadd8" },
"gitignore-grabber.nvim": { "branch": "main", "commit": "365c1a2255f1badf5aa8a963a07f869a81ab6575" },
"lake.nvim": { "branch": "main", "commit": "3b1966419b63e41ddfe23ba47f0e9cc665f133f8" },
"lake.nvim": { "branch": "main", "commit": "3a0f3f0616052e8cf5ad681d70e11ea25c02c459" },
"lazy.nvim": { "branch": "main", "commit": "3f13f080434ac942b150679223d54f5ca91e0d52" },
"leap.nvim": { "branch": "main", "commit": "626be4c4ec040aeaf6466c9aae17ee0ab09f1a5b" },
"markdowny.nvim": { "branch": "main", "commit": "9881051876f26998635d436f21de1b2b37c52e6d" },
"mini.nvim": { "branch": "main", "commit": "04f8d6e0acd5a52d01ec1c392e3947135dbfd8ef" },
"mini.nvim": { "branch": "main", "commit": "5eb6ae150d472dd35d5ecfd933fbef2a187c71dc" },
"neodev.nvim": { "branch": "main", "commit": "ce9a2e8eaba5649b553529c5498acb43a6c317cd" },
"npm_scripts.nvim": { "branch": "main", "commit": "14332129b7e916b5b22214e26c7415b9a86ac73c" },
"nvim-cmp": { "branch": "main", "commit": "8f3c541407e691af6163e2447f3af1bd6e17f9a3" },
"nvim-lspconfig": { "branch": "master", "commit": "7133e85c3df14a387da8942c094c7edddcdef309" },
"nvim-lspconfig": { "branch": "master", "commit": "aa5f4f4ee10b2688fb37fa46215672441d5cd5d9" },
"nvim-navic": { "branch": "master", "commit": "8649f694d3e76ee10c19255dece6411c29206a54" },
"nvim-spectre": { "branch": "master", "commit": "026394a8458d62c6b7b305c076ce675420dbaa4c" },
"nvim-treesitter": { "branch": "master", "commit": "ab3b3ff01028fef83cfb79b651bf65afb76ee062" },
"nvim-spectre": { "branch": "master", "commit": "4651801ba37a9407b7257287aec45b6653ffc5e9" },
"nvim-treesitter": { "branch": "master", "commit": "bbc67f736e22c37c23f2c11a05bfa23b715af30c" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "23b820146956b3b681c19e10d3a8bc0cbd9a1d4c" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "a6382f744f584bbf71d0a563af789af7190aabda" },
"plenary.nvim": { "branch": "master", "commit": "08e301982b9a057110ede7a735dd1b5285eb341f" },
"schemastore.nvim": { "branch": "main", "commit": "26d27cf72a0164cb5a25d7b7ceedbe9a72511932" },
"telescope.nvim": { "branch": "master", "commit": "35f94f0ef32d70e3664a703cefbe71bd1456d899" },
"schemastore.nvim": { "branch": "main", "commit": "6af7d312ad66a056666b1dac803517f051e66ffd" },
"telescope.nvim": { "branch": "master", "commit": "2d0d057791854decb2c9b6a0b52d43f3900dff40" },
"trouble.nvim": { "branch": "main", "commit": "b9cf677f20bb2faa2dacfa870b084e568dca9572" },
"twoslash-queries.nvim": { "branch": "main", "commit": "e000134c7ca3ea44f1095df3ceea89e485b7bdd5" },
"vim-dirvish": { "branch": "master", "commit": "3851bedb7f191b9a4a5531000b6fc0a8795cc9bb" }
Expand Down
25 changes: 13 additions & 12 deletions nvim/lua/antonk52/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function M.update_ai_completion(opts)
end

function M.setup()
local luasnip = require('luasnip')
require('antonk52.snippets').register_source()
local mapping = cmp.mapping.preset.insert({
['<Tab>'] = function(fallback)
if AI.is_visible() then
Expand Down Expand Up @@ -58,30 +58,31 @@ function M.setup()
end
end,
['<CR>'] = cmp.mapping.confirm(),
-- U for Undo
['<C-u>'] = function(fallback)
if not luasnip.jump(-1) then
fallback()
end
end,
['<C-y>'] = cmp.mapping.confirm({ select = true }),
-- O for Open
['<C-o>'] = function(fallback)
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
if require('antonk52.snippets').expand() then
return
elseif cmp.visible() then
cmp.confirm()
cmp.confirm({ select = true })
else
fallback()
end
end,
['<C-h>'] = function()
vim.snippet.jump(-1)
end,
['<C-l>'] = function()
vim.snippet.jump(1)
end,
['<C-k>'] = cmp.mapping.scroll_docs(-4),
['<C-j>'] = cmp.mapping.scroll_docs(4),
})

cmp.setup({
snippet = {
expand = function(arg)
luasnip.lsp_expand(arg.body)
vim.snippet.expand(arg.body)
end,
},
mapping = mapping,
Expand All @@ -100,7 +101,7 @@ function M.setup()
end,
},
sources = {
{ name = 'luasnip', keyword_length = 1 },
{ name = 'snip', keyword_length = 2 },
{ name = 'nvim_lsp' },
{ name = 'nvim_lua' },
{ name = 'nvim_lsp_signature_help' },
Expand Down
Loading

0 comments on commit 28fef51

Please sign in to comment.