diff --git a/doc/blink-cmp.txt b/doc/blink-cmp.txt index 8374814e..7c5098ca 100644 --- a/doc/blink-cmp.txt +++ b/doc/blink-cmp.txt @@ -922,7 +922,7 @@ For more common configurations, see the recipes <../recipes.md>. }, -- Use a preset for snippets, check the snippets documentation for more information - snippets = { preset = 'default' | 'luasnip' | 'mini_snippets' }, + snippets = { preset = 'default' | 'luasnip' | 'mini_snippets' | 'vsnip' }, -- Experimental signature help support signature = { enabled = true } @@ -1714,7 +1714,8 @@ snippets. The built-in `snippets` source will load friendly-snippets , if available, and load any snippets found at `~/.config/nvim/snippets/`. For use with Luasnip, see the |blink-cmp-luasnip-section|. For use with mini.snippets, see the -|blink-cmp-mini.snippets-section|. +|blink-cmp-mini.snippets-section|. For use with vim-vsnip, see the +|blink-cmp-vim-vsnip-section|. FRIENDLY SNIPPETS ~ @@ -1831,6 +1832,23 @@ MINI.SNIPPETS ~ < +VIM-VSNIP ~ + +>lua + { + 'saghen/blink.cmp', + dependencies = 'echasnovski/mini.snippets', + opts = { + snippets = { preset = 'mini_snippets' }, + -- ensure you have the `snippets` source (enabled by default) + sources = { + default = { 'lsp', 'path', 'snippets', 'buffer' }, + }, + } + } +< + + DISABLE ALL SNIPPETS ~ >lua diff --git a/doc/configuration/general.md b/doc/configuration/general.md index dd4c428e..221c7e9b 100644 --- a/doc/configuration/general.md +++ b/doc/configuration/general.md @@ -63,7 +63,7 @@ For more common configurations, see the [recipes](../recipes.md). }, -- Use a preset for snippets, check the snippets documentation for more information - snippets = { preset = 'default' | 'luasnip' | 'mini_snippets' }, + snippets = { preset = 'default' | 'luasnip' | 'mini_snippets' | 'vsnip' }, -- Experimental signature help support signature = { enabled = true } diff --git a/doc/configuration/snippets.md b/doc/configuration/snippets.md index d4cff88c..44231f35 100644 --- a/doc/configuration/snippets.md +++ b/doc/configuration/snippets.md @@ -3,7 +3,7 @@ title: Snippets --- # Snippets Go to default configuration -Blink uses the `vim.snippet` API by default for expanding and navigating snippets. The built-in `snippets` source will load [friendly-snippets](https://github.com/rafamadriz/friendly-snippets), if available, and load any snippets found at `~/.config/nvim/snippets/`. For use with Luasnip, see the [Luasnip section](#luasnip). For use with mini.snippets, see the [mini.snippets section](#mini-snippets). +Blink uses the `vim.snippet` API by default for expanding and navigating snippets. The built-in `snippets` source will load [friendly-snippets](https://github.com/rafamadriz/friendly-snippets), if available, and load any snippets found at `~/.config/nvim/snippets/`. For use with Luasnip, see the [Luasnip section](#luasnip). For use with mini.snippets, see the [mini.snippets section](#mini-snippets). For use with vim-vsnip, see the [vim-vsnip section](#vim-vsnip). ## Friendly Snippets @@ -98,6 +98,21 @@ There's a great introduction to writing custom snippets [in the nvim-scissors re } ``` +## `vim-vsnip` + +```lua +{ + 'saghen/blink.cmp', + dependencies = {'hrsh7th/vim-vsnip', 'https://codeberg.org/FelipeLema/bink-cmp-vsnip.git'}, + opts = { + snippets = { preset = 'vsnip' }, + sources = { + default = { 'lsp', 'path', 'vsnip', 'buffer' }, + }, + } +} +``` + ## Disable all snippets ```lua diff --git a/lua/blink/cmp/config/snippets.lua b/lua/blink/cmp/config/snippets.lua index 0d611639..a40f2f0d 100644 --- a/lua/blink/cmp/config/snippets.lua +++ b/lua/blink/cmp/config/snippets.lua @@ -1,11 +1,11 @@ --- @class (exact) blink.cmp.SnippetsConfig ---- @field preset 'default' | 'luasnip' | 'mini_snippets' +--- @field preset 'default' | 'luasnip' | 'mini_snippets' | 'vsnip' --- @field expand fun(snippet: string) Function to use when expanding LSP provided snippets --- @field active fun(filter?: { direction?: number }): boolean Function to use when checking if a snippet is active --- @field jump fun(direction: number) Function to use when jumping between tab stops in a snippet, where direction can be negative or positive --- @field score_offset number Offset to the score of all snippet items ---- @param handlers table<'default' | 'luasnip' | 'mini_snippets', fun(...): any> +--- @param handlers table<'default' | 'luasnip' | 'mini_snippets' | 'vsnip', fun(...): any> local function by_preset(handlers) return function(...) local preset = require('blink.cmp.config').snippets.preset @@ -37,6 +37,7 @@ local snippets = { -- we run after it completes it callback. We do this by resubscribing to TextChangedI require('blink.cmp').resubscribe() end, + vsnip = function(snippet) vim.fn['vsnip#anonymous'](snippet) end, }), active = by_preset({ default = function(filter) return vim.snippet.active(filter) end, @@ -50,6 +51,7 @@ local snippets = { if not _G.MiniSnippets then error('mini.snippets has not been setup') end return MiniSnippets.session.get(false) ~= nil end, + vsnip = function() return vim.fn.empty(vim.fn['vsnip#get_session']()) ~= 1 end, }), jump = by_preset({ default = function(direction) vim.snippet.jump(direction) end, @@ -62,6 +64,11 @@ local snippets = { if not _G.MiniSnippets then error('mini.snippets has not been setup') end MiniSnippets.session.jump(direction == -1 and 'prev' or 'next') end, + vsnip = function(direction) + local session = vim.fn['vsnip#get_session']() + if vim.fn.empty(session) == 1 then return false end + return session.jumpable(direction) + end, }), score_offset = -3, }, @@ -71,8 +78,8 @@ function snippets.validate(config) validate('snippets', { preset = { config.preset, - function(preset) return vim.tbl_contains({ 'default', 'luasnip', 'mini_snippets' }, preset) end, - 'one of: "default", "luasnip", "mini_snippets"', + function(preset) return vim.tbl_contains({ 'default', 'luasnip', 'mini_snippets', 'vsnip' }, preset) end, + 'one of: "default", "luasnip", "mini_snippets", "vsnip"', }, expand = { config.expand, 'function' }, active = { config.active, 'function' },