iurimateus / luasnip-latex-snippets.nvim

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

Setup with lazy and treesitter minimal config #20

Closed Hiqqup closed 1 year ago

Hiqqup commented 1 year ago

I cant get it to work, in my main config so ive extracted a minimal config to post here, maybe there is an obvious mistake somewhere.

my minimal init.lua:

local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system {
        'git',
        'clone',
        '--filter=blob:none',
        'https://github.com/folke/lazy.nvim.git',
        '--branch=stable', -- latest stable release
        lazypath,
    }
end
vim.opt.rtp:prepend(lazypath)
---
require("lazy").setup({
    {
        "iurimateus/luasnip-latex-snippets.nvim",
        config = function()
            require 'luasnip-latex-snippets'.setup({ use_treesitter = true })
        end,
    },
    {
        "nvim-treesitter/nvim-treesitter",
        config = function()
            local configs = require("nvim-treesitter.configs")

            configs.setup({
                ensure_installed = {
                    "markdown",
                    "markdown_inline",
                    "latex",
                },
                auto_install = true,
                sync_install = false,
                highlight = {
                    enable = true,
                    additional_vim_regex_highlighting = { "markdown" },
                },
                indent = { enable = true },
            })
        end
    },
    {
        "l3mon4d3/luasnip",
        config = function()
            require("luasnip.loaders.from_lua").load({ paths = "~/projects/latex-vimconfig/snippets" })
        end
    },
    {
        'hrsh7th/nvim-cmp',
        config = function()
            local cmp = require 'cmp'
            local luasnip = require 'luasnip'
            luasnip.config.setup({ enable_autosnippets = true })

            cmp.setup {
                snippet = {
                    expand = function(args)
                        luasnip.lsp_expand(args.body)
                    end,
                },
                mapping = cmp.mapping.preset.insert {
                    ['<CR>'] = cmp.mapping.confirm {
                        behavior = cmp.ConfirmBehavior.Replace,
                        select = true,
                    },
                    ['<Tab>'] = cmp.mapping(function(fallback)
                        if cmp.visible() then
                            cmp.select_next_item()
                        elseif luasnip.expand_or_locally_jumpable() then
                            luasnip.expand_or_jump()
                        else
                            fallback()
                        end
                    end, { 'i', 's' }),
                    ['<S-Tab>'] = cmp.mapping(function(fallback)
                        if cmp.visible() then
                            cmp.select_prev_item()
                        elseif luasnip.locally_jumpable(-1) then
                            luasnip.jump(-1)
                        else
                            fallback()
                        end
                    end, { 'i', 's' }),
                },
                sources = {
                    { name = 'luasnip' },
                },
            }
        end
    },
    'saadparwaiz1/cmp_luasnip',
}
)

or i mean what means minimal, those are the settings of the plugins involved i used

also other manually setup snippets work when i specifiy them in a folder in a file for example: snippets/markdown.lua

return {
    require("luasnip").snippet(
        { trig = "hi" },
        { t("Hello, world!") }
    ),
    require("luasnip").snippet(
        { trig = "foo" },
        { t("Another snippet.") }
    ),
}

Also the tree sitter parsing for markdown works uhm when i do [[example]] its in a different color and on my main config ive setup nabla with, after that even the

$$ -- some latex here $$ was proplery highlighted

Hiqqup commented 1 year ago

nevermind the issue is not having autosnippets enabled for luasnip see [[#5]], i would appreciate if this information was added in the readme.md ill edit the upper code to work