@forinda/kickjs-view-language-server 0.4.0 → 0.5.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @forinda/kickjs-view-language-server v0.4.0
2
+ * @forinda/kickjs-view-language-server v0.5.0
3
3
  *
4
4
  * Copyright (c) Felix Orinda
5
5
  *
@@ -8,6 +8,7 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
+ import { createRequire } from "node:module";
11
12
  import { existsSync, readFileSync } from "node:fs";
12
13
  import { readFile, readdir } from "node:fs/promises";
13
14
  import { basename, dirname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
@@ -18,7 +19,8 @@ import { create as create$2 } from "volar-service-html";
18
19
  import { URI } from "vscode-uri";
19
20
  import { fileURLToPath, pathToFileURL } from "node:url";
20
21
  import * as bundled from "@forinda/kickjs-view";
21
- //#region src/language-plugin.ts
22
+ import { resolveViewRoots } from "@forinda/kickjs-view/cli";
23
+ // src/language-plugin.ts
22
24
  const ALL = {
23
25
  verification: true,
24
26
  completion: true,
@@ -32,7 +34,7 @@ const EMBEDDED = {
32
34
  ...ALL,
33
35
  format: false
34
36
  };
35
- const KEYWORD$1 = /^@(else\s+if|if|for|switch|case|slot|error|layout|assets|verbatim|let|input|else|empty|default)(?![\w$-])/;
37
+ const KEYWORD$1 = /^@(else\s+if|if|for|switch|case|slot|error|layout|assets|fragment|push|snippet|render|verbatim|let|input|else|empty|default)(?![\w$-])/;
36
38
  const snapshotOf = (text) => ({
37
39
  getText: (start, end) => text.slice(start, end),
38
40
  getLength: () => text.length,
@@ -166,13 +168,21 @@ function scan(s) {
166
168
  continue;
167
169
  }
168
170
  }
171
+ if (kw === "snippet" || kw === "render") {
172
+ const name = /^\s+[A-Za-z_$][\w$]*/.exec(s.slice(j, j + 128));
173
+ if (!name) {
174
+ i++;
175
+ continue;
176
+ }
177
+ j += name[0].length;
178
+ }
169
179
  const p = skipWs(j);
170
180
  if (s[p] === "(") j = closeParen$1(s, p);
171
181
  else if (kw !== "else" && kw !== "empty" && kw !== "default") {
172
182
  i++;
173
183
  continue;
174
184
  }
175
- if (kw === "layout" || kw === "assets") {
185
+ if (kw === "layout" || kw === "assets" || kw === "render") {
176
186
  out.blank.push([i, j]);
177
187
  i = j;
178
188
  continue;
@@ -262,6 +272,7 @@ function embedded(id, languageId, text, [from, to]) {
262
272
  }]
263
273
  };
264
274
  }
275
+ /** A `.kick` document, with its HTML, `<style>` and `<script>` regions as embedded codes for their own language services. */
265
276
  var KickVirtualCode = class {
266
277
  text;
267
278
  id = "root";
@@ -342,6 +353,7 @@ var RenderCallsCode = class {
342
353
  }];
343
354
  }
344
355
  };
