Skip to content

Commit

Permalink
feat: add support for mini snippet engine ('mini.snippets') (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
echasnovski authored Dec 27, 2024
1 parent 37dd095 commit b2e7870
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,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`, `vsnip`, `nvim`.
Currently supported: `luasnip`, `snippy`, `vsnip`, `nvim`, `mini`.

```lua
require('neogen').setup({ snippet_engine = "luasnip" })
Expand Down
8 changes: 5 additions & 3 deletions lua/neogen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,12 @@ end
---
--- Note: We will only document `major` and `minor` versions, not `patch` ones. (only X and Y in X.Y.z)
---
--- ## 2.20.0~
--- - Add support for `mini` snippet engine ! (see |neogen-snippet-integration|)
--- ## 2.19.0~
--- - Add support for julia (`julia`) ! (#185)
--- - Add support for julia (`julia`) ! (#185)
--- ## 2.18.0~
--- - Add tests cases to tests/ for annotation generation with basic support for python (#174)
--- - Add tests cases to tests/ for annotation generation with basic support for python (#174)
--- ## 2.17.1~
--- - Python raises now supports `raise foo.Bar()` syntax
--- ## 2.17.0~
Expand Down Expand Up @@ -309,7 +311,7 @@ end
--- with multiple annotation conventions.
---@tag neogen-changelog
---@toc_entry Changes in neogen plugin
neogen.version = "2.19.4"
neogen.version = "2.20.0"
--minidoc_afterlines_end

return neogen
20 changes: 20 additions & 0 deletions lua/neogen/snippet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local conf = require("neogen.config").get()
--- - `"snippy"` (https://github.com/dcampos/nvim-snippy)
--- - `"vsnip"` (https://github.com/hrsh7th/vim-vsnip)
--- - `"nvim"` (`:h vim.snippet`)
--- - `"mini"` (https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-snippets.md)
---
--- If you want to customize the placeholders, you can use `placeholders_text` option:
--- >
Expand Down Expand Up @@ -143,4 +144,23 @@ snippet.engines.nvim = function(snip, pos)
vim.snippet.expand(snip)
end

--- Expand snippet for mini.snippets engine
---@param snip string the snippet to expand
---@param pos table a tuple of row, col
---@private
snippet.engines.mini = function(snip, pos)
-- Check `MiniSnippets` is set up by the user
if _G.MiniSnippets == nil then
notify("'mini.snippets' is not set up, aborting...", vim.log.levels.ERROR)
return
end

local row = pos[1]
vim.api.nvim_buf_set_lines(0, row, row, true, { "" })
vim.api.nvim_win_set_cursor(0, { row + 1, 0 })
-- Use user configured `insert` method but fall back to default
local insert = MiniSnippets.config.expand.insert or MiniSnippets.default_insert
insert({ body = snip })
end

return snippet

0 comments on commit b2e7870

Please sign in to comment.