yuhwa 1.0.2 → 1.2.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 (51) hide show
  1. package/README.md +13 -12
  2. package/client.d.ts +9 -1
  3. package/dist/astro.d.ts +2 -2
  4. package/dist/astro.js +8 -1
  5. package/dist/browser.d.ts +11 -5
  6. package/dist/browser.js +27 -7
  7. package/dist/cli.js +612 -49
  8. package/dist/editor/assets/index-BphHLTvA.js +689 -0
  9. package/dist/editor/assets/lsp.worker-sZtzIA6-.js +30 -0
  10. package/dist/editor/index.html +5 -4
  11. package/dist/figure-CA2hy0xh.d.ts +48 -0
  12. package/dist/{index-Dl845tUQ.d.ts → index-CnnoZYl0.d.ts} +76 -7
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +1 -1
  15. package/dist/ironmark.d.ts +4 -2
  16. package/dist/ironmark.js +18 -7
  17. package/dist/llms.txt +26 -17
  18. package/dist/lsp-browser.d.ts +2 -2
  19. package/dist/lsp-browser.js +1 -1
  20. package/dist/lsp-node.js +208 -212
  21. package/dist/lsp-server.d.ts +1 -1
  22. package/dist/lsp-server.js +1 -1
  23. package/dist/lsp.d.ts +44 -2
  24. package/dist/lsp.js +1 -1
  25. package/dist/markdown-it.d.ts +2 -1
  26. package/dist/markdown-it.js +7 -6
  27. package/dist/node-Bzn2uKXZ.js +224 -0
  28. package/dist/remark.d.ts +2 -1
  29. package/dist/remark.js +16 -5
  30. package/dist/{server-DJC_fQMe.d.ts → server--jHjJjOS.d.ts} +2 -2
  31. package/dist/{server-DmQuHQrG.js → server-Dxo7OG8K.js} +19 -2
  32. package/dist/{service-BYS9Qfkq.js → service-B1fpOg_L.js} +348 -44
  33. package/dist/{service-ClZ8clSQ.d.ts → service-Brvpt7Do.d.ts} +3 -1
  34. package/dist/{shared-qo_r6RUN.js → shared-Ddw88O9D.js} +3069 -742
  35. package/dist/{src-wk7tBpWs.js → src-DkQj7aIV.js} +2842 -744
  36. package/dist/style.css +14 -0
  37. package/dist/vite.d.ts +1 -1
  38. package/dist/vite.js +19 -12
  39. package/dist/vuepress.d.ts +3 -1
  40. package/dist/vuepress.js +7 -2
  41. package/dist/yuhwa.iife.js +91 -75
  42. package/dist/zoom-CCSUbX1X.d.ts +49 -0
  43. package/dist/zoom-QeqB6QlH.js +275 -0
  44. package/dist/zoom-script-CVdAzMhX.js +51 -0
  45. package/dist/zoom.d.ts +35 -0
  46. package/dist/zoom.js +19 -0
  47. package/package.json +10 -2
  48. package/dist/editor/assets/index-BQLsumas.js +0 -587
  49. package/dist/editor/assets/lsp.worker-RlPj9blG.js +0 -26
  50. package/dist/figure-BZHIKnxv.d.ts +0 -27
  51. package/dist/node-Bneu5eJV.js +0 -108
package/dist/lsp.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as YuhwaService, i as Target, n as SEMANTIC_LEGEND, r as ServiceOptions, t as Fix } from "./service-ClZ8clSQ.js";
1
+ import { a as YuhwaService, i as Target, n as SEMANTIC_LEGEND, r as ServiceOptions, t as Fix } from "./service-Brvpt7Do.js";
2
2
  import { H as Position, U as Range, nt as TextEdit } from "./main-DYrwpkoa.js";
3
3
  /** Format yuhwa source. Returns the new text; whitespace is all that changes. */
4
4
  export declare function format(text: string): string;
