Closed banana59 closed 1 month ago
Hey, could you check your logs (ls.log.set_loglevel("info")
before call to load
, ls.log.open()
)?
There should be some info on luasnip searching these paths, that should help debugging the issue :)
There are indeed some entries.
I have now inserted the set_loglevel
here in snippets.lua:
local luasnip = require("luasnip")
local types = require("luasnip.util.types")
luasnip.log.set_loglevel("info")
--Define highlight groups for virt_text
vim.api.nvim_set_hl(0, 'PortalOrange', { fg = '#FFA500', bg = 'NONE' })
vim.api.nvim_set_hl(0, 'PortalBlue', { fg = '#3388FF', bg = 'NONE' })
and .log.open()
here:
luasnip.log.open()
require("luasnip.loaders.from_vscode").lazy_load({include = {"lua"}}) -- only include these
require("luasnip.loaders.from_lua").load({paths = "./Snippets/"})
end,
The ~/.local/state/nvim/luasnip.log
INFO | lua-loader: Loading lazy-load-snippets for filetype ``
INFO | snipmate-loader: Loading lazy-load-snippets for filetype ``
INFO | vscode-loader: Loading lazy-load-snippets for filetype ``
INFO | lua-loader: Loading lazy-load-snippets for filetype `all`
INFO | snipmate-loader: Loading lazy-load-snippets for filetype `all`
INFO | vscode-loader: Loading lazy-load-snippets for filetype `all`
INFO | vscode-loader: Found manifests `{ "/home/lennart/.local/share/nvim/lazy/friendly-snippets/package.json" }` for paths `nil`.
INFO | vscode-loader: Determined roots `{}` for lazy_paths `{}`.
INFO | path-watcher: Monitoring file /home/lennart/.local/share/nvim/lazy/friendly-snippets/package.json with autocmd-monitor.
INFO | path-watcher: adding path /home/lennart/.local/share/nvim/lazy/friendly-snippets/package.json
INFO | vscode-loader: Registering lazy-load-snippets for ft `lua` from file `/home/lennart/.local/share/nvim/lazy/friendly-snippets/snippets/lua/lua.json`
INFO | vscode-loader: Initialized snippet-collection with manifest /home/lennart/.local/share/nvim/lazy/friendly-snippets/package.json
INFO | vscode-loader: Loading lazy-load-snippets for filetype ``
INFO | vscode-loader: Loading lazy-load-snippets for filetype `all`
INFO | lua-loader: Found roots `{ "/home/lennart/Documents/Neovim/default/Snippets" }` for paths `{ "./Snippets/" }`.
INFO | lua-loader: Determined roots `{}` for lazy_paths `{}`.
INFO | tree-watcher: Monitoring root-directory /home/lennart/Documents/Neovim/default/Snippets with autocmd-monitor.
INFO | lua-loader: Adding snippets for filetype `all` from file `/home/lennart/Documents/Neovim/default/Snippets/all.lua`
INFO | loaders: Adding 3 snippets and 0 autosnippets from /home/lennart/Documents/Neovim/default/Snippets/all.lua to ft `all`
INFO | lua-loader: Adding snippets for filetype `c` from file `/home/lennart/Documents/Neovim/default/Snippets/c.lua`
ERROR | lua-loader: Failed to execute
| : /home/lennart/Documents/Neovim/default/Snippets/c.lua
ERROR | lua-loader: Could not create collection at /home/lennart/Documents/Neovim/default/Snippets: ...share/nvim/lazy/LuaSnip/lua/luasnip/loaders/from_lua.lua:246: Could not create watcher: ...share/nvim/lazy/LuaSnip/lua/luasnip/loaders/from_lua.lua:169: Failed to execute /home/lennart/Documents/Neovim/default/Snippets/c.lua
| : /home/lennart/Documents/Neovim/default/Snippets/c.lua:10: module 'helper-functions' not found:
| no field package.preload['helper-functions']
| cache_loader: module helper-functions not found
| cache_loader_lib: module helper-functions not found
| no file './helper-functions.lua'
| no file '/build/nvim/parts/nvim/build/.deps/usr/share/luajit-2.1/helper-functions.lua'
| no file '/usr/local/share/lua/5.1/helper-functions.lua'
| no file '/usr/local/share/lua/5.1/helper-functions/init.lua'
| no file '/build/nvim/parts/nvim/build/.deps/usr/share/lua/5.1/helper-functions.lua'
| no file '/build/nvim/parts/nvim/build/.deps/usr/share/lua/5.1/helper-functions/init.lua'
| no file '/home/lennart/.local/state/nvim/helper-functions.lua'
| no file './helper-functions.so'
| no file '/usr/local/lib/lua/5.1/helper-functions.so'
| no file '/build/nvim/parts/nvim/build/.deps/usr/lib/lua/5.1/helper-functions.so'
| no file '/usr/local/lib/lua/5.1/loadall.so'
There seems to be a error with the helper-functions.lua which can't seem to be properly found. The other snippets don't seem to be loaded as well. Presumably because the would be loaded after c.lua. Why is there no error thrown then when writing and sourcing the snippet c.lua? Isn't
local relative_path = vim.fn.expand('%:p:h') .. '/helper-functions.lua'
package.path = package.path .. ";" .. relative_path
local helper = require("helper-functions")
local check_import = helper.check_import
this sufficient? The helper-functions.lua is in the same directory as the snippet files.
Oh, this works when sourcing the file while editing it (because '%' is the file in the current buffer), but not when luasnip does it.
You can move helper-functions.lua
to Neovim/lua/helper-functions.lua
, then require should work :)
(also, try ls.tracked_dopackage
instead of require
so that the snippets are reloaded on editing the helper-file ;D (but this is not at all necessary! require
should work))
That's it. Thank you L3MON4D3 once again :). The ls_tracked_dopackage
did it after require("luasnip")
pretty well. Futhermore it fixed another error I had with LuaSnip.
Nice, happy to help :)
Hello,
when opening a file (e.g.: /tmp/a.cpp) the snippets are not loaded (for e.g. cpp). I can only access LSP completions, but no snippets. I have to open the corresponding snippet file (e.g.: cpp.lua), write it (
:w
- which saves and:so%
with no errors) and then I can access the snippets in the file (e.g.: /tmp/a.cpp).This is my LuaSnip plugin configuration:
snippets.lua
One snippet file like e.g. cpp.lua looks like this
My directory structure looks like
Any clue or any notice which could lead to this behaviour?