-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtypescript.snippets
189 lines (160 loc) · 3 KB
/
typescript.snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
global !p
import px
import re
import px.whitespaces
import px.cursor
def is_typescript():
if vim.eval('&ft') == 'typescript':
return True;
synstack = vim.eval("synstack(line('.'), col('.'))")
if len(synstack) == 0:
return True
name = vim.eval("synIDattr(" + synstack[-1] + ", 'name')")
return name.startswith('typescript')
def is_switch_body(snip):
return px.whitespaces.match_higher_indent(snip.buffer, snip.cursor, 'switch ')
endglobal
context "is_typescript()"
snippet i "if" b
if ($1) {
$2
}
endsnippet
context "is_typescript()"
snippet s "switch" b
switch ($1) {
$2
}
endsnippet
context "is_typescript() and is_switch_body(snip)"
snippet c "case" b
case $1:
$2
break
endsnippet
context "is_typescript()"
snippet p "console.log" b
console.log("`!p
try:
once
except:
once = True
cursor = px.cursor.get()
filename = os.path.basename(px.buffer.get().name)
snip.rv = filename + ":" + str(cursor[0])
` $0")
endsnippet
context "is_typescript()"
snippet pp "console.log" b
console.log("`!p
try:
once
except:
once = True
cursor = px.cursor.get()
filename = os.path.basename(px.buffer.get().name)
snip.rv = filename + ":" + str(cursor[0])
` `!p snip.rv=t[1]`", $1)
endsnippet
snippet fo "for of" b
for (let $1 of $2) {
$3
}
endsnippet
context "is_typescript()"
snippet r "return" b
return $0
endsnippet
context "is_typescript()"
snippet rt "return true" b
return true
endsnippet
context "is_typescript()"
snippet rt "return false" b
return false
endsnippet
context "is_typescript()"
snippet .filter "array filter" i
.filter(
($1) => {
$0
}
)
endsnippet
context "is_typescript()"
snippet a "anonymous function" i
($1) => {
$0
}
endsnippet
context "is_typescript()"
snippet .forEach "array forEach" i
.forEach(
($1) => {
$0
}
)
endsnippet
context "is_typescript()"
snippet .then "promise then" i
.then(
($1) => {
$2
}
)
endsnippet
snippet vue "vue component" b
import Vue from 'vue';
// tslint:disable-next-line: no-default-export
export default Vue.extend({
$0
})
endsnippet
context "is_typescript()"
snippet "^e" "export" rA
export $0
endsnippet
context "is_typescript()"
snippet "^(\w+ )?in" "export interface" rA
`!p snip.rv = match.group(1) if match.group(1) else ''`interface $1 {
$0
}
endsnippet
context "is_typescript()"
snippet "^(\w+ )?f" "export function" r
`!p snip.rv = match.group(1) if match.group(1) else ''`function $1($2): $3 {
$0
}
endsnippet
context "is_typescript()"
snippet "^(\w+ )?cl" "export class" rA
`!p snip.rv = match.group(1) if match.group(1) else ''`class $1 {
$2
}
endsnippet
context "is_typescript()"
snippet "^i" "import from" rA
import $1 from '@/$0';
endsnippet
context "is_typescript()"
snippet "import {" "import" Ab
import { $0 }
endsnippet
context "is_typescript()"
snippet m "" w
$1($2) $3 {
$0
},
endsnippet
context "snip.visual_text"
snippet c "" w
constructor(${1:`!p
params = snip.context
params = params.strip()
params = params.replace(';', '')
params = ', '.join(
map(lambda x: 'public ' + x.strip(), params.split('\n'))
)
snip.rv = params
`}) {}
endsnippet