@@ -13,4 +13,46 @@ export declare function applyChange(text: string, change: {
13
13
  text: string;
14
14
  range?: Range;
15
15
  }): string;
16
- export { type Fix, SEMANTIC_LEGEND, type ServiceOptions, type Target, YuhwaService };
16
+ /**
17
+ * The indent for a line broken at `offset`: the current line's own, one step
18
+ * deeper when the text before the break opens a block. Indentation-shaped
19
+ * bodies (mind maps, tree views) keep their depth, so Enter starts a sibling.
20
+ */
21
+ export declare function newlineIndent(text: string, offset: number): string;
22
+ /** The indent for a `}` typed on the line holding `offset`: that of its opener. */
23
+ export declare function closeIndent(text: string, offset: number): string;
24
+ /**
25
+ * What a line broken at `offset` starts with: its indent, plus the bullet of
26
+ * an outline item (`- ` or `* `), so a list in a mind map or tree view goes on.
27
+ */
28
+ export declare function newlinePrefix(text: string, offset: number): string;
29
+ /** A text change: replace `start`..`end` with `insert`, then put the caret at `caret` if set. */
30
+ interface KeyEdit {
31
+ start: number;
32
+ end: number;
33
+ insert: string;
34
+ caret?: number;
35
+ }
36
+ /**
37
+ * Enter with the selection `from`..`to`: the new line keeps the depth (one step
38
+ * deeper after `{`) and continues a bullet. Enter on an empty bullet ends the
39
+ * list, and Enter between `{` and `}` puts the `}` on a line of its own.
40
+ */
41
+ export declare function enterEdit(text: string, from: number, to: number): KeyEdit;
42
+ /**
43
+ * Tab and Shift+Tab: indent (or outdent by one step) every line the selection
44
+ * `from`..`to` touches, wherever the caret sits on it. Mind maps and tree
45
+ * views nest by indentation, so Tab on `- item` moves the item, not its text.
46
+ * Returns the new text and selection.
47
+ */
48
+ export declare function shiftLines(text: string, from: number, to: number, out?: boolean): {
49
+ text: string;
50
+ from: number;
51
+ to: number;
52
+ };
53
+ /**
54
+ * Edits after a character was typed at `pos`: a newline re-indents the new
55
+ * line and continues a bullet, a `}` alone on its line lines up with its opener.
56
+ */
57
+ export declare function onTypeEdits(text: string, pos: Position, ch: string): TextEdit[];
58
+ export { type Fix, type KeyEdit, SEMANTIC_LEGEND, type ServiceOptions, type Target, YuhwaService };
package/dist/lsp.js CHANGED
@@ -1 +1 @@
1
- export { t as SEMANTIC_LEGEND, n as YuhwaService, r as applyChange, i as diffEdits, a as format, o as offsetAt, s as positionAt } from "./service-BYS9Qfkq.js";
1
+ export { t as SEMANTIC_LEGEND, n as YuhwaService, r as applyChange, i as closeIndent, a as diffEdits, o as enterEdit, s as format, c as newlineIndent, l as newlinePrefix, u as offsetAt, d as onTypeEdits, f as positionAt, p as shiftLines } from "./service-B1fpOg_L.js";
@@ -7,8 +7,9 @@
7
7
  *
8
8
  * Add `yuhwa/style.css` to the site for the light/dark switch.
