/
snippets.py
252 lines (245 loc) · 7.14 KB
/
snippets.py
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)
"""
Spyder default text snippets.
Notes:
1. Please preserve the structure of this dictionary. This is what
we need to send to the snippet plugin to configure it.
2. All snippets added here need to comply with the LSP snippet grammar:
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#snippet_syntax
3. The snippets are grouped according to the text that triggers it and each
snippet has the option to delete the trigger text if necessary.
4. Right now, the snippets are restricted to the languages supported by the LSP
(hard-coded), this will change on future releases of Spyder.
"""
from textwrap import dedent
PYTHON_SNIPPETS = {
'class': {
'plain': {
'text': dedent("""
class ${1:ClassName}:
def __init__(self, ${2:*args}, ${3:**kwargs}):
${4:pass}$0
""").strip(),
'remove_trigger': False
},
'inheritance': {
'text': dedent("""
class ${1:ClassName}($2):
def __init__(self, ${3:*args}, ${4:**kwargs}):
super().__init__(${5:*args}, ${6:**kwargs})$0
""").strip(),
'remove_trigger': False
}
},
'def': {
'method': {
'text': dedent("""
def ${1:method_name}(self, ${2:*args}, ${3:**kwargs}):
${4:pass}$0
""").strip(),
'remove_trigger': False
},
'function': {
'text': dedent("""
def ${1:func_name}(${2:*args}, ${3:**kwargs}):
${4:pass}$0
""").strip(),
'remove_trigger': False
}
},
'for': {
'range': {
'text': dedent("""
for ${1:i} in range(${2:0}, ${3:n}):
${4:pass}$0
""").strip(),
'remove_trigger': False
},
'iterator': {
'text': dedent("""
for ${1:x} in ${2:iterator}:
${3:pass}$0
""").strip(),
'remove_trigger': False
}
},
'while': {
'condition': {
'text': dedent("""
while ${1:cond}:
${2:pass}$0
""").strip(),
'remove_trigger': False
},
'infinite': {
'text': dedent("""
while True:
${1:pass}$0
""").strip(),
'remove_trigger': False
}
},
'import': {
'package': {
'text': dedent("""
import ${1:package}$0
""").strip(),
'remove_trigger': False
},
'alias': {
'text': dedent("""
import ${1:package} as ${2:alias}$0
""").strip(),
'remove_trigger': False
}
},
'from': {
'import': {
'text': dedent("""
from ${1:package} import ${2:module}$0
""").strip(),
'remove_trigger': False
},
'alias': {
'text': dedent("""
from ${1:package} import ${2:module} as ${3:alias}$0
""").strip(),
'remove_trigger': False
}
},
'async': {
'def': {
'text': dedent("""
async def ${1:func_name}(${2:*args}, ${3:**kwargs}):
${4:pass}$0
""").strip(),
'remove_trigger': False
},
'method': {
'text': dedent("""
async def ${1:method_name}(self, ${2:*args}, ${3:**kwargs}):
${4:pass}$0
""").strip(),
'remove_trigger': False
},
'for': {
'text': dedent("""
async for ${1:x} in ${2:iterator}:
${3:pass}$0
""").strip(),
'remove_trigger': False
}
},
'try': {
'except': {
'text': dedent("""
try:
${1:pass}
except ${2:Exception}:
${3:pass}$0
"""),
'remove_trigger': False
},
'except alias': {
'text': dedent("""
try:
${1:pass}
except ${2:Exception} as ${3:e}:
${4:pass}$0
""").strip(),
'remove_trigger': False
},
'except/finally': {
'text': dedent("""
try:
${1:pass}
except ${2:Exception}:
${3:pass}
finally:
${4:pass}$0
""").strip(),
'remove_trigger': False
},
'except alias/finally': {
'text': dedent("""
try:
${1:pass}
except ${2:Exception} as ${3:e}:
${4:pass}
finally:
${5:pass}$0
""").strip(),
'remove_trigger': False
}
},
'with': {
'context': {
'text': dedent("""
with ${1:context} as ${2:alias}:
${3:pass}$0
""").strip(),
'remove_trigger': False
}
},
'list': {
'comprehension': {
'text': dedent("""
[${1:x} for ${2:x} in ${3:iterator}]$0
""").strip(),
'remove_trigger': True
},
'comprehension if': {
'text': dedent("""
[${1:x} for ${2:x} in ${3:iterator} if ${4:cond}]$0
""").strip(),
'remove_trigger': True
},
'comprehension if/else': {
'text': dedent("""
[${1:x} if ${2:cond} else ${3:other} for ${4:x} in ${5:iterator}]$0
""").strip(),
'remove_trigger': True
}
},
'dict': {
'comprehension': {
'text': dedent(r"""
{${1:key}:${2:value} for ${3:elem} in ${4:iterator}\}$0
""").strip(),
'remove_trigger': True
},
'comprehension if': {
'text': dedent(r"""
{${1:key}:${2:value} for ${3:elem} in ${4:iterator} if ${5:cond}\}$0
""").strip(),
'remove_trigger': True
}
},
'set': {
'comprehension': {
'text': dedent(r"""
{${1:elem} for ${2:elem} in ${3:iterator}\}$0
""").strip(),
'remove_trigger': True
},
'comprehension if': {
'text': dedent(r"""
{${1:elem} for ${2:elem} in ${3:iterator} if ${4:cond}\}$0
""").strip(),
'remove_trigger': True
},
'comprehension if/else': {
'text': dedent(r"""
{${1:elem} if ${2:cond} else ${3:other} for ${4:elem} in ${5:iterator}\}$0
""").strip(),
'remove_trigger': True
}
}
}
SNIPPETS = {
'python': PYTHON_SNIPPETS
}