@bhsd/codemirror-mediawiki 3.8.1 → 3.9.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 +45 -2
- package/dist/bidi.js +3 -3
- package/dist/codemirror.d.ts +9 -1
- package/dist/codemirror.js +51 -31
- package/dist/color.d.ts +1 -2
- package/dist/color.js +5 -16
- package/dist/config.d.ts +3 -2
- package/dist/config.js +4 -13
- package/dist/constants.d.ts +2 -1
- package/dist/constants.js +2 -1
- package/dist/escape.d.ts +1 -1
- package/dist/escape.js +11 -10
- package/dist/fold.d.ts +2 -1
- package/dist/fold.js +9 -8
- package/dist/hover.d.ts +1 -1
- package/dist/hover.js +9 -8
- package/dist/html.js +6 -5
- package/dist/indent.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +38 -41
- package/dist/inlay.d.ts +1 -1
- package/dist/inlay.js +11 -15
- package/dist/keymap.d.ts +2 -1
- package/dist/keymap.js +2 -3
- package/dist/linter.d.ts +2 -11
- package/dist/linter.js +17 -31
- package/dist/lintsource.d.ts +2 -2
- package/dist/lintsource.js +18 -33
- package/dist/lua.js +2 -1
- package/dist/main.min.js +27 -24
- package/dist/matchTag.js +2 -2
- package/dist/mediawiki.d.ts +2 -2
- package/dist/mediawiki.js +20 -17
- package/dist/mw.min.js +30 -27
- package/dist/mwConfig.js +3 -2
- package/dist/openLinks.js +9 -8
- package/dist/ref.d.ts +1 -1
- package/dist/ref.js +8 -6
- package/dist/signature.d.ts +1 -1
- package/dist/signature.js +3 -3
- package/dist/statusBar.js +8 -3
- package/dist/theme.js +1 -1
- package/dist/token.d.ts +2 -3
- package/dist/token.js +5 -3
- package/dist/util.d.ts +5 -0
- package/dist/util.js +7 -2
- package/dist/vue.js +2 -2
- package/dist/wiki.min.js +29 -26
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +12 -10
package/dist/index.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import { keymap, highlightSpecialChars, highlightActiveLine, highlightWhitespace, highlightTrailingWhitespace, scrollPastEnd, drawSelection, rectangularSelection, crosshairCursor, } from '@codemirror/view';
|
|
2
|
-
import { EditorState } from '@codemirror/state';
|
|
2
|
+
import { EditorState, Prec } from '@codemirror/state';
|
|
3
3
|
import { highlightSelectionMatches } from '@codemirror/search';
|
|
4
|
-
import {
|
|
4
|
+
import { autocompletion, closeBrackets, acceptCompletion, completionKeymap, startCompletion, } from '@codemirror/autocomplete';
|
|
5
5
|
import { json } from '@codemirror/lang-json';
|
|
6
6
|
import { autoCloseTags } from '@codemirror/lang-html';
|
|
7
7
|
import { getLSP } from '@bhsd/browser';
|
|
8
|
-
import { colorPicker
|
|
9
|
-
import bidiIsolation from './bidi';
|
|
10
|
-
import { CodeMirror6, avail, languages, linterRegistry, destroyListeners, plain, optionalFunctions, themes, } from './codemirror';
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import codeFolding, { mediaWikiFold, foldHandler } from './fold';
|
|
14
|
-
import magicWordHover from './hover';
|
|
15
|
-
import { detectIndent } from './indent';
|
|
16
|
-
import inlayHints from './inlay';
|
|
17
|
-
import
|
|
18
|
-
import { getWikiLintSource, getJsLintSource, getCssLintSource, getJsonLintSource, getLuaLintSource, getVueLintSource, getHTMLLintSource, } from './lintsource';
|
|
19
|
-
import
|
|
20
|
-
import tagMatchingState from './matchTag';
|
|
21
|
-
import {
|
|
22
|
-
import openLinks from './openLinks';
|
|
23
|
-
import refHover from './ref';
|
|
24
|
-
import signatureHelp from './signature';
|
|
25
|
-
import { tagModes, getStaticMwConfig } from './static';
|
|
26
|
-
import statusBar from './statusBar';
|
|
27
|
-
import css from './css';
|
|
28
|
-
import html from './html';
|
|
29
|
-
import javascript from './javascript';
|
|
30
|
-
import lua from './lua';
|
|
31
|
-
import vue from './vue';
|
|
8
|
+
import { colorPicker } from '@bhsd/codemirror-css-color-picker';
|
|
9
|
+
import bidiIsolation from './bidi.js';
|
|
10
|
+
import { CodeMirror6, avail, languages, linterRegistry, destroyListeners, plain, optionalFunctions, themes, } from './codemirror.js';
|
|
11
|
+
import mediawikiColorPicker from './color.js';
|
|
12
|
+
import escapeKeymap from './escape.js';
|
|
13
|
+
import codeFolding, { mediaWikiFold, foldHandler } from './fold.js';
|
|
14
|
+
import magicWordHover from './hover.js';
|
|
15
|
+
import { detectIndent } from './indent.js';
|
|
16
|
+
import inlayHints from './inlay.js';
|
|
17
|
+
import formatKeymap from './keymap.js';
|
|
18
|
+
import { getWikiLintSource, getJsLintSource, getCssLintSource, getJsonLintSource, getLuaLintSource, getVueLintSource, getHTMLLintSource, } from './lintsource.js';
|
|
19
|
+
import bracketMatchingBase from './matchBrackets.js';
|
|
20
|
+
import tagMatchingState from './matchTag.js';
|
|
21
|
+
import { mediawikiBase } from './mediawiki.js';
|
|
22
|
+
import openLinks from './openLinks.js';
|
|
23
|
+
import refHover from './ref.js';
|
|
24
|
+
import signatureHelp from './signature.js';
|
|
25
|
+
import { tagModes, getStaticMwConfig } from './static.js';
|
|
26
|
+
import statusBar from './statusBar.js';
|
|
27
|
+
import css from './css.js';
|
|
28
|
+
import html from './html.js';
|
|
29
|
+
import javascript from './javascript.js';
|
|
30
|
+
import lua from './lua.js';
|
|
31
|
+
import vue from './vue.js';
|
|
32
32
|
export { CodeMirror6 };
|
|
33
33
|
/**
|
|
34
34
|
* 注册通用扩展
|
|
@@ -63,7 +63,7 @@ export const registerHighlightSelectionMatches = () => {
|
|
|
63
63
|
/** Register the `bracketMatching` extension */
|
|
64
64
|
export const registerBracketMatching = () => {
|
|
65
65
|
registerExtension('bracketMatching', ([config, e = []] = []) => [
|
|
66
|
-
|
|
66
|
+
bracketMatchingBase(config),
|
|
67
67
|
e,
|
|
68
68
|
]);
|
|
69
69
|
};
|
|
@@ -88,11 +88,11 @@ export const registerAllowMultipleSelections = () => {
|
|
|
88
88
|
export const registerAutocompletion = () => {
|
|
89
89
|
registerExtension('autocompletion', () => [
|
|
90
90
|
autocompletion({ defaultKeymap: false }),
|
|
91
|
-
keymap.of([
|
|
91
|
+
Prec.high(keymap.of([
|
|
92
92
|
...completionKeymap.filter(({ run }) => run !== startCompletion),
|
|
93
93
|
{ key: 'Shift-Enter', run: startCompletion },
|
|
94
94
|
{ key: 'Tab', run: acceptCompletion },
|
|
95
|
-
]),
|
|
95
|
+
])),
|
|
96
96
|
]);
|
|
97
97
|
};
|
|
98
98
|
/** Register the `codeFolding` extension */
|
|
@@ -101,7 +101,7 @@ export const registerCodeFolding = () => {
|
|
|
101
101
|
};
|
|
102
102
|
/** Register the `colorPicker` extension */
|
|
103
103
|
export const registerColorPicker = () => {
|
|
104
|
-
registerExtension('colorPicker',
|
|
104
|
+
registerExtension('colorPicker', (e = []) => e);
|
|
105
105
|
};
|
|
106
106
|
/** 注册所有通用扩展(除`colorPicker`) */
|
|
107
107
|
const registerExtensions = () => {
|
|
@@ -167,7 +167,7 @@ export const registerOpenLinks = () => {
|
|
|
167
167
|
};
|
|
168
168
|
/** Register the `escape` extension */
|
|
169
169
|
export const registerEscape = () => {
|
|
170
|
-
registerExtensionForMediaWiki('escape',
|
|
170
|
+
registerExtensionForMediaWiki('escape', escapeKeymap);
|
|
171
171
|
};
|
|
172
172
|
/** Register the `refHover` extension */
|
|
173
173
|
export const registerRefHover = () => {
|
|
@@ -187,10 +187,7 @@ export const registerInlayHints = () => {
|
|
|
187
187
|
};
|
|
188
188
|
/** Register the `colorPicker` extension for MediaWiki */
|
|
189
189
|
export const registerColorPickerForMediaWiki = () => {
|
|
190
|
-
registerLangExtension('mediawiki', 'colorPicker',
|
|
191
|
-
[makeColorPicker({ discoverColors }), colorPickerTheme],
|
|
192
|
-
{ marginLeft: '.6ch' },
|
|
193
|
-
]);
|
|
190
|
+
registerLangExtension('mediawiki', 'colorPicker', mediawikiColorPicker());
|
|
194
191
|
};
|
|
195
192
|
/** Register the `bracketMatching` extension for MediaWiki */
|
|
196
193
|
export const registerBracketMatchingForMediaWiki = () => {
|
|
@@ -217,10 +214,10 @@ const registerLintSource = (lang, lintSource) => {
|
|
|
217
214
|
export const registerMediaWikiCore = () => {
|
|
218
215
|
CodeMirror6.getMwConfig = (config) => getStaticMwConfig(config, tagModes);
|
|
219
216
|
languages['mediawiki'] = (config) => [
|
|
220
|
-
|
|
217
|
+
mediawikiBase(config),
|
|
221
218
|
plain(),
|
|
222
219
|
bidiIsolation,
|
|
223
|
-
|
|
220
|
+
keymap.of(formatKeymap),
|
|
224
221
|
];
|
|
225
222
|
registerLintSource('mediawiki', getWikiLintSource);
|
|
226
223
|
destroyListeners.push(view => {
|
|
@@ -242,7 +239,7 @@ export const registerCloseBracketsForHTML = () => {
|
|
|
242
239
|
};
|
|
243
240
|
/** Register the `colorPicker` extension for mixed MediaWiki-HTML */
|
|
244
241
|
export const registerColorPickerForHTML = () => {
|
|
245
|
-
registerLangExtension('html', 'colorPicker',
|
|
242
|
+
registerLangExtension('html', 'colorPicker', colorPicker);
|
|
246
243
|
};
|
|
247
244
|
/** Register mixed MediaWiki-HTML core language support */
|
|
248
245
|
export const registerHTMLCore = () => {
|
|
@@ -269,7 +266,7 @@ export const registerCSS = () => {
|
|
|
269
266
|
};
|
|
270
267
|
/** Register the `colorPicker` extension for CSS */
|
|
271
268
|
export const registerColorPickerForCSS = () => {
|
|
272
|
-
registerLangExtension('css', 'colorPicker',
|
|
269
|
+
registerLangExtension('css', 'colorPicker', colorPicker);
|
|
273
270
|
};
|
|
274
271
|
/** Register CSS core language support */
|
|
275
272
|
export const registerCSSCore = () => {
|
|
@@ -312,7 +309,7 @@ export const registerCloseBracketsForVue = () => {
|
|
|
312
309
|
};
|
|
313
310
|
/** Register the `colorPicker` extension for Vue */
|
|
314
311
|
export const registerColorPickerForVue = () => {
|
|
315
|
-
registerLangExtension('vue', 'colorPicker',
|
|
312
|
+
registerLangExtension('vue', 'colorPicker', colorPicker);
|
|
316
313
|
};
|
|
317
314
|
/** Register Vue core language support */
|
|
318
315
|
export const registerVueCore = () => {
|
|
@@ -345,4 +342,4 @@ export const registerLanguageCore = (name, lang, lintSource) => {
|
|
|
345
342
|
export const registerTheme = (name, theme) => {
|
|
346
343
|
themes[name] = theme;
|
|
347
344
|
};
|
|
348
|
-
export { nord } from './theme';
|
|
345
|
+
export { nord } from './theme.js';
|
package/dist/inlay.d.ts
CHANGED
package/dist/inlay.js
CHANGED
|
@@ -2,8 +2,8 @@ import { StateField, StateEffect } from '@codemirror/state';
|
|
|
2
2
|
import { Decoration, EditorView, WidgetType, ViewPlugin } from '@codemirror/view';
|
|
3
3
|
import { getLSP } from '@bhsd/browser';
|
|
4
4
|
import elt from 'crelt';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { base } from './constants.js';
|
|
6
|
+
import { posToIndex, } from './util.js';
|
|
7
7
|
const cls = 'cm-inlay-hint';
|
|
8
8
|
class InlayHintWidget extends WidgetType {
|
|
9
9
|
constructor(label) {
|
|
@@ -39,7 +39,7 @@ const stateEffect = StateEffect.define(), field = StateField.define({
|
|
|
39
39
|
return EditorView.decorations.from(f);
|
|
40
40
|
},
|
|
41
41
|
});
|
|
42
|
-
const
|
|
42
|
+
const update = async ({ view, docChanged }) => {
|
|
43
43
|
if (docChanged) {
|
|
44
44
|
const text = view.state.doc.toString();
|
|
45
45
|
view.dispatch({
|
|
@@ -52,18 +52,14 @@ const updateField = async ({ view, docChanged }) => {
|
|
|
52
52
|
};
|
|
53
53
|
export default (cm) => [
|
|
54
54
|
field,
|
|
55
|
-
ViewPlugin.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
update(update) {
|
|
65
|
-
void updateField(update);
|
|
66
|
-
}
|
|
55
|
+
ViewPlugin.define(view => {
|
|
56
|
+
const timer = setInterval(() => {
|
|
57
|
+
if (getLSP(view, false, cm.getWikiConfig, base.CDN)) {
|
|
58
|
+
clearInterval(timer);
|
|
59
|
+
void update({ view, docChanged: true });
|
|
60
|
+
}
|
|
61
|
+
}, 100);
|
|
62
|
+
return { update };
|
|
67
63
|
}),
|
|
68
64
|
EditorView.theme({
|
|
69
65
|
[`.${cls}`]: {
|
package/dist/keymap.d.ts
CHANGED
package/dist/keymap.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { keymap } from '@codemirror/view';
|
|
2
1
|
import { EditorSelection } from '@codemirror/state';
|
|
3
|
-
import { keybindings, encapsulateLines } from './keybindings';
|
|
2
|
+
import { keybindings, encapsulateLines } from './keybindings.js';
|
|
4
3
|
/**
|
|
5
4
|
* 生成keymap
|
|
6
5
|
* @param opt 快捷键设置
|
|
@@ -33,4 +32,4 @@ const getKeymap = ({ key, pre = '', post = '', splitlines }) => ({
|
|
|
33
32
|
},
|
|
34
33
|
preventDefault: true,
|
|
35
34
|
});
|
|
36
|
-
export default
|
|
35
|
+
export default keybindings.map(getKeymap);
|
package/dist/linter.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { Warning } from 'stylelint';
|
|
|
4
4
|
import type { Diagnostic } from 'luacheck-browserify';
|
|
5
5
|
export type Option = Record<string, unknown> | null | undefined;
|
|
6
6
|
export type LiveOption = (runtime?: boolean) => Option | Promise<Option>;
|
|
7
|
-
declare type getLinter<T> = () => (text: string) => T;
|
|
8
7
|
declare type asyncLinter<T, S = Record<string, unknown>> = ((text: string, config?: Option) => T) & {
|
|
9
8
|
config?: S;
|
|
10
9
|
fixer?: (code: string, rule?: string) => string | Promise<string>;
|
|
@@ -19,14 +18,8 @@ declare interface MixedDiagnostic extends Omit<DiagnosticBase, 'range'> {
|
|
|
19
18
|
from?: number;
|
|
20
19
|
to?: number;
|
|
21
20
|
}
|
|
22
|
-
declare
|
|
23
|
-
|
|
24
|
-
severity: 'error';
|
|
25
|
-
line: string | undefined;
|
|
26
|
-
column: string | undefined;
|
|
27
|
-
position: string | undefined;
|
|
28
|
-
}
|
|
29
|
-
export declare const stylelintRepo = "npm/@bhsd/stylelint-browserify", eslintRepo = "npm/@bhsd/eslint-browserify", luacheckRepo = "npm/luacheck-browserify";
|
|
21
|
+
export declare const stylelintRepo = "npm/@bhsd/stylelint-browserify";
|
|
22
|
+
export declare const eslintRepo = "npm/@bhsd/eslint-browserify", luacheckRepo = "npm/luacheck-browserify";
|
|
30
23
|
/**
|
|
31
24
|
* 获取 Wikitext LSP
|
|
32
25
|
* @param opt 选项
|
|
@@ -50,6 +43,4 @@ export declare const getCssLinter: getAsyncLinter<Promise<Warning[]>, string>;
|
|
|
50
43
|
* @param cdn CDN 地址
|
|
51
44
|
*/
|
|
52
45
|
export declare const getLuaLinter: getAsyncLinter<Promise<Diagnostic[]>, string>;
|
|
53
|
-
/** JSON.parse */
|
|
54
|
-
export declare const getJsonLinter: getLinter<JsonError[]>;
|
|
55
46
|
export {};
|
package/dist/linter.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { sanitizeInlineStyle } from '@bhsd/common';
|
|
2
2
|
import { loadScript, getWikiparse, getLSP } from '@bhsd/browser';
|
|
3
3
|
import { styleLint } from '@bhsd/stylelint-util';
|
|
4
|
-
export const stylelintRepo = 'npm/@bhsd/stylelint-browserify'
|
|
4
|
+
export const stylelintRepo = 'npm/@bhsd/stylelint-browserify';
|
|
5
|
+
export const eslintRepo = 'npm/@bhsd/eslint-browserify', luacheckRepo = 'npm/luacheck-browserify';
|
|
5
6
|
/**
|
|
6
7
|
* 计算位置
|
|
7
8
|
* @param range 范围
|
|
@@ -48,14 +49,20 @@ const isStylelintConfig = (config) => Boolean(config && ('extends' in config ||
|
|
|
48
49
|
export const getWikiLinter = async (opt, obj) => {
|
|
49
50
|
const cdn = opt?.['cdn'];
|
|
50
51
|
await getWikiparse(opt?.['getConfig'], opt?.['i18n'], cdn);
|
|
51
|
-
const lsp = getLSP(obj, opt?.['include'])
|
|
52
|
+
const lsp = getLSP(obj, opt?.['include']);
|
|
53
|
+
const cssLint = await getCssLinter(cdn && `${cdn}/${stylelintRepo}`);
|
|
52
54
|
const linter = async (text, config) => {
|
|
53
|
-
const defaultSeverity = config?.['defaultSeverity'] ?? 2, diagnostics = (await lsp.provideDiagnostics(text))
|
|
55
|
+
const defaultSeverity = config?.['defaultSeverity'] ?? 2, diagnostics = (await lsp.provideDiagnostics(text))
|
|
56
|
+
.filter(({ code, severity }) => Number(config?.[code] ?? defaultSeverity) > Number(severity === 2)), tokens = 'findStyleTokens' in lsp
|
|
57
|
+
&& config?.['invalid-css'] !== '0'
|
|
58
|
+
? await lsp.findStyleTokens()
|
|
59
|
+
: [];
|
|
54
60
|
if (tokens.length === 0) {
|
|
55
61
|
return diagnostics;
|
|
56
62
|
}
|
|
57
63
|
const lines = tokens.map((token, i) => `${getPrefix(token, i)}${sanitizeInlineStyle(token.childNodes[1].childNodes[0].data)
|
|
58
|
-
.replace(/\n/gu, ' ')}\n}`)
|
|
64
|
+
.replace(/\n/gu, ' ')}\n}`);
|
|
65
|
+
const cssConfig = config?.['css'], isConfig = isStylelintConfig(cssConfig), rules = {};
|
|
59
66
|
for (const [key, value] of Object.entries((isConfig ? cssConfig.rules : cssConfig) ?? {})) {
|
|
60
67
|
if (!value) {
|
|
61
68
|
rules[key] = value;
|
|
@@ -63,12 +70,13 @@ export const getWikiLinter = async (opt, obj) => {
|
|
|
63
70
|
}
|
|
64
71
|
return [
|
|
65
72
|
...diagnostics,
|
|
66
|
-
...(await cssLint(lines.join('\n'), isConfig ? { ...cssConfig, rules } : rules))
|
|
67
|
-
.map(({ line, column, endLine, endColumn, rule, severity, text: message, fix }) => {
|
|
73
|
+
...(await cssLint(lines.join('\n'), isConfig ? { ...cssConfig, rules } : rules)).map(({ line, column, endLine, endColumn, rule, severity, text: message, fix }) => {
|
|
68
74
|
const i = Math.ceil(line / 3), { range } = tokens[i - 1].childNodes[1].childNodes[0], from = offsetAt(range, line - 3 * i, column - 1), diagnostic = {
|
|
69
75
|
from,
|
|
70
76
|
to: endLine === undefined ? from : offsetAt(range, endLine - 3 * i, endColumn - 1),
|
|
71
|
-
severity: severity === 'error'
|
|
77
|
+
severity: severity === 'error'
|
|
78
|
+
? 1
|
|
79
|
+
: 2,
|
|
72
80
|
source: 'Stylelint',
|
|
73
81
|
code: rule,
|
|
74
82
|
message,
|
|
@@ -134,7 +142,8 @@ export const getJsLinter = async (cdn = eslintRepo) => {
|
|
|
134
142
|
}
|
|
135
143
|
delete config.extends;
|
|
136
144
|
linter.config = config;
|
|
137
|
-
return esLinter.verify(text, config)
|
|
145
|
+
return esLinter.verify(text, config)
|
|
146
|
+
.filter(({ ruleId, message }) => message !== `Definition for rule '${ruleId}' was not found.`);
|
|
138
147
|
};
|
|
139
148
|
linter.fixer = (code, rule) => esLinter.verifyAndFix(code, rule ? { ...linter.config, rules: { [rule]: linter.config.rules?.[rule] ?? 2 } } : linter.config).output;
|
|
140
149
|
return linter;
|
|
@@ -168,26 +177,3 @@ export const getLuaLinter = async (cdn = luacheckRepo) => {
|
|
|
168
177
|
const luachecker = await luacheck(undefined);
|
|
169
178
|
return async (text) => (await luachecker.queue(text)).filter(({ severity }) => severity);
|
|
170
179
|
};
|
|
171
|
-
/** JSON.parse */
|
|
172
|
-
export const getJsonLinter = () => str => {
|
|
173
|
-
try {
|
|
174
|
-
if (str.trim()) {
|
|
175
|
-
JSON.parse(str);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch (e) {
|
|
179
|
-
if (e instanceof SyntaxError) {
|
|
180
|
-
const { message } = e, line = /\bline (\d+)/u.exec(message)?.[1], column = /\bcolumn (\d+)/u.exec(message)?.[1], position = /\bposition (\d+)/u.exec(message)?.[1];
|
|
181
|
-
return [
|
|
182
|
-
{
|
|
183
|
-
message,
|
|
184
|
-
severity: 'error',
|
|
185
|
-
line,
|
|
186
|
-
column,
|
|
187
|
-
position,
|
|
188
|
-
},
|
|
189
|
-
];
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return [];
|
|
193
|
-
};
|
package/dist/lintsource.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EditorView } from '@codemirror/view';
|
|
2
|
-
import type {
|
|
2
|
+
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';
|
|
@@ -7,7 +7,7 @@ export type LintSource = ((state: EditorState) => Diagnostic[] | Promise<Diagnos
|
|
|
7
7
|
fixer?: (doc: Text, rule?: string) => string | Promise<string>;
|
|
8
8
|
};
|
|
9
9
|
export type LintSources = LintSource | [LintSource] | [LintSource, LintSource];
|
|
10
|
-
export type LintSourceGetter = (
|
|
10
|
+
export type LintSourceGetter = (opt?: Option | LiveOption, view?: EditorView, nestedMWLanguage?: Language) => LintSource | Promise<LintSource>;
|
|
11
11
|
export interface ExtendedAction extends Action {
|
|
12
12
|
tooltip: string | undefined;
|
|
13
13
|
}
|
package/dist/lintsource.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ensureSyntaxTree } from '@codemirror/language';
|
|
2
2
|
import { cssLanguage } from '@codemirror/lang-css';
|
|
3
3
|
import { javascriptLanguage } from '@codemirror/lang-javascript';
|
|
4
|
-
import { sanitizeInlineStyle } from '@bhsd/common';
|
|
5
|
-
import { getWikiLinter, getJsLinter, getCssLinter,
|
|
6
|
-
import { posToIndex } from './util';
|
|
4
|
+
import { sanitizeInlineStyle, lintJSON } from '@bhsd/common';
|
|
5
|
+
import { getWikiLinter, getJsLinter, getCssLinter, getLuaLinter, stylelintRepo, eslintRepo, luacheckRepo, } from './linter.js';
|
|
6
|
+
import { posToIndex, } from './util.js';
|
|
7
|
+
import { base } from './constants.js';
|
|
7
8
|
/**
|
|
8
9
|
* 获取Linter选项
|
|
9
10
|
* @param opt Linter选项
|
|
@@ -55,8 +56,8 @@ const wikiLintSource = async (wikiLint, text, opt, doc, f = 0, t) => (await wiki
|
|
|
55
56
|
? getRange(doc, r.start.line + 1, r.start.character + 1, r.end.line + 1, r.end.character + 1, f, t)
|
|
56
57
|
: { from: from + f, to: (to ?? from) + f },
|
|
57
58
|
}));
|
|
58
|
-
export const getWikiLintSource = async (
|
|
59
|
-
const wikiLint = await getWikiLinter({ ...await getOpt(opt), cdn }, v);
|
|
59
|
+
export const getWikiLintSource = async (opt, v) => {
|
|
60
|
+
const wikiLint = await getWikiLinter({ ...await getOpt(opt), cdn: base.CDN }, v);
|
|
60
61
|
const lintSource = async ({ doc }) => wikiLintSource(wikiLint, doc.toString(), await getOpt(opt, true), doc);
|
|
61
62
|
if (wikiLint.fixer) {
|
|
62
63
|
lintSource.fixer = (_, rule) => wikiLint.fixer('', rule);
|
|
@@ -91,8 +92,8 @@ const jsLintSource = (esLint, code, opt, doc, f = 0, t) => esLint(code, opt)
|
|
|
91
92
|
}
|
|
92
93
|
return diagnostic;
|
|
93
94
|
});
|
|
94
|
-
export const getJsLintSource = async (
|
|
95
|
-
const esLint = await getJsLinter(
|
|
95
|
+
export const getJsLintSource = async (opt) => {
|
|
96
|
+
const { CDN } = base, esLint = await getJsLinter(CDN && `${CDN}/${eslintRepo}`);
|
|
96
97
|
const lintSource = async ({ doc }) => jsLintSource(esLint, doc.toString(), await getOpt(opt), doc);
|
|
97
98
|
lintSource.fixer = (doc, rule) => esLint.fixer(doc.toString(), rule);
|
|
98
99
|
return lintSource;
|
|
@@ -125,14 +126,14 @@ const cssLintSource = async (styleLint, code, opt, doc, f = 0, t) => {
|
|
|
125
126
|
return diagnostic;
|
|
126
127
|
});
|
|
127
128
|
};
|
|
128
|
-
export const getCssLintSource = async (
|
|
129
|
-
const styleLint = await getCssLinter(
|
|
129
|
+
export const getCssLintSource = async (opt) => {
|
|
130
|
+
const { CDN } = base, styleLint = await getCssLinter(CDN && `${CDN}/${stylelintRepo}`);
|
|
130
131
|
const lintSource = async ({ doc }) => cssLintSource(styleLint, doc.toString(), await getOpt(opt), doc);
|
|
131
132
|
lintSource.fixer = async (doc, rule) => styleLint.fixer(doc.toString(), rule);
|
|
132
133
|
return lintSource;
|
|
133
134
|
};
|
|
134
|
-
export const getVueLintSource = async (
|
|
135
|
-
const styleLint = await getCssLinter(
|
|
135
|
+
export const getVueLintSource = async (opt) => {
|
|
136
|
+
const { CDN } = base, styleLint = await getCssLinter(CDN && `${CDN}/${stylelintRepo}`), esLint = await getJsLinter(CDN && `${CDN}/${eslintRepo}`);
|
|
136
137
|
return async (state) => {
|
|
137
138
|
const { doc } = state, option = await getOpt(opt, true) ?? {}, js = option['js'], css = option['css'];
|
|
138
139
|
return [
|
|
@@ -153,8 +154,8 @@ export const getVueLintSource = async (cdn, opt) => {
|
|
|
153
154
|
];
|
|
154
155
|
};
|
|
155
156
|
};
|
|
156
|
-
export const getHTMLLintSource = async (
|
|
157
|
-
const vueLintSource = await getVueLintSource(
|
|
157
|
+
export const getHTMLLintSource = async (opt, view, language) => {
|
|
158
|
+
const vueLintSource = await getVueLintSource(opt), wikiLint = await getWikiLinter({ include: false, ...await getOpt(opt), cdn: base.CDN }, view);
|
|
158
159
|
return async (state) => {
|
|
159
160
|
const { doc } = state, option = await getOpt(opt, true) ?? {}, wiki = option['wiki'];
|
|
160
161
|
return [
|
|
@@ -164,26 +165,10 @@ export const getHTMLLintSource = async (cdn, opt, view, language) => {
|
|
|
164
165
|
];
|
|
165
166
|
};
|
|
166
167
|
};
|
|
167
|
-
export const getJsonLintSource = () => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (e) {
|
|
172
|
-
const { message, severity, line, column, position } = e;
|
|
173
|
-
let from = 0;
|
|
174
|
-
if (position) {
|
|
175
|
-
from = Number(position);
|
|
176
|
-
}
|
|
177
|
-
else if (line && column) {
|
|
178
|
-
from = pos(doc, Number(line), Number(column));
|
|
179
|
-
}
|
|
180
|
-
return [{ message, severity, from, to: from }];
|
|
181
|
-
}
|
|
182
|
-
return [];
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
export const getLuaLintSource = async (cdn) => {
|
|
186
|
-
const luaLint = await getLuaLinter(cdn && `${cdn}/${luacheckRepo}`);
|
|
168
|
+
export const getJsonLintSource = () => ({ doc }) => lintJSON(doc.toString())
|
|
169
|
+
.map(({ message, position, severity }) => ({ message, severity, from: position, to: position }));
|
|
170
|
+
export const getLuaLintSource = async () => {
|
|
171
|
+
const { CDN } = base, luaLint = await getLuaLinter(CDN && `${CDN}/${luacheckRepo}`);
|
|
187
172
|
return async ({ doc }) => (await luaLint(doc.toString()))
|
|
188
173
|
.map(({ line, column, end_column: endColumn, msg: message, severity }) => ({
|
|
189
174
|
source: 'Luacheck',
|
package/dist/lua.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { lua } from '@codemirror/legacy-modes/mode/lua';
|
|
3
3
|
import { syntaxTree, LanguageSupport, StreamLanguage, foldService } from '@codemirror/language';
|
|
4
4
|
import { snippetCompletion } from '@codemirror/autocomplete';
|
|
5
|
+
import { leadingSpaces } from './util.js';
|
|
5
6
|
const map = {
|
|
6
7
|
1: 'constant',
|
|
7
8
|
2: 'function',
|
|
@@ -409,7 +410,7 @@ const support = foldService.of(({ doc, tabSize }, start, from) => {
|
|
|
409
410
|
if (!text.trim()) {
|
|
410
411
|
return null;
|
|
411
412
|
}
|
|
412
|
-
const getIndent = (line) =>
|
|
413
|
+
const getIndent = (line) => leadingSpaces(line).replace(/\t/gu, ' '.repeat(tabSize)).length;
|
|
413
414
|
const indent = getIndent(text);
|
|
414
415
|
let j = number, empty = true;
|
|
415
416
|
for (; j < doc.lines; j++) {
|