9
9
  * A fence with `no-render` (```yuhwa no-render) stays a code block.
10
+ * ```yuhwa file="diagrams/arch.yu" renders that file instead of the block.
10
11
  */
11
- import { t as YuhwaDocsOptions } from "./figure-BZHIKnxv.js";
12
+ import { t as YuhwaDocsOptions } from "./figure-CA2hy0xh.js";
12
13
  type Rule = (tokens: any[], idx: number, options: any, env: any, self: any) => string;
13
14
  interface MarkdownIt {
14
15
  renderer: {
@@ -1,4 +1,4 @@
1
- import { i as wantsRender, r as renderFigure, t as diskResolve } from "./node-Bneu5eJV.js";
1
+ import { a as wantsRender, i as toHtml, n as renderBlock, o as zoomTag } from "./node-Bzn2uKXZ.js";
2
2
  // src/integrations/markdown-it.ts
3
3
  /**
4
4
  * markdown-it plugin: renders ```yuhwa fences at build time.
@@ -9,6 +9,7 @@ import { i as wantsRender, r as renderFigure, t as diskResolve } from "./node-Bn
9
9
  *
10
10
  * Add `yuhwa/style.css` to the site for the light/dark switch.
11
11
  * A fence with `no-render` (```yuhwa no-render) stays a code block.
12
+ * ```yuhwa file="diagrams/arch.yu" renders that file instead of the block.
12
13
  */
13
14
  /** the markdown file being rendered, as the known hosts pass it in `env` */
14
15
  function fileOf(env) {
@@ -24,13 +25,13 @@ function yuhwaMarkdownIt(md, opts = {}) {
24
25
  return fence(tokens, idx, options, env, self);
25
26
  }
26
27
  const file = fileOf(env);
27
- return renderFigure(token.content, {
28
- resolve: diskResolve,
29
- ...opts
30
- }, {
28
+ const { html } = renderBlock(token.content, meta.join(" "), opts, {
31
29
  file,
32
30
  line: (token.map?.[0] ?? 0) + 1
33
- }).html;
31
+ });
32
+ if (opts.zoom !== "inline" || !env || env.yuhwaZoom) return html;
33
+ env.yuhwaZoom = true;
34
+ return html + toHtml(zoomTag());
34
35
  };
35
36
  }
36
37
  export { yuhwaMarkdownIt as default, yuhwaMarkdownIt };
@@ -0,0 +1,224 @@
1
+ import { readFileSync, realpathSync } from "node:fs";
2
+ import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
3
+ import { It as table, K as isYuhwaPath, n as render } from "./src-DkQj7aIV.js";
4
+ import { n as zoomScript } from "./zoom-script-CVdAzMhX.js";
5
+ import { t as zoomHeight } from "./zoom-QeqB6QlH.js";
6
+ // src/integrations/figure.ts
7
+ /**
8
+ * Shared core of the docs integrations (markdown-it, remark, Astro, VuePress):
9
+ * renders one yuhwa source to a `<figure class="yuhwa">` as a hast tree, so
10
+ * remark/MDX pipelines can use it directly and markdown-it gets it as HTML.
11
+ *
12
+ * Diagrams go in as `<img src="data:image/svg+xml,...">` by default: Vue-based
13
+ * sites strip the SVG's `<style>`, MDX cannot take raw HTML, and diagram text
14
+ * stays out of the site search index.
15
+ */
16
+ const el = (tagName, properties, children = []) => ({
17
+ type: "element",
18
+ tagName,
19
+ properties,
20
+ children
21
+ });
22
+ const dataUri = (svg) => `data:image/svg+xml,${encodeURIComponent(svg)}`;
23
+ const where = (at) => `${at.file ?? "markdown"}${at.line ? `:${at.line}` : ""}${at.diagram ? ` (${at.diagram})` : ""}`;
24
+ function errorMessage(errors, at) {
25
+ return `yuhwa block at ${where(at)}:\n${errors.map((d) => ` line ${d.line}: ${d.message}`).join("\n")}`;
26
+ }
27
+ /** a problem with the block itself (not its diagram), worded like `errorMessage` */
28
+ function blockMessage(message, at) {
29
+ return `yuhwa block at ${where(at)}:\n ${message}`;
30
+ }
31
+ /** the figure for a block that could not be read: throws when `strict`, else shows the message */
32
+ function errorFigure(message, opts = {}) {
33
+ if (opts.strict ?? true) throw new Error(message);
34
+ const hast = el("figure", {
35
+ className: ["yuhwa"],
36
+ dataYuhwa: ""
37
+ }, [el("pre", { className: ["yuhwa-error"] }, [{
38
+ type: "text",
39
+ value: message
40
+ }])]);
41
+ return {
42
+ hast,
43
+ html: toHtml(hast, false),
44
+ result: render("")
45
+ };
46
+ }
47
+ /** `file="path"` (or `file='path'`, `file=path`) in a fence's meta */
48
+ function fenceFile(meta) {
49
+ const m = /(?:^|\s)file=(?:"([^"]*)"|'([^']*)'|(\S+))/.exec(meta ?? "");
50
+ return m ? m[1] ?? m[2] ?? m[3] : void 0;
51
+ }
52
+ /**
53
+ * `zoom`, `zoom=<height>` and `no-zoom` in a fence's meta, over the options.
54
+ * A `zoom` flag keeps `zoom: 'inline'` when that is set.
55
+ */
56
+ function fenceZoom(meta, opts = {}) {
57
+ const m = /(?:^|\s)(no-zoom|zoom(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?)(?=\s|$)/.exec(meta ?? "");
58
+ if (!m) return {
59
+ zoom: opts.zoom,
60
+ zoomHeight: opts.zoomHeight
61
+ };
62
+ if (m[1] === "no-zoom") return { zoom: false };
63
+ return {
64
+ zoom: opts.zoom || true,
65
+ zoomHeight: m[2] ?? m[3] ?? m[4] ?? opts.zoomHeight
66
+ };
67
+ }
68
+ /** the pan and zoom script as an inline `<script>`, once per page */
69
+ const zoomTag = () => el("script", {}, [{
70
+ type: "text",
71
+ value: zoomScript
72
+ }]);
73
+ function renderFigure(source, opts = {}, at = {}) {
74
+ const { theme, darkTheme = "midnight", darkMode = "class", output = "img", strict = true, languages: _, root: __, zoom, zoomHeight: zoomHeightOpt, ...rest } = opts;
75
+ const base = {
76
+ ...rest,
77
+ file: at.diagram ?? at.file
78
+ };
79
+ const light = render(source, {
80
+ ...base,
81
+ theme
82
+ });
83
+ const errors = light.diagnostics.filter((d) => d.severity === "error");
84
+ if (errors.length && strict) throw new Error(errorMessage(errors, at));
85
+ const alt = light.diagram.settings.title ?? "diagram";
86
+ const dark = darkTheme && !("theme" in light.diagram.settings) ? render(source, {
87
+ ...base,
88
+ theme: darkTheme
89
+ }) : void 0;
90
+ const children = [];
91
+ const img = (svg, cls) => el("img", {
92
+ src: dataUri(svg),
93
+ alt,
94
+ className: cls,
95
+ loading: "lazy",
96
+ decoding: "async"
97
+ });
98
+ const inline = (svg, cls) => el("div", { className: cls }, [{
99
+ type: "text",
100
+ value: svg
101
+ }]);
102
+ const one = output === "svg" ? inline : img;
103
+ if (!dark) children.push(one(light.svg, ["yuhwa-svg"]));
104
+ else if (darkMode === "media" && output === "img") children.push(el("picture", {}, [el("source", {
105
+ media: "(prefers-color-scheme: dark)",
106
+ srcSet: dataUri(dark.svg)
107
+ }), img(light.svg, ["yuhwa-svg"])]));
108
+ else children.push(one(light.svg, ["yuhwa-svg", "yuhwa-light"]), one(dark.svg, ["yuhwa-svg", "yuhwa-dark"]));
109
+ if (zoom) children.splice(0, children.length, el("div", { className: ["yuhwa-view"] }, [...children]));
110
+ if (errors.length) children.push(el("pre", { className: ["yuhwa-error"] }, [{
111
+ type: "text",
112
+ value: errorMessage(errors, at)
113
+ }]));
114
+ const height = zoom ? zoomHeight(String(zoomHeightOpt ?? "")) ?? "" : void 0;
115
+ const hast = el("figure", {
116
+ className: ["yuhwa"],
117
+ dataYuhwa: "",
118
+ dataZoom: height
119
+ }, children);
120
+ return {
121
+ hast,
122
+ html: toHtml(hast, output === "svg"),
123
+ result: light
124
+ };
125
+ }
126
+ const ATTR = table({
127
+ className: "class",
128
+ srcSet: "srcset",
129
+ dataYuhwa: "data-yuhwa",
130
+ dataZoom: "data-zoom"
131
+ });
132
+ const escape = (s) => s.replace(/[&<>"]/g, (c) => ({
133
+ "&": "&amp;",
134
+ "<": "&lt;",
135
+ ">": "&gt;",
136
+ "\"": "&quot;"
137
+ })[c]);
138
+ const VOID = /* @__PURE__ */ new Set(["img", "source"]);
139
+ /** minimal hast → HTML; with `raw`, text inside a `div` is the inline SVG and stays unescaped */
140
+ function toHtml(node, raw = false, parent = "") {
141
+ if (node.type === "text") return raw && parent === "div" || parent === "script" ? node.value : escape(node.value);
142
+ const attrs = Object.entries(node.properties).filter(([, v]) => v !== void 0 && v !== false).map(([k, v]) => ` ${ATTR[k] ?? k}${v === "" || v === true ? "" : `="${escape(Array.isArray(v) ? v.join(" ") : String(v))}"`}`).join("");
143
+ if (VOID.has(node.tagName)) return `<${node.tagName}${attrs} />`;
144
+ const inner = node.children.map((c) => toHtml(c, raw, node.tagName)).join("");
145
+ return `<${node.tagName}${attrs}>${inner}</${node.tagName}>`;
146
+ }
147
+ /** `yuhwa no-render` (or any flag list) on a fence: leave it as a code block */
148
+ function wantsRender(lang, meta, languages = ["yuhwa"]) {
149
+ return !!lang && languages.includes(lang) && !/(^|\s)no-render(\s|$)/.test(meta ?? "");
150
+ }
151
+ // src/integrations/node.ts
152
+ /** Node-only helper for the CLI and build-time integrations: `import` reads from disk. */
153
+ /** Reads an `import "..."` target from disk; like `parse`, only `.yu` files. */
154
+ function diskResolve(path) {
155
+ if (!isYuhwaPath(path)) return void 0;
156
+ try {
157
+ return readFileSync(path, "utf8");
158
+ } catch {
159
+ return;
160
+ }
161
+ }
162
+ /** the real path, so a symlink inside the root cannot point out of it; a missing file resolves its folder */
163
+ const real = (path) => {
164
+ try {
165
+ return realpathSync(path);
166
+ } catch {
167
+ const up = dirname(path);
168
+ return up === path ? path : join(real(up), basename(path));
169
+ }
170
+ };
171
+ const inside = (root, path) => {
172
+ const rel = relative(real(root), real(path));
173
+ return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
174
+ };
175
+ /**
176
+ * Renders one fenced block for the markdown integrations. With
177
+ * `file="path"` in `meta` the diagram comes from that file: the path resolves
178
+ * against the markdown file (or `root` when it starts with `/` or the
179
+ * markdown file is unknown), and its imports resolve against the diagram file.
180
+ * With `root` set, the file and every import must stay inside it.
181
+ */
182
+ function renderBlock(body, meta, opts, at) {
183
+ const read = opts.resolve ?? diskResolve;
184
+ const root = opts.root === void 0 ? void 0 : resolve(opts.root);
185
+ const outside = [];
186
+ const resolve$1 = root ? (p) => {
187
+ if (inside(root, resolve(p))) return read(p);
188
+ outside.push(p);
189
+ } : read;
190
+ const fail = (message) => errorFigure(blockMessage(message, at), opts);
191
+ const name = fenceFile(meta);
192
+ let source = body;
193
+ let block = at;
194
+ if (name !== void 0) {
195
+ const base = name.startsWith("/") && root ? root : at.file ? dirname(resolve(at.file)) : root ?? process.cwd();
196
+ const path = resolve(base, name.startsWith("/") && root ? `.${name}` : name);
197
+ if (!isYuhwaPath(path)) return fail(`file="${name}" must be a .yu or .yuhwa file`);
198
+ if (root && !inside(root, path)) return fail(`file="${name}" is outside the root folder (${root})`);
199
+ let text;
200
+ try {
201
+ text = read(path);
202
+ } catch {
203
+ text = void 0;
204
+ }
205
+ if (text === void 0) return fail(`file="${name}" not found (${path})`);
206
+ if (body.trim()) console.warn(blockMessage(`file="${name}" is set, so the block's own text is ignored`, at));
207
+ source = text;
208
+ block = {
209
+ ...at,
210
+ diagram: path
211
+ };
212
+ }
213
+ try {
214
+ return renderFigure(source, {
215
+ ...opts,
216
+ ...fenceZoom(meta, opts),
217
+ resolve: resolve$1
218
+ }, block);
219
+ } catch (e) {
220
+ if (outside.length) e.message += `\n outside the root folder (${root}): ${[...new Set(outside)].join(", ")}`;
221
+ throw e;
222
+ }
223
+ }
224
+ export { wantsRender as a, toHtml as i, renderBlock as n, zoomTag as o, errorMessage as r, diskResolve as t };
package/dist/remark.d.ts CHANGED
@@ -8,7 +8,8 @@
8
8
  *
9
9
  * Add `yuhwa/style.css` to the site for the light/dark switch.
10
10
  * A fence with `no-render` (```yuhwa no-render) stays a code block.
11
+ * ```yuhwa file="diagrams/arch.yu" renders that file instead of the block.
11
12
  */
12
- import { t as YuhwaDocsOptions } from "./figure-BZHIKnxv.js";
13
+ import { t as YuhwaDocsOptions } from "./figure-CA2hy0xh.js";
13
14
  export default function remarkYuhwa(opts?: YuhwaDocsOptions): (tree: any, file?: any) => void;
14
15
  export { type YuhwaDocsOptions, remarkYuhwa };
package/dist/remark.js CHANGED
@@ -1,4 +1,4 @@
1
- import { i as wantsRender, r as renderFigure, t as diskResolve } from "./node-Bneu5eJV.js";
1
+ import { a as wantsRender, n as renderBlock, o as zoomTag } from "./node-Bzn2uKXZ.js";
2
2
  // src/integrations/remark.ts
3
3
  /**
4
4
  * remark plugin: replaces ```yuhwa code blocks with a rendered figure.
@@ -10,20 +10,20 @@ import { i as wantsRender, r as renderFigure, t as diskResolve } from "./node-Bn
10
10
  *
11
11
  * Add `yuhwa/style.css` to the site for the light/dark switch.
12
12
  * A fence with `no-render` (```yuhwa no-render) stays a code block.
13
+ * ```yuhwa file="diagrams/arch.yu" renders that file instead of the block.
13
14
  */
14
15
  function remarkYuhwa(opts = {}) {
15
16
  return (tree, file) => {
16
17
  const path = file?.path ?? file?.history?.at(-1);
18
+ let rendered = false;
17
19
  const walk = (node) => {
18
20
  node.children?.forEach((child, i) => {
19
21
  if (child.type === "code" && wantsRender(child.lang, child.meta, opts.languages)) {
20
- const { hast } = renderFigure(child.value ?? "", {
21
- resolve: diskResolve,
22
- ...opts
23
- }, {
22
+ const { hast } = renderBlock(child.value ?? "", child.meta, opts, {
24
23
  file: path,
25
24
  line: child.position?.start.line
26
25
  });
26
+ rendered = true;
27
27
  node.children[i] = {
28
28
  type: "yuhwa",
29
29
  position: child.position,
@@ -37,6 +37,17 @@ function remarkYuhwa(opts = {}) {
37
37
  });
38
38
  };
39
39
  walk(tree);
40
+ if (rendered && opts.zoom === "inline") {
41
+ const script = zoomTag();
42
+ tree.children?.push({
43
+ type: "yuhwaZoom",
44
+ data: {
45
+ hName: script.tagName,
46
+ hProperties: script.properties,
47
+ hChildren: script.children
48
+ }
49
+ });
50
+ }
40
51
  };
41
52
  }
42
53
  export { remarkYuhwa as default, remarkYuhwa };
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../typings/thenable.d.ts" preserve="true" />
2
2
  import { $ as SymbolTag, A as Hover, B as Location, C as DocumentHighlight, D as FoldingRange, E as DocumentUri, F as InlineValue, G as SelectionRange, H as Position, I as InlineValueContext, J as SemanticTokensEdit, K as SemanticTokens, L as InsertTextMode, M as InlineCompletionContext, N as InlineCompletionItem, O as FoldingRangeKind, P as InlineCompletionList, Q as SymbolKind, R as LSPAny, S as DiagnosticTag, T as DocumentSymbol, U as Range, V as MarkupKind, W as ReferenceContext, X as SignatureHelp, Y as SemanticTokensLegend, Z as SymbolInformation, _ as Declaration, a as CodeActionContext, at as VersionedTextDocumentIdentifier, b as DefinitionLink, c as CodeLens, ct as WorkspaceFolder, d as ColorPresentation, dt as uinteger, et as TextDocumentIdentifier, f as Command, g as CompletionList, h as CompletionItemTag, i as CodeAction, it as URI, j as InlayHint, k as FormattingOptions, l as Color, lt as WorkspaceSymbol, m as CompletionItemKind, n as CallHierarchyItem, nt as TextEdit, o as CodeActionKind, ot as WorkspaceEdit, p as CompletionItem, q as SemanticTokensDelta, r as CallHierarchyOutgoingCall, rt as TypeHierarchyItem, s as CodeActionTag, st as WorkspaceEditMetadata, t as CallHierarchyIncomingCall, tt as TextDocumentItem, u as ColorInformation, ut as integer, v as DeclarationLink, w as DocumentLink, x as Diagnostic, y as Definition, z as LSPObject } from "./main-DYrwpkoa.js";
3
- import { a as YuhwaService } from "./service-ClZ8clSQ.js";
3
+ import { a as YuhwaService } from "./service-Brvpt7Do.js";
4
4
  interface ResponseErrorLiteral<D = void> {
5
5
  /**
6
6
  * A number indicating the error type that occurred.
@@ -5882,7 +5882,7 @@ interface Connection extends _Connection {}
5882
5882
  interface ServerOptions {
5883
5883
  /** Source of a file that is not open in the editor, for imports; undefined when missing. */
5884
5884
  readFile?: (path: string) => string | undefined;
5885
- /** Path of a document URI, as imports name it. Default: the URI's path (`file:///a.yuhwa` → `/a.yuhwa`). */
5885
+ /** Path of a document URI, as imports name it. Default: the URI's path (`file:///a.yu` → `/a.yu`). */
5886
5886
  toPath?: (uri: string) => string;
5887
5887
  /** URI of a path, the reverse of `toPath`. */
5888
5888
  toUri?: (path: string) => string;
@@ -1,4 +1,4 @@
1
- import { n as YuhwaService, r as applyChange, t as SEMANTIC_LEGEND } from "./service-BYS9Qfkq.js";
1
+ import { n as YuhwaService, r as applyChange, t as SEMANTIC_LEGEND } from "./service-B1fpOg_L.js";
2
2
  // \0rolldown/runtime.js
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -9745,6 +9745,7 @@ var require_api = /* @__PURE__ */ __commonJSMin(((exports, module, this$1) => {
9745
9745
  // src/lsp/server.ts
9746
9746
  var import_api = require_api();
9747
9747
  const REQUEST_FAILED = -32803;
9748
+ const DEBOUNCE_MS = 150;
9748
9749
  const defaultToPath = (uri) => {
9749
9750
  try {
9750
9751
  return decodeURIComponent(new URL(uri).pathname);
@@ -9766,7 +9767,9 @@ function startServer(connection, opts = {}) {
9766
9767
  const text = (uri) => docs.get(toPath(uri)) ?? "";
9767
9768
  let pull = false;
9768
9769
  let refresh = false;
9769
- const validate = () => {
9770
+ let watch = false;
9771
+ const publish = () => {
9772
+ timer = void 0;
9770
9773
  if (pull) {
9771
9774
  if (refresh) connection.languages.diagnostics.refresh().catch(() => {});
9772
9775
  return;
@@ -9776,6 +9779,11 @@ function startServer(connection, opts = {}) {
9776
9779
  diagnostics: service.diagnostics(src, path)
9777
9780
  });
9778
9781
  };
9782
+ let timer;
9783
+ const validate = () => {
9784
+ if (timer !== void 0) clearTimeout(timer);
9785
+ timer = setTimeout(publish, DEBOUNCE_MS);
9786
+ };
9779
9787
  const changed = (uri, src) => {
9780
9788
  const path = toPath(uri);
9781
9789
  if (src === void 0) {
@@ -9795,6 +9803,7 @@ function startServer(connection, opts = {}) {
9795
9803
  connection.onInitialize(({ capabilities: c }) => {
9796
9804
  pull = !!c.textDocument?.diagnostic;
9797
9805
  refresh = !!c.workspace?.diagnostics?.refreshSupport;
9806
+ watch = !!c.workspace?.didChangeWatchedFiles?.dynamicRegistration;
9798
9807
  return {
9799
9808
  capabilities: {
9800
9809
  positionEncoding: "utf-16",
@@ -9825,6 +9834,10 @@ function startServer(connection, opts = {}) {
9825
9834
  },
9826
9835
  codeActionProvider: { codeActionKinds: ["quickfix"] },
9827
9836
  documentFormattingProvider: true,
9837
+ documentOnTypeFormattingProvider: {
9838
+ firstTriggerCharacter: "\n",
9839
+ moreTriggerCharacter: ["}"]
9840
+ },
9828
9841
  ...pull && { diagnosticProvider: {
9829
9842
  interFileDependencies: true,
9830
9843
  workspaceDiagnostics: false
@@ -9833,6 +9846,9 @@ function startServer(connection, opts = {}) {
9833
9846
  serverInfo: { name: "yuhwa-lsp" }
9834
9847
  };
9835
9848
  });
9849
+ connection.onInitialized(() => {
9850
+ if (watch) connection.client.register(import_api.DidChangeWatchedFilesNotification.type, { watchers: [{ globPattern: "**/*.{yu,yuhwa}" }] }).catch(() => {});
9851
+ });
9836
9852
  connection.onDidOpenTextDocument((p) => changed(p.textDocument.uri, p.textDocument.text));
9837
9853
  connection.onDidChangeTextDocument((p) => {
9838
9854
  if (!p.contentChanges.length) return;
@@ -9849,6 +9865,7 @@ function startServer(connection, opts = {}) {
9849
9865
  items: service.diagnostics(text(p.textDocument.uri), toPath(p.textDocument.uri))
9850
9866
  }));
9851
9867
  connection.onDocumentFormatting((p) => service.format(text(p.textDocument.uri)));
9868
+ connection.onDocumentOnTypeFormatting((p) => service.onType(text(p.textDocument.uri), p.position, p.ch));
9852
9869
  connection.onCompletion((p) => service.completion(text(p.textDocument.uri), p.position, toPath(p.textDocument.uri)));
9853
9870
  connection.onHover((p) => service.hover(text(p.textDocument.uri), p.position, toPath(p.textDocument.uri)));
9854
9871
  connection.onDefinition((p) => {