L3MON4D3 / LuaSnip

Snippet Engine for Neovim written in Lua.
Apache License 2.0
3.44k stars 243 forks source link

Error when trying to use the text_node #915

Closed aldevv closed 1 year ago

aldevv commented 1 year ago

I have a file called c.lua that is loaded using: require("luasnip.loaders.from_lua").lazy_load({ paths = "~/.dotfiles/nvim/.config/nvim/my_snippets/luasnips" })

the contents of the file are:

local t = require("luasnip").text_node -- fails if not imported
-- local t = require("luasnip.nodes.textNode").T -- fails if not imported

return {
    s("keyword", {
        t("text: "),
    }),
}

tried using the latest commit and also the latest release, but no luck

the error I'm getting is this:

Error detected while processing BufNewFile Autocommands for "*":
Error executing lua callback: /usr/local/share/nvim/runtime/filetype.lua:21: Error executing lua: /usr/local/share/nvim/runtime/filetype.lua:22: BufNewFile Autocommands for "*"..FileType Autocommands for "*": Vim(append):Error executing lua callback: ...share/nvim/lazy/LuaSnip/lua/luasnip/loaders/from_lua.lua:126: Failed to execute /home/al/.dotfiles/nvim/.config/nvim/my_snippets/luasnips/c.lua
: ...n/.dotfiles/nvim/.config/nvim/my_snippets/luasnips/c.lua:29: Expected lua string
stack traceback:
    [C]: in function 'error'
    ...share/nvim/lazy/LuaSnip/lua/luasnip/loaders/from_lua.lua:126: in function '_luasnip_load_files'
    ...share/nvim/lazy/LuaSnip/lua/luasnip/loaders/from_lua.lua:176: in function '_load_lazy_loaded_ft'
    ...share/nvim/lazy/LuaSnip/lua/luasnip/loaders/from_lua.lua:190: in function '_load_lazy_loaded'
    .../al/.local/share/nvim/lazy/LuaSnip/plugin/luasnip.lua:87: in function <.../al/.local/share/nvim/lazy/LuaSnip/plugin/luasnip.lua:86>
    [C]: in function 'nvim_cmd'
    /usr/local/share/nvim/runtime/filetype.lua:22: in function </usr/local/share/nvim/runtime/filetype.lua:21>
    [C]: in function 'nvim_buf_call'
    /usr/local/share/nvim/runtime/filetype.lua:21: in function </usr/local/share/nvim/runtime/filetype.lua:10>
stack traceback:
    [C]: in function 'nvim_cmd'
    /usr/local/share/nvim/runtime/filetype.lua:22: in function </usr/local/share/nvim/runtime/filetype.lua:21>
    [C]: in function 'nvim_buf_call'
    /usr/local/share/nvim/runtime/filetype.lua:21: in function </usr/local/share/nvim/runtime/filetype.lua:10>
stack traceback:
    [C]: in function 'nvim_buf_call'
    /usr/local/share/nvim/runtime/filetype.lua:21: in function </usr/local/share/nvim/runtime/filetype.lua:10>
Error detected while processing BufWinEnter Autocommands for "*":
Error executing lua callback: ...share/nvim/lazy/LuaSnip/lua/luasnip/loaders/from_lua.lua:126: Failed to execute /home/al/.dotfiles/nvim/.config/nvim/my_snippets/luasnips/c.lua
: ...n/.dotfiles/nvim/.config/nvim/my_snippets/luasnips/c.lua:29: Expected lua string
stack traceback:
    [C]: in function 'error'
    ...share/nvim/lazy/LuaSnip/lua/luasnip/loaders/from_lua.lua:126: in function '_luasnip_load_files'
    ...share/nvim/lazy/LuaSnip/lua/luasnip/loaders/from_lua.lua:176: in function '_load_lazy_loaded_ft'
    ...share/nvim/lazy/LuaSnip/lua/luasnip/loaders/from_lua.lua:190: in function '_load_lazy_loaded'
    .../al/.local/share/nvim/lazy/LuaSnip/plugin/luasnip.lua:87: in function <.../al/.local/share/nvim/lazy/LuaSnip/plugin/luasnip.lua:86>
E471: Argument required

and here's my config

local ls = require("luasnip")
local types = require("luasnip.util.types")

ls.config.setup({
    history = true,
    updateevents = "TextChanged,TextChangedI",
    enable_autosnippets = true,
    ext_opts = {
        [types.choiceNode] = {
            active = {
                virt_text = { { " « ", "NonTest" } },
            },
        },
    },
})

-- keymaps
vim.keymap.set({ "i", "s" }, "<a-l>", function()
    if ls.expand_or_jumpable() then
        ls.expand_or_jump()
    end
end, { silent = true })

vim.keymap.set({ "i", "s" }, "<a-k>", function()
    if ls.jumpable(1) then
        ls.jump(1)
    end
end, { silent = true })

vim.keymap.set({ "i", "s" }, "<a-s-k>", function()
    if ls.jumpable(-1) then
        ls.jump(-1)
    end
end, { silent = true })

vim.keymap.set({ "i", "s" }, "<a-s-l>", function()
    if ls.choice_active() then
        ls.change_choice(1)
    end
end)

require("luasnip.loaders.from_lua").lazy_load({ paths = "~/.dotfiles/nvim/.config/nvim/my_snippets/luasnips" })
require("luasnip.loaders.from_vscode").lazy_load({ paths = "./my_snippets/vscode" })
aldevv commented 1 year ago

found out it was because I had an old function defined which was conflicting with it:

function _G.t(str)
    return vim.api.nvim_replace_termcodes(str, true, true, true)
end