From e8c62b63f82c79345bbab16ae54758e553675bb5 Mon Sep 17 00:00:00 2001 From: Reagan Date: Sun, 16 Oct 2022 10:59:30 +1300 Subject: [PATCH] * feat(snippet): Add support for vsnip Co-authored-by: danymat --- README.md | 2 +- lua/neogen/init.lua | 4 +++- lua/neogen/snippet.lua | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 62c3b04..3735371 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ And this is done via the `snippet_engine` option in neogen's setup: - `snippet_engine` option will use provided engine to place the annotations: -Currently supported: `luasnip`, `snippy`. +Currently supported: `luasnip`, `snippy`, `vsnip`. ```lua require('neogen').setup({ snippet_engine = "luasnip" }) diff --git a/lua/neogen/init.lua b/lua/neogen/init.lua index a4ccff4..d2171a4 100644 --- a/lua/neogen/init.lua +++ b/lua/neogen/init.lua @@ -241,6 +241,8 @@ end --- --- Note: We will only document `major` and `minor` versions, not `patch` ones. (only X and Y in X.Y.z) --- +--- ## 2.9.0~ +--- - Add support for `vsnip` snippet engine ! (see |neogen-snippet-integration|) --- ## 2.8.0~ --- - Specify annotation convention on `generate()` method (see |neogen.generate()|) --- ## 2.7.0~ @@ -280,7 +282,7 @@ end --- with multiple annotation conventions. ---@tag neogen-changelog ---@toc_entry Changes in neogen plugin -neogen.version = "2.8.1" +neogen.version = "2.9.0" --minidoc_afterlines_end return neogen diff --git a/lua/neogen/snippet.lua b/lua/neogen/snippet.lua index d4f5b31..a64adb9 100644 --- a/lua/neogen/snippet.lua +++ b/lua/neogen/snippet.lua @@ -12,6 +12,7 @@ local conf = require("neogen.config").get() --- Some snippet engines come out of the box bundled with neogen: --- - `"luasnip"` (https://github.com/L3MON4D3/LuaSnip) --- - `"snippy"` (https://github.com/dcampos/nvim-snippy) +--- - `"vsnip"` (https://github.com/hrsh7th/vim-vsnip) --- --- If you want to customize the placeholders, you can use `placeholders_text` option: --- > @@ -112,4 +113,21 @@ snippet.engines.snippy = function (snip, pos) snippy.expand_snippet({body = snip}) end +--- Expand snippet for vsnip engine +---@param snip string the snippet to expand +---@param pos table a tuple of row, col +---@private +snippet.engines.vsnip = function (snip, pos) + local ok = vim.g.loaded_vsnip + if not ok then + notify("Vsnip not found, aborting...", vim.log.levels.ERROR) + return + end + local row, _ = unpack(pos) + vim.api.nvim_buf_set_lines(0, row, row, true, {''}) -- vsnip will change `row` + vim.api.nvim_win_set_cursor(0, {row + 1, 0}) -- `snip` already has indent so we should ignore `col` + snip = table.concat(snip, "\n") -- vsnip expects on string instead of a list/table of lines + vim.fn["vsnip#anonymous"](snip) +end + return snippet