@telorun/ide-support 0.15.0 → 0.16.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 (69) hide show
  1. package/dist/cel/cursor-chain.d.ts +30 -0
  2. package/dist/cel/cursor-chain.d.ts.map +1 -0
  3. package/dist/cel/cursor-chain.js +30 -0
  4. package/dist/cel/symbols.d.ts +82 -0
  5. package/dist/cel/symbols.d.ts.map +1 -0
  6. package/dist/cel/symbols.js +147 -0
  7. package/dist/cel/tokens.d.ts +32 -0
  8. package/dist/cel/tokens.d.ts.map +1 -0
  9. package/dist/cel/tokens.js +162 -0
  10. package/dist/completions/build.d.ts +6 -2
  11. package/dist/completions/build.d.ts.map +1 -1
  12. package/dist/completions/build.js +52 -24
  13. package/dist/completions/call-inputs.d.ts +25 -0
  14. package/dist/completions/call-inputs.d.ts.map +1 -0
  15. package/dist/completions/call-inputs.js +78 -0
  16. package/dist/completions/cel-completions.d.ts +26 -0
  17. package/dist/completions/cel-completions.d.ts.map +1 -0
  18. package/dist/completions/cel-completions.js +78 -0
  19. package/dist/completions/detect-context.d.ts +47 -8
  20. package/dist/completions/detect-context.d.ts.map +1 -1
  21. package/dist/completions/detect-context.js +51 -15
  22. package/dist/completions/prop-keys.d.ts +5 -1
  23. package/dist/completions/prop-keys.d.ts.map +1 -1
  24. package/dist/completions/prop-keys.js +51 -3
  25. package/dist/completions/resolve-node.d.ts +9 -2
  26. package/dist/completions/resolve-node.d.ts.map +1 -1
  27. package/dist/completions/resolve-node.js +63 -21
  28. package/dist/definition/build-definition.d.ts +6 -2
  29. package/dist/definition/build-definition.d.ts.map +1 -1
  30. package/dist/definition/build-definition.js +16 -3
  31. package/dist/definition/locate-context-binding.d.ts +15 -0
  32. package/dist/definition/locate-context-binding.d.ts.map +1 -0
  33. package/dist/definition/locate-context-binding.js +35 -0
  34. package/dist/definition/locate-step.d.ts +13 -0
  35. package/dist/definition/locate-step.d.ts.map +1 -0
  36. package/dist/definition/locate-step.js +33 -0
  37. package/dist/definition/resolve-cel-target.d.ts +11 -1
  38. package/dist/definition/resolve-cel-target.d.ts.map +1 -1
  39. package/dist/definition/resolve-cel-target.js +14 -14
  40. package/dist/doc-identity.d.ts +17 -0
  41. package/dist/doc-identity.d.ts.map +1 -0
  42. package/dist/doc-identity.js +19 -0
  43. package/dist/hover/build-hover.d.ts +6 -2
  44. package/dist/hover/build-hover.d.ts.map +1 -1
  45. package/dist/hover/build-hover.js +64 -3
  46. package/dist/semantic-tokens/build-semantic-tokens.d.ts +13 -8
  47. package/dist/semantic-tokens/build-semantic-tokens.d.ts.map +1 -1
  48. package/dist/semantic-tokens/build-semantic-tokens.js +81 -37
  49. package/dist/types.d.ts +25 -5
  50. package/dist/types.d.ts.map +1 -1
  51. package/dist/types.js +16 -2
  52. package/package.json +2 -2
  53. package/src/cel/cursor-chain.ts +58 -0
  54. package/src/cel/symbols.ts +189 -0
  55. package/src/cel/tokens.ts +169 -0
  56. package/src/completions/build.ts +85 -22
  57. package/src/completions/call-inputs.ts +92 -0
  58. package/src/completions/cel-completions.ts +108 -0
  59. package/src/completions/detect-context.ts +107 -13
  60. package/src/completions/prop-keys.ts +59 -2
  61. package/src/completions/resolve-node.ts +82 -17
  62. package/src/definition/build-definition.ts +30 -2
  63. package/src/definition/locate-context-binding.ts +53 -0
  64. package/src/definition/locate-step.ts +50 -0
  65. package/src/definition/resolve-cel-target.ts +25 -0
  66. package/src/doc-identity.ts +31 -0
  67. package/src/hover/build-hover.ts +67 -1
  68. package/src/semantic-tokens/build-semantic-tokens.ts +84 -30
  69. package/src/types.ts +47 -6
@@ -5,60 +5,114 @@ import {
5
5
  type AnalysisRegistry,
6
6
  type AstDocument,
7
7
  type AstNode,
8
+ type AstScalar,
9
+ type CelScope,
10
+ type ManifestAnalysis,
8
11
  } from "@telorun/analyzer";
9
12
  import type { SemanticToken } from "../types.js";
13
+ import { celSegmentTokens } from "../cel/tokens.js";
14
+ import { docIdentity } from "../doc-identity.js";
10
15
  import { scalarString } from "../completions/resolve-node.js";
