iurimateus / luasnip-latex-snippets.nvim

A port of Gilles Castel's UltiSnip snippets for LuaSnip.
Apache License 2.0
140 stars 60 forks source link

Cannot use this plugin in markdown file. #5

Open meicale opened 1 year ago

meicale commented 1 year ago

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.

iurimateus commented 1 year ago

Did you pass use_treesitter = true?

iurimateus commented 1 year ago

Stale. Closing in favor of #2.

meicale commented 1 year ago

Did you pass use_treesitter = true?

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

iurimateus commented 1 year ago

Per the README, in the setup function

require'luasnip-latex-snippets'.setup({ use_treesitter = true })
zcysxy commented 1 year ago

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.

iurimateus commented 1 year ago

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 commented 1 year ago

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

zcysxy commented 1 year ago

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.

iurimateus commented 1 year ago

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.

zcysxy commented 1 year ago

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

jjiangweilan commented 1 year ago

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
    },
BLACKSWORD0 commented 1 year ago

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.

v0ry commented 8 months ago

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, }, } `