luasnip-latex-snippets.nvim icon indicating copy to clipboard operation
luasnip-latex-snippets.nvim copied to clipboard

Cannot use this plugin in markdown file.

Open meicale opened this issue 2 years ago • 13 comments

It is wonderful work. But, I meet a problem. I can use the snips in tex file but not in md file. I pin the branch to "markdown" use packer plugin manager and I add the "markdown" to the ft configuration of this plugin. But I still can not trigger any snips which I can in tex file.

meicale avatar Jan 25 '23 12:01 meicale

Did you pass use_treesitter = true?

iurimateus avatar Jan 27 '23 12:01 iurimateus

Stale. Closing in favor of #2.

iurimateus avatar Feb 25 '23 18:02 iurimateus

Did you pass use_treesitter = true?

Can you say more about that? How and Where to add this config or pass this para?

meicale avatar Feb 26 '23 09:02 meicale

Per the README, in the setup function

require'luasnip-latex-snippets'.setup({ use_treesitter = true })

iurimateus avatar Feb 26 '23 09:02 iurimateus

Hi, I also encountered this issue. I have set use_treesitter = true. But the plugin is not loaded when the filetype is markdown. Strangely, if I set :setf markdown, the plugin is loaded and works properly, but the syntax highlighting is lost.

I guess this is an issue caused by nvim-treesitter? It changes the filetype so that Packer no longer detects a filetype as Markdown.

Now, my workaround is to remove the constraint ft = { "tex", "markdown" }, and then both syntax highlighting and snippets work properly.

zcysxy avatar Mar 23 '23 21:03 zcysxy

Thanks for the details.

I think it's better to handle this on the plugin, instead of deferring it to packer or some such (i.e. lazy loading shouldn't be required).

iurimateus avatar Mar 23 '23 21:03 iurimateus

I've attempted a fix on the branch lazy-loading

iurimateus avatar Mar 25 '23 21:03 iurimateus

I tried the new branch. This time, the plugin is loaded when a Markdown file is open. However, the snippets don't work, :lua require "luasnip.extras.snippet_list".open() returns empty. Then, with a manual setf markdown, the snippets work again.

zcysxy avatar Mar 26 '23 05:03 zcysxy

Are you setting ft on packer? If so, don't. setup {} just runs a FileType autocommand now, so there shouldn't be a (non negligible) startup cost (and thus, lazy loading is unnecessary).

Note that this commit makes it so when overriding a snippet, you'd have to do it after the ft aucmd. Perhaps we should consider a interface to filter unwanted snippets by trig/name. But that doesn't cover the Greek postfix snippets.

iurimateus avatar Mar 26 '23 09:03 iurimateus

Are you setting ft on packer?

No I have removed the ft statement. I am using the default snippets without overriding snippets or adding new ones

zcysxy avatar Mar 26 '23 17:03 zcysxy

You probably haven't enable autosnippets. This took me a while to configure out. Many snippets defined here are in autosnippet category. It's not enabled by default in luasnip.

    {
        'L3MON4D3/LuaSnip',
        version = "2.*",
        config = function()
            local ls = require 'luasnip'
            ls.setup({ enable_autosnippets = true })
        end
    },

jjiangweilan avatar Aug 16 '23 08:08 jjiangweilan

I meet the same problem like zcysxy, I have to setf markdown every time. After making some attempts, I find it is because of another plugin named vimwiki. In my case, when I disable vimwiki, it works well.

BLACKSWORD0 avatar Sep 20 '23 06:09 BLACKSWORD0

Did you pass use_treesitter = true?

Can you say more about that? How and Where to add this config or pass this para?

` return { { "hrsh7th/cmp-nvim-lsp", }, { "L3MON4D3/LuaSnip", dependencies = { "saadparwaiz1/cmp_luasnip", "rafamadriz/friendly-snippets", }, }, { "hrsh7th/nvim-cmp", config = function() local cmp = require("cmp") require("luasnip.loaders.from_vscode").lazy_load()

  cmp.setup({
    snippet = {
      expand = function(args)
        require("luasnip").lsp_expand(args.body)
      end,
    },
    window = {
      completion = cmp.config.window.bordered(),
      documentation = cmp.config.window.bordered(),
    },
    mapping = cmp.mapping.preset.insert({
      ["<C-b>"] = cmp.mapping.scroll_docs(-4),
      ["<C-f>"] = cmp.mapping.scroll_docs(4),
      ["<C-Space>"] = cmp.mapping.complete(),
      ["<C-e>"] = cmp.mapping.abort(),
      ["<CR>"] = cmp.mapping.confirm({ select = true }),
    }),
    sources = cmp.config.sources({
      { name = "nvim_lsp" },
      { name = "luasnip" }, -- For luasnip users.
    }, {
      { name = "buffer" },
    }),
  })
end,

}, { "iurimateus/luasnip-latex-snippets.nvim", -- vimtex isn't required if using treesitter require = { "L3MON4D3/LuaSnip", "lervag/vimtex", }, config = function() require("luasnip-latex-snippets").setup({ use_treesitter = true }) end, }, } `

v0ry avatar Feb 05 '24 15:02 v0ry