wikiparser-node 1.16.4 → 1.16.5
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 +1 -1
- package/bundle/bundle.es7.js +27 -27
- package/bundle/bundle.lsp.js +30 -30
- package/bundle/bundle.min.js +29 -29
- package/dist/addon/table.js +7 -4
- package/dist/addon/token.js +13 -7
- package/dist/addon/transclude.js +7 -5
- package/dist/base.d.mts +99 -30
- package/dist/base.d.ts +99 -30
- package/dist/index.d.ts +10 -4
- package/dist/index.js +59 -14
- package/dist/lib/attributes.js +2 -2
- package/dist/lib/element.d.ts +96 -42
- package/dist/lib/element.js +97 -45
- package/dist/lib/lsp.d.ts +64 -35
- package/dist/lib/lsp.js +99 -71
- package/dist/lib/node.d.ts +122 -53
- package/dist/lib/node.js +172 -75
- package/dist/lib/range.d.ts +83 -31
- package/dist/lib/range.js +83 -31
- package/dist/lib/ranges.d.ts +1 -1
- package/dist/lib/ranges.js +3 -2
- package/dist/lib/text.d.ts +40 -14
- package/dist/lib/text.js +47 -19
- package/dist/lib/title.d.ts +50 -16
- package/dist/lib/title.js +77 -36
- package/dist/mixin/attributesParent.d.ts +37 -21
- package/dist/mixin/attributesParent.js +0 -2
- package/dist/mixin/flagsParent.d.ts +38 -12
- package/dist/mixin/hidden.d.ts +0 -2
- package/dist/mixin/hidden.js +0 -2
- package/dist/mixin/magicLinkParent.d.ts +11 -5
- package/dist/mixin/singleLine.d.ts +0 -2
- package/dist/mixin/singleLine.js +3 -3
- package/dist/mixin/sol.d.ts +0 -2
- package/dist/mixin/sol.js +2 -3
- package/dist/mixin/syntax.d.ts +0 -2
- package/dist/mixin/syntax.js +0 -2
- package/dist/parser/braces.js +4 -2
- package/dist/parser/links.js +13 -7
- package/dist/parser/list.js +3 -1
- package/dist/parser/quotes.js +22 -2
- package/dist/parser/redirect.js +4 -1
- package/dist/src/arg.d.ts +19 -9
- package/dist/src/arg.js +34 -15
- package/dist/src/atom.d.ts +5 -1
- package/dist/src/atom.js +5 -1
- package/dist/src/attribute.d.ts +26 -8
- package/dist/src/attribute.js +30 -11
- package/dist/src/attributes.d.ts +50 -22
- package/dist/src/attributes.js +54 -26
- package/dist/src/converter.d.ts +4 -2
- package/dist/src/converter.js +12 -9
- package/dist/src/converterFlags.d.ts +45 -15
- package/dist/src/converterFlags.js +45 -15
- package/dist/src/converterRule.d.ts +30 -11
- package/dist/src/converterRule.js +46 -16
- package/dist/src/extLink.d.ts +6 -2
- package/dist/src/extLink.js +14 -11
- package/dist/src/gallery.d.ts +13 -9
- package/dist/src/gallery.js +35 -21
- package/dist/src/heading.d.ts +13 -7
- package/dist/src/heading.js +21 -11
- package/dist/src/hidden.d.ts +5 -1
- package/dist/src/hidden.js +7 -3
- package/dist/src/html.d.ts +11 -5
- package/dist/src/html.js +16 -7
- package/dist/src/imageParameter.d.ts +23 -11
- package/dist/src/imageParameter.js +22 -10
- package/dist/src/imagemap.d.ts +4 -4
- package/dist/src/imagemap.js +9 -5
- package/dist/src/imagemapLink.d.ts +3 -1
- package/dist/src/imagemapLink.js +3 -1
- package/dist/src/index.d.ts +65 -20
- package/dist/src/index.js +111 -39
- package/dist/src/link/base.d.ts +14 -6
- package/dist/src/link/base.js +40 -17
- package/dist/src/link/category.d.ts +7 -2
- package/dist/src/link/category.js +20 -4
- package/dist/src/link/file.d.ts +71 -23
- package/dist/src/link/file.js +100 -36
- package/dist/src/link/galleryImage.d.ts +8 -4
- package/dist/src/link/galleryImage.js +15 -8
- package/dist/src/link/index.d.ts +12 -4
- package/dist/src/link/index.js +15 -5
- package/dist/src/link/redirectTarget.d.ts +3 -2
- package/dist/src/link/redirectTarget.js +5 -3
- package/dist/src/magicLink.d.ts +24 -11
- package/dist/src/magicLink.js +36 -19
- package/dist/src/nested.d.ts +5 -3
- package/dist/src/nested.js +9 -6
- package/dist/src/nowiki/base.d.ts +4 -2
- package/dist/src/nowiki/base.js +6 -5
- package/dist/src/nowiki/comment.d.ts +6 -2
- package/dist/src/nowiki/comment.js +8 -3
- package/dist/src/nowiki/dd.d.ts +0 -3
- package/dist/src/nowiki/dd.js +0 -8
- package/dist/src/nowiki/doubleUnderscore.d.ts +5 -1
- package/dist/src/nowiki/doubleUnderscore.js +5 -1
- package/dist/src/nowiki/index.d.ts +5 -1
- package/dist/src/nowiki/index.js +5 -1
- package/dist/src/nowiki/list.d.ts +5 -1
- package/dist/src/nowiki/list.js +5 -1
- package/dist/src/nowiki/listBase.d.ts +15 -5
- package/dist/src/nowiki/listBase.js +40 -9
- package/dist/src/nowiki/noinclude.d.ts +5 -1
- package/dist/src/nowiki/noinclude.js +5 -1
- package/dist/src/nowiki/quote.d.ts +15 -8
- package/dist/src/nowiki/quote.js +32 -12
- package/dist/src/onlyinclude.d.ts +4 -2
- package/dist/src/onlyinclude.js +4 -2
- package/dist/src/paramTag/index.d.ts +1 -1
- package/dist/src/paramTag/index.js +1 -1
- package/dist/src/parameter.d.ts +24 -12
- package/dist/src/parameter.js +45 -27
- package/dist/src/pre.d.ts +1 -1
- package/dist/src/pre.js +1 -1
- package/dist/src/redirect.d.ts +2 -0
- package/dist/src/redirect.js +2 -0
- package/dist/src/syntax.d.ts +5 -1
- package/dist/src/syntax.js +5 -1
- package/dist/src/table/base.d.ts +5 -1
- package/dist/src/table/base.js +10 -3
- package/dist/src/table/index.d.ts +134 -66
- package/dist/src/table/index.js +149 -81
- package/dist/src/table/td.d.ts +18 -10
- package/dist/src/table/td.js +23 -15
- package/dist/src/table/tr.d.ts +13 -3
- package/dist/src/table/tr.js +14 -6
- package/dist/src/table/trBase.d.ts +28 -12
- package/dist/src/table/trBase.js +28 -18
- package/dist/src/tagPair/ext.d.ts +3 -1
- package/dist/src/tagPair/ext.js +10 -8
- package/dist/src/tagPair/include.d.ts +8 -2
- package/dist/src/tagPair/include.js +8 -2
- package/dist/src/tagPair/index.d.ts +6 -2
- package/dist/src/tagPair/index.js +6 -2
- package/dist/src/transclude.d.ts +102 -33
- package/dist/src/transclude.js +114 -42
- package/dist/util/debug.js +2 -7
- package/dist/util/html.js +1 -18
- package/dist/util/string.js +7 -1
- package/extensions/dist/base.js +25 -8
- package/extensions/dist/codejar.js +2 -1
- package/extensions/dist/lsp.js +5 -10
- package/extensions/es7/base.js +25 -8
- package/extensions/ui.css +1 -162
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +3 -3
package/dist/lib/lsp.js
CHANGED
|
@@ -213,23 +213,18 @@ class LanguageService {
|
|
|
213
213
|
* - 总是返回最新的解析结果
|
|
214
214
|
*/
|
|
215
215
|
async #parse() {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
this.#running = this.#parse();
|
|
229
|
-
/* istanbul ignore next */
|
|
230
|
-
resolve(this.#running);
|
|
231
|
-
}, 0);
|
|
232
|
-
});
|
|
216
|
+
const config = index_1.default.getConfig();
|
|
217
|
+
this.#config = index_1.default.config;
|
|
218
|
+
const text = this.#text, root = await index_1.default.partialParse(text, () => this.#text, true, config);
|
|
219
|
+
if (this.#text === text && this.#config === index_1.default.config) {
|
|
220
|
+
this.#done = root;
|
|
221
|
+
this.#running = undefined;
|
|
222
|
+
return root;
|
|
223
|
+
}
|
|
224
|
+
/* istanbul ignore next */
|
|
225
|
+
this.#running = this.#parse();
|
|
226
|
+
/* istanbul ignore next */
|
|
227
|
+
return this.#running;
|
|
233
228
|
}
|
|
234
229
|
/**
|
|
235
230
|
* 检查是否为签名语言服务器
|
|
@@ -242,10 +237,12 @@ class LanguageService {
|
|
|
242
237
|
}
|
|
243
238
|
}
|
|
244
239
|
/**
|
|
240
|
+
* Provide color decorators
|
|
241
|
+
*
|
|
245
242
|
* 提供颜色指示
|
|
246
|
-
* @param rgba 颜色解析函数
|
|
247
|
-
* @param text 源代码
|
|
248
|
-
* @param hsl 是否允许HSL颜色
|
|
243
|
+
* @param rgba color parser / 颜色解析函数
|
|
244
|
+
* @param text source Wikitext / 源代码
|
|
245
|
+
* @param hsl whether HSL colors are treated / 是否允许HSL颜色
|
|
249
246
|
*/
|
|
250
247
|
async provideDocumentColors(rgba, text, hsl = true) {
|
|
251
248
|
this.#checkSignature();
|
|
@@ -277,10 +274,15 @@ class LanguageService {
|
|
|
277
274
|
});
|
|
278
275
|
});
|
|
279
276
|
}
|
|
280
|
-
/**
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Provide color pickers
|
|
279
|
+
*
|
|
280
|
+
* 颜色选择器
|
|
281
|
+
* @param color color information / 颜色信息
|
|
282
|
+
*/
|
|
283
|
+
// eslint-disable-next-line @typescript-eslint/class-methods-use-this
|
|
284
|
+
provideColorPresentations(color) {
|
|
285
|
+
const { color: { red, green, blue, alpha }, range } = color, newText = `#${(0, common_1.numToHex)(red)}${(0, common_1.numToHex)(green)}${(0, common_1.numToHex)(blue)}${alpha < 1 ? (0, common_1.numToHex)(alpha) : ''}`;
|
|
284
286
|
return [
|
|
285
287
|
{
|
|
286
288
|
label: newText,
|
|
@@ -327,8 +329,10 @@ class LanguageService {
|
|
|
327
329
|
return this.#completionConfig;
|
|
328
330
|
}
|
|
329
331
|
/**
|
|
332
|
+
* Provide auto-completion
|
|
333
|
+
*
|
|
330
334
|
* 提供自动补全
|
|
331
|
-
* @param text 源代码
|
|
335
|
+
* @param text source Wikitext / 源代码
|
|
332
336
|
* @param position 位置
|
|
333
337
|
*/
|
|
334
338
|
async provideCompletionItems(text, position) {
|
|
@@ -386,7 +390,8 @@ class LanguageService {
|
|
|
386
390
|
return [
|
|
387
391
|
...getCompletion(params, 'Property', match, position)
|
|
388
392
|
.filter(({ label }) => !equal || !/[= ]$/u.test(label)),
|
|
389
|
-
...getCompletion(root.querySelectorAll('image-parameter#width')
|
|
393
|
+
...getCompletion(root.querySelectorAll('image-parameter#width')
|
|
394
|
+
.filter(token => token !== cur)
|
|
390
395
|
.map(width => width.text()), 'Unit', match, position),
|
|
391
396
|
];
|
|
392
397
|
}
|
|
@@ -412,20 +417,20 @@ class LanguageService {
|
|
|
412
417
|
}
|
|
413
418
|
else if (type === 'parameter-key' || type === 'parameter-value' && parentNode.anon) {
|
|
414
419
|
// parameter key
|
|
415
|
-
const transclusion = parentNode.parentNode;
|
|
416
|
-
if (
|
|
420
|
+
const transclusion = parentNode.parentNode, { type: t, name: n } = transclusion;
|
|
421
|
+
if (t === 'magic-word' && n !== 'invoke') {
|
|
417
422
|
return undefined;
|
|
418
423
|
}
|
|
419
|
-
const key = cur.toString().trimStart(), [module, func] =
|
|
424
|
+
const key = cur.toString().trimStart(), [module, func] = t === 'magic-word' ? transclusion.getModule() : [];
|
|
420
425
|
return key
|
|
421
426
|
? getCompletion(root.querySelectorAll('parameter').filter(token => {
|
|
422
427
|
if (token === parentNode
|
|
423
428
|
|| token.anon
|
|
424
|
-
|| token.parentNode.type !==
|
|
425
|
-
|| token.parentNode.name !==
|
|
429
|
+
|| token.parentNode.type !== t
|
|
430
|
+
|| token.parentNode.name !== n) {
|
|
426
431
|
return false;
|
|
427
432
|
}
|
|
428
|
-
else if (
|
|
433
|
+
else if (t === 'template') {
|
|
429
434
|
return true;
|
|
430
435
|
}
|
|
431
436
|
const [m, f] = token.parentNode.getModule();
|
|
@@ -436,13 +441,15 @@ class LanguageService {
|
|
|
436
441
|
return undefined;
|
|
437
442
|
}
|
|
438
443
|
/**
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
444
|
+
* Provide grammar check
|
|
445
|
+
*
|
|
446
|
+
* 提供语法检查
|
|
447
|
+
* @param text source Wikitext / 源代码
|
|
448
|
+
* @param warning whether to include warnings / 是否包含警告
|
|
442
449
|
*/
|
|
443
|
-
async provideDiagnostics(
|
|
450
|
+
async provideDiagnostics(text, warning = true) {
|
|
444
451
|
this.#checkSignature();
|
|
445
|
-
const root = await this.#queue(
|
|
452
|
+
const root = await this.#queue(text), errors = root.lint();
|
|
446
453
|
return (warning ? errors : errors.filter(({ severity }) => severity === 'error'))
|
|
447
454
|
.map(({ startLine, startCol, endLine, endCol, severity, rule, message, fix, suggestions }) => ({
|
|
448
455
|
range: {
|
|
@@ -461,8 +468,10 @@ class LanguageService {
|
|
|
461
468
|
}));
|
|
462
469
|
}
|
|
463
470
|
/**
|
|
471
|
+
* Provide folding ranges
|
|
472
|
+
*
|
|
464
473
|
* 提供折叠范围
|
|
465
|
-
* @param text 源代码
|
|
474
|
+
* @param text source Wikitext / 源代码
|
|
466
475
|
*/
|
|
467
476
|
async provideFoldingRanges(text) {
|
|
468
477
|
this.#checkSignature();
|
|
@@ -507,8 +516,10 @@ class LanguageService {
|
|
|
507
516
|
return ranges;
|
|
508
517
|
}
|
|
509
518
|
/**
|
|
519
|
+
* Provide links
|
|
520
|
+
*
|
|
510
521
|
* 提供链接
|
|
511
|
-
* @param text 源代码
|
|
522
|
+
* @param text source Wikitext / 源代码
|
|
512
523
|
*/
|
|
513
524
|
async provideLinks(text) {
|
|
514
525
|
this.#checkSignature();
|
|
@@ -559,7 +570,8 @@ class LanguageService {
|
|
|
559
570
|
else if (type === 'invoke-module') {
|
|
560
571
|
ns = 828;
|
|
561
572
|
}
|
|
562
|
-
const title = index_1.default
|
|
573
|
+
const title = index_1.default
|
|
574
|
+
.normalizeTitle(target, ns, false, undefined, true);
|
|
563
575
|
/* istanbul ignore if */
|
|
564
576
|
if (!title.valid) {
|
|
565
577
|
return false;
|
|
@@ -588,8 +600,10 @@ class LanguageService {
|
|
|
588
600
|
}).filter(Boolean);
|
|
589
601
|
}
|
|
590
602
|
/**
|
|
603
|
+
* Provide references
|
|
604
|
+
*
|
|
591
605
|
* 提供引用
|
|
592
|
-
* @param text 源代码
|
|
606
|
+
* @param text source Wikitext / 源代码
|
|
593
607
|
* @param position 位置
|
|
594
608
|
*/
|
|
595
609
|
async provideReferences(text, position) {
|
|
@@ -608,15 +622,17 @@ class LanguageService {
|
|
|
608
622
|
return refs.length === 0 ? undefined : refs;
|
|
609
623
|
}
|
|
610
624
|
/**
|
|
625
|
+
* Provide definitions
|
|
626
|
+
*
|
|
611
627
|
* 提供定义
|
|
612
|
-
* @param text 源代码
|
|
613
|
-
* @param
|
|
614
|
-
* @param pos.line 行号
|
|
615
|
-
* @param pos.character 列号
|
|
628
|
+
* @param text source Wikitext / 源代码
|
|
629
|
+
* @param position 位置
|
|
616
630
|
*/
|
|
617
|
-
async provideDefinition(text,
|
|
631
|
+
async provideDefinition(text, position) {
|
|
618
632
|
this.#checkSignature();
|
|
619
|
-
const root = await this.#queue(text), node = root.elementFromPoint(character, line), ext = node.is('ext') && node.name === 'ref'
|
|
633
|
+
const root = await this.#queue(text), node = root.elementFromPoint(position.character, position.line), ext = node.is('ext') && node.name === 'ref'
|
|
634
|
+
? node
|
|
635
|
+
: node.closest('ext#ref'), refName = getRefTagAttr(ext, 'name');
|
|
620
636
|
if (!refName) {
|
|
621
637
|
return undefined;
|
|
622
638
|
}
|
|
@@ -628,15 +644,15 @@ class LanguageService {
|
|
|
628
644
|
return refs.length === 0 ? undefined : refs;
|
|
629
645
|
}
|
|
630
646
|
/**
|
|
647
|
+
* Provide locations for renaming
|
|
648
|
+
*
|
|
631
649
|
* 提供变量更名准备
|
|
632
|
-
* @param text 源代码
|
|
633
|
-
* @param
|
|
634
|
-
* @param pos.line 行号
|
|
635
|
-
* @param pos.character 列号
|
|
650
|
+
* @param text source Wikitext / 源代码
|
|
651
|
+
* @param position 位置
|
|
636
652
|
*/
|
|
637
|
-
async resolveRenameLocation(text,
|
|
653
|
+
async resolveRenameLocation(text, position) {
|
|
638
654
|
this.#checkSignature();
|
|
639
|
-
const root = await this.#queue(text), node = root.elementFromPoint(character, line), { type } = node, refName = getRefName(node), refGroup = getRefGroup(node);
|
|
655
|
+
const root = await this.#queue(text), node = root.elementFromPoint(position.character, position.line), { type } = node, refName = getRefName(node), refGroup = getRefGroup(node);
|
|
640
656
|
return !refName && !refGroup && (!renameTypes.has(type)
|
|
641
657
|
|| type === 'parameter-key' && /^[1-9]\d*$/u.test(node.parentNode.name)
|
|
642
658
|
|| type === 'link-target' && !['link', 'redirect-target'].includes(node.parentNode.type))
|
|
@@ -644,16 +660,16 @@ class LanguageService {
|
|
|
644
660
|
: createNodeRange(node);
|
|
645
661
|
}
|
|
646
662
|
/**
|
|
663
|
+
* Provide rename edits
|
|
664
|
+
*
|
|
647
665
|
* 变量更名
|
|
648
|
-
* @param text 源代码
|
|
649
|
-
* @param
|
|
650
|
-
* @param
|
|
651
|
-
* @param pos.character 列号
|
|
652
|
-
* @param newName 新名称
|
|
666
|
+
* @param text source Wikitext / 源代码
|
|
667
|
+
* @param position 位置
|
|
668
|
+
* @param newName new name / 新名称
|
|
653
669
|
*/
|
|
654
|
-
async provideRenameEdits(text,
|
|
670
|
+
async provideRenameEdits(text, position, newName) {
|
|
655
671
|
this.#checkSignature();
|
|
656
|
-
const root = await this.#queue(text), node = root.elementFromPoint(character, line), { type } = node, refName = getRefName(node), refNameGroup = refName && getRefTagAttr(node.parentNode.parentNode, 'group'), refGroup = getRefGroup(node), name = getName(node), refs = root.querySelectorAll(type).filter(token => {
|
|
672
|
+
const root = await this.#queue(text), node = root.elementFromPoint(position.character, position.line), { type } = node, refName = getRefName(node), refNameGroup = refName && getRefTagAttr(node.parentNode.parentNode, 'group'), refGroup = getRefGroup(node), name = getName(node), refs = root.querySelectorAll(type).filter(token => {
|
|
657
673
|
const { type: t } = token.parentNode;
|
|
658
674
|
if (type === 'link-target' && t !== 'link' && t !== 'redirect-target') {
|
|
659
675
|
return false;
|
|
@@ -680,11 +696,14 @@ class LanguageService {
|
|
|
680
696
|
* @param name 函数名
|
|
681
697
|
*/
|
|
682
698
|
#getParserFunction(name) {
|
|
683
|
-
return this.data.parserFunctions
|
|
699
|
+
return this.data.parserFunctions
|
|
700
|
+
.find(({ aliases }) => aliases.some(alias => alias.replace(/^#/u, '') === name));
|
|
684
701
|
}
|
|
685
702
|
/**
|
|
703
|
+
* Provide hover information
|
|
704
|
+
*
|
|
686
705
|
* 提供悬停信息
|
|
687
|
-
* @param text 源代码
|
|
706
|
+
* @param text source Wikitext / 源代码
|
|
688
707
|
* @param position 位置
|
|
689
708
|
*/
|
|
690
709
|
async provideHover(text, position) {
|
|
@@ -695,17 +714,15 @@ class LanguageService {
|
|
|
695
714
|
this.#checkSignature();
|
|
696
715
|
const root = await this.#queue(text), { offsetNode, offset } = caretPositionFromWord(root, position), token = offsetNode.type === 'text' ? offsetNode.parentNode : offsetNode, { type, parentNode, length, name } = token;
|
|
697
716
|
let info, f, range;
|
|
698
|
-
if (token.is('double-underscore')) {
|
|
699
|
-
if (offset === 0 && token.getBoundingClientRect().left > position.character) {
|
|
700
|
-
return undefined;
|
|
701
|
-
}
|
|
717
|
+
if (token.is('double-underscore') && offset > 0) {
|
|
702
718
|
info = this.data.behaviorSwitches.find(({ aliases }) => aliases.includes(token.innerText.toLowerCase()));
|
|
703
719
|
}
|
|
704
720
|
else if (type === 'magic-word-name') {
|
|
705
721
|
info = this.#getParserFunction(parentNode.name);
|
|
706
722
|
f = token.toString(true).trim();
|
|
707
723
|
}
|
|
708
|
-
else if (token.is('magic-word') && length === 1
|
|
724
|
+
else if (token.is('magic-word') && !token.modifier && length === 1
|
|
725
|
+
&& (offset > 0 || token.getBoundingClientRect().left === position.character)) {
|
|
709
726
|
info = this.#getParserFunction(name);
|
|
710
727
|
f = token.firstChild.toString(true).trim();
|
|
711
728
|
}
|
|
@@ -733,8 +750,10 @@ class LanguageService {
|
|
|
733
750
|
};
|
|
734
751
|
}
|
|
735
752
|
/**
|
|
753
|
+
* Provide signature help for magic words
|
|
754
|
+
*
|
|
736
755
|
* 提供魔术字帮助
|
|
737
|
-
* @param text 源代码
|
|
756
|
+
* @param text source Wikitext / 源代码
|
|
738
757
|
* @param position 位置
|
|
739
758
|
*/
|
|
740
759
|
async provideSignatureHelp(text, position) {
|
|
@@ -784,8 +803,10 @@ class LanguageService {
|
|
|
784
803
|
};
|
|
785
804
|
}
|
|
786
805
|
/**
|
|
806
|
+
* Provide CodeLens
|
|
807
|
+
*
|
|
787
808
|
* 提供 CodeLens
|
|
788
|
-
* @param text 源代码
|
|
809
|
+
* @param text source Wikitext / 源代码
|
|
789
810
|
*/
|
|
790
811
|
async provideInlayHints(text) {
|
|
791
812
|
this.#checkSignature();
|
|
@@ -802,7 +823,12 @@ class LanguageService {
|
|
|
802
823
|
return hints;
|
|
803
824
|
}
|
|
804
825
|
/* NOT FOR BROWSER ONLY */
|
|
805
|
-
/**
|
|
826
|
+
/**
|
|
827
|
+
* Provide quick fixes
|
|
828
|
+
*
|
|
829
|
+
* 提供快速修复建议
|
|
830
|
+
* @param diagnostics grammar diagnostics / 语法诊断信息
|
|
831
|
+
*/
|
|
806
832
|
// eslint-disable-next-line @typescript-eslint/class-methods-use-this
|
|
807
833
|
provideCodeAction(diagnostics) {
|
|
808
834
|
return diagnostics.flatMap(diagnostic => diagnostic.data.map((data) => ({
|
|
@@ -816,8 +842,10 @@ class LanguageService {
|
|
|
816
842
|
})));
|
|
817
843
|
}
|
|
818
844
|
/**
|
|
845
|
+
* Provide document sections
|
|
846
|
+
*
|
|
819
847
|
* 提供章节
|
|
820
|
-
* @param text 源代码
|
|
848
|
+
* @param text source Wikitext / 源代码
|
|
821
849
|
*/
|
|
822
850
|
async provideDocumentSymbols(text) {
|
|
823
851
|
this.#checkSignature();
|
package/dist/lib/node.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { LintError, AstNode as AstNodeBase, TokenTypes } from '../base';
|
|
2
2
|
import type { AstText, Token } from '../internal';
|
|
3
|
+
export interface Font {
|
|
4
|
+
bold: boolean;
|
|
5
|
+
italic: boolean;
|
|
6
|
+
}
|
|
3
7
|
export type AstNodes = AstText | Token;
|
|
4
8
|
export interface Dimension {
|
|
5
9
|
readonly height: number;
|
|
@@ -13,163 +17,228 @@ export interface CaretPosition {
|
|
|
13
17
|
readonly offsetNode: AstNodes;
|
|
14
18
|
readonly offset: number;
|
|
15
19
|
}
|
|
16
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Node-like
|
|
22
|
+
*
|
|
23
|
+
* 类似Node
|
|
24
|
+
*/
|
|
17
25
|
export declare abstract class AstNode implements AstNodeBase {
|
|
18
26
|
#private;
|
|
19
27
|
data?: string | undefined;
|
|
20
28
|
readonly childNodes: readonly AstNodes[];
|
|
21
29
|
abstract get type(): TokenTypes | 'text';
|
|
22
30
|
abstract set type(value: TokenTypes | "text");
|
|
23
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Get the visible text
|
|
33
|
+
*
|
|
34
|
+
* 可见部分
|
|
35
|
+
*/
|
|
24
36
|
text(): string;
|
|
25
37
|
lint(): LintError[];
|
|
26
38
|
print(): string;
|
|
27
|
-
/** 首位子节点 */
|
|
39
|
+
/** first child node / 首位子节点 */
|
|
28
40
|
get firstChild(): AstNodes | undefined;
|
|
29
|
-
/** 末位子节点 */
|
|
41
|
+
/** last child node / 末位子节点 */
|
|
30
42
|
get lastChild(): AstNodes | undefined;
|
|
31
|
-
/** 父节点 */
|
|
43
|
+
/** parent node / 父节点 */
|
|
32
44
|
get parentNode(): Token | undefined;
|
|
33
|
-
/** 后一个兄弟节点 */
|
|
45
|
+
/** next sibling node / 后一个兄弟节点 */
|
|
34
46
|
get nextSibling(): AstNodes | undefined;
|
|
35
|
-
/** 前一个兄弟节点 */
|
|
47
|
+
/** previous sibling node / 前一个兄弟节点 */
|
|
36
48
|
get previousSibling(): AstNodes | undefined;
|
|
37
|
-
/** 行数 */
|
|
49
|
+
/** number of lines / 行数 */
|
|
38
50
|
get offsetHeight(): number;
|
|
39
|
-
/** 最后一行的列数 */
|
|
51
|
+
/** number of columns of the last line / 最后一行的列数 */
|
|
40
52
|
get offsetWidth(): number;
|
|
41
|
-
/** 后一个非文本兄弟节点 */
|
|
53
|
+
/** next sibling element / 后一个非文本兄弟节点 */
|
|
42
54
|
get nextElementSibling(): Token | undefined;
|
|
43
|
-
/** 前一个非文本兄弟节点 */
|
|
55
|
+
/** previous sibling element / 前一个非文本兄弟节点 */
|
|
44
56
|
get previousElementSibling(): Token | undefined;
|
|
45
|
-
/** 后一个可见的兄弟节点 */
|
|
57
|
+
/** next visibling sibling node / 后一个可见的兄弟节点 */
|
|
46
58
|
get nextVisibleSibling(): AstNodes | undefined;
|
|
47
|
-
/** 前一个可见的兄弟节点 */
|
|
59
|
+
/** previous visible sibling node / 前一个可见的兄弟节点 */
|
|
48
60
|
get previousVisibleSibling(): AstNodes | undefined;
|
|
49
|
-
/** 是否具有根节点 */
|
|
61
|
+
/** whether to be connected to a root token / 是否具有根节点 */
|
|
50
62
|
get isConnected(): boolean;
|
|
51
|
-
/** 后方是否还有其他节点(不含后代) */
|
|
63
|
+
/** whether to be the end of a document / 后方是否还有其他节点(不含后代) */
|
|
52
64
|
get eof(): boolean | undefined;
|
|
53
|
-
/** 相对于父容器的行号 */
|
|
65
|
+
/** line number relative to its parent / 相对于父容器的行号 */
|
|
54
66
|
get offsetTop(): number;
|
|
55
|
-
/** 相对于父容器的列号 */
|
|
67
|
+
/** column number of the last line relative to its parent / 相对于父容器的列号 */
|
|
56
68
|
get offsetLeft(): number;
|
|
57
|
-
/** 位置、大小和padding */
|
|
69
|
+
/** position, dimension and paddings / 位置、大小和padding */
|
|
58
70
|
get style(): Position & Dimension & {
|
|
59
71
|
padding: number;
|
|
60
72
|
};
|
|
61
|
-
/** 字体样式 */
|
|
62
|
-
get font():
|
|
63
|
-
|
|
64
|
-
italic: boolean;
|
|
65
|
-
};
|
|
66
|
-
/** 是否粗体 */
|
|
73
|
+
/** font weigth and style / 字体样式 */
|
|
74
|
+
get font(): Font;
|
|
75
|
+
/** whether to be bold / 是否粗体 */
|
|
67
76
|
get bold(): boolean;
|
|
68
|
-
/** 是否斜体 */
|
|
77
|
+
/** whether to be italic / 是否斜体 */
|
|
69
78
|
get italic(): boolean;
|
|
70
79
|
constructor();
|
|
71
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* Get the root node
|
|
82
|
+
*
|
|
83
|
+
* 获取根节点
|
|
84
|
+
*/
|
|
72
85
|
getRootNode(): Token | this;
|
|
73
86
|
/**
|
|
87
|
+
* Convert the position to the character index
|
|
88
|
+
*
|
|
74
89
|
* 将行列号转换为字符位置
|
|
75
|
-
* @param top 行号
|
|
76
|
-
* @param left 列号
|
|
90
|
+
* @param top line number / 行号
|
|
91
|
+
* @param left column number / 列号
|
|
77
92
|
*/
|
|
78
93
|
indexFromPos(top: number, left: number): number | undefined;
|
|
79
94
|
/**
|
|
95
|
+
* Convert the character indenx to the position
|
|
96
|
+
*
|
|
80
97
|
* 将字符位置转换为行列号
|
|
81
|
-
* @param index 字符位置
|
|
98
|
+
* @param index character index / 字符位置
|
|
82
99
|
*/
|
|
83
100
|
posFromIndex(index: number): Position | undefined;
|
|
84
101
|
/**
|
|
102
|
+
* Get the relative character index of the current node, or its `j`-th child node
|
|
103
|
+
*
|
|
85
104
|
* 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
|
|
86
|
-
* @param j 子节点序号
|
|
105
|
+
* @param j rank of the child node / 子节点序号
|
|
87
106
|
*/
|
|
88
107
|
getRelativeIndex(j?: number): number;
|
|
89
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* Get the absolute character index of the current node
|
|
110
|
+
*
|
|
111
|
+
* 获取当前节点的绝对位置
|
|
112
|
+
*/
|
|
90
113
|
getAbsoluteIndex(): number;
|
|
91
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* Get the position and dimension of the current node
|
|
116
|
+
*
|
|
117
|
+
* 获取当前节点的行列位置和大小
|
|
118
|
+
*/
|
|
92
119
|
getBoundingClientRect(): Dimension & Position;
|
|
93
120
|
/**
|
|
121
|
+
* Whether to be of a certain type
|
|
122
|
+
*
|
|
94
123
|
* 是否是某种类型的节点
|
|
95
|
-
* @param type 节点类型
|
|
124
|
+
* @param type token type / 节点类型
|
|
96
125
|
*/
|
|
97
126
|
is<T extends Token>(type: TokenTypes): this is T;
|
|
98
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* Get the text and the start/end positions of all lines
|
|
129
|
+
*
|
|
130
|
+
* 获取所有行的wikitext和起止位置
|
|
131
|
+
*/
|
|
99
132
|
getLines(): [string, number, number][];
|
|
100
133
|
/**
|
|
134
|
+
* Check if the node is identical
|
|
135
|
+
*
|
|
101
136
|
* 是否是全同节点
|
|
102
|
-
* @param node 待比较的节点
|
|
137
|
+
* @param node node to be compared to / 待比较的节点
|
|
103
138
|
* @throws `assert.AssertionError`
|
|
104
139
|
*/
|
|
105
140
|
isEqualNode(node: AstNode): boolean;
|
|
106
141
|
/**
|
|
142
|
+
* Insert a batch of sibling nodes after the current node
|
|
143
|
+
*
|
|
107
144
|
* 在后方批量插入兄弟节点
|
|
108
|
-
* @param nodes 插入节点
|
|
145
|
+
* @param nodes nodes to be inserted / 插入节点
|
|
109
146
|
*/
|
|
110
147
|
after(...nodes: (AstNodes | string)[]): void;
|
|
111
148
|
/**
|
|
149
|
+
* Insert a batch of sibling nodes before the current node
|
|
150
|
+
*
|
|
112
151
|
* 在前方批量插入兄弟节点
|
|
113
|
-
* @param nodes 插入节点
|
|
152
|
+
* @param nodes nodes to be inserted / 插入节点
|
|
114
153
|
*/
|
|
115
154
|
before(...nodes: (AstNodes | string)[]): void;
|
|
116
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* Remove the current node
|
|
157
|
+
*
|
|
158
|
+
* 移除当前节点
|
|
159
|
+
*/
|
|
117
160
|
remove(): void;
|
|
118
161
|
/**
|
|
162
|
+
* Replace the current node with new nodes
|
|
163
|
+
*
|
|
119
164
|
* 将当前节点批量替换为新的节点
|
|
120
|
-
* @param nodes 插入节点
|
|
165
|
+
* @param nodes nodes to be inserted / 插入节点
|
|
121
166
|
*/
|
|
122
167
|
replaceWith(...nodes: (AstNodes | string)[]): void;
|
|
123
168
|
/**
|
|
169
|
+
* Check if the node is a descendant
|
|
170
|
+
*
|
|
124
171
|
* 是自身或后代节点
|
|
125
|
-
* @param node 待检测节点
|
|
172
|
+
* @param node node to be compared to / 待检测节点
|
|
126
173
|
*/
|
|
127
174
|
contains(node: AstNode): boolean;
|
|
128
175
|
/**
|
|
176
|
+
* Add an event listener
|
|
177
|
+
*
|
|
129
178
|
* 添加事件监听
|
|
130
|
-
* @param types 事件类型
|
|
131
|
-
* @param listener 监听函数
|
|
179
|
+
* @param types event type / 事件类型
|
|
180
|
+
* @param listener listener function / 监听函数
|
|
132
181
|
* @param options 选项
|
|
133
|
-
* @param options.once 仅执行一次
|
|
182
|
+
* @param options.once to be executed only once / 仅执行一次
|
|
134
183
|
*/
|
|
135
184
|
addEventListener(types: string | string[], listener: (...args: any[]) => void, options?: {
|
|
136
185
|
once?: boolean;
|
|
137
186
|
}): void;
|
|
138
187
|
/**
|
|
188
|
+
* Remove an event listener
|
|
189
|
+
*
|
|
139
190
|
* 移除事件监听
|
|
140
|
-
* @param types 事件类型
|
|
141
|
-
* @param listener 监听函数
|
|
191
|
+
* @param types event type / 事件类型
|
|
192
|
+
* @param listener listener function / 监听函数
|
|
142
193
|
*/
|
|
143
194
|
removeEventListener(types: string | string[], listener: (...args: any[]) => void): void;
|
|
144
195
|
/**
|
|
196
|
+
* Remove all event listeners
|
|
197
|
+
*
|
|
145
198
|
* 移除事件的所有监听
|
|
146
|
-
* @param types 事件类型
|
|
199
|
+
* @param types event type / 事件类型
|
|
147
200
|
*/
|
|
148
201
|
removeAllEventListeners(types: string | string[]): void;
|
|
149
202
|
/**
|
|
203
|
+
* List all event listeners
|
|
204
|
+
*
|
|
150
205
|
* 列举事件监听
|
|
151
|
-
* @param type 事件类型
|
|
206
|
+
* @param type event type / 事件类型
|
|
152
207
|
*/
|
|
153
208
|
listEventListeners(type: string): Function[];
|
|
154
209
|
/**
|
|
210
|
+
* Dispatch an event
|
|
211
|
+
*
|
|
155
212
|
* 触发事件
|
|
156
|
-
* @param e 事件对象
|
|
157
|
-
* @param data 事件数据
|
|
213
|
+
* @param e event object / 事件对象
|
|
214
|
+
* @param data event data / 事件数据
|
|
158
215
|
*/
|
|
159
216
|
dispatchEvent(e: Event, data: unknown): void;
|
|
160
|
-
/**
|
|
217
|
+
/**
|
|
218
|
+
* Get all the ancestor nodes
|
|
219
|
+
*
|
|
220
|
+
* 获取所有祖先节点
|
|
221
|
+
*/
|
|
161
222
|
getAncestors(): Token[];
|
|
162
223
|
/**
|
|
224
|
+
* Compare the relative position with another node
|
|
225
|
+
*
|
|
163
226
|
* 比较和另一个节点的相对位置
|
|
164
|
-
* @param other 待比较的节点
|
|
227
|
+
* @param other node to be compared with / 待比较的节点
|
|
165
228
|
* @throws `RangeError` 不在同一个语法树
|
|
166
229
|
*/
|
|
167
230
|
compareDocumentPosition(other: AstNodes): number;
|
|
168
|
-
/**
|
|
231
|
+
/**
|
|
232
|
+
* Destroy the instance
|
|
233
|
+
*
|
|
234
|
+
* 销毁
|
|
235
|
+
*/
|
|
169
236
|
destroy(): void;
|
|
170
237
|
/**
|
|
238
|
+
* Get the wikitext of a line
|
|
239
|
+
*
|
|
171
240
|
* 获取某一行的wikitext
|
|
172
|
-
* @param n 行号
|
|
241
|
+
* @param n line number / 行号
|
|
173
242
|
*/
|
|
174
243
|
getLine(n: number): string | undefined;
|
|
175
244
|
}
|