11
16
  import { CAPABILITY_VALUES } from "../completions/valid-capabilities.js";
12
17
 
13
18
  const CAPABILITIES = new Set<string>(CAPABILITY_VALUES);
14
19
 
20
+ /** Append one key segment to a concrete path (`routes[0]` + `handler`). */
21
+ function joinKey(concrete: string, key: string): string {
22
+ return concrete ? `${concrete}.${key}` : key;
23
+ }
24
+
15
25
  /** Registry-aware semantic tokens: a `kind:` value that resolves to a known
16
26
  * definition is a `type`; a `capability:` value is an `interface`; a `!ref`
17
- * target is a `variable`. Everything else (structure, CEL, tags) is left to the
18
- * TextMate grammar. Ref targets are colored here rather than in the grammar
19
- * because a `!ref` after a `key:` is tokenized by the bundled YAML grammar
20
- * before a Telo pattern can claim it the AST sees it unambiguously. An
21
- * unresolved kind gets no token, so a typo stays uncolored — a quiet signal
22
- * that pairs with the analyzer's `UNDEFINED_KIND` diagnostic. */
27
+ * target is a `variable`. Ref targets are colored here rather than in the
28
+ * grammar because a `!ref` after a `key:` is tokenized by the bundled YAML
29
+ * grammar before a Telo pattern can claim it the AST sees it unambiguously.
30
+ * An unresolved kind gets no token, so a typo stays uncolored a quiet signal
31
+ * that pairs with the analyzer's `UNDEFINED_KIND` diagnostic.
32
+ *
33
+ * The inside of a `!cel` / `${{ }}` body is colored here too, and for the same
34
+ * reason one level down: a grammar can only know the roots someone hardcoded
35
+ * into it, while `scopeQuery` knows what is in scope at this exact site. With
36
+ * no query the names are colored syntactically instead — a CEL body must never
37
+ * read as a plain string, which is what the stock YAML grammar makes of it. */
23
38
  export function buildSemanticTokens(
24
39
  text: string,
25
40
  registry: AnalysisRegistry | undefined,
26
41
  docs?: AstDocument[],
42
+ analysis?: ManifestAnalysis,
27
43
  ): SemanticToken[] {
28
44
  const astDocs = docs ?? parseToAst(text);
29
45
  const lineOffsets = buildLineOffsets(text);
30
46
 
31
47
  const tokens: SemanticToken[] = [];
32
- const emit = (node: AstNode | undefined, type: SemanticToken["type"]): void => {
33
- if (!node) return;
34
- const start = offsetToPosition(node.range[0], lineOffsets);
35
- const end = offsetToPosition(node.range[1], lineOffsets);
36
- // Kind / capability values never span lines; a clamped single-line token.
48
+ const emitRange = (range: [number, number], type: SemanticToken["type"]): void => {
49
+ const start = offsetToPosition(range[0], lineOffsets);
50
+ const end = offsetToPosition(range[1], lineOffsets);
51
+ // Kind / capability values and CEL identifiers never span lines; a clamped
52
+ // single-line token.
37
53
  if (start.line !== end.line) return;
38
- tokens.push({ line: start.line, character: start.character, length: end.character - start.character, type });
54
+ tokens.push({
55
+ line: start.line,
56
+ character: start.character,
57
+ length: end.character - start.character,
58
+ type,
59
+ });
60
+ };
61
+ const emit = (node: AstNode | undefined, type: SemanticToken["type"]): void => {
62
+ if (node) emitRange(node.range, type);
39
63
  };
40
64
 
41
- const walk = (node: AstNode): void => {
42
- if (node.kind === "map") {
43
- for (const pair of node.entries) {
44
- const key = scalarString(pair.key);
45
- const value = scalarString(pair.value);
46
- if (key === "kind" && value && registry?.resolveDefinition(value)) {
47
- emit(pair.value, "type");
48
- } else if (key === "capability" && value && CAPABILITIES.has(value)) {
49
- emit(pair.value, "interface");
65
+ for (const doc of astDocs) {
66
+ if (!doc.root) continue;
67
+
68
+ // The scope is resolved per SITE. `scopeAt` caches per (resource, path) for
69
+ // the analysis's lifetime, which is what keeps a whole-file colourizer off
70
+ // the per-keystroke cost of rebuilding a context-matched environment.
71
+ const identity = docIdentity(doc);
72
+ const scopeQuery = analysis?.celScope;
73
+ const resource = scopeQuery?.resourceFor(identity.kind, identity.name);
74
+ const scopeAt = (path: string): CelScope | undefined =>
75
+ scopeQuery && resource ? scopeQuery.scopeAt(resource, path) : undefined;
76
+
77
+ const celTokens = (node: AstScalar, path: string): void => {
78
+ const segments = node.celSegments();
79
+ if (segments.length === 0) return;
80
+ const scope = scopeAt(path);
81
+ for (const segment of segments) {
82
+ for (const span of celSegmentTokens(text, segment, scope)) emitRange(span.range, span.type);
83
+ }
84
+ };
85
+
86
+ const walk = (node: AstNode, concrete: string): void => {
87
+ if (node.kind === "map") {
88
+ for (const pair of node.entries) {
89
+ const key = scalarString(pair.key);
90
+ const value = scalarString(pair.value);
91
+ if (key === "kind" && value && registry?.resolveDefinition(value)) {
92
+ emit(pair.value, "type");
93
+ } else if (key === "capability" && value && CAPABILITIES.has(value)) {
94
+ emit(pair.value, "interface");
95
+ }
96
+ if (pair.value) walk(pair.value, key != null ? joinKey(concrete, key) : concrete);
50
97
  }
51
- if (pair.value) walk(pair.value);
98
+ return;
52
99
  }
53
- } else if (node.kind === "seq") {
54
- for (const item of node.items) walk(item);
55
- } else if (node.kind === "scalar" && node.tag === "!ref") {
56
- emit(node, "variable");
57
- }
58
- };
100
+ if (node.kind === "seq") {
101
+ // Indices are kept: a CEL site's scope is addressed per item, so an
102
+ // index-erased path resolves the wrong context or none.
103
+ node.items.forEach((item, index) => walk(item, `${concrete}[${index}]`));
104
+ return;
105
+ }
106
+ if (node.kind === "scalar") {
107
+ if (node.tag === "!ref") {
108
+ emit(node, "variable");
109
+ return;
110
+ }
111
+ celTokens(node, concrete);
112
+ }
113
+ };
59
114
 
60
- for (const doc of astDocs) {
61
- if (doc.root) walk(doc.root);
115
+ walk(doc.root, "");
62
116
  }
63
117
  return tokens;
64
118
  }
package/src/types.ts CHANGED
@@ -54,14 +54,55 @@ export interface HoverResult {
54
54
 
55
55
  /** Semantic token type names emitted by `buildSemanticTokens`. Kept to the
56
56
  * standard VS Code / LSP set so hosts register them against a stock legend and
57
- * every theme colors them without extra configuration. `type` marks a resolved
58
- * resource kind; `interface` marks a capability value; `variable` marks a
59
- * `!ref` target. */
60
- export type SemanticTokenType = "type" | "interface" | "variable";
57
+ * every theme colors them without extra configuration.
58
+ *
59
+ * Manifest structure: `type` marks a resolved resource kind; `interface` marks
60
+ * a capability value; `variable` marks a `!ref` target.
61
+ *
62
+ * Inside a CEL body: `namespace` marks the ROOT of a chain, `property` a member
63
+ * it can resolve, `function` a call, and `number` / `string` / `keyword` /
64
+ * `operator` the syntax around them. A CEL name the scope CANNOT confirm gets
65
+ * no token — the same quiet signal an unresolved `kind:` gives, pairing with
66
+ * the analyzer's `CEL_UNKNOWN_FIELD`.
67
+ *
68
+ * The root is a `namespace` rather than a `variable` because colour encodes
69
+ * what a symbol IS, which is the invariant every language holds to — and a CEL
70
+ * root is not data the author declared, it is a scope the runtime injects
71
+ * (`request`, `steps`, `variables`, `self`). Members are uniformly `property`
72
+ * however deep, so a chain reads as scope · path. Colouring by the SHAPE of the
73
+ * value behind a name — object vs scalar — was considered and rejected: it is
74
+ * type-directed highlighting, so the palette becomes a type legend, a name
75
+ * changes colour as analysis resolves, and it says nothing exactly where the
76
+ * scope declares no shape. */
77
+ export type SemanticTokenType =
78
+ | "type"
79
+ | "interface"
80
+ | "variable"
81
+ | "property"
82
+ | "function"
83
+ | "number"
84
+ | "string"
85
+ | "keyword"
86
+ | "operator"
87
+ | "namespace";
61
88
 
62
89
  /** The legend a host registers before mapping `buildSemanticTokens` output. The
63
- * numeric token-type of each `SemanticToken` is its index in this array. */
64
- export const SEMANTIC_TOKEN_LEGEND: readonly SemanticTokenType[] = ["type", "interface", "variable"];
90
+ * numeric token-type of each `SemanticToken` is its index in this array, and a
91
+ * host registers it once at activation — so new types are APPENDED, never
92
+ * inserted, or an already-registered legend would repaint every existing
93
+ * token as something else. */
94
+ export const SEMANTIC_TOKEN_LEGEND: readonly SemanticTokenType[] = [
95
+ "type",
96
+ "interface",
97
+ "variable",
98
+ "property",
99
+ "function",
100
+ "number",
101
+ "string",
102
+ "keyword",
103
+ "operator",
104
+ "namespace",
105
+ ];
65
106
 
66
107
  /** One absolute-positioned semantic token. Every Telo semantic token is
67
108
  * single-line (kinds and capabilities never wrap), so a `{line, char, length}`