@bhsd/codemirror-mediawiki 3.9.2 → 3.10.1
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 +147 -87
- package/dist/bidi.d.ts +9 -8
- package/dist/bidi.js +38 -23
- package/dist/codemirror.d.ts +7 -0
- package/dist/codemirror.js +22 -9
- package/dist/color.d.ts +8 -5
- package/dist/color.js +5 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.js +1 -0
- package/dist/constants.d.ts +3 -2
- package/dist/constants.js +3 -2
- package/dist/css.d.ts +5 -0
- package/dist/css.js +14 -6
- package/dist/escape.d.ts +22 -2
- package/dist/escape.js +44 -25
- package/dist/fold.d.ts +57 -5
- package/dist/fold.js +149 -58
- package/dist/hover.d.ts +16 -3
- package/dist/hover.js +84 -67
- package/dist/html.js +17 -12
- package/dist/indent.d.ts +7 -0
- package/dist/indent.js +7 -1
- package/dist/index.d.ts +54 -16
- package/dist/index.js +91 -38
- package/dist/inlay.d.ts +1 -1
- package/dist/inlay.js +26 -25
- package/dist/javascript.d.ts +10 -1
- package/dist/javascript.js +50 -2
- package/dist/keybindings.d.ts +1 -0
- package/dist/keybindings.js +1 -0
- package/dist/keymap.d.ts +11 -0
- package/dist/keymap.js +3 -4
- package/dist/linter.d.ts +31 -2
- package/dist/linter.js +10 -3
- package/dist/lintsource.d.ts +47 -3
- package/dist/lintsource.js +50 -11
- package/dist/lua.d.ts +0 -2
- package/dist/lua.js +27 -10
- package/dist/main.min.js +31 -29
- package/dist/matchBrackets.d.ts +16 -0
- package/dist/matchBrackets.js +16 -0
- package/dist/matchTag.d.ts +5 -2
- package/dist/matchTag.js +11 -7
- package/dist/mediawiki.d.ts +15 -2
- package/dist/mediawiki.js +59 -45
- package/dist/mw.min.js +33 -37
- package/dist/mwConfig.js +2 -2
- package/dist/openLinks.d.ts +12 -2
- package/dist/openLinks.js +64 -54
- package/dist/ref.d.ts +16 -2
- package/dist/ref.js +110 -95
- package/dist/signature.d.ts +7 -1
- package/dist/signature.js +53 -49
- package/dist/static.d.ts +4 -0
- package/dist/static.js +4 -0
- package/dist/statusBar.js +9 -8
- package/dist/theme.d.ts +1 -0
- package/dist/theme.js +8 -0
- package/dist/token.d.ts +29 -7
- package/dist/token.js +33 -18
- package/dist/util.d.ts +25 -2
- package/dist/util.js +47 -1
- package/dist/wiki.min.js +32 -36
- package/i18n/en.json +2 -2
- package/i18n/zh-hans.json +2 -2
- package/i18n/zh-hant.json +2 -2
- package/package.json +15 -13
package/dist/lintsource.d.ts
CHANGED
|
@@ -3,10 +3,11 @@ import type { Text, EditorState } from '@codemirror/state';
|
|
|
3
3
|
import type { Language } from '@codemirror/language';
|
|
4
4
|
import type { Diagnostic, Action } from '@codemirror/lint';
|
|
5
5
|
import type { Option, LiveOption } from './linter';
|
|
6
|
-
|
|
6
|
+
import type { DocRange } from './fold';
|
|
7
|
+
export type LintSource = ((state: EditorState) => readonly Diagnostic[] | Promise<readonly Diagnostic[]>) & {
|
|
7
8
|
fixer?: (doc: Text, rule?: string) => string | Promise<string>;
|
|
8
9
|
};
|
|
9
|
-
export type LintSources = LintSource | [LintSource
|
|
10
|
+
export type LintSources = LintSource | [LintSource, ...LintSource[]];
|
|
10
11
|
export type LintSourceGetter = (opt?: Option | LiveOption, view?: EditorView, nestedMWLanguage?: Language) => LintSource | Promise<LintSource>;
|
|
11
12
|
export interface ExtendedAction extends Action {
|
|
12
13
|
tooltip: string | undefined;
|
|
@@ -17,10 +18,53 @@ export interface ExtendedAction extends Action {
|
|
|
17
18
|
* @param runtime 是否为运行时选项
|
|
18
19
|
*/
|
|
19
20
|
export declare const getOpt: (opt: Option | LiveOption, runtime?: boolean) => Option | Promise<Option>;
|
|
20
|
-
|
|
21
|
+
/**
|
|
22
|
+
* 获取指定行列的位置
|
|
23
|
+
* @param doc 文档
|
|
24
|
+
* @param line 行号
|
|
25
|
+
* @param column 列号
|
|
26
|
+
* @param from 子语言起始位置
|
|
27
|
+
* @test
|
|
28
|
+
*/
|
|
29
|
+
export declare const pos: (doc: Text, line: number, column: number, from?: number) => number;
|
|
30
|
+
/**
|
|
31
|
+
* 将行列范围转换为位置范围
|
|
32
|
+
* @ignore
|
|
33
|
+
* @test
|
|
34
|
+
*/
|
|
35
|
+
export declare const getRange: (doc: Text, line: number, column: number, endLine?: number, endColumn?: number, f?: number, t?: number) => DocRange;
|
|
36
|
+
/**
|
|
37
|
+
* @implements
|
|
38
|
+
* @test
|
|
39
|
+
*/
|
|
40
|
+
export declare const getWikiLintSource: (articlePath?: string) => LintSourceGetter;
|
|
41
|
+
/**
|
|
42
|
+
* @implements
|
|
43
|
+
* @test
|
|
44
|
+
*/
|
|
21
45
|
export declare const getJsLintSource: LintSourceGetter;
|
|
46
|
+
/**
|
|
47
|
+
* @implements
|
|
48
|
+
* @test
|
|
49
|
+
*/
|
|
22
50
|
export declare const getCssLintSource: LintSourceGetter;
|
|
51
|
+
/**
|
|
52
|
+
* @implements
|
|
53
|
+
* @test
|
|
54
|
+
*/
|
|
23
55
|
export declare const getVueLintSource: LintSourceGetter;
|
|
56
|
+
/**
|
|
57
|
+
* @implements
|
|
58
|
+
* @test
|
|
59
|
+
*/
|
|
24
60
|
export declare const getHTMLLintSource: LintSourceGetter;
|
|
61
|
+
/**
|
|
62
|
+
* @implements
|
|
63
|
+
* @test
|
|
64
|
+
*/
|
|
25
65
|
export declare const getJsonLintSource: LintSourceGetter;
|
|
66
|
+
/**
|
|
67
|
+
* @implements
|
|
68
|
+
* @test
|
|
69
|
+
*/
|
|
26
70
|
export declare const getLuaLintSource: LintSourceGetter;
|
package/dist/lintsource.js
CHANGED
|
@@ -3,7 +3,7 @@ import { cssLanguage } from '@codemirror/lang-css';
|
|
|
3
3
|
import { javascriptLanguage } from '@codemirror/lang-javascript';
|
|
4
4
|
import { sanitizeInlineStyle, lintJSON } from '@bhsd/common';
|
|
5
5
|
import { getWikiLinter, getJsLinter, getCssLinter, getLuaLinter, stylelintRepo, eslintRepo, luacheckRepo, } from './linter.js';
|
|
6
|
-
import { posToIndex, } from './util.js';
|
|
6
|
+
import { posToIndex, toConfigGetter, } from './util.js';
|
|
7
7
|
import { base } from './constants.js';
|
|
8
8
|
/**
|
|
9
9
|
* 获取Linter选项
|
|
@@ -17,8 +17,9 @@ export const getOpt = (opt, runtime) => typeof opt === 'function' ? opt(runtime)
|
|
|
17
17
|
* @param line 行号
|
|
18
18
|
* @param column 列号
|
|
19
19
|
* @param from 子语言起始位置
|
|
20
|
+
* @test
|
|
20
21
|
*/
|
|
21
|
-
const pos = (doc, line, column, from = 0) => {
|
|
22
|
+
export const pos = (doc, line, column, from = 0) => {
|
|
22
23
|
if (from === 0) {
|
|
23
24
|
return posToIndex(doc, { line: line - 1, character: column - 1 });
|
|
24
25
|
}
|
|
@@ -28,7 +29,12 @@ const pos = (doc, line, column, from = 0) => {
|
|
|
28
29
|
character: (line === 1 ? from - lineDesc.from : 0) + column - 1,
|
|
29
30
|
});
|
|
30
31
|
};
|
|
31
|
-
|
|
32
|
+
/**
|
|
33
|
+
* 将行列范围转换为位置范围
|
|
34
|
+
* @ignore
|
|
35
|
+
* @test
|
|
36
|
+
*/
|
|
37
|
+
export const getRange = (doc, line, column, endLine, endColumn, f = 0, t = Infinity) => {
|
|
32
38
|
const start = pos(doc, line, column, f);
|
|
33
39
|
return {
|
|
34
40
|
from: start,
|
|
@@ -45,8 +51,7 @@ const wikiLintSource = async (wikiLint, text, opt, doc, f = 0, t) => (await wiki
|
|
|
45
51
|
apply(view) {
|
|
46
52
|
view.dispatch({
|
|
47
53
|
changes: {
|
|
48
|
-
|
|
49
|
-
to: posToIndex(doc, range.end),
|
|
54
|
+
...getRange(doc, range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1, f, t),
|
|
50
55
|
insert: newText,
|
|
51
56
|
},
|
|
52
57
|
});
|
|
@@ -56,9 +61,19 @@ const wikiLintSource = async (wikiLint, text, opt, doc, f = 0, t) => (await wiki
|
|
|
56
61
|
? getRange(doc, r.start.line + 1, r.start.character + 1, r.end.line + 1, r.end.character + 1, f, t)
|
|
57
62
|
: { from: from + f, to: (to ?? from) + f },
|
|
58
63
|
}));
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
/**
|
|
65
|
+
* @implements
|
|
66
|
+
* @test
|
|
67
|
+
*/
|
|
68
|
+
export const getWikiLintSource = (articlePath) => async (opt, v) => {
|
|
69
|
+
const options = { ...await getOpt(opt), cdn: base.CDN };
|
|
70
|
+
if (articlePath) {
|
|
71
|
+
options.getConfig = toConfigGetter(options.getConfig, articlePath);
|
|
72
|
+
}
|
|
73
|
+
const wikiLint = await getWikiLinter(options, v);
|
|
74
|
+
const lintSource = async ({ doc }) => {
|
|
75
|
+
return wikiLintSource(wikiLint, doc.toString(), await getOpt(opt, true), doc);
|
|
76
|
+
};
|
|
62
77
|
if (wikiLint.fixer) {
|
|
63
78
|
lintSource.fixer = (_, rule) => wikiLint.fixer('', rule);
|
|
64
79
|
}
|
|
@@ -92,6 +107,10 @@ const jsLintSource = (esLint, code, opt, doc, f = 0, t) => esLint(code, opt)
|
|
|
92
107
|
}
|
|
93
108
|
return diagnostic;
|
|
94
109
|
});
|
|
110
|
+
/**
|
|
111
|
+
* @implements
|
|
112
|
+
* @test
|
|
113
|
+
*/
|
|
95
114
|
export const getJsLintSource = async (opt) => {
|
|
96
115
|
const { CDN } = base, esLint = await getJsLinter(CDN && `${CDN}/${eslintRepo}`);
|
|
97
116
|
const lintSource = async ({ doc }) => jsLintSource(esLint, doc.toString(), await getOpt(opt), doc);
|
|
@@ -126,12 +145,20 @@ const cssLintSource = async (styleLint, code, opt, doc, f = 0, t) => {
|
|
|
126
145
|
return diagnostic;
|
|
127
146
|
});
|
|
128
147
|
};
|
|
148
|
+
/**
|
|
149
|
+
* @implements
|
|
150
|
+
* @test
|
|
151
|
+
*/
|
|
129
152
|
export const getCssLintSource = async (opt) => {
|
|
130
153
|
const { CDN } = base, styleLint = await getCssLinter(CDN && `${CDN}/${stylelintRepo}`);
|
|
131
154
|
const lintSource = async ({ doc }) => cssLintSource(styleLint, doc.toString(), await getOpt(opt), doc);
|
|
132
155
|
lintSource.fixer = async (doc, rule) => styleLint.fixer(doc.toString(), rule);
|
|
133
156
|
return lintSource;
|
|
134
157
|
};
|
|
158
|
+
/**
|
|
159
|
+
* @implements
|
|
160
|
+
* @test
|
|
161
|
+
*/
|
|
135
162
|
export const getVueLintSource = async (opt) => {
|
|
136
163
|
const { CDN } = base, styleLint = await getCssLinter(CDN && `${CDN}/${stylelintRepo}`), esLint = await getJsLinter(CDN && `${CDN}/${eslintRepo}`);
|
|
137
164
|
return async (state) => {
|
|
@@ -154,6 +181,10 @@ export const getVueLintSource = async (opt) => {
|
|
|
154
181
|
];
|
|
155
182
|
};
|
|
156
183
|
};
|
|
184
|
+
/**
|
|
185
|
+
* @implements
|
|
186
|
+
* @test
|
|
187
|
+
*/
|
|
157
188
|
export const getHTMLLintSource = async (opt, view, language) => {
|
|
158
189
|
const vueLintSource = await getVueLintSource(opt), wikiLint = await getWikiLinter({ include: false, ...await getOpt(opt), cdn: base.CDN }, view);
|
|
159
190
|
return async (state) => {
|
|
@@ -165,16 +196,24 @@ export const getHTMLLintSource = async (opt, view, language) => {
|
|
|
165
196
|
];
|
|
166
197
|
};
|
|
167
198
|
};
|
|
199
|
+
/**
|
|
200
|
+
* @implements
|
|
201
|
+
* @test
|
|
202
|
+
*/
|
|
168
203
|
export const getJsonLintSource = () => ({ doc }) => lintJSON(doc.toString())
|
|
169
|
-
.map(({ message,
|
|
204
|
+
.map(({ message, from, to = from, severity }) => ({ message, severity, from, to }));
|
|
205
|
+
/**
|
|
206
|
+
* @implements
|
|
207
|
+
* @test
|
|
208
|
+
*/
|
|
170
209
|
export const getLuaLintSource = async () => {
|
|
171
210
|
const { CDN } = base, luaLint = await getLuaLinter(CDN && `${CDN}/${luacheckRepo}`);
|
|
172
211
|
return async ({ doc }) => (await luaLint(doc.toString()))
|
|
173
|
-
.map(({ line, column, end_column
|
|
212
|
+
.map(({ line, column, end_column, msg: message, severity }) => ({
|
|
174
213
|
source: 'Luacheck',
|
|
175
214
|
message,
|
|
176
215
|
severity: severity === 1 ? 'warning' : 'error',
|
|
177
216
|
from: pos(doc, line, column),
|
|
178
|
-
to: pos(doc, line,
|
|
217
|
+
to: pos(doc, line, end_column + 1),
|
|
179
218
|
}));
|
|
180
219
|
};
|
package/dist/lua.d.ts
CHANGED
package/dist/lua.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/* eslint-disable no-template-curly-in-string */
|
|
2
2
|
import { lua } from '@codemirror/legacy-modes/mode/lua';
|
|
3
|
-
import { syntaxTree, LanguageSupport, StreamLanguage, foldService } from '@codemirror/language';
|
|
3
|
+
import { syntaxTree, LanguageSupport, StreamLanguage, foldService, HighlightStyle, syntaxHighlighting, } from '@codemirror/language';
|
|
4
4
|
import { snippetCompletion } from '@codemirror/autocomplete';
|
|
5
|
-
import {
|
|
5
|
+
import { tags } from '@lezer/highlight';
|
|
6
|
+
import { leadingSpaces, sliceDoc } from './util.js';
|
|
7
|
+
import { getLightHighlightStyle } from './theme.js';
|
|
6
8
|
const map = {
|
|
7
9
|
1: 'constant',
|
|
8
10
|
2: 'function',
|
|
@@ -84,7 +86,9 @@ const map = {
|
|
|
84
86
|
addWarning: 2,
|
|
85
87
|
allToString: 2,
|
|
86
88
|
clone: 2,
|
|
89
|
+
getContentLanguage: 2,
|
|
87
90
|
getCurrentFrame: 2,
|
|
91
|
+
getLanguage: 2,
|
|
88
92
|
incrementExpensiveFunctionCount: 2,
|
|
89
93
|
isSubsting: 2,
|
|
90
94
|
loadData: 2,
|
|
@@ -300,8 +304,12 @@ const map = {
|
|
|
300
304
|
detail: 'in loop',
|
|
301
305
|
type: 'keyword',
|
|
302
306
|
}),
|
|
303
|
-
], types = new Set(['variableName', 'variableName.standard', 'keyword']);
|
|
304
|
-
|
|
307
|
+
], types = new Set(['variableName', 'variableName.standard', 'keyword']), lang = StreamLanguage.define(lua);
|
|
308
|
+
/**
|
|
309
|
+
* @implements
|
|
310
|
+
* @test
|
|
311
|
+
*/
|
|
312
|
+
const source = context => {
|
|
305
313
|
const { state, pos } = context, node = syntaxTree(state).resolveInner(pos, -1);
|
|
306
314
|
if (!types.has(node.name)) {
|
|
307
315
|
return null;
|
|
@@ -396,7 +404,7 @@ lua.languageData['autocomplete'] = (context => {
|
|
|
396
404
|
return {
|
|
397
405
|
from,
|
|
398
406
|
options: prevSibling?.name !== 'keyword'
|
|
399
|
-
|| builtin.includes(
|
|
407
|
+
|| builtin.includes(sliceDoc(state, prevSibling))
|
|
400
408
|
? [...binary, ...blocks]
|
|
401
409
|
: [...builtins, ...constants, ...tables, ...unary, ...blocks],
|
|
402
410
|
validFor,
|
|
@@ -404,8 +412,12 @@ lua.languageData['autocomplete'] = (context => {
|
|
|
404
412
|
}
|
|
405
413
|
}
|
|
406
414
|
return null;
|
|
407
|
-
}
|
|
408
|
-
|
|
415
|
+
};
|
|
416
|
+
/**
|
|
417
|
+
* @implements
|
|
418
|
+
* @test
|
|
419
|
+
*/
|
|
420
|
+
const fold = ({ doc, tabSize }, start, from) => {
|
|
409
421
|
const { text, number } = doc.lineAt(start);
|
|
410
422
|
if (!text.trim()) {
|
|
411
423
|
return null;
|
|
@@ -424,6 +436,11 @@ const support = foldService.of(({ doc, tabSize }, start, from) => {
|
|
|
424
436
|
}
|
|
425
437
|
}
|
|
426
438
|
return empty || j === number ? null : { from, to: doc.line(j).to };
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
|
|
439
|
+
};
|
|
440
|
+
const support = [
|
|
441
|
+
getLightHighlightStyle(),
|
|
442
|
+
syntaxHighlighting(HighlightStyle.define([{ tag: tags.standard(tags.variableName), class: 'cm-globals' }])),
|
|
443
|
+
lang.data.of({ autocomplete: source }),
|
|
444
|
+
foldService.of(fold),
|
|
445
|
+
];
|
|
446
|
+
export default () => new LanguageSupport(lang, support);
|