-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbase.ts
More file actions
639 lines (566 loc) · 13.1 KB
/
base.ts
File metadata and controls
639 lines (566 loc) · 13.1 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
import type {
Range,
Position,
ColorInformation,
ColorPresentation,
CompletionItem as CompletionItemBase,
CompletionItemKind,
FoldingRange,
DocumentLink,
Location,
WorkspaceEdit,
Diagnostic,
Hover,
SignatureHelp,
InlayHint,
CodeAction,
/* NOT FOR BROWSER ONLY */
DocumentSymbol,
} from 'vscode-languageserver-types';
export interface Config {
ext: string[];
readonly html: [string[], string[], string[]];
readonly namespaces: Record<string, string>;
readonly nsid: Record<string, number>;
readonly variable: string[];
readonly functionHook: string[];
readonly parserFunction: [Record<string, string>, Record<string, string>, string[], string[]];
readonly doubleUnderscore: [string[], string[], Record<string, string>, Record<string, string>];
readonly protocol: string;
readonly interwiki: string[];
readonly img: Record<string, string>;
readonly redirection: string[];
readonly variants: string[];
readonly articlePath?: string;
/** @private */
readonly excludes: string[];
/** @private */
inExt?: boolean;
/** @private */
regexRedirect?: RegExp;
/** @private */
regexHrAndDoubleUnderscore?: RegExp;
/** @private */
regexLinks?: RegExp;
/** @private */
regexExternalLinks?: RegExp;
/** @private */
regexMagicLinks?: RegExp;
/** @private */
regexConverter?: RegExp;
/** @private */
insensitiveDoubleUnderscore?: Set<string>;
/** @private */
sensitiveDoubleUnderscore?: Set<string>;
/** @private */
htmlElements?: Set<string>;
/* NOT FOR BROWSER */
readonly conversionTable?: [string, string][];
readonly redirects?: [string, string][];
}
export type ConfigData = Omit<Config, 'excludes'>;
export type TokenTypes = 'root'
| 'plain'
| 'redirect'
| 'redirect-syntax'
| 'redirect-target'
| 'translate'
| 'translate-attr'
| 'translate-inner'
| 'tvar'
| 'tvar-name'
| 'onlyinclude'
| 'noinclude'
| 'include'
| 'comment'
| 'ext'
| 'ext-attrs'
| 'ext-attr-dirty'
| 'ext-attr'
| 'attr-key'
| 'attr-value'
| 'ext-inner'
| 'arg'
| 'arg-name'
| 'arg-default'
| 'hidden'
| 'magic-word'
| 'magic-word-name'
| 'invoke-function'
| 'invoke-module'
| 'template'
| 'template-name'
| 'parameter'
| 'parameter-key'
| 'parameter-value'
| 'heading'
| 'heading-title'
| 'heading-trail'
| 'html'
| 'html-attrs'
| 'html-attr-dirty'
| 'html-attr'
| 'table'
| 'tr'
| 'td'
| 'table-syntax'
| 'table-attrs'
| 'table-attr-dirty'
| 'table-attr'
| 'table-inter'
| 'td-inner'
| 'hr'
| 'double-underscore'
| 'link'
| 'link-target'
| 'link-text'
| 'category'
| 'file'
| 'gallery-image'
| 'imagemap-image'
| 'image-parameter'
| 'quote'
| 'ext-link'
| 'ext-link-text'
| 'ext-link-url'
| 'free-ext-link'
| 'magic-link'
| 'list'
| 'dd'
| 'converter'
| 'converter-flags'
| 'converter-flag'
| 'converter-rule'
| 'converter-rule-variant'
| 'converter-rule-to'
| 'converter-rule-from'
| 'param-line'
| 'imagemap-link'
/* NOT FOR BROWSER */
| 'list-range';
export const stages = /* #__PURE__ */ (() => {
const obj = {
redirect: 1,
onlyinclude: 1,
noinclude: 1,
include: 1,
comment: 1,
ext: 1,
arg: 2,
'magic-word': 2,
template: 2,
heading: 2,
html: 3,
table: 4,
hr: 5,
'double-underscore': 5,
link: 6,
category: 6,
file: 6,
quote: 7,
'ext-link': 8,
'free-ext-link': 9,
'magic-link': 9,
list: 10,
dd: 10,
converter: 11,
/* NOT FOR BROWSER */
'list-range': 11,
} satisfies Partial<Record<TokenTypes, number>>;
Object.setPrototypeOf(obj, null);
return obj;
})();
export type Stage = keyof typeof stages;
export const rules = /* #__PURE__ */ (() => {
const arr = [
'arg-in-ext',
'blank-alt',
'bold-header',
'format-leakage',
'fostered-content',
'h1',
'illegal-attr',
'insecure-style',
'invalid-gallery',
'invalid-imagemap',
'invalid-invoke',
'invalid-isbn',
'invalid-json',
'invalid-url',
'lonely-apos',
'lonely-bracket',
'lonely-http',
'nested-link',
'no-arg',
'no-duplicate',
'no-ignored',
'obsolete-attr',
'obsolete-tag',
'parsing-order',
'pipe-like',
'syntax-like',
'table-layout',
'tag-like',
'unbalanced-header',
'unclosed-comment',
'unclosed-quote',
'unclosed-table',
'unescaped',
'unknown-page',
'unmatched-tag',
'unterminated-url',
'url-encoding',
'var-anchor',
'void-ext',
/* NOT FOR BROWSER ONLY */
'invalid-css',
'invalid-math',
] as const;
Object.freeze(arr);
return arr;
})();
export namespace LintError {
export type Severity = 'error' | 'warning';
export type Rule = typeof rules[number];
export interface Fix {
readonly range: [number, number];
text: string;
desc: string;
}
}
export interface LintError {
rule: LintError.Rule;
message: string;
severity: LintError.Severity;
startIndex: number;
endIndex: number;
startLine: number;
startCol: number;
endLine: number;
endCol: number;
fix?: LintError.Fix;
suggestions?: LintError.Fix[];
/* NOT FOR BROWSER ONLY */
code?: string;
}
/* PRINT ONLY */
export type AST = Record<string, string | number | boolean> & {
range: [number, number];
type?: TokenTypes;
name?: string;
childNodes?: AST[];
data?: string;
};
/* PRINT ONLY END */
/**
* Node-like
*
* 类似Node
*/
export interface AstNode {
readonly childNodes: readonly AstNode[];
/**
* node type
*
* 节点类型
*/
type: string;
toString(...args: unknown[]): string;
/** @private */
getAttribute(key: string): unknown;
/** Linter */
lint(): LintError[];
/**
* print in HTML
*
* 以HTML格式打印
*/
print(): string;
}
/**
* base class for all tokens
*
* 所有节点的基类
*/
interface Token extends AstNode {
readonly name?: string;
/**
* Get all descendants that match the selector
*
* 符合选择器的所有后代节点
* @param selector selector / 选择器
*/
querySelectorAll<T = Token>(selector: string): T[];
/**
* Save in JSON format
*
* 保存为JSON
* @param file file name / 文件名
* @param depth depth of the node / 节点深度
*/
json(file?: string, depth?: number): AST;
/* NOT FOR BROWSER */
/**
* Generate HTML
*
* 生成HTML
* @since v1.10.0
*/
toHtml(): string;
}
interface SignatureParameter {
label: string;
const?: boolean;
rest?: boolean;
}
export interface SignatureInfo {
aliases: string[];
description: string;
signatures?: SignatureParameter[][];
}
export interface SignatureData {
behaviorSwitches: SignatureInfo[];
parserFunctions: SignatureInfo[];
}
export type CompletionItem = Omit<CompletionItemBase, 'kind'> & {
kind?: CompletionItemKind | keyof typeof CompletionItemKind;
};
export interface LanguageService {
include: boolean;
/** @private */
data?: SignatureData;
/**
* Destroy the instance
*
* 销毁实例
*/
destroy(): Promise<void>;
/**
* Provide color decorators
*
* 提供颜色指示
* @param rgba color parser / 颜色解析函数
* @param text source Wikitext / 源代码
* @param hsl whether HSL colors are treated / 是否允许HSL颜色
*/
provideDocumentColors(
rgba: (s: string) => [number, number, number, number] | [],
text: string,
hsl?: boolean,
): Promise<ColorInformation[]>;
/**
* Provide color pickers
*
* 颜色选择器
* @param color color information / 颜色信息
*/
provideColorPresentations(color: ColorInformation): ColorPresentation[];
/**
* Provide auto-completion
*
* 提供自动补全
* @param text source Wikitext / 源代码
* @param position position / 位置
*/
provideCompletionItems(text: string, position: Position): Promise<CompletionItem[] | undefined>;
/**
* Provide grammar check
*
* 提供语法检查
* @param text source Wikitext / 源代码
* @param warning whether to include warnings / 是否包含警告
*/
provideDiagnostics(text: string, warning?: boolean): Promise<Diagnostic[]>;
/**
* Resolve fix-all code action
*
* 实现修复全部代码的操作
* @param action code action / 代码操作
*/
resolveCodeAction(action: CodeAction): CodeAction;
/**
* Provide folding ranges
*
* 提供折叠范围
* @param text source Wikitext / 源代码
*/
provideFoldingRanges(text: string): Promise<FoldingRange[]>;
/**
* Provide links
*
* 提供链接
* @param text source Wikitext / 源代码
*/
provideLinks(text: string): Promise<DocumentLink[]>;
/**
* Provide references
*
* 提供引用
* @param text source Wikitext / 源代码
* @param position position / 位置
*/
provideReferences(text: string, position: Position): Promise<Omit<Location, 'uri'>[] | undefined>;
/**
* Provide definitions
*
* 提供定义
* @param text source Wikitext / 源代码
* @param position position / 位置
*/
provideDefinition(text: string, position: Position): Promise<Omit<Location, 'uri'>[] | undefined>;
/**
* Provide locations for renaming
*
* 提供变量更名准备
* @param text source Wikitext / 源代码
* @param position position / 位置
*/
resolveRenameLocation(text: string, position: Position): Promise<Range | undefined>;
/**
* Provide rename edits
*
* 变量更名
* @param text source Wikitext / 源代码
* @param position position / 位置
* @param newName new name / 新名称
*/
provideRenameEdits(text: string, position: Position, newName: string): Promise<WorkspaceEdit | undefined>;
/**
* Provide hover information
*
* 提供悬停信息
* @param text source Wikitext / 源代码
* @param position position / 位置
*/
provideHover(text: string, position: Position): Promise<Hover | undefined>;
/**
* Provide signature help for magic words
*
* 提供魔术字帮助
* @param text source Wikitext / 源代码
* @param position position / 位置
*/
provideSignatureHelp(text: string, position: Position): Promise<SignatureHelp | undefined>;
/**
* Provide CodeLens
*
* 提供 CodeLens
* @param text source Wikitext / 源代码
*/
provideInlayHints(text: string): Promise<InlayHint[]>;
/**
* Provide refactoring actions
*
* 提供重构操作
* @param text source Wikitext / 源代码
* @param range range of the refactoring / 重构范围
*/
provideRefactoringAction(text: string, range?: Range): Promise<CodeAction[]>;
/** @private */
findStyleTokens(): Token[];
/** @private */
querySelectorAll<T = Token>(selector: string): T[];
/* NOT FOR BROWSER ONLY */
/**
* Provide quick fixes
*
* 提供快速修复建议
* @param diagnostics grammar diagnostics / 语法诊断信息
*/
provideCodeAction(diagnostics: Diagnostic[]): CodeAction[];
/**
* Provide document sections
*
* 提供章节
* @param text source Wikitext / 源代码
*/
provideDocumentSymbols(text: string): Promise<DocumentSymbol[]>;
/**
* Set the target Wikipedia
*
* 设置目标维基百科
* @param wiki Wikipedia URL / 维基百科网址
* @param user URI for wiki userpage or email address of the user / 维基用户页面地址或用户的电子邮件地址
*/
setTargetWikipedia(wiki: string, user: string): Promise<void>;
[Symbol.dispose](): void;
}
export type SeverityLevel = 0 | 1 | 2 | false | 'off' | 'warning' | 'error';
export type LintConfigValue = SeverityLevel | [SeverityLevel, Record<string, SeverityLevel>?];
export type LintRuleConfig = Partial<Record<LintError.Rule, LintConfigValue>>;
export interface FullLintConfig {
rules: LintRuleConfig;
configurationComment?: string;
ignoreDisables?: boolean;
fix?: boolean;
computeEditInfo?: boolean;
}
export type LintConfig = LintRuleConfig | FullLintConfig;
export interface LintRuleConfiguration extends LintRuleConfig {
getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
}
export interface LintConfiguration extends FullLintConfig {
rules: LintRuleConfiguration;
getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
}
export interface Parser {
config:
string | // eslint-disable-line @stylistic/operator-linebreak
ConfigData;
i18n: Record<string, string>
| string
| undefined;
/** @since v1.22.0 */
lintConfig: LintConfig;
/** @since v1.9.0 */
viewOnly: boolean;
/* PRINT ONLY */
/** @private */
internal: boolean;
/* PRINT ONLY END */
/**
* Get the current parser configuration
*
* 获取当前的解析设置
* @param config unprocessed parser configuration / 未处理的解析设置
*/
getConfig(config?: ConfigData): Config;
/**
* Parse wikitext
*
* 解析wikitext
* @param include whether to be transcluded / 是否嵌入
* @param maxStage max stage for parsing / 最大解析层级
* @param page page name / 页面名称
*/
parse(
wikitext: string,
include?: boolean,
maxStage?: number | Stage | Stage[],
config?: Config,
page?: string,
): Token;
parse(
wikitext: string,
page: string,
include?: boolean,
maxStage?: number | Stage | Stage[],
config?: Config,
): Token;
/**
* Create a language server
*
* 创建语言服务
* @param uri document URI / 文档标识
* @since v1.16.1
*/
createLanguageService(uri?: object): LanguageService;
/**
* Linter
* @param include whether to be transcluded / 是否嵌入
* @param page page name / 页面名称
* @since v1.32.0
*/
lint(wikitext: string, include?: boolean, config?: Config, page?: string): LintError[];
lint(wikitext: string, page: string, include?: boolean, config?: Config): LintError[];
}