@bhsd/codemirror-mediawiki 2.28.2 → 2.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -2
- package/dist/bidi.js +84 -0
- package/dist/codemirror.js +608 -0
- package/dist/color.js +52 -0
- package/dist/config.js +119 -0
- package/dist/css.js +30 -0
- package/dist/escape.js +35 -0
- package/dist/fold.js +445 -0
- package/dist/hover.js +52 -0
- package/dist/indent.js +50 -0
- package/dist/inlay.js +68 -0
- package/dist/javascript.js +5 -0
- package/dist/keybindings.js +35 -0
- package/dist/keymap.js +36 -0
- package/dist/linter.d.ts +1 -0
- package/dist/linter.js +134 -0
- package/dist/lua.js +428 -0
- package/dist/main.min.js +25 -29
- package/dist/matchBrackets.d.ts +7 -0
- package/dist/matchBrackets.js +58 -0
- package/dist/matchTag.js +139 -0
- package/dist/mediawiki.js +443 -0
- package/dist/mw.min.js +31 -35
- package/dist/openLinks.js +97 -0
- package/dist/ref.js +85 -0
- package/dist/signature.js +69 -0
- package/dist/static.js +46 -0
- package/dist/statusBar.js +138 -0
- package/dist/token.js +1888 -0
- package/dist/wiki.min.js +33 -37
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +19 -18
- package/dist/keybindings.d.mts +0 -15
- package/dist/keybindings.mjs +0 -34
- package/dist/linter.d.mts +0 -43
- package/dist/linter.mjs +0 -132
- /package/dist/{mwConfig.d.mts → mwConfig.d.ts} +0 -0
- /package/dist/{mwConfig.mjs → mwConfig.js} +0 -0
package/dist/lua.js
ADDED
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import { lua } from '@codemirror/legacy-modes/mode/lua';
|
|
2
|
+
import { syntaxTree, LanguageSupport, StreamLanguage, foldService } from '@codemirror/language';
|
|
3
|
+
import { snippetCompletion } from '@codemirror/autocomplete';
|
|
4
|
+
const map = {
|
|
5
|
+
1: 'constant',
|
|
6
|
+
2: 'function',
|
|
7
|
+
3: 'interface',
|
|
8
|
+
4: 'namespace',
|
|
9
|
+
}, globals = {
|
|
10
|
+
debug: {
|
|
11
|
+
traceback: 2,
|
|
12
|
+
},
|
|
13
|
+
math: {
|
|
14
|
+
abs: 2,
|
|
15
|
+
acos: 2,
|
|
16
|
+
asin: 2,
|
|
17
|
+
atan: 2,
|
|
18
|
+
atan2: 2,
|
|
19
|
+
ceil: 2,
|
|
20
|
+
cos: 2,
|
|
21
|
+
cosh: 2,
|
|
22
|
+
deg: 2,
|
|
23
|
+
exp: 2,
|
|
24
|
+
floor: 2,
|
|
25
|
+
fmod: 2,
|
|
26
|
+
frexp: 2,
|
|
27
|
+
huge: 1,
|
|
28
|
+
ldexp: 2,
|
|
29
|
+
log: 2,
|
|
30
|
+
log10: 2,
|
|
31
|
+
max: 2,
|
|
32
|
+
min: 2,
|
|
33
|
+
modf: 2,
|
|
34
|
+
pi: 1,
|
|
35
|
+
pow: 2,
|
|
36
|
+
rad: 2,
|
|
37
|
+
random: 2,
|
|
38
|
+
randomseed: 2,
|
|
39
|
+
sin: 2,
|
|
40
|
+
sinh: 2,
|
|
41
|
+
sqrt: 2,
|
|
42
|
+
tan: 2,
|
|
43
|
+
tanh: 2,
|
|
44
|
+
},
|
|
45
|
+
os: {
|
|
46
|
+
clock: 2,
|
|
47
|
+
date: 2,
|
|
48
|
+
difftime: 2,
|
|
49
|
+
time: 2,
|
|
50
|
+
},
|
|
51
|
+
package: {
|
|
52
|
+
loaded: 3,
|
|
53
|
+
loaders: 3,
|
|
54
|
+
preload: 3,
|
|
55
|
+
seeall: 2,
|
|
56
|
+
},
|
|
57
|
+
string: {
|
|
58
|
+
byte: 2,
|
|
59
|
+
char: 2,
|
|
60
|
+
find: 2,
|
|
61
|
+
format: 2,
|
|
62
|
+
gmatch: 2,
|
|
63
|
+
gsub: 2,
|
|
64
|
+
len: 2,
|
|
65
|
+
lower: 2,
|
|
66
|
+
match: 2,
|
|
67
|
+
rep: 2,
|
|
68
|
+
reverse: 2,
|
|
69
|
+
sub: 2,
|
|
70
|
+
ulower: 2,
|
|
71
|
+
upper: 2,
|
|
72
|
+
uupper: 2,
|
|
73
|
+
},
|
|
74
|
+
table: {
|
|
75
|
+
concat: 2,
|
|
76
|
+
insert: 2,
|
|
77
|
+
maxn: 2,
|
|
78
|
+
remove: 2,
|
|
79
|
+
sort: 2,
|
|
80
|
+
},
|
|
81
|
+
mw: {
|
|
82
|
+
addWarning: 2,
|
|
83
|
+
allToString: 2,
|
|
84
|
+
clone: 2,
|
|
85
|
+
getCurrentFrame: 2,
|
|
86
|
+
incrementExpensiveFunctionCount: 2,
|
|
87
|
+
isSubsting: 2,
|
|
88
|
+
loadData: 2,
|
|
89
|
+
loadJsonData: 2,
|
|
90
|
+
dumpObject: 2,
|
|
91
|
+
log: 2,
|
|
92
|
+
logObject: 2,
|
|
93
|
+
hash: {
|
|
94
|
+
hashValue: 2,
|
|
95
|
+
listAlgorithms: 2,
|
|
96
|
+
},
|
|
97
|
+
html: {
|
|
98
|
+
create: 2,
|
|
99
|
+
},
|
|
100
|
+
language: {
|
|
101
|
+
fetchLanguageName: 2,
|
|
102
|
+
fetchLanguageNames: 2,
|
|
103
|
+
getContentLanguage: 2,
|
|
104
|
+
getFallbacksFor: 2,
|
|
105
|
+
isKnownLanguageTag: 2,
|
|
106
|
+
isSupportedLanguage: 2,
|
|
107
|
+
isValidBuiltInCode: 2,
|
|
108
|
+
isValidCode: 2,
|
|
109
|
+
new: 2,
|
|
110
|
+
},
|
|
111
|
+
message: {
|
|
112
|
+
new: 2,
|
|
113
|
+
newFallbackSequence: 2,
|
|
114
|
+
newRawMessage: 2,
|
|
115
|
+
rawParam: 2,
|
|
116
|
+
numParam: 2,
|
|
117
|
+
getDefaultLanguage: 2,
|
|
118
|
+
},
|
|
119
|
+
site: {
|
|
120
|
+
currentVersion: 1,
|
|
121
|
+
scriptPath: 1,
|
|
122
|
+
server: 1,
|
|
123
|
+
siteName: 1,
|
|
124
|
+
stylePath: 1,
|
|
125
|
+
namespaces: 3,
|
|
126
|
+
contentNamespaces: 3,
|
|
127
|
+
subjectNamespaces: 3,
|
|
128
|
+
talkNamespaces: 3,
|
|
129
|
+
stats: {
|
|
130
|
+
pages: 1,
|
|
131
|
+
articles: 1,
|
|
132
|
+
files: 1,
|
|
133
|
+
edits: 1,
|
|
134
|
+
users: 1,
|
|
135
|
+
activeUsers: 1,
|
|
136
|
+
admins: 1,
|
|
137
|
+
pagesInCategory: 2,
|
|
138
|
+
pagesInNamespace: 2,
|
|
139
|
+
usersInGroup: 2,
|
|
140
|
+
interwikiMap: 2,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
text: {
|
|
144
|
+
decode: 2,
|
|
145
|
+
encode: 2,
|
|
146
|
+
jsonDecode: 2,
|
|
147
|
+
jsonEncode: 2,
|
|
148
|
+
killMarkers: 2,
|
|
149
|
+
listToText: 2,
|
|
150
|
+
nowiki: 2,
|
|
151
|
+
split: 2,
|
|
152
|
+
gsplit: 2,
|
|
153
|
+
tag: 2,
|
|
154
|
+
trim: 2,
|
|
155
|
+
truncate: 2,
|
|
156
|
+
unstripNoWiki: 2,
|
|
157
|
+
unstrip: 2,
|
|
158
|
+
JSON_PRESERVE_KEYS: 1,
|
|
159
|
+
JSON_TRY_FIXING: 1,
|
|
160
|
+
JSON_PRETTY: 1,
|
|
161
|
+
},
|
|
162
|
+
title: {
|
|
163
|
+
equals: 2,
|
|
164
|
+
compare: 2,
|
|
165
|
+
getCurrentTitle: 2,
|
|
166
|
+
new: 2,
|
|
167
|
+
makeTitle: 2,
|
|
168
|
+
},
|
|
169
|
+
uri: {
|
|
170
|
+
encode: 2,
|
|
171
|
+
decode: 2,
|
|
172
|
+
anchorEncode: 2,
|
|
173
|
+
buildQueryString: 2,
|
|
174
|
+
parseQueryString: 2,
|
|
175
|
+
canonicalUrl: 2,
|
|
176
|
+
fullUrl: 2,
|
|
177
|
+
localUrl: 2,
|
|
178
|
+
new: 2,
|
|
179
|
+
validate: 2,
|
|
180
|
+
},
|
|
181
|
+
ustring: {
|
|
182
|
+
maxPatternLength: 1,
|
|
183
|
+
maxStringLength: 1,
|
|
184
|
+
byte: 2,
|
|
185
|
+
byteoffset: 2,
|
|
186
|
+
char: 2,
|
|
187
|
+
codepoint: 2,
|
|
188
|
+
find: 2,
|
|
189
|
+
format: 2,
|
|
190
|
+
gcodepoint: 2,
|
|
191
|
+
gmatch: 2,
|
|
192
|
+
gsub: 2,
|
|
193
|
+
isutf8: 2,
|
|
194
|
+
len: 2,
|
|
195
|
+
lower: 2,
|
|
196
|
+
match: 2,
|
|
197
|
+
rep: 2,
|
|
198
|
+
sub: 2,
|
|
199
|
+
toNFC: 2,
|
|
200
|
+
toNFD: 2,
|
|
201
|
+
toNFKC: 2,
|
|
202
|
+
toNFKD: 2,
|
|
203
|
+
upper: 2,
|
|
204
|
+
},
|
|
205
|
+
ext: 4,
|
|
206
|
+
},
|
|
207
|
+
}, builtin = ['false', 'nil', 'true'], builtins = builtin.map(label => ({ label, type: 'constant' })), tables = [
|
|
208
|
+
'_G',
|
|
209
|
+
...Object.keys(globals),
|
|
210
|
+
].map(label => ({ label, type: 'namespace' })), constants = [
|
|
211
|
+
{ label: '_VERSION', type: 'constant' },
|
|
212
|
+
...[
|
|
213
|
+
'assert',
|
|
214
|
+
'error',
|
|
215
|
+
'getfenv',
|
|
216
|
+
'getmetatable',
|
|
217
|
+
'ipairs',
|
|
218
|
+
'next',
|
|
219
|
+
'pairs',
|
|
220
|
+
'pcall',
|
|
221
|
+
'rawequal',
|
|
222
|
+
'rawget',
|
|
223
|
+
'rawset',
|
|
224
|
+
'select',
|
|
225
|
+
'setmetatable',
|
|
226
|
+
'tonumber',
|
|
227
|
+
'tostring',
|
|
228
|
+
'type',
|
|
229
|
+
'unpack',
|
|
230
|
+
'xpcall',
|
|
231
|
+
'require',
|
|
232
|
+
].map(label => ({ label, type: 'function' })),
|
|
233
|
+
], binary = [
|
|
234
|
+
'and',
|
|
235
|
+
'or',
|
|
236
|
+
'in',
|
|
237
|
+
].map(label => ({ label, type: 'keyword' })), unary = [
|
|
238
|
+
...[
|
|
239
|
+
'not',
|
|
240
|
+
'function',
|
|
241
|
+
].map(label => ({ label, type: 'keyword' })),
|
|
242
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
243
|
+
snippetCompletion('function ${name}(${})\n\t${}\nend', {
|
|
244
|
+
label: 'function',
|
|
245
|
+
detail: 'definition',
|
|
246
|
+
type: 'keyword',
|
|
247
|
+
}),
|
|
248
|
+
], blocks = [
|
|
249
|
+
'break',
|
|
250
|
+
'elseif',
|
|
251
|
+
'return',
|
|
252
|
+
'end',
|
|
253
|
+
'then',
|
|
254
|
+
'else',
|
|
255
|
+
'do',
|
|
256
|
+
'until',
|
|
257
|
+
'goto',
|
|
258
|
+
].map(label => ({ label, type: 'keyword' })), keywords = [
|
|
259
|
+
...[
|
|
260
|
+
'if',
|
|
261
|
+
'while',
|
|
262
|
+
'repeat',
|
|
263
|
+
'for',
|
|
264
|
+
'local',
|
|
265
|
+
].map(label => ({ label, type: 'keyword' })),
|
|
266
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
267
|
+
snippetCompletion('if ${condition} then\n\t${}\nend', {
|
|
268
|
+
label: 'if',
|
|
269
|
+
detail: 'block',
|
|
270
|
+
type: 'keyword',
|
|
271
|
+
}),
|
|
272
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
273
|
+
snippetCompletion('if ${condition} then\n\t${}\nelse\n\t${}\nend', {
|
|
274
|
+
label: 'if',
|
|
275
|
+
detail: '/ else block',
|
|
276
|
+
type: 'keyword',
|
|
277
|
+
}),
|
|
278
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
279
|
+
snippetCompletion('while ${condition} do\n\t${}\nend', {
|
|
280
|
+
label: 'while',
|
|
281
|
+
detail: 'loop',
|
|
282
|
+
type: 'keyword',
|
|
283
|
+
}),
|
|
284
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
285
|
+
snippetCompletion('repeat \n\t${}\nuntil ${condition}', {
|
|
286
|
+
label: 'repeat',
|
|
287
|
+
detail: 'loop',
|
|
288
|
+
type: 'keyword',
|
|
289
|
+
}),
|
|
290
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
291
|
+
snippetCompletion('for ${name} = ${from}, ${to}, ${step} do\n\t${}\nend', {
|
|
292
|
+
label: 'for',
|
|
293
|
+
detail: 'loop',
|
|
294
|
+
type: 'keyword',
|
|
295
|
+
}),
|
|
296
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
297
|
+
snippetCompletion('for ${...} in ${...} do\n\t${}\nend', {
|
|
298
|
+
label: 'for',
|
|
299
|
+
detail: 'in loop',
|
|
300
|
+
type: 'keyword',
|
|
301
|
+
}),
|
|
302
|
+
], types = new Set(['variableName', 'variableName.standard', 'keyword']);
|
|
303
|
+
lua.languageData['autocomplete'] = (context => {
|
|
304
|
+
const { state, pos } = context, node = syntaxTree(state).resolveInner(pos, -1);
|
|
305
|
+
if (!types.has(node.name)) {
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
const match = context.matchBefore(/(?:(?:^|\S|\.\.)\s+|^|[^\w\s]|\.\.)\w+$|\.{1,2}$/u);
|
|
309
|
+
if (!match || match.text === '..') {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
const { from: f, text } = match, pre = /^(.*?)(?:\b\w*)?$/u.exec(text)[1], char = pre.trim(), from = f + pre.length, validFor = /^\w*$/u;
|
|
313
|
+
switch (char) {
|
|
314
|
+
case '.': {
|
|
315
|
+
const mt = context.matchBefore(/(?:^|[^\w.]|\.\.)\w(?:\w|\.(?!\.))+$/u);
|
|
316
|
+
if (mt) {
|
|
317
|
+
let cur = globals, s = mt.text;
|
|
318
|
+
if (s.startsWith('.')) {
|
|
319
|
+
s = s.slice(2);
|
|
320
|
+
}
|
|
321
|
+
else if (/^\W/u.test(s)) {
|
|
322
|
+
s = s.slice(1);
|
|
323
|
+
}
|
|
324
|
+
for (const part of s.split('.').slice(0, -1)) {
|
|
325
|
+
cur = cur[part];
|
|
326
|
+
if (typeof cur !== 'object') {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
from,
|
|
332
|
+
options: Object.keys(cur).map((label) => ({
|
|
333
|
+
label,
|
|
334
|
+
type: typeof cur[label] === 'object' ? 'namespace' : map[cur[label]],
|
|
335
|
+
})),
|
|
336
|
+
validFor,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
case '#':
|
|
342
|
+
if (pre === char) {
|
|
343
|
+
return {
|
|
344
|
+
from,
|
|
345
|
+
options: tables,
|
|
346
|
+
validFor,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
break;
|
|
350
|
+
case '..':
|
|
351
|
+
case '+':
|
|
352
|
+
case '-':
|
|
353
|
+
case '*':
|
|
354
|
+
case '/':
|
|
355
|
+
case '%':
|
|
356
|
+
case '^':
|
|
357
|
+
case '&':
|
|
358
|
+
case '|':
|
|
359
|
+
case '~':
|
|
360
|
+
case '<':
|
|
361
|
+
case '>':
|
|
362
|
+
case '[':
|
|
363
|
+
return {
|
|
364
|
+
from,
|
|
365
|
+
options: [...constants, ...tables],
|
|
366
|
+
validFor,
|
|
367
|
+
};
|
|
368
|
+
case '=':
|
|
369
|
+
case '{':
|
|
370
|
+
case '(':
|
|
371
|
+
case ',':
|
|
372
|
+
return {
|
|
373
|
+
from,
|
|
374
|
+
options: [...builtins, ...constants, ...tables, ...unary],
|
|
375
|
+
validFor,
|
|
376
|
+
};
|
|
377
|
+
case '}':
|
|
378
|
+
case ']':
|
|
379
|
+
case ')':
|
|
380
|
+
return {
|
|
381
|
+
from,
|
|
382
|
+
options: [...binary, ...blocks],
|
|
383
|
+
validFor,
|
|
384
|
+
};
|
|
385
|
+
case ';':
|
|
386
|
+
case '':
|
|
387
|
+
return {
|
|
388
|
+
from,
|
|
389
|
+
options: [...keywords, ...blocks, ...unary, ...constants, ...tables, ...builtins],
|
|
390
|
+
validFor,
|
|
391
|
+
};
|
|
392
|
+
default:
|
|
393
|
+
if (pre !== char) {
|
|
394
|
+
const { prevSibling } = node;
|
|
395
|
+
return {
|
|
396
|
+
from,
|
|
397
|
+
options: prevSibling?.name !== 'keyword'
|
|
398
|
+
|| builtin.includes(state.sliceDoc(prevSibling.from, prevSibling.to))
|
|
399
|
+
? [...binary, ...blocks]
|
|
400
|
+
: [...builtins, ...constants, ...tables, ...unary, ...blocks],
|
|
401
|
+
validFor,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return null;
|
|
406
|
+
});
|
|
407
|
+
const support = foldService.of(({ doc, tabSize }, start, from) => {
|
|
408
|
+
const { text, number } = doc.lineAt(start);
|
|
409
|
+
if (!text.trim()) {
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
const getIndent = (line) => /^\s*/u.exec(line)[0].replace(/\t/gu, ' '.repeat(tabSize)).length;
|
|
413
|
+
const indent = getIndent(text);
|
|
414
|
+
let j = number, empty = true;
|
|
415
|
+
for (; j < doc.lines; j++) {
|
|
416
|
+
const { text: next } = doc.line(j + 1);
|
|
417
|
+
if (next.trim()) {
|
|
418
|
+
const nextIndent = getIndent(next);
|
|
419
|
+
if (indent >= nextIndent) {
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
empty = false;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return empty || j === number ? null : { from, to: doc.line(j).to };
|
|
426
|
+
});
|
|
427
|
+
export default () => new LanguageSupport(StreamLanguage.define(lua), support);
|
|
428
|
+
export { lua };
|