@forinda/kickjs-view-language-server 0.4.1 → 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.
- package/README.md +1 -1
- package/dist/index.d.ts +39 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/main.js +2 -2
- package/dist/{server-8LrzPkVt.js → server-g7Phx27h.js} +320 -64
- package/dist/server-g7Phx27h.js.map +1 -0
- package/package.json +7 -7
- package/dist/server-8LrzPkVt.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs-view-language-server v0.
|
|
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,6 +19,7 @@ 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";
|
|
22
|
+
import { resolveViewRoots } from "@forinda/kickjs-view/cli";
|
|
21
23
|
// src/language-plugin.ts
|
|
22
24
|
const ALL = {
|
|
23
25
|
verification: 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;
|
|
@@ -394,12 +406,19 @@ function headerNames(kw, header) {
|
|
|
394
406
|
const as = /;\s*as\s+([\w$]+)/.exec(header);
|
|
395
407
|
return as ? [as[1]] : [];
|
|
396
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
|
+
}
|
|
397
414
|
return [];
|
|
398
415
|
}
|
|
399
416
|
/** Names in scope at `stop`: inputs, then each enclosing block's, outermost first. */
|
|
400
417
|
function scopeAt(s, stop) {
|
|
401
418
|
const inputs = [];
|
|
402
419
|
const frames = [[]];
|
|
420
|
+
/** Frame indexes where a `@snippet` body starts: only its own names are in scope there. */
|
|
421
|
+
const snippets = [];
|
|
403
422
|
let i = 0;
|
|
404
423
|
while (i < stop) {
|
|
405
424
|
const c = s[i];
|
|
@@ -416,7 +435,7 @@ function scopeAt(s, stop) {
|
|
|
416
435
|
continue;
|
|
417
436
|
}
|
|
418
437
|
if (c === "@" && !/[\w@.-]/.test(s[i - 1] ?? "")) {
|
|
419
|
-
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));
|
|
420
439
|
if (m) {
|
|
421
440
|
const kw = m[1].replace(/\s+/g, " ");
|
|
422
441
|
let j = i + m[0].length;
|
|
@@ -435,6 +454,11 @@ function scopeAt(s, stop) {
|
|
|
435
454
|
}
|
|
436
455
|
let header = "";
|
|
437
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
|
+
}
|
|
438
462
|
if (s[j] === "(") {
|
|
439
463
|
const end = closeParen(s, j, stop);
|
|
440
464
|
if (end < 0) break;
|
|
@@ -444,6 +468,7 @@ function scopeAt(s, stop) {
|
|
|
444
468
|
while (j < stop && /\s/.test(s[j])) j++;
|
|
445
469
|
if (s[j] === "{") {
|
|
446
470
|
frames.push(headerNames(kw, header));
|
|
471
|
+
if (kw === "snippet") snippets.push(frames.length - 1);
|
|
447
472
|
i = j + 1;
|
|
448
473
|
continue;
|
|
449
474
|
}
|
|
@@ -451,10 +476,14 @@ function scopeAt(s, stop) {
|
|
|
451
476
|
continue;
|
|
452
477
|
}
|
|
453
478
|
}
|
|
454
|
-
if (c === "}" && frames.length > 1)
|
|
479
|
+
if (c === "}" && frames.length > 1) {
|
|
480
|
+
if (snippets.at(-1) === frames.length - 1) snippets.pop();
|
|
481
|
+
frames.pop();
|
|
482
|
+
}
|
|
455
483
|
i++;
|
|
456
484
|
}
|
|
457
|
-
|
|
485
|
+
const from = snippets.at(-1);
|
|
486
|
+
return [...inputs, ...(from === void 0 ? frames : frames.slice(from)).flat()];
|
|
458
487
|
}
|
|
459
488
|
function exprContext(segment, s, offset) {
|
|
460
489
|
const pipe = /\|\s*([A-Za-z_$][\w$]*)?$/.exec(segment);
|
|
@@ -473,9 +502,33 @@ function cursorContext(s, offset) {
|
|
|
473
502
|
const before = s.slice(0, offset);
|
|
474
503
|
const open = before.lastIndexOf("{{");
|
|
475
504
|
if (open >= 0 && open > before.lastIndexOf("}}") && !before.startsWith("{{--", open)) return exprContext(before.slice(open + 2), s, offset);
|
|
476
|
-
const
|
|
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);
|
|
477
526
|
if (named) return {
|
|
478
|
-
kind:
|
|
527
|
+
kind: {
|
|
528
|
+
layout: "template-name",
|
|
529
|
+
slot: "slot-name",
|
|
530
|
+
push: "stack-name"
|
|
531
|
+
}[named[1]],
|
|
479
532
|
prefix: named[2]
|
|
480
533
|
};
|
|
481
534
|
const letExpr = /@let\s+[\w$]+\s*=\s*([^;\n]*)$/.exec(before);
|
|
@@ -529,6 +582,18 @@ function wordAt(s, offset) {
|
|
|
529
582
|
end
|
|
530
583
|
};
|
|
531
584
|
}
|
|
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
|
+
}
|
|
532
597
|
// src/plugin/completion.ts
|
|
533
598
|
const SNIPPET = 2;
|
|
534
599
|
const KEYWORD = 14;
|
|
@@ -558,12 +623,16 @@ const KEYWORDS = {
|
|
|
558
623
|
slot: "slot('${1:name}') {\n $0\n}",
|
|
559
624
|
error: "error('${1:field}') {\n $0\n}",
|
|
560
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}",
|
|
561
630
|
verbatim: "verbatim {\n $0\n}"
|
|
562
631
|
};
|
|
563
632
|
/** The template a component tag names, if any. */
|
|
564
633
|
function componentOf(ws, tag) {
|
|
565
634
|
const dir = ws.componentsDir();
|
|
566
|
-
return ws.names().find((n) =>
|
|
635
|
+
return ws.names().find((n) => ws.isComponent(n) && ws.view.componentTag(n, dir) === tag);
|
|
567
636
|
}
|
|
568
637
|
/** Slot names the layouts above `name` declare, nearest first. */
|
|
569
638
|
function layoutSlots(ws, name) {
|
|
@@ -578,7 +647,7 @@ function layoutSlots(ws, name) {
|
|
|
578
647
|
}
|
|
579
648
|
const base = ws.baseLayout();
|
|
580
649
|
const page = name === void 0 ? void 0 : ws.astOf(name);
|
|
581
|
-
if (base !== void 0 && name !== void 0 && page?.layout !== null && !
|
|
650
|
+
if (base !== void 0 && name !== void 0 && page?.layout !== null && !ws.isComponent(name) && name !== base && !seen.has(base)) chain.push(base);
|
|
582
651
|
for (const l of chain) {
|
|
583
652
|
const ast = ws.astOf(l);
|
|
584
653
|
if (!ast) continue;
|
|
@@ -590,10 +659,43 @@ function layoutSlots(ws, name) {
|
|
|
590
659
|
else if (n.k === "if") for (const b of n.branches) stack.push(b.body);
|
|
591
660
|
else if (n.k === "for") stack.push(n.body, n.empty ?? []);
|
|
592
661
|
else if (n.k === "switch") stack.push(...n.cases.map((c) => c.body), n.default ?? []);
|
|
593
|
-
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);
|
|
594
681
|
}
|
|
595
682
|
return [...out];
|
|
596
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
|
+
}
|
|
597
699
|
function completions(ws, uri, text, offset) {
|
|
598
700
|
const c = cursorContext(text, offset);
|
|
599
701
|
switch (c.kind) {
|
|
@@ -613,7 +715,7 @@ function completions(ws, uri, text, offset) {
|
|
|
613
715
|
}));
|
|
614
716
|
case "tag": {
|
|
615
717
|
const dir = ws.componentsDir();
|
|
616
|
-
return ws.names().filter((n) =>
|
|
718
|
+
return ws.names().filter((n) => ws.isComponent(n)).map((n) => {
|
|
617
719
|
const tag = ws.view.componentTag(n, dir);
|
|
618
720
|
const attrs = (ws.astOf(n)?.inputs ?? []).filter((i) => !i.default).map((i, k) => ` [${i.name}]="$${k + 1}"`).join("");
|
|
619
721
|
return {
|
|
@@ -649,17 +751,33 @@ function completions(ws, uri, text, offset) {
|
|
|
649
751
|
}
|
|
650
752
|
];
|
|
651
753
|
}
|
|
652
|
-
case "template-name": {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
kind: FILE$1
|
|
657
|
-
}));
|
|
658
|
-
}
|
|
754
|
+
case "template-name": return ws.names().filter((n) => !ws.isComponent(n)).map((label) => ({
|
|
755
|
+
label,
|
|
756
|
+
kind: FILE$1
|
|
757
|
+
}));
|
|
659
758
|
case "slot-name": return layoutSlots(ws, ws.nameOf(uri)).map((label) => ({
|
|
660
759
|
label,
|
|
661
760
|
kind: PROPERTY
|
|
662
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
|
+
}
|
|
663
781
|
case "expr": return [.../* @__PURE__ */ new Set([...c.scope, ...FORM_STATE])].map((label) => ({
|
|
664
782
|
label,
|
|
665
783
|
kind: VARIABLE
|
|
@@ -732,7 +850,7 @@ const TOP$1 = {
|
|
|
732
850
|
character: 0
|
|
733
851
|
}
|
|
734
852
|
};
|
|
735
|
-
function definition(ws,
|
|
853
|
+
function definition(ws, uri, text, offset) {
|
|
736
854
|
const { word, start, end } = wordAt(text, offset);
|
|
737
855
|
if (!word) return null;
|
|
738
856
|
const origin = {
|
|
@@ -750,7 +868,13 @@ function definition(ws, _uri, text, offset) {
|
|
|
750
868
|
const name = componentOf(ws, word.toLowerCase());
|
|
751
869
|
return name === void 0 ? null : link(ws.uriOf(name));
|
|
752
870
|
}
|
|
753
|
-
if (c.kind === "template-name")
|
|
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
|
+
}
|
|
754
878
|
if (c.kind === "pipe") {
|
|
755
879
|
const decl = ws.pipeDeclaration(word);
|
|
756
880
|
if (!decl) return null;
|
|
@@ -776,8 +900,7 @@ const CALLS = /\b(?:ctx|views)\.render\(\s*(['"`])([^'"`\n]*)\1/g;
|
|
|
776
900
|
const FILE = 17;
|
|
777
901
|
/** Template names a page can render: everything but components. */
|
|
778
902
|
function renderable(ws) {
|
|
779
|
-
|
|
780
|
-
return ws.names().filter((n) => !n.startsWith(dir));
|
|
903
|
+
return ws.names().filter((n) => !ws.isComponent(n));
|
|
781
904
|
}
|
|
782
905
|
function renderCompletions(ws, text, offset) {
|
|
783
906
|
const m = OPEN_CALL.exec(text.slice(0, offset));
|
|
@@ -1080,8 +1203,18 @@ const rangeOf = (text, offset, length) => ({
|
|
|
1080
1203
|
start: posOf(text, offset),
|
|
1081
1204
|
end: posOf(text, offset + length)
|
|
1082
1205
|
});
|
|
1083
|
-
/**
|
|
1084
|
-
|
|
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) {
|
|
1085
1218
|
const t = kickTokens(text, (tag) => componentOf(ws, tag) !== void 0).find((k) => offset >= k.offset && offset <= k.offset + k.length);
|
|
1086
1219
|
if (!t) return void 0;
|
|
1087
1220
|
const word = text.slice(t.offset, t.offset + t.length);
|
|
@@ -1104,14 +1237,15 @@ function targetAt(ws, text, offset) {
|
|
|
1104
1237
|
...t
|
|
1105
1238
|
};
|
|
1106
1239
|
if (t.type === "string" && /@layout\s*\(\s*$/.test(text.slice(0, t.offset))) {
|
|
1107
|
-
const
|
|
1240
|
+
const written = word.slice(1, -1);
|
|
1241
|
+
const name = ws.refOf(uri === void 0 ? void 0 : ws.nameOf(uri), written);
|
|
1108
1242
|
return ws.astOf(name) ? {
|
|
1109
1243
|
target: {
|
|
1110
1244
|
kind: "layout",
|
|
1111
1245
|
name
|
|
1112
1246
|
},
|
|
1113
1247
|
offset: t.offset + 1,
|
|
1114
|
-
length:
|
|
1248
|
+
length: written.length
|
|
1115
1249
|
} : void 0;
|
|
1116
1250
|
}
|
|
1117
1251
|
}
|
|
@@ -1123,9 +1257,11 @@ function usesOf(ws, target) {
|
|
|
1123
1257
|
if (text === void 0) continue;
|
|
1124
1258
|
const uri = ws.uriOf(name);
|
|
1125
1259
|
if (target.kind === "layout") {
|
|
1126
|
-
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({
|
|
1127
1261
|
uri,
|
|
1128
1262
|
text,
|
|
1263
|
+
from: name,
|
|
1264
|
+
written: m[2],
|
|
1129
1265
|
offset: m.index + m[0].length - m[2].length - 1,
|
|
1130
1266
|
length: m[2].length
|
|
1131
1267
|
});
|
|
@@ -1136,6 +1272,8 @@ function usesOf(ws, target) {
|
|
|
1136
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({
|
|
1137
1273
|
uri,
|
|
1138
1274
|
text,
|
|
1275
|
+
from: name,
|
|
1276
|
+
written: match,
|
|
1139
1277
|
...t
|
|
1140
1278
|
});
|
|
1141
1279
|
}
|
|
@@ -1160,8 +1298,8 @@ function pipeDeclaration(ws, name) {
|
|
|
1160
1298
|
}
|
|
1161
1299
|
};
|
|
1162
1300
|
}
|
|
1163
|
-
function references(ws, text, offset, includeDeclaration) {
|
|
1164
|
-
const at = targetAt(ws, text, offset);
|
|
1301
|
+
function references(ws, text, offset, includeDeclaration, uri) {
|
|
1302
|
+
const at = targetAt(ws, text, offset, uri);
|
|
1165
1303
|
if (!at) return [];
|
|
1166
1304
|
const { target } = at;
|
|
1167
1305
|
const locations = usesOf(ws, target).map((u) => ({
|
|
@@ -1180,8 +1318,8 @@ function references(ws, text, offset, includeDeclaration) {
|
|
|
1180
1318
|
return locations;
|
|
1181
1319
|
}
|
|
1182
1320
|
/** What F2 renames here: a pipe, a component tag or a layout name. */
|
|
1183
|
-
function renameRange(ws, text, offset) {
|
|
1184
|
-
const at = targetAt(ws, text, offset);
|
|
1321
|
+
function renameRange(ws, text, offset, uri) {
|
|
1322
|
+
const at = targetAt(ws, text, offset, uri);
|
|
1185
1323
|
if (!at) return void 0;
|
|
1186
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.` };
|
|
1187
1325
|
return rangeOf(text, at.offset, at.length);
|
|
@@ -1191,9 +1329,13 @@ const TAG = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$/;
|
|
|
1191
1329
|
function componentNameFor(ws, oldName, tag) {
|
|
1192
1330
|
if (!TAG.test(tag)) return void 0;
|
|
1193
1331
|
const dir = ws.componentsDir();
|
|
1194
|
-
const
|
|
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);
|
|
1195
1336
|
const prefix = folders.join("-");
|
|
1196
|
-
const
|
|
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}`;
|
|
1197
1339
|
return ws.view.componentTag(name, dir) === tag ? name : void 0;
|
|
1198
1340
|
}
|
|
1199
1341
|
/** Every use of `target` replaced with `newText`, then the template's file renamed. */
|
|
@@ -1205,7 +1347,7 @@ function renameTemplate(ws, target, newText, newName) {
|
|
|
1205
1347
|
const edits = byUri.get(u.uri) ?? [];
|
|
1206
1348
|
edits.push({
|
|
1207
1349
|
range: rangeOf(u.text, u.offset, u.length),
|
|
1208
|
-
newText
|
|
1350
|
+
newText: typeof newText === "string" ? newText : newText(u)
|
|
1209
1351
|
});
|
|
1210
1352
|
byUri.set(u.uri, edits);
|
|
1211
1353
|
}
|
|
@@ -1222,15 +1364,19 @@ function renameTemplate(ws, target, newText, newName) {
|
|
|
1222
1364
|
}] };
|
|
1223
1365
|
}
|
|
1224
1366
|
/** A pipe renamed in every template and in `pipes.ts`; a component or layout, file included. */
|
|
1225
|
-
function renameEdits(ws, text, offset, newName) {
|
|
1226
|
-
const at = targetAt(ws, text, offset);
|
|
1367
|
+
function renameEdits(ws, text, offset, newName, uri) {
|
|
1368
|
+
const at = targetAt(ws, text, offset, uri);
|
|
1227
1369
|
if (!at) return void 0;
|
|
1228
1370
|
const { target } = at;
|
|
1229
1371
|
if (target.kind === "component") {
|
|
1230
1372
|
const name = componentNameFor(ws, target.name, newName);
|
|
1231
1373
|
return name === void 0 ? void 0 : renameTemplate(ws, target, newName, name);
|
|
1232
1374
|
}
|
|
1233
|
-
if (target.kind === "layout")
|
|
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
|
+
}
|
|
1234
1380
|
if (!IDENT.test(newName) || ws.project().pipes.has(newName)) return void 0;
|
|
1235
1381
|
const decl = pipeDeclaration(ws, target.name);
|
|
1236
1382
|
if (!decl) return void 0;
|
|
@@ -1259,8 +1405,8 @@ async function fileRenameEdits(ws, oldUri, newUri) {
|
|
|
1259
1405
|
const changes = {};
|
|
1260
1406
|
const dir = ws.componentsDir();
|
|
1261
1407
|
for (const [oldName, newName] of renamed) {
|
|
1262
|
-
const comp =
|
|
1263
|
-
const newTag =
|
|
1408
|
+
const comp = ws.isComponent(oldName);
|
|
1409
|
+
const newTag = ws.isComponent(newName) ? ws.view.componentTag(newName, dir) : void 0;
|
|
1264
1410
|
const targets = [[{
|
|
1265
1411
|
kind: "layout",
|
|
1266
1412
|
name: oldName
|
|
@@ -1272,10 +1418,10 @@ async function fileRenameEdits(ws, oldUri, newUri) {
|
|
|
1272
1418
|
}, newTag]);
|
|
1273
1419
|
for (const [target, newText] of targets) for (const u of usesOf(ws, target)) (changes[u.uri] ??= []).push({
|
|
1274
1420
|
range: rangeOf(u.text, u.offset, u.length),
|
|
1275
|
-
newText
|
|
1421
|
+
newText: target.kind === "layout" ? layoutText(ws, u, newText) : newText
|
|
1276
1422
|
});
|
|
1277
1423
|
}
|
|
1278
|
-
const pages = [...renamed].filter(([n]) => !
|
|
1424
|
+
const pages = [...renamed].filter(([n]) => !ws.isComponent(n));
|
|
1279
1425
|
if (pages.length) {
|
|
1280
1426
|
const to = new Map(pages);
|
|
1281
1427
|
for (const script of await ws.scripts()) for (const c of calls(script.text)) {
|
|
@@ -1289,6 +1435,7 @@ async function fileRenameEdits(ws, oldUri, newUri) {
|
|
|
1289
1435
|
return Object.keys(changes).length ? { changes } : void 0;
|
|
1290
1436
|
}
|
|
1291
1437
|
// src/plugin/index.ts
|
|
1438
|
+
/** The Volar service plugin for `.kick` documents: diagnostics, completion, hover, definitions, references, rename, formatting and semantic tokens. */
|
|
1292
1439
|
function createKickServicePlugin(ws) {
|
|
1293
1440
|
const diagnostics = createDiagnosticsPlugin(ws);
|
|
1294
1441
|
return {
|
|
@@ -1359,15 +1506,15 @@ function createKickServicePlugin(ws) {
|
|
|
1359
1506
|
},
|
|
1360
1507
|
provideReferences(document, position, context) {
|
|
1361
1508
|
const d = open(document);
|
|
1362
|
-
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;
|
|
1363
1510
|
},
|
|
1364
1511
|
provideRenameRange(document, position) {
|
|
1365
1512
|
const d = open(document);
|
|
1366
|
-
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;
|
|
1367
1514
|
},
|
|
1368
1515
|
provideRenameEdits(document, position, newName) {
|
|
1369
1516
|
const d = open(document);
|
|
1370
|
-
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;
|
|
1371
1518
|
},
|
|
1372
1519
|
provideFileRenameEdits(oldUri, newUri) {
|
|
1373
1520
|
return fileRenameEdits(ws, oldUri.toString(), newUri.toString());
|
|
@@ -1481,6 +1628,10 @@ function findProjectView(root) {
|
|
|
1481
1628
|
};
|
|
1482
1629
|
}
|
|
1483
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
|
+
*/
|
|
1484
1635
|
async function loadViewModule(root, warn, trusted) {
|
|
1485
1636
|
if (!trusted) return {
|
|
1486
1637
|
view: bundled,
|
|
@@ -1514,6 +1665,43 @@ async function loadViewModule(root, warn, trusted) {
|
|
|
1514
1665
|
version: BUNDLED_VERSION
|
|
1515
1666
|
};
|
|
1516
1667
|
}
|
|
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
|
+
}
|
|
1517
1705
|
// src/pipes.ts
|
|
1518
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;
|
|
1519
1707
|
function pipeDeclarations(source) {
|
|
@@ -1549,6 +1737,18 @@ const toRange = (span) => ({
|
|
|
1549
1737
|
* runtime uses, cached per template and invalidated along the graph of
|
|
1550
1738
|
* which template uses which component or layout.
|
|
1551
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
|
+
*/
|
|
1552
1752
|
var Workspace = class {
|
|
1553
1753
|
opts;
|
|
1554
1754
|
entries = /* @__PURE__ */ new Map();
|
|
@@ -1565,32 +1765,72 @@ var Workspace = class {
|
|
|
1565
1765
|
async load() {
|
|
1566
1766
|
await this.loadPipes();
|
|
1567
1767
|
await this.loadValidators();
|
|
1568
|
-
for (const path of await this.opts.list(
|
|
1768
|
+
for (const { dir } of this.folders()) for (const path of await this.opts.list(dir)) {
|
|
1569
1769
|
const name = this.nameOfPath(path);
|
|
1570
1770
|
if (name) this.update(name, { disk: await this.opts.read(path) });
|
|
1571
1771
|
}
|
|
1572
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
|
+
}
|
|
1573
1795
|
nameOfPath(path) {
|
|
1574
|
-
const
|
|
1575
|
-
|
|
1576
|
-
|
|
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
|
+
}
|
|
1577
1802
|
}
|
|
1578
|
-
|
|
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
|
+
*/
|
|
1579
1814
|
relOf(uri) {
|
|
1580
|
-
const
|
|
1581
|
-
|
|
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
|
+
}
|
|
1582
1821
|
}
|
|
1583
1822
|
nameOf(uri) {
|
|
1584
1823
|
return this.nameOfPath(URI.parse(uri).fsPath);
|
|
1585
1824
|
}
|
|
1586
1825
|
uriOf(name) {
|
|
1587
|
-
return URI.file(
|
|
1826
|
+
return URI.file(this.pathOf(name)).toString();
|
|
1588
1827
|
}
|
|
1589
1828
|
componentsDir() {
|
|
1590
1829
|
return this.opts.componentsDir;
|
|
1591
1830
|
}
|
|
1592
1831
|
pathOf(name) {
|
|
1593
|
-
|
|
1832
|
+
const { dir, path } = this.dirOf(name);
|
|
1833
|
+
return `${dir}/${path}.kick`;
|
|
1594
1834
|
}
|
|
1595
1835
|
names() {
|
|
1596
1836
|
return [...this.entries.keys()];
|
|
@@ -1678,12 +1918,16 @@ var Workspace = class {
|
|
|
1678
1918
|
const stack = [parsed.ast.body];
|
|
1679
1919
|
while (stack.length) for (const n of stack.pop()) if (n.k === "element") {
|
|
1680
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
|
+
}
|
|
1681
1925
|
stack.push(n.children);
|
|
1682
1926
|
} else if (n.k === "if") for (const b of n.branches) stack.push(b.body);
|
|
1683
1927
|
else if (n.k === "for") stack.push(n.body, n.empty ?? []);
|
|
1684
1928
|
else if (n.k === "switch") stack.push(...n.cases.map((c) => c.body), n.default ?? []);
|
|
1685
1929
|
else if (n.k === "slot-outlet") stack.push(n.fallback);
|
|
1686
|
-
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);
|
|
1687
1931
|
const isNew = !this.entries.has(name);
|
|
1688
1932
|
this.entries.set(name, {
|
|
1689
1933
|
...src,
|
|
@@ -1695,8 +1939,10 @@ var Workspace = class {
|
|
|
1695
1939
|
this.invalidate(name, isNew);
|
|
1696
1940
|
}
|
|
1697
1941
|
remove(name) {
|
|
1942
|
+
const users = this.dependentsOf(name);
|
|
1698
1943
|
this.entries.delete(name);
|
|
1699
1944
|
this.invalidate(name, true);
|
|
1945
|
+
for (const u of users) this.invalidate(u, false);
|
|
1700
1946
|
}
|
|
1701
1947
|
/** Drop cached diagnostics for `name` and every template that uses it, transitively. */
|
|
1702
1948
|
invalidate(name, membershipChanged) {
|
|
@@ -1709,7 +1955,7 @@ var Workspace = class {
|
|
|
1709
1955
|
this.cache.delete(n);
|
|
1710
1956
|
for (const d of this.dependentsOf(n)) todo.push(d);
|
|
1711
1957
|
}
|
|
1712
|
-
if (membershipChanged &&
|
|
1958
|
+
if (membershipChanged && this.isComponent(name)) {
|
|
1713
1959
|
const tag = this.opts.view.componentTag(name, this.opts.componentsDir);
|
|
1714
1960
|
for (const [n, e] of this.entries) if (e.tags.has(tag)) this.cache.delete(n);
|
|
1715
1961
|
}
|
|
@@ -1718,10 +1964,11 @@ var Workspace = class {
|
|
|
1718
1964
|
dependentsOf(name) {
|
|
1719
1965
|
if (this.configuredLayouts().has(name)) return new Set(this.names().filter((n) => n !== name));
|
|
1720
1966
|
const out = /* @__PURE__ */ new Set();
|
|
1721
|
-
const tag =
|
|
1967
|
+
const tag = this.isComponent(name) ? this.opts.view.componentTag(name, this.opts.componentsDir) : void 0;
|
|
1722
1968
|
for (const [n, e] of this.entries) {
|
|
1723
1969
|
if (n === name) continue;
|
|
1724
|
-
|
|
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);
|
|
1725
1972
|
}
|
|
1726
1973
|
return out;
|
|
1727
1974
|
}
|
|
@@ -1769,9 +2016,9 @@ var Workspace = class {
|
|
|
1769
2016
|
layoutOf(name) {
|
|
1770
2017
|
const ast = this.astOf(name);
|
|
1771
2018
|
if (!ast) return void 0;
|
|
1772
|
-
if (ast.layout !== void 0) return ast.layout
|
|
2019
|
+
if (ast.layout !== void 0) return ast.layout ? this.refOf(name, ast.layout) : void 0;
|
|
1773
2020
|
const { layout } = this.opts;
|
|
1774
|
-
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;
|
|
1775
2022
|
if (typeof layout === "string") return layout;
|
|
1776
2023
|
const hit = Object.keys(layout).toSorted((a, b) => b.length - a.length).find((p) => p === "" || name === p || name.startsWith(`${p}/`));
|
|
1777
2024
|
return hit === void 0 ? void 0 : layout[hit];
|
|
@@ -1859,6 +2106,12 @@ function watchPatterns(root, pipesFile, validatorsFile) {
|
|
|
1859
2106
|
if (validatorsFile && !/^validators\.(ts|js)$/.test(basename(validatorsFile))) patterns.push(relative(root, validatorsFile).split(sep).join("/"));
|
|
1860
2107
|
return patterns;
|
|
1861
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
|
+
*/
|
|
1862
2115
|
function startServer() {
|
|
1863
2116
|
const connection = createConnection();
|
|
1864
2117
|
const server = createServer(connection);
|
|
@@ -1870,7 +2123,9 @@ function startServer() {
|
|
|
1870
2123
|
const root = folder ? URI.parse(folder).fsPath : process.cwd();
|
|
1871
2124
|
const opts = params.initializationOptions ?? {};
|
|
1872
2125
|
const at = (p) => isAbsolute(p) ? p : resolve(root, p);
|
|
1873
|
-
const
|
|
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");
|
|
1874
2129
|
const hasViews = existsSync(viewsDir);
|
|
1875
2130
|
const { view } = await loadViewModule(root, (m) => hasViews && connection.console.warn(m), opts.trusted === true);
|
|
1876
2131
|
const pipesFile = at(opts.pipesFile ?? join(viewsDir, "pipes.ts"));
|
|
@@ -1887,6 +2142,7 @@ function startServer() {
|
|
|
1887
2142
|
list: listKick,
|
|
1888
2143
|
layout: opts.layout || void 0,
|
|
1889
2144
|
baseLayout: opts.baseLayout || void 0,
|
|
2145
|
+
roots: setup.roots,
|
|
1890
2146
|
scripts: async () => mapLimit(await listScripts(root), 64, async (p) => {
|
|
1891
2147
|
const uri = URI.file(p).toString();
|
|
1892
2148
|
return {
|
|
@@ -1926,8 +2182,8 @@ function startServer() {
|
|
|
1926
2182
|
});
|
|
1927
2183
|
connection.onRequest("kick/templateNames", () => {
|
|
1928
2184
|
if (!ws) return [];
|
|
1929
|
-
const
|
|
1930
|
-
return
|
|
2185
|
+
const w = ws;
|
|
2186
|
+
return w.names().filter((n) => !w.isComponent(n));
|
|
1931
2187
|
});
|
|
1932
2188
|
connection.onRequest("kick/renderDefinition", ({ text, offset }) => {
|
|
1933
2189
|
const link = ws && renderDefinition(ws, text, offset);
|
|
@@ -1941,4 +2197,4 @@ function startServer() {
|
|
|
1941
2197
|
}
|
|
1942
2198
|
export { KickVirtualCode as a, createKickServicePlugin as i, Workspace as n, kickLanguagePlugin as o, loadViewModule as r, startServer as t };
|
|
1943
2199
|
|
|
1944
|
-
//# sourceMappingURL=server-
|
|
2200
|
+
//# sourceMappingURL=server-g7Phx27h.js.map
|