wikilint 2.15.0 → 2.16.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.
Files changed (52) hide show
  1. package/README.md +2 -1
  2. package/config/.schema.json +14 -1
  3. package/config/llwiki.json +1 -0
  4. package/config/minimum.json +2 -0
  5. package/config/moegirl.json +1 -0
  6. package/config/zhwiki.json +24 -23
  7. package/coverage/badge.svg +1 -0
  8. package/dist/base.d.mts +164 -0
  9. package/dist/base.d.ts +68 -0
  10. package/dist/base.js +70 -63
  11. package/dist/base.mjs +74 -0
  12. package/dist/bin/coverage.js +19 -0
  13. package/dist/index.d.ts +6 -0
  14. package/dist/index.js +13 -3
  15. package/dist/internal.d.ts +41 -41
  16. package/dist/lib/lsp.d.ts +68 -0
  17. package/dist/lib/lsp.js +610 -0
  18. package/dist/lib/node.js +2 -2
  19. package/dist/lib/rect.d.ts +3 -5
  20. package/dist/lib/rect.js +13 -10
  21. package/dist/lib/text.js +6 -7
  22. package/dist/parser/braces.js +2 -0
  23. package/dist/parser/commentAndExt.js +1 -0
  24. package/dist/parser/converter.js +1 -0
  25. package/dist/parser/externalLinks.js +2 -1
  26. package/dist/parser/hrAndDoubleUnderscore.js +2 -1
  27. package/dist/parser/html.js +1 -0
  28. package/dist/parser/links.js +1 -0
  29. package/dist/parser/list.js +1 -0
  30. package/dist/parser/magicLinks.js +2 -1
  31. package/dist/parser/quotes.js +1 -0
  32. package/dist/parser/redirect.js +1 -0
  33. package/dist/parser/table.js +1 -0
  34. package/dist/src/attribute.d.ts +4 -2
  35. package/dist/src/attribute.js +3 -4
  36. package/dist/src/attributes.js +1 -1
  37. package/dist/src/heading.js +3 -1
  38. package/dist/src/html.js +3 -4
  39. package/dist/src/link/redirectTarget.d.ts +2 -3
  40. package/dist/src/link/redirectTarget.js +1 -2
  41. package/dist/src/magicLink.js +1 -1
  42. package/dist/src/nowiki/comment.d.ts +1 -1
  43. package/dist/src/nowiki/comment.js +1 -1
  44. package/dist/src/nowiki/quote.js +8 -12
  45. package/dist/util/debug.js +14 -2
  46. package/dist/util/diff.js +5 -0
  47. package/dist/util/html.js +3 -1
  48. package/dist/util/lint.js +16 -4
  49. package/dist/util/sharable.js +5 -4
  50. package/dist/util/sharable.mjs +4 -4
  51. package/dist/util/string.js +12 -1
  52. package/package.json +39 -21
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ const diff_1 = require("./util/diff");
12
12
  * @param file 文件名
13
13
  * @param dir 子路径
14
14
  */
