wikilint 2.16.2 → 2.16.4

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.
@@ -1 +1 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="98" height="20" role="img" aria-label="Coverage: 86%"><title>Coverage: 86%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="98" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="63" height="20" fill="#555"/><rect x="63" width="35" height="20" fill="#4c1"/><rect width="98" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="325" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">Coverage</text><text x="325" y="140" transform="scale(.1)" fill="#fff" textLength="530">Coverage</text><text aria-hidden="true" x="795" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">86%</text><text x="795" y="140" transform="scale(.1)" fill="#fff" textLength="250">86%</text></g></svg>
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="98" height="20" role="img" aria-label="Coverage: 87%"><title>Coverage: 87%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="98" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="63" height="20" fill="#555"/><rect x="63" width="35" height="20" fill="#4c1"/><rect width="98" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="325" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">Coverage</text><text x="325" y="140" transform="scale(.1)" fill="#fff" textLength="530">Coverage</text><text aria-hidden="true" x="795" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">87%</text><text x="795" y="140" transform="scale(.1)" fill="#fff" textLength="250">87%</text></g></svg>
@@ -1628,6 +1628,49 @@
1628
1628
  ],
1629
1629
  "description": "Transclude the introduction of a page (i.e. the content before the first heading), or the whole content of the first occurrence of the *section X* (which includes all its sub-sections but excludes the heading of *section X* itself), or the content from the first occurrence of *section X* (excluding the heading of *section X* itself) until it reaches the next occurrence of *section Y*. Note that *section Y* acts as a stop point so the transclusion doesn't contain the content of *section Y*."
1630
1630
  },
