dart.lua (3153B)
1 local U = require 'snippets.utils' 2 3 -- function test_func(name) 4 -- return function() U.match_indentation(string.format('%s(\'$1\', () {\n$0\n});', name)) end 5 -- end 6 7 local function test_func_snippet(name, nodesc) 8 local S 9 if nodesc then 10 S = [[ 11 ${-1}(() { 12 $0 13 });]] 14 else 15 S = [[ 16 ${-1}('$1', () { 17 $0 18 });]] 19 end 20 S = U.match_indentation(S) 21 return U.iterate_variables_by_id(S, -1, function(v) v.default = name end) 22 end 23 24 return { 25 ['lib'] = [[library ${1};]], 26 ['im'] = [[import 'package:${1}/${2}.dart';]], 27 ['rgx'] = U.match_indentation [[new RegExp(r'${1}')]], 28 ['var'] = U.match_indentation [[var ${1} = ${2};]], 29 ['st'] = U.match_indentation [[static ${0}]], 30 ['fi'] = U.match_indentation [[final ${0}]], 31 ['re'] = U.match_indentation [[return ${0}]], 32 ['br'] = U.match_indentation [[break;]], 33 ['th'] = [[throw ${0}]], 34 ['cl'] = [[class ${1=camel_case(vim.fn.expand("%:t:r"))} ${0}]], 35 ['in'] = [[interface ${1=camel_case(vim.fn.expand("%:t:r"))} ${0}]], 36 ['imp'] = [[implements ${0}]], 37 ['ext'] = [[extends ${0}]], 38 39 ['if'] = U.match_indentation [[ 40 if (${1:true}) { 41 ${0} 42 }]], 43 44 ['ife'] = U.match_indentation [[ 45 if (${1:true}) { 46 ${2} 47 } else { 48 ${0} 49 } 50 ]], 51 52 ['el'] = U.match_indentation [[ 53 else 54 ]], 55 56 ['sw'] = U.match_indentation [[ 57 switch (${1}) { 58 ${0} 59 } 60 ]], 61 62 ['cs'] = U.match_indentation [[ 63 case ${1}: 64 ${0}]], 65 66 ['de'] = U.match_indentation [[ 67 default: 68 ${0}]], 69 70 ['wh'] = U.match_indentation [[ 71 while (${1:/* condition */}) { 72 ${0} 73 }]], 74 75 ['dowh'] = U.match_indentation [[ 76 do { 77 ${0} 78 } while (${0:/* condition */});]], 79 80 ['as'] = U.match_indentation [[assert(${0:/* condition */});]], 81 82 ['try'] = [[ 83 try { 84 ${0:${VISUAL}} 85 } catch (${1:Exception e}) { 86 }]], 87 88 ['tryf'] = [[ 89 try { 90 ${0:${VISUAL}} 91 } catch (${1:Exception e}) { 92 } finally { 93 }]], 94 95 ['main'] = [[ 96 main() { 97 ${0} 98 }]], 99 100 ['for'] = U.match_indentation [[ 101 for (var ${1:i} = 0; $1 < ${2}; $1++) { 102 $0 103 }]], 104 105 ['fore'] = U.match_indentation [[ 106 for (final $1 in $2) { 107 $0 108 }]], 109 110 -- test 111 ['ex'] = U.match_indentation [[expect($1, $0);]], 112 ['exr'] = U.match_indentation [[expect($2, $0, reason: '$1');]], 113 ['tst'] = test_func_snippet('test'), 114 ['grp'] = test_func_snippet('group'), 115 ['stp'] = test_func_snippet('setUp', true), 116 ['td'] = test_func_snippet('tearDown', true), 117 118 -- Angular 119 ['ngc'] = U.match_indentation [[ 120 @Component( 121 selector: '${1=vim.fn.expand("%:t:r"):gsub("_", "-")}', 122 templateUrl: '${2=vim.fn.expand("%:t:r")}.html', 123 styleUrls: ['$2.css'], 124 directives: [coreDirectives], 125 providers: [], 126 changeDetection: ChangeDetectionStrategy.OnPush, 127 ) 128 class ${3=camel_case(vim.fn.expand("%:t:r"))} { 129 $0 130 }]], 131 132 ['ngcp'] = U.match_indentation [[ 133 @Component( 134 selector: '${1=vim.fn.expand("%:t:r"):gsub("_", "-")}', 135 templateUrl: '${2=vim.fn.expand("%:t:r")}.html', 136 styleUrls: ['$2.css'], 137 directives: [coreDirectives], 138 providers: [], 139 changeDetection: ChangeDetectionStrategy.OnPush, 140 ) 141 class ${3=camel_case(vim.fn.expand("%:t:r"))} { 142 final ChangeDetectorRef changeDetector; 143 144 $3(this.changeDetector); 145 146 $0 147 }]], 148 }