15
- const rootRequire = (file, dir) => require(path.isAbsolute(file) ? file : path.join('..', file.includes('/') ? '' : dir, file));
15
+ const rootRequire = (file, dir) => require(path.isAbsolute(file) ? /* istanbul ignore next */ file : path.join('..', file.includes('/') ? '' : dir, file));
16
16
  const Parser = {
17
17
  config: 'default',
18
18
  i18n: undefined,
@@ -21,6 +21,7 @@ const Parser = {
21
21
  getConfig() {
22
22
  if (typeof this.config === 'string') {
23
23
  this.config = rootRequire(this.config, 'config');
24
+ /* istanbul ignore if */
24
25
  if (this.config.doubleUnderscore.length < 3 || Array.isArray(this.config.parserFunction[1])) {
25
26
  (0, diff_1.error)(`The schema (${path.resolve(__dirname, '..', 'config', '.schema.json')}) of parser configuration is updated.`);
26
27
  }
@@ -90,11 +91,11 @@ const Parser = {
90
91
  try {
91
92
  return token.parse(maxStage, include);
92
93
  }
93
- catch (e) {
94
+ catch (e) /* istanbul ignore next */ {
94
95
  if (e instanceof Error) {
95
96
  const file = path.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
96
97
  for (const k in config) {
97
- if (k.startsWith('regex')) {
98
+ if (k.startsWith('regex') || config[k] instanceof Set) {
98
99
  delete config[k];
99
100
  }
100
101
  }
@@ -107,12 +108,21 @@ const Parser = {
107
108
  });
108
109
  return root;
109
110
  },
111
+ /** @implements */
112
+ createLanguageService(uri) {
113
+ let mod;
114
+ // eslint-disable-next-line no-unused-labels
115
+ LSP: mod = require('./lib/lsp');
116
+ const { LanguageService, tasks } = mod;
117
+ return tasks.get(uri) ?? new LanguageService(uri);
118
+ },
110
119
  };
111
120
  const def = {
112
121
  default: { value: Parser },
113
122
  }, enumerable = new Set([
114
123
  'normalizeTitle',
115
124
  'parse',
125
+ 'createLanguageService',
116
126
  ]);
117
127
  for (const key in Parser) {
118
128
  if (!enumerable.has(key)) {
@@ -1,46 +1,46 @@
1
- export type { AstNodes, } from './lib/node';
2
- export type * from './lib/text';
1
+ export type { AstNodes } from './lib/node';
2
+ export type { AstText } from './lib/text';
3
3
  export type { Token } from './src/index';
4
- export type * from './src/redirect';
5
- export type * from './src/link/redirectTarget';
6
- export type * from './src/onlyinclude';
7
- export type * from './src/nowiki/noinclude';
8
- export type * from './src/tagPair/include';
9
- export type * from './src/nowiki/comment';
10
- export type * from './src/atom';
4
+ export type { RedirectToken } from './src/redirect';
5
+ export type { RedirectTargetToken } from './src/link/redirectTarget';
6
+ export type { OnlyincludeToken } from './src/onlyinclude';
7
+ export type { NoincludeToken } from './src/nowiki/noinclude';
8
+ export type { IncludeToken } from './src/tagPair/include';
9
+ export type { CommentToken } from './src/nowiki/comment';
10
+ export type { AtomToken } from './src/atom';
11
11
  export type { AttributeToken } from './src/attribute';
12
- export type * from './src/attributes';
13
- export type * from './src/tagPair/ext';
14
- export type * from './src/hidden';
15
- export type * from './src/arg';
16
- export type * from './src/syntax';
17
- export type * from './src/parameter';
18
- export type * from './src/transclude';
19
- export type * from './src/heading';
20
- export type * from './src/html';
12
+ export type { AttributesToken } from './src/attributes';
13
+ export type { ExtToken } from './src/tagPair/ext';
14
+ export type { HiddenToken } from './src/hidden';
15
+ export type { ArgToken } from './src/arg';
16
+ export type { SyntaxToken } from './src/syntax';
17
+ export type { ParameterToken } from './src/parameter';
18
+ export type { TranscludeToken } from './src/transclude';
19
+ export type { HeadingToken } from './src/heading';
20
+ export type { HtmlToken } from './src/html';
21
21
  export type { TdToken } from './src/table/td';
22
- export type * from './src/table/tr';
22
+ export type { TrToken } from './src/table/tr';
23
23
  export type { TableToken } from './src/table/index';
24
- export type * from './src/nowiki/hr';
25
- export type * from './src/nowiki/doubleUnderscore';
26
- export type * from './src/link/index';
27
- export type * from './src/link/category';
24
+ export type { HrToken } from './src/nowiki/hr';
25
+ export type { DoubleUnderscoreToken } from './src/nowiki/doubleUnderscore';
26
+ export type { LinkToken } from './src/link/index';
27
+ export type { CategoryToken } from './src/link/category';
28
28
  export type { ImageParameterToken } from './src/imageParameter';
29
- export type * from './src/link/file';
30
- export type * from './src/link/galleryImage';
31
- export type * from './src/nowiki/quote';
32
- export type * from './src/magicLink';
33
- export type * from './src/extLink';
34
- export type * from './src/nowiki/dd';
35
- export type * from './src/nowiki/list';
36
- export type * from './src/converterFlags';
37
- export type * from './src/converterRule';
38
- export type * from './src/converter';
39
- export type * from './src/nowiki/index';
40
- export type * from './src/pre';
41
- export type * from './src/paramTag/index';
42
- export type * from './src/paramTag/inputbox';
43
- export type * from './src/nested';
44
- export type * from './src/gallery';
45
- export type * from './src/imagemapLink';
46
- export type * from './src/imagemap';
29
+ export type { FileToken } from './src/link/file';
30
+ export type { GalleryImageToken } from './src/link/galleryImage';
31
+ export type { QuoteToken } from './src/nowiki/quote';
32
+ export type { MagicLinkToken } from './src/magicLink';
33
+ export type { ExtLinkToken } from './src/extLink';
34
+ export type { DdToken } from './src/nowiki/dd';
35
+ export type { ListToken } from './src/nowiki/list';
36
+ export type { ConverterFlagsToken } from './src/converterFlags';
37
+ export type { ConverterRuleToken } from './src/converterRule';
38
+ export type { ConverterToken } from './src/converter';
39
+ export type { NowikiToken } from './src/nowiki/index';
40
+ export type { PreToken } from './src/pre';
41
+ export type { ParamTagToken } from './src/paramTag/index';
42
+ export type { InputboxToken } from './src/paramTag/inputbox';
43
+ export type { NestedToken } from './src/nested';
44
+ export type { GalleryToken } from './src/gallery';
45
+ export type { ImagemapLinkToken } from './src/imagemapLink';
46
+ export type { ImagemapToken } from './src/imagemap';
@@ -0,0 +1,68 @@
1
+ import type { Range, Position, ColorInformation, ColorPresentation, CompletionItem, FoldingRange, DocumentSymbol, DocumentLink, Location, WorkspaceEdit } from 'vscode-languageserver-types';
2
+ import type { LanguageService as LanguageServiceBase } from '../base';
3
+ export declare const tasks: WeakMap<object, LanguageService>;
4
+ /** VSCode-style language service */
5
+ export declare class LanguageService implements LanguageServiceBase {
6
+ #private;
7
+ /** @param uri 任务标识 */
8
+ constructor(uri: object);
9
+ /**
10
+ * 提供颜色指示
11
+ * @param rgba 颜色解析函数
12
+ * @param text 源代码
13
+ * @param hsl 是否允许HSL颜色
14
+ */
15
+ provideDocumentColors(rgba: (s: string) => [number, number, number, number] | [], text: string, hsl?: boolean): Promise<ColorInformation[]>;
16
+ /**
17
+ * 颜色选择器
18
+ * @ignore
19
+ */
20
+ provideColorPresentations(// eslint-disable-line @typescript-eslint/class-methods-use-this
21
+ { color: { red, green, blue, alpha }, range }: ColorInformation): ColorPresentation[];
22
+ /**
23
+ * 提供自动补全
24
+ * @param text 源代码
25
+ * @param position 位置
26
+ */
27
+ provideCompletionItems(text: string, position: Position): Promise<CompletionItem[] | undefined>;
28
+ /**
29
+ * 提供折叠范围
30
+ * @param text 源代码
31
+ */
32
+ provideFoldingRanges(text: string): Promise<FoldingRange[]>;
33
+ /**
34
+ * 提供章节
35
+ * @param text 源代码
36
+ */
37
+ provideDocumentSymbols(text: string): Promise<DocumentSymbol[]>;
38
+ /**
39
+ * 提供链接
40
+ * @param text 源代码
41
+ */
42
+ provideLinks(text: string): Promise<DocumentLink[]>;
43
+ /**
44
+ * 提供引用
45
+ * @param text 源代码
46
+ * @param position 位置
47
+ */
48
+ provideReferences(text: string, position: Position): Promise<Omit<Location, 'uri'>[] | undefined>;
49
+ /**
50
+ * 提供定义
51
+ * @param text 源代码
52
+ * @param position 位置
53
+ */
54
+ provideDefinition(text: string, position: Position): Promise<Omit<Location, 'uri'>[] | undefined>;
55
+ /**
56
+ * 提供变量更名准备
57
+ * @param text 源代码
58
+ * @param position 位置
59
+ */
60
+ resolveRenameLocation(text: string, position: Position): Promise<Range | undefined>;
61
+ /**
62
+ * 变量更名
63
+ * @param text 源代码
64
+ * @param position 位置
65
+ * @param newName 新名称
66
+ */
67
+ provideRenameEdits(text: string, position: Position, newName: string): Promise<WorkspaceEdit | undefined>;
68
+ }