-
-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-context-snippets #774
Conversation
90cc190
to
f60967e
Compare
Some more changes:
An example: ls.setup_snip_env()
local ms = require("luasnip.extras.multi_snippet").new_multisnippet
local first_a = require("luasnip.extras.conditions").make_condition(function(ltc)
return ltc:sub(1,1) == "a"
end)
ls.add_snippets("all", {
ms({
-- this is applied to all of the multiple contexts.
common = {trig = "a"},
-- first character not a => autotrigger
{condition = -first_a, snippetType = "autosnippet"},
-- otherwise: still allow manual triggering
{condition = first_a},
-- override common trigger.
"c"
}, {t"a or b"})
}, {
key = "ab"
}) Also, ms({"a", "b", {trig="c", hidden = true}}, {<some nodes>}, {{condition = cond_for_a}, {condition = cond_for_b}, {no_condition_for_c = nil}}) OTOH, if we now settle for only a single opts-table (so not a list of opts-tables), it'll be hard to add later 🥲 |
4aca2c4
to
c9a9826
Compare
|
a16375e
to
06ebc31
Compare
9cab739
to
0b8c50b
Compare
…add_snippets`. only for internal usage for now, not api.
Since `init_context` is now responsible for creating a table which can be added by add_snippets, has `invalidate`, `matches`, ..., `invalidated` should be initilized in there.
don't reuse passed-in context-table, wrap context in string at api-boundary, and not in internal methods (`init_snippet_context`).
common = {snippetType = "autosnippet"}, | ||
{trig = "a", snippetType = "snippet"}, | ||
"b", | ||
{trig = "c", condition = function(line_to_cursor) | ||
return line_to_cursor == "" | ||
end} | ||
}, { | ||
t"a or b (but autotriggered!!)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't common not supposed to override settings specific to each entry? In that case, a will not be autoTriggered. or I am missing something?
Also, will be cool to account for C in the snippet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, that snippet-string bit imprecise. In this case b
and c
would be autotriggered, but a
would not. I'll amend that later👍
@L3MON4D3 api looks great. I just added a little comment on PR for docs. Sorry for being that late |
Don't worry, thank you for taking a look :D |
Example:
1676497115.mp4
The main changes/ideas to accomodate this are:
anything inside a table passed to add_snippets is expected to have a function,
retrieve_all
which returns all "expandable" objects associated with that "addable""expandable" objects only have to be able to perform
matches
(formatch_snippet
insnippet_collection
)copy
(currently copies the snippet stored insnippet_collection
, since we need each of the snippets inserted into the buffer to be unique)get_docstring
(to get docstring shown in completion-engines) andinvalidate
(to disable the snippet, but not yet delete it from the collection)but don't have to be actual snippets, which allows us to point multiple of these "expandables" to just one snippet-object (it just has to be returned on
copy
)Missing:
opts
(at all, and different ones (maybe only different conditions)). If we allowStuff to think about:
ms
is not that great, we'd probably want to do some merging of the tables, such that common keys don't have to be repeated. Not sure what's the user-friendliest behaviour herecontext
, the first table passed tos
, to containcondition
andshow_condition
. I'd like to make that the default shown in the docs since it makes more sense (conceptually: the first table is for stuff affecting the expansion of the snippet, while the third/[second non-nodes-] table is for stuff affecting the expanded snippet), while still respecting the conditions when set in theopts
-table. I'm uncertain whether here, in this new, so-far-unused function, we should also accomodate the conditions when they're set in theopts
-table. It would make more sense without knowing too much about the internals ("why does this behave differently froms
??"), but would slightly complicate the implementation. Seems better to allow it, but worth thinking about.Finally:
I think I'll add e88165f not in this PR, but directly to master, since it is completely tangential and I just noticed it while working on this.