356
+ /** The Volar language plugin: `.kick` files, plus TS / JS files for their `ctx.render(...)` template names. */
345
357
  const kickLanguagePlugin = {
346
358
  getLanguageId(uri) {
347
359
  return uri.path.endsWith(".kick") ? "kick" : void 0;
@@ -352,8 +364,7 @@ const kickLanguagePlugin = {
352
364
  if (SCRIPT_IDS.has(languageId) || SCRIPT_FILE.test(uri.path)) return new RenderCallsCode(text);
353
365
  }
354
366
  };
355
- //#endregion
356
- //#region src/context.ts
367
+ // src/context.ts
357
368
  const LOOP_VARS = [
358
369
  "$index",
359
370
  "$first",
@@ -395,12 +406,19 @@ function headerNames(kw, header) {
395
406
  const as = /;\s*as\s+([\w$]+)/.exec(header);
396
407
  return as ? [as[1]] : [];
397
408
  }
409
+ if (kw === "snippet") return header.split(",").map((p) => p.split("=")[0].trim()).filter(Boolean);
410
+ if (kw === "slot") {
411
+ const lets = /;\s*let\s+(.*)$/s.exec(header);
412
+ return lets ? lets[1].split(",").map((d) => d.split("=")[0].trim()).filter(Boolean) : [];
413
+ }
398
414
  return [];
399
415
  }
400
416
  /** Names in scope at `stop`: inputs, then each enclosing block's, outermost first. */
401
417
  function scopeAt(s, stop) {
402
418
  const inputs = [];
403
419
  const frames = [[]];
420
+ /** Frame indexes where a `@snippet` body starts: only its own names are in scope there. */
421
+ const snippets = [];
404
422
  let i = 0;
405
423
  while (i < stop) {
406
424
  const c = s[i];
@@ -417,7 +435,7 @@ function scopeAt(s, stop) {
417
435
  continue;
418
436
  }
419
437
  if (c === "@" && !/[\w@.-]/.test(s[i - 1] ?? "")) {
420
- const m = /^@(else\s+if|for|if|switch|case|slot|error|else|empty|default|let|input)(?![\w$-])/.exec(s.slice(i, i + 16));
438
+ const m = /^@(else\s+if|for|if|switch|case|slot|error|fragment|push|snippet|else|empty|default|let|input)(?![\w$-])/.exec(s.slice(i, i + 16));
421
439
  if (m) {
422
440
  const kw = m[1].replace(/\s+/g, " ");
423
441
  let j = i + m[0].length;
@@ -436,6 +454,11 @@ function scopeAt(s, stop) {
436
454
  }
437
455
  let header = "";
438
456
  while (j < stop && /\s/.test(s[j])) j++;
457
+ if (kw === "snippet") {
458
+ const name = /^[A-Za-z_$][\w$]*/.exec(s.slice(j, j + 64));
459
+ if (name) j += name[0].length;
460
+ while (j < stop && /\s/.test(s[j])) j++;
461
+ }
439
462
  if (s[j] === "(") {
440
463
  const end = closeParen(s, j, stop);
441
464
  if (end < 0) break;
@@ -445,6 +468,7 @@ function scopeAt(s, stop) {
445
468
  while (j < stop && /\s/.test(s[j])) j++;
446
469
  if (s[j] === "{") {
447
470
  frames.push(headerNames(kw, header));
471
+ if (kw === "snippet") snippets.push(frames.length - 1);
448
472
  i = j + 1;
449
473
  continue;
450
474
  }
@@ -452,10 +476,14 @@ function scopeAt(s, stop) {
452
476
  continue;
453
477
  }
454
478
  }
455
- if (c === "}" && frames.length > 1) frames.pop();
479
+ if (c === "}" && frames.length > 1) {
480
+ if (snippets.at(-1) === frames.length - 1) snippets.pop();
481
+ frames.pop();
482
+ }
456
483
  i++;
457
484
  }
458
- return [...inputs, ...frames.flat()];
485
+ const from = snippets.at(-1);
486
+ return [...inputs, ...(from === void 0 ? frames : frames.slice(from)).flat()];
459
487
  }
460
488
  function exprContext(segment, s, offset) {
461
489
  const pipe = /\|\s*([A-Za-z_$][\w$]*)?$/.exec(segment);
@@ -474,9 +502,33 @@ function cursorContext(s, offset) {
474
502
  const before = s.slice(0, offset);
475
503
  const open = before.lastIndexOf("{{");
476
504
  if (open >= 0 && open > before.lastIndexOf("}}") && !before.startsWith("{{--", open)) return exprContext(before.slice(open + 2), s, offset);
477
- const named = /@(layout|slot)\s*\(\s*['"]([^'"]*)$/.exec(before);
505
+ const rnd = /@render\s+([\w$]*)$/.exec(before);
506
+ if (rnd) return {
507
+ kind: "snippet-name",
508
+ prefix: rnd[1]
509
+ };
510
+ const slotLet = /@slot\s*\(\s*(?:['"]([^'"]*)['"]|default)\s*;\s*let\s+(?:[\w$]+\s*(?:=\s*[\w$]+\s*)?,\s*)*([\w$]*)$/.exec(before);
511
+ if (slotLet) {
512
+ const tag = enclosingComponent(before);
513
+ return {
514
+ kind: "slot-let",
515
+ slot: slotLet[1] ?? "",
516
+ prefix: slotLet[2],
517
+ ...tag ? { tag } : {}
518
+ };
519
+ }
520
+ const ofAttr = /<component\b[^>]*\bof\s*=\s*"([^"]*)$/.exec(before);
521
+ if (ofAttr) return {
522
+ kind: "component-tag",
523
+ prefix: ofAttr[1].split(/\s+/).at(-1)
524
+ };
525
+ const named = /@(layout|slot|push)\s*\(\s*['"]([^'"]*)$/.exec(before);
478
526
  if (named) return {
479
- kind: named[1] === "layout" ? "template-name" : "slot-name",
527
+ kind: {
528
+ layout: "template-name",
529
+ slot: "slot-name",
530
+ push: "stack-name"
531
+ }[named[1]],
480
532
  prefix: named[2]
481
533
  };
482
534
  const letExpr = /@let\s+[\w$]+\s*=\s*([^;\n]*)$/.exec(before);
@@ -530,8 +582,19 @@ function wordAt(s, offset) {
530
582
  end
531
583
  };
532
584
  }
533
- //#endregion
534
- //#region src/plugin/completion.ts
585
+ /** The innermost component tag (one with a `-`) still open in `before`. */
586
+ function enclosingComponent(before) {
587
+ const open = [];
588
+ for (const m of before.matchAll(/<(\/?)([a-z][\w]*-[\w-]*)\b[^>]*?(\/?)>/gi)) {
589
+ const tag = m[2].toLowerCase();
590
+ if (m[1]) {
591
+ const at = open.lastIndexOf(tag);
592
+ if (at >= 0) open.splice(at);
593
+ } else if (!m[3]) open.push(tag);
594
+ }
595
+ return open.at(-1);
596
+ }
597
+ // src/plugin/completion.ts
535
598
  const SNIPPET = 2;
536
599
  const KEYWORD = 14;
537
600
  const FUNCTION = 3;
@@ -560,12 +623,16 @@ const KEYWORDS = {
560
623
  slot: "slot('${1:name}') {\n $0\n}",
561
624
  error: "error('${1:field}') {\n $0\n}",
562
625
  assets: "assets('$1')",
626
+ snippet: "snippet ${1:name}($2) {\n $0\n}",
627
+ render: "render ${1:name}($2)",
628
+ fragment: "fragment('${1:name}') {\n $0\n}",
629
+ push: "push('${1:stack}') {\n $0\n}",
563
630
  verbatim: "verbatim {\n $0\n}"
564
631
  };
565
632
  /** The template a component tag names, if any. */
566
633
  function componentOf(ws, tag) {
567
634
  const dir = ws.componentsDir();
568
- return ws.names().find((n) => n.startsWith(`${dir}/`) && ws.view.componentTag(n, dir) === tag);
635
+ return ws.names().find((n) => ws.isComponent(n) && ws.view.componentTag(n, dir) === tag);
569
636
  }
570
637
  /** Slot names the layouts above `name` declare, nearest first. */
571
638
  function layoutSlots(ws, name) {
@@ -580,7 +647,7 @@ function layoutSlots(ws, name) {
580
647
  }
581
648
  const base = ws.baseLayout();
582
649
  const page = name === void 0 ? void 0 : ws.astOf(name);
583
- if (base !== void 0 && name !== void 0 && page?.layout !== null && !name.startsWith(`${ws.componentsDir()}/`) && name !== base && !seen.has(base)) chain.push(base);
650
+ if (base !== void 0 && name !== void 0 && page?.layout !== null && !ws.isComponent(name) && name !== base && !seen.has(base)) chain.push(base);
584
651
  for (const l of chain) {
585
652
  const ast = ws.astOf(l);
586
653
  if (!ast) continue;
@@ -592,10 +659,43 @@ function layoutSlots(ws, name) {
592
659
  else if (n.k === "if") for (const b of n.branches) stack.push(b.body);
593
660
  else if (n.k === "for") stack.push(n.body, n.empty ?? []);
594
661
  else if (n.k === "switch") stack.push(...n.cases.map((c) => c.body), n.default ?? []);
595
- else if (n.k === "slot-fill") stack.push(n.body);
662
+ else if (n.k === "slot-fill" || n.k === "fragment" || n.k === "push" || n.k === "snippet") stack.push(n.body);
663
+ }
664
+ return [...out];
665
+ }
666
+ /** Every `<stack name>` in the project's pages and layouts. */
667
+ function stackNames(ws) {
668
+ const out = /* @__PURE__ */ new Set();
669
+ for (const name of ws.names()) {
670
+ if (ws.isComponent(name)) continue;
671
+ const ast = ws.astOf(name);
672
+ if (!ast) continue;
673
+ const stack = [ast.body];
674
+ while (stack.length) for (const n of stack.pop()) if (n.k === "stack") out.add(n.name);
675
+ else if (n.k === "element") stack.push(n.children);
676
+ else if (n.k === "if") for (const b of n.branches) stack.push(b.body);
677
+ else if (n.k === "for") stack.push(n.body, n.empty ?? []);
678
+ else if (n.k === "switch") stack.push(...n.cases.map((c) => c.body), n.default ?? []);
679
+ else if (n.k === "slot-outlet") stack.push(n.fallback);
680
+ else if (n.k === "slot-fill" || n.k === "fragment" || n.k === "push" || n.k === "snippet") stack.push(n.body);
596
681
  }
597
682
  return [...out];
598
683
  }
684
+ /** The value names slot `slot` of component template `name` passes to its caller's content. */
685
+ function slotOffers(ws, name, slot) {
686
+ const ast = name === void 0 ? void 0 : ws.astOf(name);
687
+ if (!ast) return [];
688
+ const stack = [ast.body];
689
+ while (stack.length) for (const n of stack.pop()) if (n.k === "slot-outlet") {
690
+ if ((n.name ?? "") === slot) return n.offers.map((o) => o.name);
691
+ stack.push(n.fallback);
692
+ } else if (n.k === "element") stack.push(n.children);
693
+ else if (n.k === "if") for (const b of n.branches) stack.push(b.body);
694
+ else if (n.k === "for") stack.push(n.body, n.empty ?? []);
695
+ else if (n.k === "switch") stack.push(...n.cases.map((c) => c.body), n.default ?? []);
696
+ else if (n.k === "slot-fill" || n.k === "fragment" || n.k === "push" || n.k === "snippet") stack.push(n.body);
697
+ return [];
698
+ }
599
699
  function completions(ws, uri, text, offset) {
600
700
  const c = cursorContext(text, offset);
601
701
  switch (c.kind) {
@@ -615,7 +715,7 @@ function completions(ws, uri, text, offset) {
615
715
  }));
616
716
  case "tag": {
617
717
  const dir = ws.componentsDir();
618
- return ws.names().filter((n) => n.startsWith(`${dir}/`)).map((n) => {
718
+ return ws.names().filter((n) => ws.isComponent(n)).map((n) => {
619
719
  const tag = ws.view.componentTag(n, dir);
620
720
  const attrs = (ws.astOf(n)?.inputs ?? []).filter((i) => !i.default).map((i, k) => ` [${i.name}]="$${k + 1}"`).join("");
621
721
  return {
@@ -651,17 +751,33 @@ function completions(ws, uri, text, offset) {
651
751
  }
652
752
  ];
653
753
  }
654
- case "template-name": {
655
- const dir = ws.componentsDir();
656
- return ws.names().filter((n) => !n.startsWith(`${dir}/`)).map((label) => ({
657
- label,
658
- kind: FILE$1
659
- }));
660
- }
754
+ case "template-name": return ws.names().filter((n) => !ws.isComponent(n)).map((label) => ({
755
+ label,
756
+ kind: FILE$1
757
+ }));
661
758
  case "slot-name": return layoutSlots(ws, ws.nameOf(uri)).map((label) => ({
662
759
  label,
663
760
  kind: PROPERTY
664
761
  }));
762
+ case "stack-name": return stackNames(ws).map((label) => ({
763
+ label,
764
+ kind: PROPERTY
765
+ }));
766
+ case "snippet-name": return [...text.matchAll(/@snippet\s+([A-Za-z_$][\w$]*)\s*\(/g)].map((m) => ({
767
+ label: m[1],
768
+ kind: FUNCTION
769
+ }));
770
+ case "slot-let": return slotOffers(ws, c.tag === void 0 ? void 0 : componentOf(ws, c.tag), c.slot).map((label) => ({
771
+ label,
772
+ kind: VARIABLE
773
+ }));
774
+ case "component-tag": {
775
+ const dir = ws.componentsDir();
776
+ return ws.names().filter((n) => ws.isComponent(n)).map((n) => ({
777
+ label: ws.view.componentTag(n, dir),
778
+ kind: CLASS
779
+ }));
780
+ }
665
781
  case "expr": return [.../* @__PURE__ */ new Set([...c.scope, ...FORM_STATE])].map((label) => ({
666
782
  label,
667
783
  kind: VARIABLE
@@ -669,8 +785,7 @@ function completions(ws, uri, text, offset) {
669
785
  default: return [];
670
786
  }
671
787
  }
672
- //#endregion
673
- //#region src/plugin/hover.ts
788
+ // src/plugin/hover.ts
674
789
  /** Worded as in the guide's pipe table. */
675
790
  const BUILTIN = {
676
791
  uppercase: "`uppercase` — the text in upper case",
@@ -681,6 +796,8 @@ const BUILTIN = {
681
796
  currency: "`currency:code:digits?` — e.g. `currency:'KES'`",
682
797
  percent: "`percent:digits?` — a ratio as a percentage",
683
798
  slice: "`slice:start:end` — part of a list or string",
799
+ join: "`join:separator?` — a list as text, e.g. `join:', '` (the default)",
800
+ compact: "`compact` — a list without `null`, `undefined`, `false` or empty strings; `0` stays",
684
801
  keys: "`keys` — an object’s keys",
685
802
  entries: "`entries` — an object’s `[key, value]` pairs",
686
803
  json: "`json` — the value as JSON",
@@ -722,8 +839,7 @@ function posOf(text, offset) {
722
839
  character: before.at(-1).length
723
840
  };
724
841
  }
725
- //#endregion
726
- //#region src/plugin/definition.ts
842
+ // src/plugin/definition.ts
727
843
  const TOP$1 = {
728
844
  start: {
729
845
  line: 0,
@@ -734,7 +850,7 @@ const TOP$1 = {
734
850
  character: 0
735
851
  }
736
852
  };
737
- function definition(ws, _uri, text, offset) {
853
+ function definition(ws, uri, text, offset) {
738
854
  const { word, start, end } = wordAt(text, offset);
739
855
  if (!word) return null;
740
856
  const origin = {
@@ -752,7 +868,13 @@ function definition(ws, _uri, text, offset) {
752
868
  const name = componentOf(ws, word.toLowerCase());
753
869
  return name === void 0 ? null : link(ws.uriOf(name));
754
870
  }
755
- if (c.kind === "template-name") return ws.astOf(word) ? link(ws.uriOf(word)) : null;
871
+ if (c.kind === "template-name") {
872
+ const before = /['"]([^'"\n]*)$/.exec(text.slice(0, offset));
873
+ const after = /^[^'"\n]*/.exec(text.slice(offset));
874
+ const written = before ? before[1] + (after?.[0] ?? "") : word;
875
+ const name = ws.refOf(ws.nameOf(uri), written);
876
+ return ws.astOf(name) ? link(ws.uriOf(name)) : null;
877
+ }
756
878
  if (c.kind === "pipe") {
757
879
  const decl = ws.pipeDeclaration(word);
758
880
  if (!decl) return null;
@@ -770,8 +892,7 @@ function definition(ws, _uri, text, offset) {
770
892
  }
771
893
  return null;
772
894
  }
773
- //#endregion
774
- //#region src/plugin/render-calls.ts
895
+ // src/plugin/render-calls.ts
775
896
  /** A call's template name as typed so far, up to the cursor. */
776
897
  const OPEN_CALL = /\b(?:ctx|views)\.render\(\s*(['"`])([^'"`\n]*)$/;
777
898
  /** Every call with a literal name. */
@@ -779,8 +900,7 @@ const CALLS = /\b(?:ctx|views)\.render\(\s*(['"`])([^'"`\n]*)\1/g;
779
900
  const FILE = 17;
780
901
  /** Template names a page can render: everything but components. */
781
902
  function renderable(ws) {
782
- const dir = `${ws.componentsDir()}/`;
783
- return ws.names().filter((n) => !n.startsWith(dir));
903
+ return ws.names().filter((n) => !ws.isComponent(n));
784
904
  }
785
905
  function renderCompletions(ws, text, offset) {
786
906
  const m = OPEN_CALL.exec(text.slice(0, offset));
@@ -839,8 +959,7 @@ function renderDiagnostics(ws, text) {
839
959
  message: `template '${c.name}' not found`
840
960
  }));
841
961
  }
842
- //#endregion
843
- //#region src/plugin/diagnostics.ts
962
+ // src/plugin/diagnostics.ts
844
963
  /** The `.kick` file a root virtual-code document belongs to. */
845
964
  function sourceUri(context, uri) {
846
965
  return context.decodeEmbeddedDocumentUri?.(URI.parse(uri))?.[0].toString() ?? uri;
@@ -863,8 +982,7 @@ function createDiagnosticsPlugin(ws) {
863
982
  }
864
983
  };
865
984
  }
866
- //#endregion
867
- //#region src/plugin/format.ts
985
+ // src/plugin/format.ts
868
986
  /** One whole-document edit, or none on a parse error or when nothing changes. */
869
987
  function formatEdits(view, text, file, tabSize) {
870
988
  const { output } = view.format(text, file, { indent: tabSize });
@@ -880,8 +998,7 @@ function formatEdits(view, text, file, tabSize) {
880
998
  newText: output
881
999
  }];
882
1000
  }
883
- //#endregion
884
- //#region src/plugin/tokens.ts
1001
+ // src/plugin/tokens.ts
885
1002
  /**
886
1003
  * Semantic tokens for `.kick` templates, so every LSP editor highlights the
887
1004
  * template syntax, not only VS Code with its TextMate grammar. Found by a
@@ -1069,8 +1186,7 @@ function kickTokens(s, isComponent) {
1069
1186
  }
1070
1187
  return out;
1071
1188
  }
1072
- //#endregion
1073
- //#region src/plugin/references.ts
1189
+ // src/plugin/references.ts
1074
1190
  const TOP = {
1075
1191
  start: {
1076
1192
  line: 0,
@@ -1087,8 +1203,18 @@ const rangeOf = (text, offset, length) => ({
1087
1203
  start: posOf(text, offset),
1088
1204
  end: posOf(text, offset + length)
1089
1205
  });
1090
- /** The shared name under the cursor, with where it sits in `text`. */
1091
- function targetAt(ws, text, offset) {
1206
+ /** `ui::layouts/main` → `ui`; an app template has none. */
1207
+ const rootOf = (name) => name.includes("::") ? name.slice(0, name.indexOf("::")) : void 0;
1208
+ /**
1209
+ * What to write for a layout renamed to `newFull`, at a use written as
1210
+ * `written` in template `from`: unqualified when it stays in that root.
1211
+ */
1212
+ function layoutText(ws, use, newFull) {
1213
+ const root = rootOf(newFull);
1214
+ return !use.written.includes("::") && root !== void 0 && rootOf(use.from) === root ? ws.pathPart(newFull) : newFull;
1215
+ }
1216
+ /** The shared name under the cursor, with where it sits in `text` (the template at `uri`). */
1217
+ function targetAt(ws, text, offset, uri) {
1092
1218
  const t = kickTokens(text, (tag) => componentOf(ws, tag) !== void 0).find((k) => offset >= k.offset && offset <= k.offset + k.length);
1093
1219
  if (!t) return void 0;
1094
1220
  const word = text.slice(t.offset, t.offset + t.length);
@@ -1111,14 +1237,15 @@ function targetAt(ws, text, offset) {
1111
1237
  ...t
1112
1238
  };
1113
1239
  if (t.type === "string" && /@layout\s*\(\s*$/.test(text.slice(0, t.offset))) {
1114
- const name = word.slice(1, -1);
1240
+ const written = word.slice(1, -1);
1241
+ const name = ws.refOf(uri === void 0 ? void 0 : ws.nameOf(uri), written);
1115
1242
  return ws.astOf(name) ? {
1116
1243
  target: {
1117
1244
  kind: "layout",
1118
1245
  name
1119
1246
  },
1120
1247
  offset: t.offset + 1,
1121
- length: name.length
1248
+ length: written.length
1122
1249
  } : void 0;
1123
1250
  }
1124
1251
  }
@@ -1130,9 +1257,11 @@ function usesOf(ws, target) {
1130
1257
  if (text === void 0) continue;
1131
1258
  const uri = ws.uriOf(name);
1132
1259
  if (target.kind === "layout") {
1133
- for (const m of text.matchAll(LAYOUT)) if (m[2] === target.name) out.push({
1260
+ for (const m of text.matchAll(LAYOUT)) if (ws.refOf(name, m[2]) === target.name) out.push({
1134
1261
  uri,
1135
1262
  text,
1263
+ from: name,
1264
+ written: m[2],
1136
1265
  offset: m.index + m[0].length - m[2].length - 1,
1137
1266
  length: m[2].length
1138
1267
  });
@@ -1143,6 +1272,8 @@ function usesOf(ws, target) {
1143
1272
  for (const t of kickTokens(text, (tag) => target.kind === "component" && tag === target.tag)) if (t.type === want && text.slice(t.offset, t.offset + t.length).toLowerCase() === match.toLowerCase()) out.push({
1144
1273
  uri,
1145
1274
  text,
1275
+ from: name,
1276
+ written: match,
1146
1277
  ...t
1147
1278
  });
1148
1279
  }
@@ -1167,8 +1298,8 @@ function pipeDeclaration(ws, name) {
1167
1298
  }
1168
1299
  };
1169
1300
  }
1170
- function references(ws, text, offset, includeDeclaration) {
1171
- const at = targetAt(ws, text, offset);
1301
+ function references(ws, text, offset, includeDeclaration, uri) {
1302
+ const at = targetAt(ws, text, offset, uri);
1172
1303
  if (!at) return [];
1173
1304
  const { target } = at;
1174
1305
  const locations = usesOf(ws, target).map((u) => ({
@@ -1187,8 +1318,8 @@ function references(ws, text, offset, includeDeclaration) {
1187
1318
  return locations;
1188
1319
  }
1189
1320
  /** What F2 renames here: a pipe, a component tag or a layout name. */
1190
- function renameRange(ws, text, offset) {
1191
- const at = targetAt(ws, text, offset);
1321
+ function renameRange(ws, text, offset, uri) {
1322
+ const at = targetAt(ws, text, offset, uri);
1192
1323
  if (!at) return void 0;
1193
1324
  if (at.target.kind === "pipe" && !pipeDeclaration(ws, at.target.name)) return { message: `Rename ${at.target.name} in your pipes file; it isn't declared in a form the editor can rename.` };
1194
1325
  return rangeOf(text, at.offset, at.length);
@@ -1198,9 +1329,13 @@ const TAG = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$/;
1198
1329
  function componentNameFor(ws, oldName, tag) {
1199
1330
  if (!TAG.test(tag)) return void 0;
1200
1331
  const dir = ws.componentsDir();
1201
- const folders = oldName.slice(dir.length + 1).split("/").slice(0, -1);
1332
+ const root = rootOf(oldName);
1333
+ if (root !== void 0 && !tag.startsWith(`${root}-`)) return void 0;
1334
+ const rest = root === void 0 ? tag : tag.slice(root.length + 1);
1335
+ const folders = ws.pathPart(oldName).slice(dir.length + 1).split("/").slice(0, -1);
1202
1336
  const prefix = folders.join("-");
1203
- const name = prefix && tag.startsWith(`${prefix}-`) ? `${dir}/${folders.join("/")}/${tag.slice(prefix.length + 1)}` : `${dir}/${tag}`;
1337
+ const path = prefix && rest.startsWith(`${prefix}-`) ? `${dir}/${folders.join("/")}/${rest.slice(prefix.length + 1)}` : `${dir}/${rest}`;
1338
+ const name = root === void 0 ? path : `${root}::${path}`;
1204
1339
  return ws.view.componentTag(name, dir) === tag ? name : void 0;
1205
1340
  }
1206
1341
  /** Every use of `target` replaced with `newText`, then the template's file renamed. */
@@ -1212,7 +1347,7 @@ function renameTemplate(ws, target, newText, newName) {
1212
1347
  const edits = byUri.get(u.uri) ?? [];
1213
1348
  edits.push({
1214
1349
  range: rangeOf(u.text, u.offset, u.length),
1215
- newText
1350
+ newText: typeof newText === "string" ? newText : newText(u)
1216
1351
  });
1217
1352
  byUri.set(u.uri, edits);
1218
1353
  }
@@ -1229,15 +1364,19 @@ function renameTemplate(ws, target, newText, newName) {
1229
1364
  }] };
1230
1365
  }
1231
1366
  /** A pipe renamed in every template and in `pipes.ts`; a component or layout, file included. */
1232
- function renameEdits(ws, text, offset, newName) {
1233
- const at = targetAt(ws, text, offset);
1367
+ function renameEdits(ws, text, offset, newName, uri) {
1368
+ const at = targetAt(ws, text, offset, uri);
1234
1369
  if (!at) return void 0;
1235
1370
  const { target } = at;
1236
1371
  if (target.kind === "component") {
1237
1372
  const name = componentNameFor(ws, target.name, newName);
1238
1373
  return name === void 0 ? void 0 : renameTemplate(ws, target, newName, name);
1239
1374
  }
1240
- if (target.kind === "layout") return renameTemplate(ws, target, newName, newName);
1375
+ if (target.kind === "layout") {
1376
+ const root = rootOf(target.name);
1377
+ const full = root !== void 0 && !newName.includes("::") ? `${root}::${newName}` : newName;
1378
+ return renameTemplate(ws, target, (u) => layoutText(ws, u, full), full);
1379
+ }
1241
1380
  if (!IDENT.test(newName) || ws.project().pipes.has(newName)) return void 0;
1242
1381
  const decl = pipeDeclaration(ws, target.name);
1243
1382
  if (!decl) return void 0;
@@ -1266,8 +1405,8 @@ async function fileRenameEdits(ws, oldUri, newUri) {
1266
1405
  const changes = {};
1267
1406
  const dir = ws.componentsDir();
1268
1407
  for (const [oldName, newName] of renamed) {
1269
- const comp = oldName.startsWith(`${dir}/`);
1270
- const newTag = newName.startsWith(`${dir}/`) ? ws.view.componentTag(newName, dir) : void 0;
1408
+ const comp = ws.isComponent(oldName);
1409
+ const newTag = ws.isComponent(newName) ? ws.view.componentTag(newName, dir) : void 0;
1271
1410
  const targets = [[{
1272
1411
  kind: "layout",
1273
1412
  name: oldName
@@ -1279,10 +1418,10 @@ async function fileRenameEdits(ws, oldUri, newUri) {
1279
1418
  }, newTag]);
1280
1419
  for (const [target, newText] of targets) for (const u of usesOf(ws, target)) (changes[u.uri] ??= []).push({
1281
1420
  range: rangeOf(u.text, u.offset, u.length),
1282
- newText
1421
+ newText: target.kind === "layout" ? layoutText(ws, u, newText) : newText
1283
1422
  });
1284
1423
  }
1285
- const pages = [...renamed].filter(([n]) => !n.startsWith(`${dir}/`));
1424
+ const pages = [...renamed].filter(([n]) => !ws.isComponent(n));
1286
1425
  if (pages.length) {
1287
1426
  const to = new Map(pages);
1288
1427
  for (const script of await ws.scripts()) for (const c of calls(script.text)) {
@@ -1295,8 +1434,8 @@ async function fileRenameEdits(ws, oldUri, newUri) {
1295
1434
  }
1296
1435
  return Object.keys(changes).length ? { changes } : void 0;
1297
1436
  }
1298
- //#endregion
1299
- //#region src/plugin/index.ts
1437
+ // src/plugin/index.ts
1438
+ /** The Volar service plugin for `.kick` documents: diagnostics, completion, hover, definitions, references, rename, formatting and semantic tokens. */
1300
1439
  function createKickServicePlugin(ws) {
1301
1440
  const diagnostics = createDiagnosticsPlugin(ws);
1302
1441
  return {
@@ -1367,15 +1506,15 @@ function createKickServicePlugin(ws) {
1367
1506
  },
1368
1507
  provideReferences(document, position, context) {
1369
1508
  const d = open(document);
1370
- return d ? references(ws, d.text, document.offsetAt(position), context.includeDeclaration) : void 0;
1509
+ return d ? references(ws, d.text, document.offsetAt(position), context.includeDeclaration, d.uri) : void 0;
1371
1510
  },
1372
1511
  provideRenameRange(document, position) {
1373
1512
  const d = open(document);
1374
- return d ? renameRange(ws, d.text, document.offsetAt(position)) : void 0;
1513
+ return d ? renameRange(ws, d.text, document.offsetAt(position), d.uri) : void 0;
1375
1514
  },
1376
1515
  provideRenameEdits(document, position, newName) {
1377
1516
  const d = open(document);
1378
- return d ? renameEdits(ws, d.text, document.offsetAt(position), newName) : void 0;
1517
+ return d ? renameEdits(ws, d.text, document.offsetAt(position), newName, d.uri) : void 0;
1379
1518
  },
1380
1519
  provideFileRenameEdits(oldUri, newUri) {
1381
1520
  return fileRenameEdits(ws, oldUri.toString(), newUri.toString());
@@ -1411,8 +1550,7 @@ function createKickServicePlugin(ws) {
1411
1550
  }
1412
1551
  };
1413
1552
  }
1414
- //#endregion
1415
- //#region src/view-module.ts
1553
+ // src/view-module.ts
1416
1554
  /**
1417
1555
  * Which `@forinda/kickjs-view` the server runs: the project's own, so the
1418
1556
  * editor parses, checks and formats exactly as the app's build does, or the
@@ -1490,6 +1628,10 @@ function findProjectView(root) {
1490
1628
  };
1491
1629
  }
1492
1630
  }
1631
+ /**
1632
+ * Loads the project's `@forinda/kickjs-view` when the workspace is trusted and it has the needed
1633
+ * exports; otherwise uses the bundled copy, warning once with the reason when the project's copy was not usable.
1634
+ */
1493
1635
  async function loadViewModule(root, warn, trusted) {
1494
1636
  if (!trusted) return {
1495
1637
  view: bundled,
@@ -1523,8 +1665,44 @@ async function loadViewModule(root, warn, trusted) {
1523
1665
  version: BUNDLED_VERSION
1524
1666
  };
1525
1667
  }
1526
- //#endregion
1527
- //#region src/pipes.ts
1668
+ // src/kick-config.ts
1669
+ /**
1670
+ * The editor's views folder and named roots: the editor settings win, else
1671
+ * kick.config's `views` block (read through the project's CLI, only in a
1672
+ * trusted workspace — loading kick.config runs the project's code).
1673
+ */
1674
+ /** The views folder (when kick.config or the settings name one) and the roots, or why they're unusable. */
1675
+ function viewsSetup(root, settings, config) {
1676
+ const views = config?.views;
1677
+ const dir = settings.viewsDir ?? views?.dir;
1678
+ const viewsDir = dir === void 0 ? void 0 : isAbsolute(dir) ? dir : resolve(root, dir);
1679
+ try {
1680
+ const roots = resolveViewRoots(root, { roots: settings.roots ?? views?.roots }).roots.map(({ name, dir }) => ({
1681
+ name,
1682
+ dir
1683
+ }));
1684
+ return {
1685
+ ...viewsDir ? { viewsDir } : {},
1686
+ roots
1687
+ };
1688
+ } catch (err) {
1689
+ return {
1690
+ ...viewsDir ? { viewsDir } : {},
1691
+ roots: [],
1692
+ error: err.message
1693
+ };
1694
+ }
1695
+ }
1696
+ /** kick.config through the project's `@forinda/kickjs-cli`; `null` when it can't be loaded. */
1697
+ async function loadKickConfig(root) {
1698
+ try {
1699
+ const entry = createRequire(join(root, "package.json")).resolve("@forinda/kickjs-cli");
1700
+ return await (await import(pathToFileURL(entry).href)).loadKickConfig?.(root) ?? null;
1701
+ } catch {
1702
+ return null;
1703
+ }
1704
+ }
1705
+ // src/pipes.ts
1528
1706
  const DECL = /^export\s+(?:(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=]*)?=\s*(?:\(([^)]*)\)|([A-Za-z_$][\w$]*)\s*=>)|function\s+([A-Za-z_$][\w$]*)\s*(?:<[^>]*>)?\s*\(([^)]*)\))/d;
1529
1707
  function pipeDeclarations(source) {
1530
1708
  const out = /* @__PURE__ */ new Map();
@@ -1542,8 +1720,7 @@ function pipeDeclarations(source) {
1542
1720
  });
1543
1721
  return out;
1544
1722
  }
1545
- //#endregion
1546
- //#region src/positions.ts
1723
+ // src/positions.ts
1547
1724
  const toPosition = (pos) => ({
1548
1725
  line: pos.line - 1,
1549
1726
  character: pos.column - 1
@@ -1552,8 +1729,7 @@ const toRange = (span) => ({
1552
1729
  start: toPosition(span.start),
1553
1730
  end: toPosition(span.end)
1554
1731
  });
1555
- //#endregion
1556
- //#region src/workspace.ts
1732
+ // src/workspace.ts
1557
1733
  /**
1558
1734
  * The editor's view of an app's templates: every `.kick` file under the
1559
1735
  * views folder (an open buffer wins over the file on disk) and the pipe names
@@ -1561,6 +1737,18 @@ const toRange = (span) => ({
1561
1737
  * runtime uses, cached per template and invalidated along the graph of
1562
1738
  * which template uses which component or layout.
1563
1739
  */
1740
+ /** `ui::components/x` → root `ui`, path `components/x`. */
1741
+ function split(name) {
1742
+ const at = name.indexOf("::");
1743
+ return at < 0 ? { path: name } : {
1744
+ root: name.slice(0, at),
1745
+ path: name.slice(at + 2)
1746
+ };
1747
+ }
1748
+ /**
1749
+ * The editor's view of an app's templates: every `.kick` file under the views folder (an open
1750
+ * buffer wins over the file on disk), with diagnostics from the same `parse` and `check` the runtime uses.
1751
+ */
1564
1752
  var Workspace = class {
1565
1753
  opts;
1566
1754
  entries = /* @__PURE__ */ new Map();
@@ -1577,32 +1765,72 @@ var Workspace = class {
1577
1765
  async load() {
1578
1766
  await this.loadPipes();
1579
1767
  await this.loadValidators();
1580
- for (const path of await this.opts.list(this.opts.viewsDir)) {
1768
+ for (const { dir } of this.folders()) for (const path of await this.opts.list(dir)) {
1581
1769
  const name = this.nameOfPath(path);
1582
1770
  if (name) this.update(name, { disk: await this.opts.read(path) });
1583
1771
  }
1584
1772
  }
1773
+ /** The app's views folder, then each root's. */
1774
+ folders() {
1775
+ return [{ dir: this.opts.viewsDir }, ...(this.opts.roots ?? []).map((r) => ({
1776
+ root: r.name,
1777
+ dir: r.dir
1778
+ }))];
1779
+ }
1780
+ /** What `ref`, written in template `from`, names: its own root's template first, then the app's. */
1781
+ refOf(from, ref) {
1782
+ const root = from === void 0 ? void 0 : split(from).root;
1783
+ if (ref.includes("::") || root === void 0) return ref;
1784
+ const own = `${root}::${ref}`;
1785
+ return this.entries.has(own) ? own : ref;
1786
+ }
1787
+ /** A template name's path, without its root. */
1788
+ pathPart(name) {
1789
+ return split(name).path;
1790
+ }
1791
+ /** A component: under the components folder, in the app's views or a root's. */
1792
+ isComponent(name) {
1793
+ return split(name).path.startsWith(`${this.opts.componentsDir}/`);
1794
+ }
1585
1795
  nameOfPath(path) {
1586
- const rel = relative(this.opts.viewsDir, path).split(sep).join(posix.sep);
1587
- if (rel.startsWith("..") || !rel.endsWith(".kick")) return void 0;
1588
- return this.opts.view.templateName(rel.slice(0, -5));
1796
+ for (const { root, dir } of this.folders()) {
1797
+ const rel = relative(dir, path).split(sep).join(posix.sep);
1798
+ if (rel.startsWith("..") || isAbsolute(rel) || !rel.endsWith(".kick")) continue;
1799
+ const name = this.opts.view.templateName(rel.slice(0, -5));
1800
+ return name && (root === void 0 ? name : `${root}::${name}`);
1801
+ }
1589
1802
  }
1590
- /** `uri`'s path inside the views folder (`layouts/main.kick`, `layouts`); `undefined` outside it. */
1803
+ dirOf(name) {
1804
+ const { root, path } = split(name);
1805
+ return {
1806
+ dir: (root === void 0 ? this.opts.viewsDir : this.opts.roots?.find((r) => r.name === root)?.dir) ?? this.opts.viewsDir,
1807
+ path
1808
+ };
1809
+ }
1810
+ /**
1811
+ * `uri`'s path inside the views folder (`layouts/main.kick`, `layouts`), or
1812
+ * inside a root with its prefix (`ui::layouts`); `undefined` outside them.
1813
+ */
1591
1814
  relOf(uri) {
1592
- const rel = relative(this.opts.viewsDir, URI.parse(uri).fsPath).split(sep).join(posix.sep);
1593
- return rel.startsWith("..") || isAbsolute(rel) ? void 0 : rel;
1815
+ const path = URI.parse(uri).fsPath;
1816
+ for (const { root, dir } of this.folders()) {
1817
+ const rel = relative(dir, path).split(sep).join(posix.sep);
1818
+ if (rel.startsWith("..") || isAbsolute(rel)) continue;
1819
+ return root === void 0 ? rel : `${root}::${rel}`;
1820
+ }
1594
1821
  }
1595
1822
  nameOf(uri) {
1596
1823
  return this.nameOfPath(URI.parse(uri).fsPath);
1597
1824
  }
1598
1825
  uriOf(name) {
1599
- return URI.file(`${this.opts.viewsDir}/${name}.kick`).toString();
1826
+ return URI.file(this.pathOf(name)).toString();
1600
1827
  }
1601
1828
  componentsDir() {
1602
1829
  return this.opts.componentsDir;
1603
1830
  }
1604
1831
  pathOf(name) {
1605
- return `${this.opts.viewsDir}/${name}.kick`;
1832
+ const { dir, path } = this.dirOf(name);
1833
+ return `${dir}/${path}.kick`;
1606
1834
  }
1607
1835
  names() {
1608
1836
  return [...this.entries.keys()];
@@ -1690,12 +1918,16 @@ var Workspace = class {
1690
1918
  const stack = [parsed.ast.body];
1691
1919
  while (stack.length) for (const n of stack.pop()) if (n.k === "element") {
1692
1920
  if (!n.foreign && n.tag.includes("-")) tags.add(n.tag.toLowerCase());
1921
+ if (!n.foreign && n.tag.toLowerCase() === "component") {
1922
+ const of = n.attrs.find((a) => a.name.toLowerCase() === "of" && a.kind === "static");
1923
+ for (const t of String(of?.parts?.[0] ?? "").split(/\s+/)) if (t) tags.add(t.toLowerCase());
1924
+ }
1693
1925
  stack.push(n.children);
1694
1926
  } else if (n.k === "if") for (const b of n.branches) stack.push(b.body);
1695
1927
  else if (n.k === "for") stack.push(n.body, n.empty ?? []);
1696
1928
  else if (n.k === "switch") stack.push(...n.cases.map((c) => c.body), n.default ?? []);
1697
1929
  else if (n.k === "slot-outlet") stack.push(n.fallback);
1698
- else if (n.k === "slot-fill") stack.push(n.body);
1930
+ else if (n.k === "slot-fill" || n.k === "fragment" || n.k === "push" || n.k === "snippet") stack.push(n.body);
1699
1931
  const isNew = !this.entries.has(name);
1700
1932
  this.entries.set(name, {
1701
1933
  ...src,
@@ -1707,8 +1939,10 @@ var Workspace = class {
1707
1939
  this.invalidate(name, isNew);
1708
1940
  }
1709
1941
  remove(name) {
1942
+ const users = this.dependentsOf(name);
1710
1943
  this.entries.delete(name);
1711
1944
  this.invalidate(name, true);
1945
+ for (const u of users) this.invalidate(u, false);
1712
1946
  }
1713
1947
  /** Drop cached diagnostics for `name` and every template that uses it, transitively. */
1714
1948
  invalidate(name, membershipChanged) {
@@ -1721,7 +1955,7 @@ var Workspace = class {
1721
1955
  this.cache.delete(n);
1722
1956
  for (const d of this.dependentsOf(n)) todo.push(d);
1723
1957
  }
1724
- if (membershipChanged && name.startsWith(`${this.opts.componentsDir}/`)) {
1958
+ if (membershipChanged && this.isComponent(name)) {
1725
1959
  const tag = this.opts.view.componentTag(name, this.opts.componentsDir);
1726
1960
  for (const [n, e] of this.entries) if (e.tags.has(tag)) this.cache.delete(n);
1727
1961
  }
@@ -1730,10 +1964,11 @@ var Workspace = class {
1730
1964
  dependentsOf(name) {
1731
1965
  if (this.configuredLayouts().has(name)) return new Set(this.names().filter((n) => n !== name));
1732
1966
  const out = /* @__PURE__ */ new Set();
1733
- const tag = name.startsWith(`${this.opts.componentsDir}/`) ? this.opts.view.componentTag(name, this.opts.componentsDir) : void 0;
1967
+ const tag = this.isComponent(name) ? this.opts.view.componentTag(name, this.opts.componentsDir) : void 0;
1734
1968
  for (const [n, e] of this.entries) {
1735
1969
  if (n === name) continue;
1736
- if (tag && e.tags.has(tag) && this.entries.has(name) || e.layouts.has(name)) out.add(n);
1970
+ const usesLayout = [...e.layouts].some((l) => this.refOf(n, l) === name);
1971
+ if (tag && e.tags.has(tag) && this.entries.has(name) || usesLayout) out.add(n);
1737
1972
  }
1738
1973
  return out;
1739
1974
  }
@@ -1781,9 +2016,9 @@ var Workspace = class {
1781
2016
  layoutOf(name) {
1782
2017
  const ast = this.astOf(name);
1783
2018
  if (!ast) return void 0;
1784
- if (ast.layout !== void 0) return ast.layout ?? void 0;
2019
+ if (ast.layout !== void 0) return ast.layout ? this.refOf(name, ast.layout) : void 0;
1785
2020
  const { layout } = this.opts;
1786
- if (layout === void 0 || name.startsWith(`${this.opts.componentsDir}/`) || this.configuredLayouts().has(name)) return void 0;
2021
+ if (layout === void 0 || split(name).path.startsWith(`${this.opts.componentsDir}/`) || this.configuredLayouts().has(name)) return void 0;
1787
2022
  if (typeof layout === "string") return layout;
1788
2023
  const hit = Object.keys(layout).toSorted((a, b) => b.length - a.length).find((p) => p === "" || name === p || name.startsWith(`${p}/`));
1789
2024
  return hit === void 0 ? void 0 : layout[hit];
@@ -1805,8 +2040,7 @@ var Workspace = class {
1805
2040
  return out;
1806
2041
  }
1807
2042
  };
1808
- //#endregion
1809
- //#region src/server.ts
2043
+ // src/server.ts
1810
2044
  /**
1811
2045
  * The language server: Volar's server with the `.kick` language plugin and
1812
2046
  * the HTML, CSS, Emmet and kick service plugins, over the project's own
@@ -1872,6 +2106,12 @@ function watchPatterns(root, pipesFile, validatorsFile) {
1872
2106
  if (validatorsFile && !/^validators\.(ts|js)$/.test(basename(validatorsFile))) patterns.push(relative(root, validatorsFile).split(sep).join("/"));
1873
2107
  return patterns;
1874
2108
  }
2109
+ /**
2110
+ * Starts the `.kick` language server on the connection the editor opened (the transport
2111
+ * comes from the command-line arguments, such as `--stdio`).
2112
+ *
2113
+ * @see https://kickjs.app/guide/view-editors
2114
+ */
1875
2115
  function startServer() {
1876
2116
  const connection = createConnection();
1877
2117
  const server = createServer(connection);
@@ -1883,7 +2123,9 @@ function startServer() {
1883
2123
  const root = folder ? URI.parse(folder).fsPath : process.cwd();
1884
2124
  const opts = params.initializationOptions ?? {};
1885
2125
  const at = (p) => isAbsolute(p) ? p : resolve(root, p);
1886
- const viewsDir = at(opts.viewsDir ?? "src/views");
2126
+ const setup = viewsSetup(root, opts, opts.trusted === true ? await loadKickConfig(root) : null);
2127
+ if (setup.error) connection.console.warn(`kick views: ${setup.error}`);
2128
+ const viewsDir = setup.viewsDir ?? at("src/views");
1887
2129
  const hasViews = existsSync(viewsDir);
1888
2130
  const { view } = await loadViewModule(root, (m) => hasViews && connection.console.warn(m), opts.trusted === true);
1889
2131
  const pipesFile = at(opts.pipesFile ?? join(viewsDir, "pipes.ts"));
@@ -1900,6 +2142,7 @@ function startServer() {
1900
2142
  list: listKick,
1901
2143
  layout: opts.layout || void 0,
1902
2144
  baseLayout: opts.baseLayout || void 0,
2145
+ roots: setup.roots,
1903
2146
  scripts: async () => mapLimit(await listScripts(root), 64, async (p) => {
1904
2147
  const uri = URI.file(p).toString();
1905
2148
  return {
@@ -1939,8 +2182,8 @@ function startServer() {
1939
2182
  });
1940
2183
  connection.onRequest("kick/templateNames", () => {
1941
2184
  if (!ws) return [];
1942
- const dir = `${ws.componentsDir()}/`;
1943
- return ws.names().filter((n) => !n.startsWith(dir));
2185
+ const w = ws;
2186
+ return w.names().filter((n) => !w.isComponent(n));
1944
2187
  });
1945
2188
  connection.onRequest("kick/renderDefinition", ({ text, offset }) => {
1946
2189
  const link = ws && renderDefinition(ws, text, offset);
@@ -1952,7 +2195,6 @@ function startServer() {
1952
2195
  connection.onRequest("kick/renderDiagnostics", ({ text }) => ws ? renderDiagnostics(ws, text) : []);
1953
2196
  connection.onShutdown(() => server.shutdown());
1954
2197
  }
1955
- //#endregion
1956
2198
  export { KickVirtualCode as a, createKickServicePlugin as i, Workspace as n, kickLanguagePlugin as o, loadViewModule as r, startServer as t };
1957
2199
 
1958
- //# sourceMappingURL=server-B2sP928V.js.map
2200
+ //# sourceMappingURL=server-g7Phx27h.js.map