1631
+ {
1632
+ "aliases": [
1633
+ "msg",
1634
+ "raw",
1635
+ "原始"
1636
+ ],
1637
+ "signatures": [
1638
+ [
1639
+ {
1640
+ "label": "xyz"
1641
+ }
1642
+ ]
1643
+ ],
1644
+ "description": "Even if there is a magic word named `xyz`, use template:xyz unless the template doesn't exist (equivalent to `{{template:xyz}}`). Normally, magic words have priority when there is a conflict."
1645
+ },
1646
+ {
1647
+ "aliases": [
1648
+ "subst",
1649
+ "替代"
1650
+ ],
1651
+ "signatures": [
1652
+ [
1653
+ {
1654
+ "label": "xyz"
1655
+ }
1656
+ ]
1657
+ ],
1658
+ "description": "In the wikitext, the tag is substituted by the content (single-level evaluation only), see [Help:Templates](https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Templates#Usage)."
1659
+ },
1660
+ {
1661
+ "aliases": [
1662
+ "safesubst",
1663
+ "安全替代"
1664
+ ],
1665
+ "signatures": [
1666
+ [
1667
+ {
1668
+ "label": "xyz"
1669
+ }
1670
+ ]
1671
+ ],
1672
+ "description": "See [Help:Templates](https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Templates#Usage)."
1673
+ },
1631
1674
  {
1632
1675
  "aliases": [
1633
1676
  "currentyear",
@@ -1,6 +1,10 @@
1
1
  import { AstNode } from './node';
2
2
  import type { LintError } from '../base';
3
3
  import type { AstNodes, Token } from '../internal';
4
+ export interface CaretPosition {
5
+ readonly offsetNode: AstNodes;
6
+ readonly offset: number;
7
+ }
4
8
  /** 类似HTMLElement */
5
9
  export declare abstract class AstElement extends AstNode {
6
10
  #private;
@@ -50,4 +54,20 @@ export declare abstract class AstElement extends AstNode {
50
54
  * @param i 子节点位置
51
55
  */
52
56
  setText(str: string, i?: number): string;
57
+ /**
58
+ * 找到给定位置
59
+ * @param index 位置
60
+ */
61
+ caretPositionFromIndex(index?: number): CaretPosition | undefined;
62
+ /**
63
+ * 找到给定位置所在的最外层节点
64
+ * @param index 位置
65
+ */
66
+ elementFromIndex(index?: number): Token | undefined;
67
+ /**
68
+ * 找到给定位置所在的最外层节点
69
+ * @param x 列数
70
+ * @param y 行数
71
+ */
72
+ elementFromPoint(x: number, y: number): Token | undefined;
53
73
  }
@@ -156,6 +156,65 @@ class AstElement extends node_1.AstNode {
156
156
  toString(skip, separator = '') {
157
157
  return this.childNodes.map(child => child.toString(skip)).join(separator);
158
158
  }
159
+ /**
160
+ * 找到给定位置
161
+ * @param index 位置
162
+ */
163
+ caretPositionFromIndex(index) {
164
+ LSP: { // eslint-disable-line no-unused-labels
165
+ if (index === undefined) {
166
+ return undefined;
167
+ }
168
+ const { length } = this.toString();
169
+ if (index > length || index < -length) {
170
+ return undefined;
171
+ }
172
+ index += index < 0 ? length : 0;
173
+ let self = this, acc = 0, start = 0;
174
+ while (self.type !== 'text') {
175
+ const { childNodes } = self;
176
+ acc += self.getAttribute('padding');
177
+ for (let i = 0; acc <= index && i < childNodes.length; i++) {
178
+ const cur = childNodes[i], { nextSibling } = cur, str = cur.toString(), l = str.length;
179
+ acc += l;
180
+ // 优先选择靠前的非文本兄弟节点,但永不进入假节点
181
+ if (acc > index
182
+ || acc === index && l > 0 && (!nextSibling
183
+ || nextSibling.type === 'text'
184
+ || cur.type !== 'text' && (str.trim() || !nextSibling.toString().trim()))) {
185
+ self = cur;
186
+ acc -= l;
187
+ start = acc;
188
+ break;
189
+ }
190
+ acc += self.getGaps(i);
191
+ }
192
+ if (self.childNodes === childNodes) {
193
+ return { offsetNode: self, offset: index - start };
194
+ }
195
+ }
196
+ return { offsetNode: self, offset: index - start };
197
+ }
198
+ }
199
+ /**
200
+ * 找到给定位置所在的最外层节点
201
+ * @param index 位置
202
+ */
203
+ elementFromIndex(index) {
204
+ LSP: { // eslint-disable-line no-unused-labels
205
+ const node = this.caretPositionFromIndex(index)?.offsetNode;
206
+ return node?.type === 'text' ? node.parentNode : node;
207
+ }
208
+ }
209
+ /**
210
+ * 找到给定位置所在的最外层节点
211
+ * @param x 列数
212
+ * @param y 行数
213
+ */
214
+ elementFromPoint(x, y) {
215
+ // eslint-disable-next-line no-unused-labels
216
+ LSP: return this.elementFromIndex(this.indexFromPos(y, x));
217
+ }
159
218
  /** @private */
160
219
  lint(start = this.getAbsoluteIndex(), re) {
161
220
  const errors = [];
package/dist/lib/lsp.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import Parser from '../index';
2
- import type { Range, Position, ColorInformation, ColorPresentation, FoldingRange, DocumentSymbol, DocumentLink, Location, WorkspaceEdit, Diagnostic as DiagnosticBase, TextEdit, Hover, SignatureHelp, InlayHint, CodeAction } from 'vscode-languageserver-types';
2
+ import type { Range, Position, ColorInformation, ColorPresentation, FoldingRange, DocumentLink, Location, WorkspaceEdit, Diagnostic as DiagnosticBase, TextEdit, Hover, SignatureHelp, InlayHint, CodeAction, DocumentSymbol } from 'vscode-languageserver-types';
3
3
  import type { LanguageService as LanguageServiceBase, CompletionItem, SignatureData } from '../base';
4
+ declare interface Diagnostic extends DiagnosticBase {
5
+ data: QuickFixData[];
6
+ }
4
7
  declare interface QuickFixData extends TextEdit {
5
8
  title: string;
6
9
  fix: boolean;
7
10
  }
8
- declare interface Diagnostic extends DiagnosticBase {
9
- data: QuickFixData[];
10
- }
11
11
  export declare const tasks: WeakMap<object, Parser.LanguageService>;
12
12
  /** VSCode-style language service */
13
13
  export declare class LanguageService implements LanguageServiceBase {
@@ -57,22 +57,28 @@ export declare class LanguageService implements LanguageServiceBase {
57
57
  /**
58
58
  * 提供定义
59
59
  * @param text 源代码
60
- * @param position 位置
60
+ * @param pos 位置
61
+ * @param pos.line 行号
62
+ * @param pos.character 列号
61
63
  */
62
- provideDefinition(text: string, position: Position): Promise<Omit<Location, 'uri'>[] | undefined>;
64
+ provideDefinition(text: string, { line, character }: Position): Promise<Omit<Location, 'uri'>[] | undefined>;
63
65
  /**
64
66
  * 提供变量更名准备
65
67
  * @param text 源代码
66
- * @param position 位置
68
+ * @param pos 位置
69
+ * @param pos.line 行号
70
+ * @param pos.character 列号
67
71
  */
68
- resolveRenameLocation(text: string, position: Position): Promise<Range | undefined>;
72
+ resolveRenameLocation(text: string, { line, character }: Position): Promise<Range | undefined>;
69
73
  /**
70
74
  * 变量更名
71
75
  * @param text 源代码
72
- * @param position 位置
76
+ * @param pos 位置
77
+ * @param pos.line 行号
78
+ * @param pos.character 列号
73
79
  * @param newName 新名称
74
80
  */
75
- provideRenameEdits(text: string, position: Position, newName: string): Promise<WorkspaceEdit | undefined>;
81
+ provideRenameEdits(text: string, { line, character }: Position, newName: string): Promise<WorkspaceEdit | undefined>;
76
82
  /**
77
83
  * 提供悬停信息
78
84
  * @param text 源代码