3

I am following this guide to setup Snippets in lua. I managed to get the first example snippet working,

but then noticed the Readme for Luasnip ( Resources for beginners section) mention that

"Unfortunately there were some breaking changes in LuaSnip since these videos were recorded:

Snippets are now added via ls.add_snippets instead of with ls.snippets = {}"

But the guide is still using ls.snippets which seems to be working for me

PS this is a example from the guide (works on my setup)

return {

-- A snippet that expands the trigger "hi" into the string "Hello, world!".

 require("luasnip").snippet(

{ trig = "hi" },

{ t("Hello, world!")}

),

}
ls = require("luansip")

So Whats the difference between these two? are they interchangeable? Is there any problem if I use ls.snippets{} Any advice is much appreciated

Additional Info Nvim version -nightly

6
  • Welcome to Vim :-) I'm not I can identify your question. Could you precise what you want to know? What do you want to do? What have you tried? What are the symptômes of failure? Other tyoe of questions more general are also welcome but I don't identify yours :-/ Sep 14, 2023 at 2:15
  • I am trying to add snippets via Luasnip plugin. The guide I am following (linked above) uses ls.snippet to define new snippets, but the Readme for LuaSnip says that ls,add has been depriciated and the new way of defining snippets is via ls.add_snippets.But since ls.snippets work for me still my question is Is it safe to continue using ls.snipets?
    – kay
    Sep 14, 2023 at 2:36
  • Thanks for the clarification :-). Could you tell us: Which snippet do you want to add? What have you tried? And what are the symptômes of failure? It will help us reproduce your problem and validate a solution we could find :-) Sep 14, 2023 at 2:39
  • 1
    Using LuaSnio ill add snippets for python lua latex and julia I have tried the instructions in the guide There is no failure,as I mentioned the docs says the method used in the guide no longer works, But It works for me.My question is basically regarding weather or not it is safe to continue using the ls.snippets method
    – kay
    Sep 14, 2023 at 4:38
  • Reading the doc and tutorial at first it look it has been adapted to use add_snippets. I believe you are safe. Sep 14, 2023 at 5:28

1 Answer 1

1

You are mixing up 2 ways , or rather 2 functions , here.

It is true :

... Unfortunately there were some breaking changes in LuaSnip ... :  
Snippets are now added via `ls.add_snippets` instead of with `ls.snippets = {}` ...  

You are instead using ls.snippet() which is still valid. [[ Highlighting : it is not snippets , it is snippet ]]

Documentation gives the clear Picture :

https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md

The snippets for a given filetype have to be added to luasnip via  
ls.add_snippets(filetype, snippets).  
Snippets that should be accessible globally (in all filetypes)  
have to be added to the special filetype all.  

[[ this is what you saw ]]

Earlier it says :

All code snippets in this help assume the following:  
local ls = require("luasnip")  
local s = ls.snippet  
Snippets are always created using the s(trigger:string, nodes:table)-function.  
It is explained in more detail in Snippets, but the gist is that it creates a snippet  

The s here is ls.snippet which is valid while ls.snippets is invalid.
You were using the valid way !
Everything is Consistent !

1
  • Thankyou so much!
    – kay
    Sep 14, 2023 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.