garymjr / nvim-snippets

Snippet support using native neovim snippets
MIT License
245 stars 15 forks source link

improve documentation with examples. #7

Open monoira opened 6 months ago

monoira commented 6 months ago

setting up this plugin with custom vscode snippets is way too hard for me. documentation is way too small and not noobie-friendly.

I have to go back to luasnip until documentation becomes better.

chrisgrieser commented 6 months ago

@monoira The readme of nvim-scissors has an intro into how to use vscode snippets which you might find helpful: https://github.com/chrisgrieser/nvim-scissors?tab=readme-ov-file#example-for-the-vscode-style-snippet-format

garymjr commented 6 months ago

I do need to spend some time adding/improving documentation. I'll try to find some time this weekend to start working on this.

Mr-LLLLL commented 6 months ago

not worked according README setting

kevinm6 commented 6 months ago

@monoira and @Mr-LLLLL , you could take a look into my config, especially the snippet expansion and the config for nvim-snippets to make it works.

It should be pretty straightforward, even if I’m using a personal fork of friendly-snippets.

The expansion should be this or equivalent with Lazy.nvim

{
  "hrsh7th/nvim-cmp",
  event = { "InsertEnter", "CmdlineEnter" },
  opts = function(_, o)
    o.snippet = {
      expand = function(args)
        vim.snippet.expand(args.body)
      end,
    }
    -- other opts
}

and the config for nvim-snippets similar to

{
  "garymjr/nvim-snippets",
  event = "InsertEnter",
  -- this is for a custom fork of friendly-snippets located in `dev` folder (check Lazy.nvim for docs)
  dependencies = { "kevinm6/snippets", dev = true },
  opts = function(_, o)
    o.extended_filetypes = {
      typescript = { "javascript", "tsdoc” },
      javascript = { "jsdoc” },
      html = { "css", "javascript” },
      lua = { "luadoc” },
      python = { "python-docstring” },
      java = { "javadoc", "java-testing” },
      sh = { "shelldoc” },
      php = { "phpdoc” },
      ruby = { "rdoc” },
      quarto = { "markdown” },
      rmarkdown = { "markdown” },
    }
    -- location used to find `package.json` or snippets with valid file/folder structure
    o.search_paths = { vim.env.HOME .. "/dev/snippets" }

    -- other opts
}
ChillerDragon commented 6 months ago

@kevinm6 you can press Y on github to get a permanent link. Yours are 404 already after 14 hours :c

kevinm6 commented 6 months ago

@kevinm6 you can press Y on github to get a permanent link. Yours are 404 already after 14 hours :c

I did, but I was on mobile and I pasted the wrong link..! Try now

towry commented 6 months ago

Here is an usage example with fzf-lua (without nvim-cmp):

<c-x><c-e> to trigger the picker:

https://github.com/towry/nvim/blob/e0dc02c216467bf0609024ba8c60501003daf087/lua/user/plugins/finder.lua#L903

https://github.com/towry/nvim/blob/e0dc02c216467bf0609024ba8c60501003daf087/lua/userlib/snippets/init.lua#L32

https://github.com/garymjr/nvim-snippets/assets/8279858/f612dd95-5efc-403f-b36a-4612319d94cd

Mr-LLLLL commented 6 months ago

@monoira and @Mr-LLLLL , you could take a look into my config, especially the snippet expansion and the config for nvim-snippets to make it works.

It should be pretty straightforward, even if I’m using a personal fork of friendly-snippets.

The expansion should be this or equivalent with Lazy.nvim

{
  "hrsh7th/nvim-cmp”,
  event = { "InsertEnter", "CmdlineEnter” },
  opts = function(_, o)
    o.snippet = {
      expand = function(args)
        vim.snippet.expand(args.body)
      end,
    }
    -- other opts
}

and the config for nvim-snippets similar to

{
  "garymjr/nvim-snippets”,
  event = “InsertEnter”,
  -- this is for a custom fork of friendly-snippets located in `dev` folder (check Lazy.nvim for docs)
  dependencies = { "kevinm6/snippets", dev = true },
  opts = function(_, o)
    o.extended_filetypes = {
      typescript = { "javascript", "tsdoc” },
      javascript = { "jsdoc” },
      html = { "css", "javascript” },
      lua = { "luadoc” },
      python = { "python-docstring” },
      java = { "javadoc", "java-testing” },
      sh = { "shelldoc” },
      php = { "phpdoc” },
      ruby = { "rdoc” },
      quarto = { "markdown” },
      rmarkdown = { "markdown” },
    }
    -- location used to find `package.json` or snippets with valid file/folder structure
    o.search_paths = { vim.env.HOME .. "/dev/snippets” } -- location used to find `package.json` or snippets with valid file/folder structure

    -- other opts
}

thank you very much. it worked.

aymericderazey commented 6 months ago

Does someone has an exemple on how to use this plugin with user defined snippets for Typescript ? Thank you.

monoira commented 1 month ago

Documentation is still not good enough for this plugin to count as drop-in-replacement for luasnip for me. I am still on lazyvim + luasnip. I want to change luasnip for this if it's possible to use custom vscode snippets with this plugin but currently it's all way too complicated as a drop-in-replacement for luasnip. Maybe someone will make video or something about going from lazyVim + luasnip to lazyVim + nvim-snippets, But until then I have to stick around with luaSnip.

przepompownia commented 1 month ago

none-ls users can add such source:

local none = require('null-ls')

local nvimSnippets = {
  name = 'nvim_snippets',
  method = none.methods.COMPLETION,
  filetypes = {},
  generator = {
    fn = function (params, done)
      local items = {}
      local snips = require('snippets').get_loaded_snippets()
      local targets = vim.tbl_filter(function (item)
        return string.match(item.prefix, '^' .. params.word_to_complete)
      end, snips)
      for _, item in ipairs(targets) do
        table.insert(items, {
          label = item.prefix,
          kind = vim.lsp.protocol.CompletionItemKind.Snippet,
          insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet,
          detail = item.description,
          insertText = (type(item.body) == 'table') and table.concat(item.body, '\n') or item.body,
          insertTextMode = 2,
        })
      end
      done({{items = items, isIncomplete = #items == 0}})
    end,
    async = true,
  },
}

none.register(nvimSnippets)

(based on vsnip source distributed with the plugin).

przepompownia commented 1 month ago

I converted it into completion source https://github.com/nvimtools/none-ls.nvim/pull/201