243 lines
6.5 KiB
Text
243 lines
6.5 KiB
Text
{
|
|
"Function": {
|
|
"prefix": "fun",
|
|
"body": [
|
|
"fun ${1:name}(${2}): ${3:Unit} {",
|
|
" $0",
|
|
"}"
|
|
],
|
|
"description": "Gotlin function"
|
|
},
|
|
"Main Function": {
|
|
"prefix": "main",
|
|
"body": [
|
|
"fun main() {",
|
|
" $0",
|
|
"}"
|
|
],
|
|
"description": "Gotlin main function"
|
|
},
|
|
"Package": {
|
|
"prefix": "package",
|
|
"body": ["package ${1:demo}"],
|
|
"description": "Gotlin package declaration"
|
|
},
|
|
"Go Import": {
|
|
"prefix": "importgo",
|
|
"body": ["import ${1:alias} \"${2:example.com/module/package}\""],
|
|
"description": "Import a Go module path with an alias"
|
|
},
|
|
"Data Class": {
|
|
"prefix": "dataclass",
|
|
"body": [
|
|
"data class ${1:Name}(",
|
|
" val ${2:value}: ${3:String}",
|
|
")"
|
|
],
|
|
"description": "Gotlin data class"
|
|
},
|
|
"SQL Table Row": {
|
|
"prefix": "tablerow",
|
|
"body": [
|
|
"@table(\"${1:table_name}\")",
|
|
"data class ${2:Row}(",
|
|
" @generated @id val ${3:id}: ${4:Int},",
|
|
" @column(\"${5:value}\") var ${6:value}: ${7:String}",
|
|
")"
|
|
],
|
|
"description": "Annotated SQL table row data class"
|
|
},
|
|
"Embedded Value": {
|
|
"prefix": "embed",
|
|
"body": ["@embed(\"${1:path/to/file}\") val ${2:name}: ${3:ByteSlice}"],
|
|
"description": "Embed a file as a top-level value"
|
|
},
|
|
"Rust-style Enum": {
|
|
"prefix": "enum",
|
|
"body": [
|
|
"enum ${1:Result} {",
|
|
" ${2:Success}(${3:String})",
|
|
" ${4:Failure}(${5:String})",
|
|
" ${6:Pending}",
|
|
"}"
|
|
],
|
|
"description": "Rust-style algebraic enum"
|
|
},
|
|
"Exhaustive Enum Match": {
|
|
"prefix": "match",
|
|
"body": [
|
|
"match (${1:result}) {",
|
|
" ${2:Result}::${3:Success}(${4:value}) -> {",
|
|
" $5",
|
|
" }",
|
|
" ${2:Result}::${6:Failure}(${7:reason}) -> {",
|
|
" $8",
|
|
" }",
|
|
" ${2:Result}::${9:Pending} -> {",
|
|
" $0",
|
|
" }",
|
|
"}"
|
|
],
|
|
"description": "Exhaustive match over enum variants"
|
|
},
|
|
"Exhaustive Match Expression": {
|
|
"prefix": "matchvalue",
|
|
"body": [
|
|
"val ${1:value} = match (${2:result}) {",
|
|
" ${3:Result}::${4:Success}(${5:item}) -> ${5:item}",
|
|
" ${3:Result}::${6:Failure}(${7:reason}) -> ${7:reason}",
|
|
" $0",
|
|
"}"
|
|
],
|
|
"description": "Return a typed value from an exhaustive enum match"
|
|
},
|
|
"Recursive Structural Mapping": {
|
|
"prefix": "mapto",
|
|
"body": ["val ${1:target} = ${2:source}.mapTo<${3:Target}>()"],
|
|
"description": "Recursively map compatible classes or enums"
|
|
},
|
|
"Nullable Safe Access": {
|
|
"prefix": "safe",
|
|
"body": ["${1:value}?.${2:field}"],
|
|
"description": "Safely access a nullable value"
|
|
},
|
|
"Non-null Assertion": {
|
|
"prefix": "nonnull",
|
|
"body": ["${1:value}!!"],
|
|
"description": "Assert that a nullable value is non-null"
|
|
},
|
|
"Result Function": {
|
|
"prefix": "resultfun",
|
|
"body": [
|
|
"fun ${1:name}(${2}): Result<${3:Value}, Error> {",
|
|
" val ${4:value} = ${5:operation}()?",
|
|
" return Result::Ok(${4:value})",
|
|
"}"
|
|
],
|
|
"description": "Function with Rust-style Result propagation"
|
|
},
|
|
"Result Match": {
|
|
"prefix": "resultmatch",
|
|
"body": [
|
|
"match (${1:result}) {",
|
|
" Result::Ok(${2:value}) -> { $3 }",
|
|
" Result::Err(${4:error}) -> { $0 }",
|
|
"}"
|
|
],
|
|
"description": "Match a Result value"
|
|
},
|
|
"Coroutine Scope": {
|
|
"prefix": "coroutinescope",
|
|
"body": ["coroutineScope {", " $0", "}"],
|
|
"description": "Structured child coroutine scope"
|
|
},
|
|
"Launch Coroutine": {
|
|
"prefix": "launch",
|
|
"body": ["launch {", " $0", "}"],
|
|
"description": "Launch a structured child coroutine"
|
|
},
|
|
"Async Coroutine": {
|
|
"prefix": "async",
|
|
"body": ["val ${1:result} = async<${2:Type}> {", " $0", "}"],
|
|
"description": "Start a typed deferred coroutine"
|
|
},
|
|
"Defer Call": {
|
|
"prefix": "defer",
|
|
"body": ["defer ${1:resource}.${2:close}()"],
|
|
"description": "Defer a function call"
|
|
},
|
|
"For Each": {
|
|
"prefix": "foreach",
|
|
"body": [
|
|
"for (${1:item} in ${2:items}) {",
|
|
" $0",
|
|
"}"
|
|
],
|
|
"description": "Iterate over a collection"
|
|
},
|
|
"Typed SQL Fetch": {
|
|
"prefix": "sqlfetch",
|
|
"body": [
|
|
"val ${1:rows}: List<${2:Row}> = sql.from<${2:Row}>()",
|
|
" .where { ${3:it.id == id} }",
|
|
" .fetch(${4:pool}, ${5:ctx})"
|
|
],
|
|
"description": "Fetch typed SQL rows"
|
|
},
|
|
"Typed SQL Single": {
|
|
"prefix": "sqlsingle",
|
|
"body": [
|
|
"val ${1:row}: ${2:Row} = sql.from<${2:Row}>()",
|
|
" .where { ${3:it.id == id} }",
|
|
" .single(${4:pool}, ${5:ctx})"
|
|
],
|
|
"description": "Fetch one typed SQL row"
|
|
},
|
|
"Typed SQL Iterator": {
|
|
"prefix": "sqliterator",
|
|
"body": [
|
|
"val ${1:rows}: GotlinSQLIterator<${2:Row}> = sql.from<${2:Row}>()",
|
|
" .where { ${3:it.id == id} }",
|
|
" .iterator(${4:pool}, ${5:ctx})"
|
|
],
|
|
"description": "Iterate over typed SQL rows"
|
|
},
|
|
"SQL Insert On Conflict Do Nothing": {
|
|
"prefix": "sqlinsertnothing",
|
|
"body": [
|
|
"sql.insert<${1:Row}>(${2:row})",
|
|
" .onConflict { ${3:it.id} }",
|
|
" .doNothing()",
|
|
" .build()"
|
|
],
|
|
"description": "Build an insert that ignores a typed conflict"
|
|
},
|
|
"SQL Insert On Conflict Do Update": {
|
|
"prefix": "sqlinsertupdate",
|
|
"body": [
|
|
"sql.insert<${1:Row}>(${2:row})",
|
|
" .onConflict { ${3:it.id} }",
|
|
" .doUpdate { ${4:excluded} ->",
|
|
" set(${1:Row}.${5:value}, ${4:excluded}.${5:value})",
|
|
" }",
|
|
" .build()"
|
|
],
|
|
"description": "Build an insert that updates on a typed conflict"
|
|
},
|
|
"SQL Update Returning": {
|
|
"prefix": "sqlupdatereturning",
|
|
"body": [
|
|
"val ${1:updated}: *${2:Row} = sql.update<${2:Row}>()",
|
|
" .set { ${3:row} ->",
|
|
" set(${3:row}.${4:value}, ${5:newValue})",
|
|
" }",
|
|
" .where { ${6:it.id == id} }",
|
|
" .returning { it }",
|
|
" .single(${7:pool}, ${8:ctx})"
|
|
],
|
|
"description": "Update and return a typed SQL row"
|
|
},
|
|
"If": {
|
|
"prefix": "if",
|
|
"body": [
|
|
"if (${1:condition}) {",
|
|
" $0",
|
|
"}"
|
|
],
|
|
"description": "If statement"
|
|
},
|
|
"Lambda": {
|
|
"prefix": "lambda",
|
|
"body": ["{ ${1:it} -> $0 }"],
|
|
"description": "Lambda expression"
|
|
},
|
|
"Override Method": {
|
|
"prefix": "override",
|
|
"body": [
|
|
"override fun ${1:name}(${2}): ${3:Unit} {",
|
|
" $0",
|
|
"}"
|
|
],
|
|
"description": "Override a class or interface method"
|
|
}
|
|
}
|