How to make optional arguments

Asked by bob saget

I want to make a self documenting function snippet with any optional number of arguments, so for example

function moo(a, b) {

}

would get
/**
* TODO
* @method moo
* param {} a
* param {} b
**/

With a, b and any other arguments being completely optional (including no arguments). Something like infinitely optional arguments would be great

* {?@param {} $n}
function ${1:function_name}({$n separator=", "}) {

Or something like that,. Is that possible?

Question information

Language:
English Edit question
Status:
Answered
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
SirVer (sirver) said :
#1

You cannot define tabstops dynamically, no. But what you want to achieve is still possible. Have you tried?

set ft=python
def<tab>

now overwrite arg1 with >a, b, c, d<. Is this what you want to do? If so, check out how it is done in the shipped python snippets.

Can you help with this problem?

Provide an answer of your own, or ask bob saget for more information if necessary.

To post a message you must log in.