-
Am I missing something regarding how condtions are supposed to work? I would think that condtion is a function that determines whether or not a snippet is available. However, this snippet is always available, whether or not I make the function return true or false: s('zzhfg', {
t({ '/**', ' * ' }),
d(1, function()
return sn(1, {
c(1, {
t('0'),
t('1'),
t('2'),
t('3'),
t('4'),
t('5'),
}),
})
end),
t({ '', ' * @file ' }),
f(util_funcs.get_file_name),
t({ '', ' */', '', '#ifndef ' }),
f(util_funcs.to_header_guard, { 1 }),
t({ '', '#define ' }),
f(util_funcs.to_header_guard, { 1 }),
t({ '', '', '#endif // ' }),
f(util_funcs.to_header_guard, { 1 }),
t({ '', '' }),
}, {
condition = function()
return false
end,
}),
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Or a more simple example: s('testSnip', t('Simple text'), {
condition = function()
return false
end,
}), |
Beta Was this translation helpful? Give feedback.
-
And to clarify, I'm returning this snippet in an array from its own file, then in my config function I have: -- Load custom snippets from the snippets directory
require('luasnip.loaders.from_lua').load({
paths = {
vim.fn.stdpath('config') .. '/snippets',
},
})
|
Beta Was this translation helpful? Give feedback.
-
Hi! :) I think you're using something like In fact, To hide the snippet in a completion listing, you can pass your function to These two are separate because manual expansion and listing the snippet have different circumstances, for example there is no trigger available for Hope this helps, and sorry for the late reply :) |
Beta Was this translation helpful? Give feedback.
Hi! :)
I think you're using something like
nvim-cmp
, and the snippets keeps showing up despitecondition=false
, is that correct?In fact,
condition
only deals with manual expand, so typing the trigger and then whatever key you havels.expand()
mapped to; ifcondition
returns false then, the snippet won't expand.To hide the snippet in a completion listing, you can pass your function to
show_condition
instead ofcondition
.These two are separate because manual expansion and listing the snippet have different circumstances, for example there is no trigger available for
show_condition
.Hope this helps, and sorry for the late reply :)