Skip to content

Instantly share code, notes, and snippets.

@drhayes
Created June 14, 2021 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drhayes/a8e64c1b31ec9e0bd71d3a73fc73a051 to your computer and use it in GitHub Desktop.
Save drhayes/a8e64c1b31ec9e0bd71d3a73fc73a051 to your computer and use it in GitHub Desktop.
My current custom lua snippets for Visual Studio Code.
{
// Place your snippets for lua here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Busted describe block": {
"prefix": "desc",
"body": [
"describe('${1:thing to test}', function()",
" $0",
"end)"
]
},
"Busted it block": {
"prefix": "it",
"body": [
"it('${1:does a thing}', function()",
" $0",
"end)"
]
},
"Local require": {
"prefix": "lreq",
"body": [
"local ${1:lume} = require '${2:lib.$1}'$0"
]
},
"assert.are.equal": {
"prefix": "aae",
"body": [
"assert.are.equal(${1:first}, ${2:second})"
]
},
"method": {
"prefix": "fun:",
"body": [
"function ${1:${TM_FILENAME_BASE/(.*)$/${1:/capitalize}/}}:${2:functionName}($3)",
"\t$0",
"end"
]
},
"function": {
"prefix": "fun",
"body": [
"function ${1:$TM_FILENAME_BASE}.${2:functionName}($3)",
"\t$0",
"end"
]
},
"ldi": {
"prefix": "ldi",
"body": "log.debug(inspect($0))"
},
"super": {
"prefix": "super",
"body": "${1:${TM_FILENAME_BASE/(.*)$/${1:/capitalize}/}}.super.${2:Method}(self$0)"
},
"inc": {
"prefix": "inc",
"body": "${1:var} = $1 + ${2:1}$0"
},
"dec": {
"prefix": "dec",
"body": "${1:var} = $1 - ${2:1}$0"
},
"For pairs iterator": {
"prefix": "forp",
"body": [
"for ${1:key}, ${2:value} in pairs($3) do",
"\t$0",
"end"
]
},
"For loop over collection": {
"prefix": "for",
"body": [
"for ${1:i} = 1, #${2:collection} do",
"\tlocal ${3:child} = $2[$1]$0",
"end",
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment