* feat(snippet): Add support for vsnip
Co-authored-by: danymat <d.danymat@gmail.com>
This commit is contained in:
@@ -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" })
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user