Skip to content

feature request: Add API to add snippetes from lua. #1

Description

@MironPascalCaseFan

Problem:

No way to add snippets in Lua.

Solution:

Add require("yasp").add with a signature like this:

---Add VS Code-style snippet  
---@param trig string  
---@param body string VS Code-style snippet string  
---@param opts {ft: string, desc: string}  

So it can be used like this:

require("yasp").add("au", [[  
vim.api.nvim_create_autocmd("${1:Event}", {  
  callback = function(args)  
    $0  
  end  
})  
]], { ft = "lua", desc = "Neovim autocmd" })  

Benefits:

It will allow users to organize their snippets however they want and will not require creating separate snippet files for this.

I am especially interested in this because I put all language-specific configurations in one separate file for each language. You can take a look here:
https://github.com/miroshQa/dotfiles/blob/main/nvim/lua/languages/lua.lua

Since I already have lua.lua, js.lua, I don’t want to create snippets/lua.json, snippets/js.json as well, because it will be hard to fuzzy-find them and will create too many files. Also it simply much more pleasant to write snippets using lua multistring literals.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions