LuaSnip
LuaSnip copied to clipboard
Stored values in Snippet Node
Actual
I have a seperate plugin of snippets. Pretty much all the components are reusable. Following is how I have defined a Javascript function
function lexical_declarative_arrow_function()
-- returns a lexical declarative arrow function node
end
function lexical_declarative_arrow_function()
-- returns a declarative function node
end
function func()
return fmt('{}', {
c(1, {
lexical_declarative_arrow_function(),
declarative_function(),
}),
})
end
Now the user can register the snippet to a any trigger string they want as follows
s('f', js.dynamic.func(), {
stored = {
name = i(1, 'name'),
param = i(1),
body = i(1),
},
})
Expected
Here stored values for RestoreNode is defined at ls.s. As a result, anyone who want to use my snippets needs to know what the names of the stored values should be by digging up the source code. I think it would be lovely to have them defined at SnippetNode level like below.
function func()
return sn(nil, {
fmt('{}', {
c(1, {
lexical_declarative_arrow_function(),
declarative_function(),
}),
}),
}, {
stored = {
name = i(1, 'name'),
param = i(1),
body = i(1),
},
})
end
Now the user can forget about the stored values completly and just register the snippet
s('f', js.dynamic.func())
I think this would be a cool feature to have.
Oh cool, nice idea (first of all :D)
Have you considered defining the default-value in the restoreNode itself? That would at least solve the immediate problem.
But, this kind of issue is likely to reappear, because the snippet-nodes often expect the trigger/snippet-definition to uphold some assumptions (trigger has captures, there is some callback defined on the snippet).
We have some code that separates the snippet from the object that is added via add_snippets, and that would circumvent most of these issues (excepting the trigger-captures, that has to be specified outside the code somehow), but it's currently non-documented.
If it would be useful to you, I can add it to the api