Add support for nvim snippet engine (vim.snippet) (#164)

* doc: Add reference to `:h vim.snippet`
* doc: Update docs

---------

Co-authored-by: danymat <d.danymat@gmail.com>
This commit is contained in:
Sachin Rawat
2024-03-03 20:56:10 +00:00
committed by GitHub
parent 3e97116543
commit f10d046863
2 changed files with 16 additions and 1 deletions

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)
---
--- ## 2.16.0~
--- - Add support for `nvim` snippet engine (default nvim snippet engine) ! (see |neogen-snippet-integration|)
--- ## 2.15.0~
--- - Google docstrings now include "Yields:", whenever possible
--- ## 2.14.0~
@@ -299,7 +301,7 @@ end
--- with multiple annotation conventions.
---@tag neogen-changelog
---@toc_entry Changes in neogen plugin
neogen.version = "2.15.3"
neogen.version = "2.16.0"
--minidoc_afterlines_end
return neogen

View File

@@ -13,6 +13,7 @@ local conf = require("neogen.config").get()
--- - `"luasnip"` (https://github.com/L3MON4D3/LuaSnip)
--- - `"snippy"` (https://github.com/dcampos/nvim-snippy)
--- - `"vsnip"` (https://github.com/hrsh7th/vim-vsnip)
--- - `"nvim"` (`:h vim.snippet`)
---
--- If you want to customize the placeholders, you can use `placeholders_text` option:
--- >
@@ -130,4 +131,16 @@ snippet.engines.vsnip = function(snip, pos)
vim.fn["vsnip#anonymous"](snip)
end
--- Expand snippet for vim.snippet engine
---@param snip string the snippet to expand
---@param pos table a tuple of row, col
---@private
snippet.engines.nvim = function(snip, pos)
local row, _ = unpack(pos)
vim.api.nvim_buf_set_lines(0, row, row, true, { "" })
vim.api.nvim_win_set_cursor(0, { row + 1, 0 })
snip = table.concat(snip, "\n")
vim.snippet.expand(snip)
end
return snippet