rafamadriz / friendly-snippets

Set of preconfigured snippets for different languages.
MIT License
2.02k stars 457 forks source link

Running LuaSnipListAvailable does not list react-es7 snippets #171

Closed sisodiaa closed 2 years ago

sisodiaa commented 2 years ago

I recently migrated from vim-vsnip to LuaSnip. I am using friendly-snippets collections of snippets.

Today while coding a react project I noticed that snippets in javascript/react-es7.json are not listed amongst the completion items. I ran :LuaSnipListAvailable to cross check but these snippets were not loaded over there either.

Following are the relevant blocks from configuration

local cmp = require('cmp')
local luasnip = require('luasnip')

local has_words_before = function()
  local line, col = unpack(vim.api.nvim_win_get_cursor(0))
  return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end

cmp.setup({
  completion = { autocomplete = false, },

  snippet = {
    expand = function(args)
      luasnip.lsp_expand(args.body)
    end
  },

  mapping = {
    ['<C-p>'] = cmp.mapping.select_prev_item(),
    ['<C-n>'] = cmp.mapping.select_next_item(),
    ['<C-d>'] = cmp.mapping.scroll_docs(-4),
    ['<C-f>'] = cmp.mapping.scroll_docs(4),
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.close(),
    ['<CR>'] = cmp.mapping.confirm({
      behavior = cmp.ConfirmBehavior.Insert,
      select = true,
    }),

    ["<Tab>"] = cmp.mapping(function(fallback)
      if cmp.visible() then
        cmp.select_next_item()
      elseif luasnip.expand_or_jumpable() then
        luasnip.expand_or_jump()
      elseif has_words_before() then
        cmp.complete()
      else
        fallback()
      end
    end, { "i", "s" }),

    ["<S-Tab>"] = cmp.mapping(function(fallback)
      if cmp.visible() then
        cmp.select_prev_item()
      elseif luasnip.jumpable(-1) then
        luasnip.jump(-1)
      else
        fallback()
      end
    end, { "i", "s" }),
  },

  sources = cmp.config.sources({
    { name = 'nvim_lsp' },
    { name = 'luasnip' },
  }, {
    { name = 'buffer' },
    { name = 'path' },
  }),
})

luasnip.filetype_extend("javascript", { "javascriptreact" })
luasnip.filetype_extend("javascript", { "html" })

require("luasnip.loaders.from_vscode").lazy_load()

Please guide me on how to use react-es7 snippets thorough LuaSnip.

OkelleyDevelopment commented 2 years ago

Hello @sisodiaa !

You are on the right track with extending the file types.

The issue was due to an inconsistent naming of the file in the package.json and the actual file the snippets were stored in... which I missed during my code review on #164 :pensive: ... however I merged #172 and if you resync your snippets they should be working correctly :sunglasses:

If you have any further issues though, let us know and we can reopen the issue and help further !