* feat(snippet): Add support for vsnip

Co-authored-by: danymat <d.danymat@gmail.com>
This commit is contained in:
Reagan
2022-10-16 10:59:30 +13:00
committed by GitHub
parent 8bddb5acfc
commit e8c62b63f8
3 changed files with 22 additions and 2 deletions

View File

@@ -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: - `snippet_engine` option will use provided engine to place the annotations:
Currently supported: `luasnip`, `snippy`. Currently supported: `luasnip`, `snippy`, `vsnip`.
```lua ```lua
require('neogen').setup({ snippet_engine = "luasnip" }) require('neogen').setup({ snippet_engine = "luasnip" })

View File

@@ -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) --- 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~ --- ## 2.8.0~
--- - Specify annotation convention on `generate()` method (see |neogen.generate()|) --- - Specify annotation convention on `generate()` method (see |neogen.generate()|)
--- ## 2.7.0~ --- ## 2.7.0~
@@ -280,7 +282,7 @@ end
--- with multiple annotation conventions. --- with multiple annotation conventions.
---@tag neogen-changelog ---@tag neogen-changelog
---@toc_entry Changes in neogen plugin ---@toc_entry Changes in neogen plugin
neogen.version = "2.8.1" neogen.version = "2.9.0"
--minidoc_afterlines_end --minidoc_afterlines_end
return neogen return neogen

View File

@@ -12,6 +12,7 @@ local conf = require("neogen.config").get()
--- Some snippet engines come out of the box bundled with neogen: --- Some snippet engines come out of the box bundled with neogen:
--- - `"luasnip"` (https://github.com/L3MON4D3/LuaSnip) --- - `"luasnip"` (https://github.com/L3MON4D3/LuaSnip)
--- - `"snippy"` (https://github.com/dcampos/nvim-snippy) --- - `"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: --- 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}) snippy.expand_snippet({body = snip})
end 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 return snippet