@cosense-toolbox/lsp 0.1.0-beta.3 → 0.1.0-beta.5
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 +9 -0
- package/dist/check.mjs +1 -1
- package/dist/completion.d.mts +4 -1
- package/dist/completion.d.mts.map +1 -1
- package/dist/completion.mjs +8 -2
- package/dist/completion.mjs.map +1 -1
- package/dist/link.d.mts +37 -0
- package/dist/link.d.mts.map +1 -0
- package/dist/link.mjs +91 -0
- package/dist/link.mjs.map +1 -0
- package/dist/main.mjs +1 -1
- package/dist/{server-DWgrivkG.mjs → server-B7AZxbRw.mjs} +3 -3
- package/dist/{server-DWgrivkG.mjs.map → server-B7AZxbRw.mjs.map} +1 -1
- package/dist/tokens.d.mts +5 -1
- package/dist/tokens.d.mts.map +1 -1
- package/dist/tokens.mjs +282 -1
- package/dist/tokens.mjs.map +1 -0
- package/dist/tree-sXzD2703.mjs +29 -0
- package/dist/tree-sXzD2703.mjs.map +1 -0
- package/dist/{workspace-XJqmAxae.mjs → workspace-A-W0PU0g.mjs} +3 -2
- package/dist/{workspace-XJqmAxae.mjs.map → workspace-A-W0PU0g.mjs.map} +1 -1
- package/package.json +8 -2
- package/dist/tokens-pb6vW18i.mjs +0 -303
- package/dist/tokens-pb6vW18i.mjs.map +0 -1
package/dist/tokens-pb6vW18i.mjs
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { Array, Match, Option, Order, pipe } from "effect";
|
|
2
|
-
import { normalizeLineEndings, parse } from "@cosense-toolbox/parser";
|
|
3
|
-
import { visit } from "@cosense-toolbox/parser/utils";
|
|
4
|
-
//#region src/tree.ts
|
|
5
|
-
const leaf = (items) => ({
|
|
6
|
-
items,
|
|
7
|
-
descend: false
|
|
8
|
-
});
|
|
9
|
-
const branch = (items) => ({
|
|
10
|
-
items,
|
|
11
|
-
descend: true
|
|
12
|
-
});
|
|
13
|
-
/**
|
|
14
|
-
* Everything `pick` takes from `tree`, in document order.
|
|
15
|
-
*
|
|
16
|
-
* The parser's `visit` hands nodes to a callback, so something has to hold what the callback
|
|
17
|
-
* finds. That is kept to here: `pick` stays a pure function of one node.
|
|
18
|
-
*/
|
|
19
|
-
const gather = (tree, pick) => {
|
|
20
|
-
const found = [];
|
|
21
|
-
visit(tree, (node) => {
|
|
22
|
-
const { items, descend } = pick(node);
|
|
23
|
-
found.push(...items);
|
|
24
|
-
return descend ? void 0 : "skip";
|
|
25
|
-
});
|
|
26
|
-
return found;
|
|
27
|
-
};
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region src/tokens.ts
|
|
30
|
-
/**
|
|
31
|
-
* Cosense notation as LSP semantic tokens.
|
|
32
|
-
*
|
|
33
|
-
* These names are the ones this package reasons in, and they are not what goes on the wire.
|
|
34
|
-
* A client announces the token types it knows at initialize and drops everything else —
|
|
35
|
-
* some send the LSP's own list and nothing more — so `quote` would simply never be drawn.
|
|
36
|
-
* LEGEND below is what is sent, and LSP_TYPE is the translation.
|
|
37
|
-
*/
|
|
38
|
-
const TOKEN_TYPES = [
|
|
39
|
-
"title",
|
|
40
|
-
"link",
|
|
41
|
-
"projectLink",
|
|
42
|
-
"externalLink",
|
|
43
|
-
"hashtag",
|
|
44
|
-
"code",
|
|
45
|
-
"codeBlock",
|
|
46
|
-
"formula",
|
|
47
|
-
"icon",
|
|
48
|
-
"quote",
|
|
49
|
-
"bold",
|
|
50
|
-
"italic",
|
|
51
|
-
"strike",
|
|
52
|
-
"underline",
|
|
53
|
-
"image",
|
|
54
|
-
"table",
|
|
55
|
-
"bold2",
|
|
56
|
-
"bold3",
|
|
57
|
-
"component",
|
|
58
|
-
"attribute",
|
|
59
|
-
"attributeValue",
|
|
60
|
-
"expression",
|
|
61
|
-
"frontmatter",
|
|
62
|
-
"notation"
|
|
63
|
-
];
|
|
64
|
-
/**
|
|
65
|
-
* The legend sent to the client: the LSP's own token types, in its own order.
|
|
66
|
-
*
|
|
67
|
-
* Every entry is in the set a client is expected to understand, which is what makes the
|
|
68
|
-
* colours appear without the reader configuring anything.
|
|
69
|
-
*/
|
|
70
|
-
const LEGEND = [
|
|
71
|
-
"namespace",
|
|
72
|
-
"type",
|
|
73
|
-
"function",
|
|
74
|
-
"variable",
|
|
75
|
-
"property",
|
|
76
|
-
"parameter",
|
|
77
|
-
"decorator",
|
|
78
|
-
"macro",
|
|
79
|
-
"keyword",
|
|
80
|
-
"string",
|
|
81
|
-
"number",
|
|
82
|
-
"comment"
|
|
83
|
-
];
|
|
84
|
-
/**
|
|
85
|
-
* What each notation is drawn as. Chosen so that things a reader separates by eye land on
|
|
86
|
-
* different entries: a link is not a tag, and a quote is not a heading. `bold` and its
|
|
87
|
-
* louder siblings share one entry, because the LSP has no notion of weight and a theme
|
|
88
|
-
* gives each type a single colour.
|
|
89
|
-
*/
|
|
90
|
-
const LSP_TYPE = {
|
|
91
|
-
title: "namespace",
|
|
92
|
-
link: "function",
|
|
93
|
-
projectLink: "function",
|
|
94
|
-
externalLink: "string",
|
|
95
|
-
icon: "function",
|
|
96
|
-
image: "string",
|
|
97
|
-
hashtag: "decorator",
|
|
98
|
-
code: "string",
|
|
99
|
-
codeBlock: "string",
|
|
100
|
-
formula: "number",
|
|
101
|
-
table: "property",
|
|
102
|
-
quote: "comment",
|
|
103
|
-
frontmatter: "comment",
|
|
104
|
-
component: "type",
|
|
105
|
-
attribute: "parameter",
|
|
106
|
-
attributeValue: "string",
|
|
107
|
-
expression: "variable",
|
|
108
|
-
bold: "keyword",
|
|
109
|
-
bold2: "keyword",
|
|
110
|
-
bold3: "keyword",
|
|
111
|
-
italic: "macro",
|
|
112
|
-
strike: "comment",
|
|
113
|
-
underline: "variable",
|
|
114
|
-
notation: "decorator"
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* LEGEND with the names of `notations` after it, each once: the legend for a client that
|
|
118
|
-
* accepts token types of the caller's own naming. The LSP's types keep their places.
|
|
119
|
-
*/
|
|
120
|
-
const legendOf = (notations) => Array.dedupe([...LEGEND, ...Array.map(notations, (notation) => notation.name)]);
|
|
121
|
-
/** Leaf inline nodes that map 1:1. Each sits on one line, so no splitting is needed. */
|
|
122
|
-
const INLINE_TOKEN_TYPE = {
|
|
123
|
-
internalLink: "link",
|
|
124
|
-
externalLink: "externalLink",
|
|
125
|
-
projectLink: "projectLink",
|
|
126
|
-
hashtag: "hashtag",
|
|
127
|
-
inlineCode: "code",
|
|
128
|
-
image: "image",
|
|
129
|
-
icon: "icon",
|
|
130
|
-
formula: "formula"
|
|
131
|
-
};
|
|
132
|
-
/** Top to bottom, then left to right: the order the LSP encoding needs. */
|
|
133
|
-
const BY_POSITION = Order.combine(Order.mapInput(Order.number, (token) => token.line), Order.mapInput(Order.number, (token) => token.char));
|
|
134
|
-
const onlyIf = (condition, value) => condition ? Option.some(value) : Option.none();
|
|
135
|
-
/** A token over `[from, to)` of one line. */
|
|
136
|
-
const token = (type, line, from, to) => ({
|
|
137
|
-
line,
|
|
138
|
-
char: from,
|
|
139
|
-
length: to - from,
|
|
140
|
-
type
|
|
141
|
-
});
|
|
142
|
-
const spanToken = (type, position) => token(type, position.start.line, position.start.column, position.end.column);
|
|
143
|
-
/** How many characters from `from` the `^`-anchored `pattern` takes; 0 when it takes none. */
|
|
144
|
-
const matchLength = (pattern, text, from) => pipe(Option.fromNullable(pattern.exec(text.slice(from))), Option.match({
|
|
145
|
-
onNone: () => 0,
|
|
146
|
-
onSome: ([matched]) => matched.length
|
|
147
|
-
}));
|
|
148
|
-
/** Cosense sizes emphasis by asterisk count (`[*]`..`[*****]`); sizeLevel is 0-indexed. */
|
|
149
|
-
const boldTokenType = (sizeLevel) => Match.value(sizeLevel).pipe(Match.when((level) => level >= 2, () => "bold3"), Match.when(1, () => "bold2"), Match.orElse(() => "bold"));
|
|
150
|
-
/** Every decoration a run carries, since Cosense applies all of them: `[-* x]` is both. */
|
|
151
|
-
const decorationTokenTypes = (node) => Array.getSomes([
|
|
152
|
-
onlyIf(node.underline, "underline"),
|
|
153
|
-
onlyIf(node.strike, "strike"),
|
|
154
|
-
onlyIf(node.italic, "italic"),
|
|
155
|
-
onlyIf(node.bold, boldTokenType(node.sizeLevel))
|
|
156
|
-
]);
|
|
157
|
-
const COMPONENT_LINE = /^\s*<\/?[A-Z][A-Za-z0-9_.]*(\s|\/?>)/;
|
|
158
|
-
const TAG_OPEN = /^(\s*<\/?)([A-Z][A-Za-z0-9_.]*)/;
|
|
159
|
-
const ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*/;
|
|
160
|
-
const SPACE = /^\s*/;
|
|
161
|
-
/** Where a quoted value opened at `from` ends: after its closing quote, or at the line's end. */
|
|
162
|
-
const quotedEnd = (text, from) => pipe(text.indexOf(text.charAt(from), from + 1), Option.liftPredicate((close) => close >= 0), Option.match({
|
|
163
|
-
onNone: () => text.length,
|
|
164
|
-
onSome: (close) => close + 1
|
|
165
|
-
}));
|
|
166
|
-
/** Where `{ ... }` opened at `from` ends, counting nested braces: after its `}`, or the line's end. */
|
|
167
|
-
const bracedEnd = (text, from) => pipe(text.slice(from).split(""), Array.scan(0, (depth, char) => char === "{" ? depth + 1 : char === "}" ? depth - 1 : depth), Array.drop(1), Array.findFirstIndex((depth) => depth === 0), Option.match({
|
|
168
|
-
onNone: () => text.length,
|
|
169
|
-
onSome: (index) => from + index + 1
|
|
170
|
-
}));
|
|
171
|
-
/** The attribute value that starts at `from`: its type and where it ends. */
|
|
172
|
-
const valueAt = (text, from) => Match.value(text.charAt(from)).pipe(Match.when((char) => char === "\"" || char === "'", () => Option.some(["attributeValue", quotedEnd(text, from)])), Match.when("{", () => Option.some(["expression", bracedEnd(text, from)])), Match.orElse(() => Option.none()));
|
|
173
|
-
/** `at` past any whitespace. */
|
|
174
|
-
const skipSpace = (text, at) => at + matchLength(SPACE, text, at);
|
|
175
|
-
/** Whether the tag closes at `at`, with `>` or `/>`, or the line ends there. */
|
|
176
|
-
const closesAt = (text, at) => at >= text.length || text.startsWith(">", at) || text.startsWith("/>", at);
|
|
177
|
-
/**
|
|
178
|
-
* An attribute named over `[at, nameEnd)`: the name, then `=` and a value if one follows.
|
|
179
|
-
* A name with no `=` after it stands alone, as JSX reads `<Dialog open>`.
|
|
180
|
-
*/
|
|
181
|
-
const attribute = (line, text, at, nameEnd) => {
|
|
182
|
-
const name = token("attribute", line, at, nameEnd);
|
|
183
|
-
const afterName = skipSpace(text, nameEnd);
|
|
184
|
-
return pipe(Option.liftPredicate(afterName, (equals) => text.charAt(equals) === "="), Option.map((equals) => skipSpace(text, equals + 1)), Option.match({
|
|
185
|
-
onNone: () => [[name], afterName],
|
|
186
|
-
onSome: (valueStart) => pipe(valueAt(text, valueStart), Option.match({
|
|
187
|
-
onNone: () => [[name], valueStart],
|
|
188
|
-
onSome: ([type, end]) => [[name, token(type, line, valueStart, end)], end]
|
|
189
|
-
}))
|
|
190
|
-
}));
|
|
191
|
-
};
|
|
192
|
-
/** One attribute from `from`, or None once the tag has closed. */
|
|
193
|
-
const attributeStep = (line, text) => (from) => pipe(Option.liftPredicate(skipSpace(text, from), (at) => !closesAt(text, at)), Option.map((at) => pipe(Option.liftPredicate(at + matchLength(ATTRIBUTE_NAME, text, at), (end) => end > at), Option.match({
|
|
194
|
-
onNone: () => [[], at + 1],
|
|
195
|
-
onSome: (nameEnd) => attribute(line, text, at, nameEnd)
|
|
196
|
-
}))));
|
|
197
|
-
/**
|
|
198
|
-
* The tag that opens a component line, read as JSX: its name, then each attribute and its
|
|
199
|
-
* value, up to the `>` that closes it. Text after the tag is left alone; it is neither
|
|
200
|
-
* Cosense notation nor part of the tag.
|
|
201
|
-
*/
|
|
202
|
-
const componentTokens = (line, text) => pipe(Option.fromNullable(TAG_OPEN.exec(text)), Option.map(([head, lead = "", name = ""]) => [token("component", line, lead.length, lead.length + name.length), ...Array.flatten(Array.unfold(head.length, attributeStep(line, text)))]), Option.getOrElse(() => []));
|
|
203
|
-
/** The last line of the `---` fence around YAML at the very top, if the file opens with one. */
|
|
204
|
-
const frontmatterEnd = (lines) => pipe(Option.liftPredicate(lines, (all) => all[0]?.trim() === "---"), Option.flatMap(Array.findFirstIndex((line, index) => index > 0 && line.trim() === "---")));
|
|
205
|
-
/**
|
|
206
|
-
* `frontmatterEnd`, or None when the caller reads no frontmatter: a Cosense page has none,
|
|
207
|
-
* and a page whose title is `---` would otherwise lose its first lines to it.
|
|
208
|
-
*/
|
|
209
|
-
const fenceOf = (lines, frontmatter) => Option.flatMap(onlyIf(frontmatter, lines), frontmatterEnd);
|
|
210
|
-
/** Each non-empty line from `first` to `last`, whole. */
|
|
211
|
-
const lineSpans = (type, lines, first, last) => Array.filterMap(Array.range(first, last), (line) => pipe(Option.fromNullable(lines[line]), Option.filter((text) => text.length > 0), Option.map((text) => token(type, line, 0, text.length))));
|
|
212
|
-
/** The line's text, when the file reads components and the line opens with a tag. */
|
|
213
|
-
const componentLine = (page, line) => pipe(Option.fromNullable(page.lines[line]), Option.filter((text) => page.components && COMPONENT_LINE.test(text)));
|
|
214
|
-
/** The `>` and spaces that open a quote line, from its indentation onwards. */
|
|
215
|
-
const quoteToken = (page, node, line) => pipe(onlyIf(node.quote, page.lines[line] ?? ""), Option.map((text) => matchLength(/^[> ]*/, text, node.indent)), Option.filter((length) => length > 0), Option.map((length) => token("quote", line, node.indent, node.indent + length)));
|
|
216
|
-
/** A token for each of `notations` whose marker opens the decoration. */
|
|
217
|
-
const notationTokens = (notations, node, position) => Array.filterMap(notations, ({ marker, name }) => onlyIf(node.markers.includes(marker), {
|
|
218
|
-
line: position.start.line,
|
|
219
|
-
char: position.start.column,
|
|
220
|
-
length: position.end.column - position.start.column,
|
|
221
|
-
type: "notation",
|
|
222
|
-
name
|
|
223
|
-
}));
|
|
224
|
-
const nodeTokens = (page) => (node) => {
|
|
225
|
-
const lineOf = (position) => position.start.line + page.offset;
|
|
226
|
-
const shift = (position) => ({
|
|
227
|
-
start: {
|
|
228
|
-
...position.start,
|
|
229
|
-
line: position.start.line + page.offset
|
|
230
|
-
},
|
|
231
|
-
end: {
|
|
232
|
-
...position.end,
|
|
233
|
-
line: position.end.line + page.offset
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
return Match.value(node).pipe(Match.discriminators("type")({
|
|
237
|
-
title: (title) => leaf(pipe(componentLine(page, lineOf(title.position)), Option.match({
|
|
238
|
-
onNone: () => [spanToken("title", shift(title.position))],
|
|
239
|
-
onSome: (text) => componentTokens(lineOf(title.position), text)
|
|
240
|
-
}))),
|
|
241
|
-
codeBlock: (block) => leaf(lineSpans("codeBlock", page.lines, lineOf(block.position), block.position.end.line + page.offset)),
|
|
242
|
-
table: (table) => leaf(lineSpans("table", page.lines, lineOf(table.position), table.position.end.line + page.offset)),
|
|
243
|
-
line: (line) => pipe(componentLine(page, lineOf(line.position)), Option.match({
|
|
244
|
-
onSome: (text) => leaf(componentTokens(lineOf(line.position), text)),
|
|
245
|
-
onNone: () => branch(Option.toArray(quoteToken(page, line, lineOf(line.position))))
|
|
246
|
-
})),
|
|
247
|
-
decoration: (decoration) => branch([...decorationTokenTypes(decoration).map((type) => spanToken(type, shift(decoration.position))), ...notationTokens(page.notations, decoration, shift(decoration.position))])
|
|
248
|
-
}), Match.orElse((other) => branch(pipe(Option.fromNullable(INLINE_TOKEN_TYPE[other.type]), Option.map((type) => spanToken(type, shift(other.position))), Option.toArray))));
|
|
249
|
-
};
|
|
250
|
-
/** Pure text -> tokens. The LSP delta encoding lives in encodeTokens, so this stays testable. */
|
|
251
|
-
const computeTokens = (text, options = {}) => {
|
|
252
|
-
const lines = normalizeLineEndings(text).split("\n");
|
|
253
|
-
const notations = options.notations ?? [];
|
|
254
|
-
const fence = fenceOf(lines, options.frontmatter ?? true);
|
|
255
|
-
const page = {
|
|
256
|
-
lines,
|
|
257
|
-
offset: Option.match(fence, {
|
|
258
|
-
onNone: () => 0,
|
|
259
|
-
onSome: (end) => end + 1
|
|
260
|
-
}),
|
|
261
|
-
components: options.components ?? false,
|
|
262
|
-
notations
|
|
263
|
-
};
|
|
264
|
-
const frontmatterTokens = Option.match(fence, {
|
|
265
|
-
onNone: () => [],
|
|
266
|
-
onSome: (end) => lineSpans("frontmatter", lines, 0, end)
|
|
267
|
-
});
|
|
268
|
-
const body = parse(lines.slice(page.offset).join("\n"), options.parseOptions ?? {});
|
|
269
|
-
return pipe([...frontmatterTokens, ...gather(body, nodeTokens(page))], Array.filter((t) => t.length > 0), Array.sort(BY_POSITION));
|
|
270
|
-
};
|
|
271
|
-
/**
|
|
272
|
-
* Each token's place in `legend`: a notation's own name when the legend has it, else the
|
|
273
|
-
* LSP type its kind is drawn as.
|
|
274
|
-
*/
|
|
275
|
-
const legendIndex = (legend) => {
|
|
276
|
-
const placeOf = (type) => Option.liftPredicate(legend.indexOf(type), (index) => index >= 0);
|
|
277
|
-
const drawnAs = (token) => Option.getOrElse(placeOf(LSP_TYPE[token.type]), () => 0);
|
|
278
|
-
return (token) => Match.value(token).pipe(Match.when({ type: "notation" }, (notation) => Option.getOrElse(placeOf(notation.name), () => drawnAs(notation))), Match.orElse(drawnAs));
|
|
279
|
-
};
|
|
280
|
-
/**
|
|
281
|
-
* LSP relative encoding: [deltaLine, deltaStartChar, length, tokenType, tokenModifiers]*.
|
|
282
|
-
* `legend` is the one sent at initialize: LEGEND, or `legendOf(notations)`.
|
|
283
|
-
*/
|
|
284
|
-
const encodeTokens = (tokens, legend = LEGEND) => {
|
|
285
|
-
const indexOf = legendIndex(legend);
|
|
286
|
-
return pipe(Array.sort(tokens, BY_POSITION), Array.mapAccum({
|
|
287
|
-
line: 0,
|
|
288
|
-
char: 0
|
|
289
|
-
}, (previous, t) => [{
|
|
290
|
-
line: t.line,
|
|
291
|
-
char: t.char
|
|
292
|
-
}, [
|
|
293
|
-
t.line - previous.line,
|
|
294
|
-
t.line === previous.line ? t.char - previous.char : t.char,
|
|
295
|
-
t.length,
|
|
296
|
-
indexOf(t),
|
|
297
|
-
0
|
|
298
|
-
]]), ([, rows]) => Array.flatten(rows));
|
|
299
|
-
};
|
|
300
|
-
//#endregion
|
|
301
|
-
export { encodeTokens as a, legendOf as c, leaf as d, computeTokens as i, branch as l, LEGEND as n, fenceOf as o, TOKEN_TYPES as r, frontmatterEnd as s, COMPONENT_LINE as t, gather as u };
|
|
302
|
-
|
|
303
|
-
//# sourceMappingURL=tokens-pb6vW18i.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens-pb6vW18i.mjs","names":["Arr"],"sources":["../src/tree.ts","../src/tokens.ts"],"sourcesContent":["import type { AnyNode } from \"@cosense-toolbox/parser\"\nimport { visit } from \"@cosense-toolbox/parser/utils\"\n\n/** What one node gives, and whether its children are read too. */\nexport interface Picked<A> {\n readonly items: ReadonlyArray<A>\n readonly descend: boolean\n}\n\nexport const leaf = <A>(items: ReadonlyArray<A>): Picked<A> => ({ items, descend: false })\n\nexport const branch = <A>(items: ReadonlyArray<A>): Picked<A> => ({ items, descend: true })\n\n/**\n * Everything `pick` takes from `tree`, in document order.\n *\n * The parser's `visit` hands nodes to a callback, so something has to hold what the callback\n * finds. That is kept to here: `pick` stays a pure function of one node.\n */\nexport const gather = <A>(tree: AnyNode, pick: (node: AnyNode) => Picked<A>): ReadonlyArray<A> => {\n const found: A[] = []\n visit(tree, (node) => {\n const { items, descend } = pick(node)\n found.push(...items)\n return descend ? undefined : \"skip\"\n })\n return found\n}\n","import type {\n AnyNode,\n AnyNodeType,\n Decoration,\n NodeOfType,\n ParseOptions,\n Position,\n} from \"@cosense-toolbox/parser\"\nimport { normalizeLineEndings, parse } from \"@cosense-toolbox/parser\"\nimport { Array as Arr, Match, Option, Order, pipe } from \"effect\"\n\nimport { branch, gather, leaf, type Picked } from \"./tree\"\n\n/**\n * Cosense notation as LSP semantic tokens.\n *\n * These names are the ones this package reasons in, and they are not what goes on the wire.\n * A client announces the token types it knows at initialize and drops everything else —\n * some send the LSP's own list and nothing more — so `quote` would simply never be drawn.\n * LEGEND below is what is sent, and LSP_TYPE is the translation.\n */\nexport const TOKEN_TYPES = [\n \"title\",\n \"link\",\n \"projectLink\",\n \"externalLink\",\n \"hashtag\",\n \"code\",\n \"codeBlock\",\n \"formula\",\n \"icon\",\n \"quote\",\n \"bold\",\n \"italic\",\n \"strike\",\n \"underline\",\n \"image\",\n \"table\",\n \"bold2\",\n \"bold3\",\n // `.csnx` only: a line that opens with a component tag. The tag's name, its attribute\n // names, and the two kinds of value, as JSX reads them.\n \"component\",\n \"attribute\",\n \"attributeValue\",\n \"expression\",\n // The YAML at the top of the file, which is not Cosense notation at all.\n \"frontmatter\",\n // A notation the caller defines (see `Notation`), such as `[! 注意]`. The token carries\n // the name the caller gave it.\n \"notation\",\n] as const\n\nexport type TokenType = (typeof TOKEN_TYPES)[number]\n\n/** Every token type but `notation`, whose tokens also carry a name. */\ntype BuiltinTokenType = Exclude<TokenType, \"notation\">\n\ninterface Span {\n readonly line: number\n readonly char: number\n readonly length: number\n}\n\nexport type RawToken =\n | (Span & { readonly type: BuiltinTokenType })\n | (Span & { readonly type: \"notation\"; readonly name: string })\n\n/**\n * A name the caller gives to a decoration marker, as `warning` to the `!` of `[! 注意]`: the\n * token type that decoration is sent as.\n *\n * The marker has to be one Cosense decorates with (`` !\"#%&'()*+,-./{|}<>_~= ``), since\n * those are the ones the parser reads as a decoration. Any other, such as `@`, leaves the\n * bracket a link, as it is in Cosense Web: how a notation looks does not change how it parses.\n */\nexport interface Notation {\n readonly marker: string\n readonly name: string\n}\n\n/**\n * The legend sent to the client: the LSP's own token types, in its own order.\n *\n * Every entry is in the set a client is expected to understand, which is what makes the\n * colours appear without the reader configuring anything.\n */\nexport const LEGEND = [\n \"namespace\",\n \"type\",\n \"function\",\n \"variable\",\n \"property\",\n \"parameter\",\n \"decorator\",\n \"macro\",\n \"keyword\",\n \"string\",\n \"number\",\n \"comment\",\n] as const\n\n/**\n * What each notation is drawn as. Chosen so that things a reader separates by eye land on\n * different entries: a link is not a tag, and a quote is not a heading. `bold` and its\n * louder siblings share one entry, because the LSP has no notion of weight and a theme\n * gives each type a single colour.\n */\nconst LSP_TYPE: Record<TokenType, (typeof LEGEND)[number]> = {\n title: \"namespace\",\n link: \"function\",\n projectLink: \"function\",\n externalLink: \"string\",\n icon: \"function\",\n image: \"string\",\n hashtag: \"decorator\",\n code: \"string\",\n codeBlock: \"string\",\n formula: \"number\",\n table: \"property\",\n quote: \"comment\",\n frontmatter: \"comment\",\n component: \"type\",\n attribute: \"parameter\",\n attributeValue: \"string\",\n expression: \"variable\",\n bold: \"keyword\",\n bold2: \"keyword\",\n bold3: \"keyword\",\n italic: \"macro\",\n strike: \"comment\",\n underline: \"variable\",\n // What a caller's notation is sent as when the legend has no type of its name.\n notation: \"decorator\",\n}\n\n/**\n * LEGEND with the names of `notations` after it, each once: the legend for a client that\n * accepts token types of the caller's own naming. The LSP's types keep their places.\n */\nexport const legendOf = (notations: ReadonlyArray<Notation>): ReadonlyArray<string> =>\n Arr.dedupe([...LEGEND, ...Arr.map(notations, (notation) => notation.name)])\n\n/** Leaf inline nodes that map 1:1. Each sits on one line, so no splitting is needed. */\nconst INLINE_TOKEN_TYPE: Partial<Record<AnyNodeType, BuiltinTokenType>> = {\n internalLink: \"link\",\n externalLink: \"externalLink\",\n projectLink: \"projectLink\",\n hashtag: \"hashtag\",\n inlineCode: \"code\",\n image: \"image\",\n icon: \"icon\",\n formula: \"formula\",\n}\n\n/** Top to bottom, then left to right: the order the LSP encoding needs. */\nconst BY_POSITION: Order.Order<RawToken> = Order.combine(\n Order.mapInput(Order.number, (token: RawToken) => token.line),\n Order.mapInput(Order.number, (token: RawToken) => token.char),\n)\n\nconst onlyIf = <A>(condition: boolean, value: A): Option.Option<A> =>\n condition ? Option.some(value) : Option.none()\n\n/** A token over `[from, to)` of one line. */\nconst token = (type: BuiltinTokenType, line: number, from: number, to: number): RawToken => ({\n line,\n char: from,\n length: to - from,\n type,\n})\n\nconst spanToken = (type: BuiltinTokenType, position: Position): RawToken =>\n token(type, position.start.line, position.start.column, position.end.column)\n\n/** How many characters from `from` the `^`-anchored `pattern` takes; 0 when it takes none. */\nconst matchLength = (pattern: RegExp, text: string, from: number): number =>\n pipe(\n Option.fromNullable(pattern.exec(text.slice(from))),\n Option.match({ onNone: () => 0, onSome: ([matched]) => matched.length }),\n )\n\n// --- Emphasis ---------------------------------------------------------------------------\n\n/** Cosense sizes emphasis by asterisk count (`[*]`..`[*****]`); sizeLevel is 0-indexed. */\nconst boldTokenType = (sizeLevel: number): BuiltinTokenType =>\n Match.value(sizeLevel).pipe(\n Match.when(\n (level) => level >= 2,\n (): BuiltinTokenType => \"bold3\",\n ),\n Match.when(1, (): BuiltinTokenType => \"bold2\"),\n Match.orElse((): BuiltinTokenType => \"bold\"),\n )\n\n/** Every decoration a run carries, since Cosense applies all of them: `[-* x]` is both. */\nconst decorationTokenTypes = (node: Decoration): ReadonlyArray<BuiltinTokenType> =>\n Arr.getSomes([\n onlyIf(node.underline, \"underline\" as const),\n onlyIf(node.strike, \"strike\" as const),\n onlyIf(node.italic, \"italic\" as const),\n onlyIf(node.bold, boldTokenType(node.sizeLevel)),\n ])\n\n// --- Component lines (`.csnx`) ----------------------------------------------------------\n\nexport const COMPONENT_LINE = /^\\s*<\\/?[A-Z][A-Za-z0-9_.]*(\\s|\\/?>)/\nconst TAG_OPEN = /^(\\s*<\\/?)([A-Z][A-Za-z0-9_.]*)/\nconst ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*/\nconst SPACE = /^\\s*/\n\n/** Where a quoted value opened at `from` ends: after its closing quote, or at the line's end. */\nconst quotedEnd = (text: string, from: number): number =>\n pipe(\n text.indexOf(text.charAt(from), from + 1),\n Option.liftPredicate((close) => close >= 0),\n Option.match({ onNone: () => text.length, onSome: (close) => close + 1 }),\n )\n\n/** Where `{ ... }` opened at `from` ends, counting nested braces: after its `}`, or the line's end. */\nconst bracedEnd = (text: string, from: number): number =>\n pipe(\n text.slice(from).split(\"\"),\n Arr.scan(0, (depth, char) => (char === \"{\" ? depth + 1 : char === \"}\" ? depth - 1 : depth)),\n // scan starts with the depth before any character; the rest line up with the characters.\n Arr.drop(1),\n Arr.findFirstIndex((depth) => depth === 0),\n Option.match({ onNone: () => text.length, onSome: (index) => from + index + 1 }),\n )\n\ntype ValueType = \"attributeValue\" | \"expression\"\n\n/** The attribute value that starts at `from`: its type and where it ends. */\nconst valueAt = (text: string, from: number): Option.Option<readonly [ValueType, number]> =>\n Match.value(text.charAt(from)).pipe(\n Match.when(\n (char) => char === '\"' || char === \"'\",\n () => Option.some([\"attributeValue\", quotedEnd(text, from)] as const),\n ),\n Match.when(\"{\", () => Option.some([\"expression\", bracedEnd(text, from)] as const)),\n Match.orElse(() => Option.none()),\n )\n\n/** The tokens of one attribute, and where the next may start. */\ntype Step = readonly [ReadonlyArray<RawToken>, number]\n\n/** `at` past any whitespace. */\nconst skipSpace = (text: string, at: number): number => at + matchLength(SPACE, text, at)\n\n/** Whether the tag closes at `at`, with `>` or `/>`, or the line ends there. */\nconst closesAt = (text: string, at: number): boolean =>\n at >= text.length || text.startsWith(\">\", at) || text.startsWith(\"/>\", at)\n\n/**\n * An attribute named over `[at, nameEnd)`: the name, then `=` and a value if one follows.\n * A name with no `=` after it stands alone, as JSX reads `<Dialog open>`.\n */\nconst attribute = (line: number, text: string, at: number, nameEnd: number): Step => {\n const name = token(\"attribute\", line, at, nameEnd)\n const afterName = skipSpace(text, nameEnd)\n return pipe(\n Option.liftPredicate(afterName, (equals) => text.charAt(equals) === \"=\"),\n Option.map((equals) => skipSpace(text, equals + 1)),\n Option.match({\n onNone: (): Step => [[name], afterName],\n onSome: (valueStart): Step =>\n pipe(\n valueAt(text, valueStart),\n Option.match({\n onNone: (): Step => [[name], valueStart],\n onSome: ([type, end]): Step => [[name, token(type, line, valueStart, end)], end],\n }),\n ),\n }),\n )\n}\n\n/** One attribute from `from`, or None once the tag has closed. */\nconst attributeStep =\n (line: number, text: string) =>\n (from: number): Option.Option<Step> =>\n pipe(\n Option.liftPredicate(skipSpace(text, from), (at) => !closesAt(text, at)),\n Option.map((at) =>\n pipe(\n Option.liftPredicate(at + matchLength(ATTRIBUTE_NAME, text, at), (end) => end > at),\n Option.match({\n // Not a name: step over the character, since the tag may still go on after it.\n onNone: (): Step => [[], at + 1],\n onSome: (nameEnd) => attribute(line, text, at, nameEnd),\n }),\n ),\n ),\n )\n\n/**\n * The tag that opens a component line, read as JSX: its name, then each attribute and its\n * value, up to the `>` that closes it. Text after the tag is left alone; it is neither\n * Cosense notation nor part of the tag.\n */\nconst componentTokens = (line: number, text: string): ReadonlyArray<RawToken> =>\n pipe(\n Option.fromNullable(TAG_OPEN.exec(text)),\n Option.map(([head, lead = \"\", name = \"\"]) => [\n token(\"component\", line, lead.length, lead.length + name.length),\n ...Arr.flatten(Arr.unfold(head.length, attributeStep(line, text))),\n ]),\n Option.getOrElse(() => []),\n )\n\n// --- The page ---------------------------------------------------------------------------\n\n/** The last line of the `---` fence around YAML at the very top, if the file opens with one. */\nexport const frontmatterEnd = (lines: ReadonlyArray<string>): Option.Option<number> =>\n pipe(\n Option.liftPredicate(lines, (all) => all[0]?.trim() === \"---\"),\n Option.flatMap(Arr.findFirstIndex((line, index) => index > 0 && line.trim() === \"---\")),\n )\n\n/**\n * `frontmatterEnd`, or None when the caller reads no frontmatter: a Cosense page has none,\n * and a page whose title is `---` would otherwise lose its first lines to it.\n */\nexport const fenceOf = (\n lines: ReadonlyArray<string>,\n frontmatter: boolean,\n): Option.Option<number> => Option.flatMap(onlyIf(frontmatter, lines), frontmatterEnd)\n\n/** What the node visitor needs to know about the file around the parsed body. */\ninterface Page {\n readonly lines: ReadonlyArray<string>\n /** Lines before the body: the frontmatter, which the parser never sees. */\n readonly offset: number\n readonly components: boolean\n readonly notations: ReadonlyArray<Notation>\n}\n\n/** Each non-empty line from `first` to `last`, whole. */\nconst lineSpans = (\n type: BuiltinTokenType,\n lines: ReadonlyArray<string>,\n first: number,\n last: number,\n): ReadonlyArray<RawToken> =>\n Arr.filterMap(Arr.range(first, last), (line) =>\n pipe(\n Option.fromNullable(lines[line]),\n Option.filter((text) => text.length > 0),\n Option.map((text) => token(type, line, 0, text.length)),\n ),\n )\n\n/** The line's text, when the file reads components and the line opens with a tag. */\nconst componentLine = (page: Page, line: number): Option.Option<string> =>\n pipe(\n Option.fromNullable(page.lines[line]),\n Option.filter((text) => page.components && COMPONENT_LINE.test(text)),\n )\n\n/** The `>` and spaces that open a quote line, from its indentation onwards. */\nconst quoteToken = (page: Page, node: NodeOfType<\"line\">, line: number): Option.Option<RawToken> =>\n pipe(\n onlyIf(node.quote, page.lines[line] ?? \"\"),\n Option.map((text) => matchLength(/^[> ]*/, text, node.indent)),\n Option.filter((length) => length > 0),\n Option.map((length) => token(\"quote\", line, node.indent, node.indent + length)),\n )\n\n/** A token for each of `notations` whose marker opens the decoration. */\nconst notationTokens = (\n notations: ReadonlyArray<Notation>,\n node: Decoration,\n position: Position,\n): ReadonlyArray<RawToken> =>\n Arr.filterMap(notations, ({ marker, name }) =>\n onlyIf(node.markers.includes(marker), {\n line: position.start.line,\n char: position.start.column,\n length: position.end.column - position.start.column,\n type: \"notation\" as const,\n name,\n }),\n )\n\nconst nodeTokens =\n (page: Page) =>\n (node: AnyNode): Picked<RawToken> => {\n const lineOf = (position: Position) => position.start.line + page.offset\n const shift = (position: Position): Position => ({\n start: { ...position.start, line: position.start.line + page.offset },\n end: { ...position.end, line: position.end.line + page.offset },\n })\n return Match.value(node).pipe(\n Match.discriminators(\"type\")({\n // A page that opens with a component has no title line: the tag is what it is.\n title: (title) =>\n leaf(\n pipe(\n componentLine(page, lineOf(title.position)),\n Option.match({\n onNone: () => [spanToken(\"title\", shift(title.position))],\n onSome: (text) => componentTokens(lineOf(title.position), text),\n }),\n ),\n ),\n codeBlock: (block) =>\n leaf(\n lineSpans(\n \"codeBlock\",\n page.lines,\n lineOf(block.position),\n block.position.end.line + page.offset,\n ),\n ),\n table: (table) =>\n leaf(\n lineSpans(\n \"table\",\n page.lines,\n lineOf(table.position),\n table.position.end.line + page.offset,\n ),\n ),\n // A component tag owns its line, so nothing on it is Cosense notation.\n line: (line) =>\n pipe(\n componentLine(page, lineOf(line.position)),\n Option.match({\n onSome: (text) => leaf(componentTokens(lineOf(line.position), text)),\n onNone: () => branch(Option.toArray(quoteToken(page, line, lineOf(line.position)))),\n }),\n ),\n // Descend: a decoration can wrap a link or an image (`[* [page]]`), and that child\n // needs its own token over the same span.\n decoration: (decoration) =>\n branch([\n ...decorationTokenTypes(decoration).map((type) =>\n spanToken(type, shift(decoration.position)),\n ),\n ...notationTokens(page.notations, decoration, shift(decoration.position)),\n ]),\n }),\n Match.orElse((other) =>\n branch(\n pipe(\n Option.fromNullable(INLINE_TOKEN_TYPE[other.type]),\n Option.map((type) => spanToken(type, shift(other.position))),\n Option.toArray,\n ),\n ),\n ),\n )\n }\n\nexport interface ComputeTokensOptions {\n /** `.csnx` also reads a line that is one component tag. `.csn` never does. */\n readonly components?: boolean\n /** How to parse: the site's own notation extensions, as its build parses with them. */\n readonly parseOptions?: ParseOptions\n /** Notations the caller adds, each sent as a token of its own name (see `Notation`). */\n readonly notations?: ReadonlyArray<Notation>\n /**\n * Whether a `---` fence on the first line opens YAML to skip (default: true). Off for\n * Cosense pages, which have no frontmatter.\n */\n readonly frontmatter?: boolean\n}\n\n/** Pure text -> tokens. The LSP delta encoding lives in encodeTokens, so this stays testable. */\nexport const computeTokens = (text: string, options: ComputeTokensOptions = {}): RawToken[] => {\n const lines = normalizeLineEndings(text).split(\"\\n\")\n const notations = options.notations ?? []\n // Frontmatter is YAML, so the Cosense parser must not see it: `---` would otherwise read\n // as a strikethrough marker and the keys as plain text on the title line.\n const fence = fenceOf(lines, options.frontmatter ?? true)\n const page: Page = {\n lines,\n offset: Option.match(fence, { onNone: () => 0, onSome: (end) => end + 1 }),\n components: options.components ?? false,\n notations,\n }\n\n const frontmatterTokens = Option.match(fence, {\n onNone: () => [],\n onSome: (end) => lineSpans(\"frontmatter\", lines, 0, end),\n })\n const body = parse(lines.slice(page.offset).join(\"\\n\"), options.parseOptions ?? {})\n\n return pipe(\n [...frontmatterTokens, ...gather(body, nodeTokens(page))],\n Arr.filter((t) => t.length > 0),\n Arr.sort(BY_POSITION),\n )\n}\n\n/**\n * Each token's place in `legend`: a notation's own name when the legend has it, else the\n * LSP type its kind is drawn as.\n */\nconst legendIndex = (legend: ReadonlyArray<string>) => {\n const placeOf = (type: string): Option.Option<number> =>\n Option.liftPredicate(legend.indexOf(type), (index) => index >= 0)\n const drawnAs = (token: RawToken) => Option.getOrElse(placeOf(LSP_TYPE[token.type]), () => 0)\n return (token: RawToken): number =>\n Match.value(token).pipe(\n Match.when({ type: \"notation\" }, (notation) =>\n Option.getOrElse(placeOf(notation.name), () => drawnAs(notation)),\n ),\n Match.orElse(drawnAs),\n )\n}\n\n/**\n * LSP relative encoding: [deltaLine, deltaStartChar, length, tokenType, tokenModifiers]*.\n * `legend` is the one sent at initialize: LEGEND, or `legendOf(notations)`.\n */\nexport const encodeTokens = (\n tokens: ReadonlyArray<RawToken>,\n legend: ReadonlyArray<string> = LEGEND,\n): number[] => {\n const indexOf = legendIndex(legend)\n return pipe(\n Arr.sort(tokens, BY_POSITION),\n Arr.mapAccum({ line: 0, char: 0 }, (previous, t) => [\n { line: t.line, char: t.char },\n [\n t.line - previous.line,\n t.line === previous.line ? t.char - previous.char : t.char,\n t.length,\n indexOf(t),\n 0,\n ],\n ]),\n ([, rows]) => Arr.flatten(rows),\n )\n}\n"],"mappings":";;;;AASA,MAAa,QAAW,WAAwC;CAAE;CAAO,SAAS;AAAM;AAExF,MAAa,UAAa,WAAwC;CAAE;CAAO,SAAS;AAAK;;;;;;;AAQzF,MAAa,UAAa,MAAe,SAAyD;CAChG,MAAM,QAAa,CAAC;CACpB,MAAM,OAAO,SAAS;EACpB,MAAM,EAAE,OAAO,YAAY,KAAK,IAAI;EACpC,MAAM,KAAK,GAAG,KAAK;EACnB,OAAO,UAAU,KAAA,IAAY;CAC/B,CAAC;CACD,OAAO;AACT;;;;;;;;;;;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