David Bambušek David Bambušek - 1 year ago 166
CoffeeScript Question

Visual Studio Code loops in snippets

Is there a way how to use loops or conditionals when creating snippets in VS Code? I am trying to create a snippet that will generate a template for JSDoc documentation syntax for a function. Example (I am using coffeescript):

myFunction: (param1, param2): ->
# some code
return


And I would like a snippet that generates:

###*
* @param {} param1
* @param {} param2
* @return {}
###
myFunction: (param1, param2): ->
# some code
return


I am able to create a snippet, that will simply generate:

###*
* @return {}
###


using this snippet settings:

"JSDocs Template": {
"prefix": "jsdoc",
"body": [
"###*",
" * @return {}",
"###"
],
"description": "create template for JSDocs"
}


But to achieve want I need, I would have to use a loop to go through the param list and that is where I struggle...

Answer Source

So after some research I found out that such a behaviour is not possible with snippets only, therefore I have create my own extension CoffeeScript JSDoc. Feel free to use it and extend it if necessary...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download