-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__init__.py
More file actions
231 lines (203 loc) · 4.39 KB
/
Copy path__init__.py
File metadata and controls
231 lines (203 loc) · 4.39 KB
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
from cudatext import *
ST_NONE = 'none'
ST_SEL = 'sel'
ST_AFTER = 'after'
ST_BEGIN = 'begin'
ST_MIDDLE = 'mid'
def log(s):
#print('[DocBlock]', s)
pass
JSDOCS = [
'abstract',
'access',
'alias',
'arg',
'argument',
'augments',
'author',
'borrows',
'callback',
'class',
'classdesc',
'const',
'constant',
'constructor',
'constructs',
'copyright',
'default',
'defaultvalue',
'deprecated',
'desc',
'description',
'emits',
'enum',
'event',
'example',
'exception',
'exports',
'extends',
'external',
'file',
'fileoverview',
'fires',
'func',
'function',
'global',
'host',
'ignore',
'inner',
'instance',
'kind',
'lends',
'license',
'link',
'member',
'memberof',
'method',
'mixes',
'mixin',
'module',
'name',
'namespace',
'overview',
'param',
'private',
'prop',
'property',
'protected',
'public',
'readonly',
'requires',
'return',
'returns',
'see',
'since',
'static',
'summary',
'this',
'throws',
'todo',
'tutorial',
'type',
'typedef',
'var',
'variation',
'version',
'virtual',
]
PHPDOCS = [
'abstract',
'access',
'author',
'copyright',
'deprec',
'deprecated',
'example',
'global',
'ignore',
'internal',
'link',
'name',
'package',
'param',
'php',
'return',
'see',
'since',
'static',
'staticvar',
'subpackage',
'todo',
'version',
]
def get_completions(word, is_js):
prefix = 'jsdoc' if is_js else 'phpdoc'
tags = JSDOCS if is_js else PHPDOCS
if bool(word):
tags = [t for t in tags if t.startswith(word)]
items = [prefix + '|' + t + '|' for t in tags]
return '\n'.join(items)+'\n'
def status_on_complete(ed):
x0, y0, x1, y1 = ed.get_carets()[0]
if y1>=0:
return ST_SEL
ln = ed.get_text_line(y0)
if x0 > len(ln):
return ST_AFTER
if not ln.lstrip().startswith('* '):
return ST_NONE
n = ln.find('* ')
if x0<=n:
return ST_NONE
return ST_MIDDLE
def status_on_key(ed):
x0, y0, x1, y1 = ed.get_carets()[0]
if y1>=0:
return ST_SEL
ln = ed.get_text_line(y0)
if ln.rstrip().endswith('/**'):
n = ln.rfind('/**')
if x0>=len(ln.rstrip()):
return ST_BEGIN
else:
return ST_NONE
if ln.lstrip().startswith('*'):
n = ln.find('*')
if x0>=n+2:
return ST_MIDDLE
else:
return ST_NONE
return ST_NONE
class Command:
def on_complete(self, ed_self):
''' autocomplete only after "@" or "@text" '''
log('on_complete init')
st = status_on_complete(ed)
if st not in [ST_MIDDLE]:
return log('on_complete bad status: '+str(st))
x0, y0, x1, y1 = ed.get_carets()[0]
line = ed.get_text_line(y0)
if x0>len(line):
return log('on_complete, after line end')
x0init = x0
while (x0>0) and line[x0-1].isalpha():
x0 -= 1
txt = line[x0-1]
if txt != '@':
return log('on_complete not after @')
lex = ed.get_prop(PROP_LEXER_CARET)
is_js = 'Script' in lex or lex=='JSDoc'
word = line[x0:x0init]
text = get_completions(word, is_js)
len1 = len(word)
x2 = x0init
while x2<len(line) and line[x2].isalpha():
x2 += 1
len2 = x2-x0init
log('on_complete, word="%s" len1=%d len2=%d'%(word, len1, len2))
ed.complete(text, len1, len2)
return True
def on_key(self, ed_self, key, state):
log('on_key init')
ed = ed_self
eol = '\n'
st = status_on_key(ed)
if st not in [ST_BEGIN, ST_MIDDLE]:
return log('on_key, bad status: '+str(st))
if key!=13:
return log('on_key, unknown key')
log('on_key, status: '+str(st))
x, y, x1, y1 = ed.get_carets()[0]
ln = ed.get_text_line(y)
if st==ST_BEGIN:
pos = ln.rfind('/**')
indent = ln[0:pos] + ' '
ed.insert(x, y, eol+indent+'* '+eol+indent+'*/')
ed.set_caret(len(indent)+2, y+1)
return False #block Enter
if st==ST_MIDDLE:
pos = ln.find('* ')
indent = ln[0:pos]
ed.insert(x, y, eol+indent+'* ')
ed.set_caret(len(indent)+2, y+1)
return False #block Enter